5
5
import lombok .RequiredArgsConstructor ;
6
6
import lombok .extern .slf4j .Slf4j ;
7
7
import org .apache .commons .lang3 .StringUtils ;
8
+ import org .apache .commons .lang3 .tuple .Pair ;
8
9
import org .lowcoder .api .application .view .ApplicationInfoView ;
9
10
import org .lowcoder .api .application .view .ApplicationView ;
10
11
import org .lowcoder .api .home .SessionUserService ;
11
12
import org .lowcoder .api .usermanagement .view .AddMemberRequest ;
12
13
import org .lowcoder .api .usermanagement .view .UpdateRoleRequest ;
14
+ import org .lowcoder .domain .application .service .ApplicationRecordServiceImpl ;
13
15
import org .lowcoder .domain .application .service .ApplicationService ;
14
16
import org .lowcoder .domain .datasource .model .Datasource ;
15
17
import org .lowcoder .domain .datasource .service .DatasourceService ;
40
42
import org .lowcoder .infra .event .groupmember .GroupMemberRoleUpdateEvent ;
41
43
import org .lowcoder .infra .event .user .UserLoginEvent ;
42
44
import org .lowcoder .infra .event .user .UserLogoutEvent ;
45
+ import org .lowcoder .infra .util .TupleUtils ;
43
46
import org .lowcoder .plugin .api .event .LowcoderEvent .EventType ;
44
47
import org .lowcoder .sdk .constants .Authentication ;
45
48
import org .lowcoder .sdk .util .LocaleUtils ;
@@ -65,6 +68,7 @@ public class BusinessEventPublisher {
65
68
private final ApplicationService applicationService ;
66
69
private final DatasourceService datasourceService ;
67
70
private final ResourcePermissionService resourcePermissionService ;
71
+ private final ApplicationRecordServiceImpl applicationRecordServiceImpl ;
68
72
69
73
public Mono <Void > publishFolderCommonEvent (String folderId , String folderName , EventType eventType ) {
70
74
@@ -93,13 +97,14 @@ public Mono<Void> publishFolderCommonEvent(String folderId, String folderName, E
93
97
});
94
98
}
95
99
96
- public Mono <Void > publishApplicationCommonEvent (String applicationId , @ Nullable String folderId , EventType eventType ) {
100
+ public Mono <Void > publishApplicationCommonEvent (String applicationId , @ Nullable String folderIdFrom , @ Nullable String folderId , EventType eventType ) {
97
101
return applicationService .findByIdWithoutDsl (applicationId )
98
102
.map (application -> {
99
103
ApplicationInfoView applicationInfoView = ApplicationInfoView .builder ()
100
104
.applicationId (applicationId )
101
105
.name (application .getName ())
102
106
.folderId (folderId )
107
+ .folderIdFrom (folderIdFrom )
103
108
.build ();
104
109
return ApplicationView .builder ()
105
110
.applicationInfoView (applicationInfoView )
@@ -125,21 +130,48 @@ public Mono<Void> publishApplicationCommonEvent(ApplicationView applicationView,
125
130
.map (Optional ::of )
126
131
.onErrorReturn (Optional .empty ());
127
132
}))
133
+ .zipWith (Mono .defer (() -> {
134
+ String folderId = applicationView .getApplicationInfoView ().getFolderIdFrom ();
135
+ if (StringUtils .isBlank (folderId )) {
136
+ return Mono .just (Optional .<Folder > empty ());
137
+ }
138
+ return folderService .findById (folderId )
139
+ .map (Optional ::of )
140
+ .onErrorReturn (Optional .empty ());
141
+ }), TupleUtils ::merge )
128
142
.zipWith (sessionUserService .getVisitorToken ())
143
+ .zipWith (Mono .defer (() -> {
144
+ String appId = applicationView .getApplicationInfoView ().getApplicationId ();
145
+ return applicationService .findById (appId )
146
+ .zipWhen (application -> application .getCategory (applicationRecordServiceImpl ))
147
+ .zipWhen (application -> application .getT1 ().getDescription (applicationRecordServiceImpl ))
148
+ .map (tuple -> {
149
+ String category = tuple .getT1 ().getT2 ();
150
+ String description = tuple .getT2 ();
151
+ return Pair .of (category , description );
152
+ });
153
+ }), TupleUtils ::merge )
129
154
.doOnNext (tuple -> {
130
155
OrgMember orgMember = tuple .getT1 ().getT1 ();
131
156
Optional <Folder > optional = tuple .getT1 ().getT2 ();
157
+ Optional <Folder > optionalFrom = tuple .getT1 ().getT3 ();
132
158
String token = tuple .getT2 ();
159
+ String category = tuple .getT3 ().getLeft ();
160
+ String description = tuple .getT3 ().getRight ();
133
161
ApplicationInfoView applicationInfoView = applicationView .getApplicationInfoView ();
134
162
ApplicationCommonEvent event = ApplicationCommonEvent .builder ()
135
163
.orgId (orgMember .getOrgId ())
136
164
.userId (orgMember .getUserId ())
137
165
.applicationId (applicationInfoView .getApplicationId ())
138
166
.applicationGid (applicationInfoView .getApplicationGid ())
139
167
.applicationName (applicationInfoView .getName ())
168
+ .applicationCategory (category )
169
+ .applicationDescription (description )
140
170
.type (eventType )
141
171
.folderId (optional .map (Folder ::getId ).orElse (null ))
142
172
.folderName (optional .map (Folder ::getName ).orElse (null ))
173
+ .oldFolderId (optionalFrom .map (Folder ::getId ).orElse (null ))
174
+ .oldFolderName (optionalFrom .map (Folder ::getName ).orElse (null ))
143
175
.isAnonymous (anonymous )
144
176
.sessionHash (Hashing .sha512 ().hashString (token , StandardCharsets .UTF_8 ).toString ())
145
177
.build ();
0 commit comments