55import lombok .RequiredArgsConstructor ;
66import lombok .extern .slf4j .Slf4j ;
77import org .apache .commons .lang3 .StringUtils ;
8+ import org .apache .commons .lang3 .tuple .Pair ;
89import org .lowcoder .api .application .view .ApplicationInfoView ;
910import org .lowcoder .api .application .view .ApplicationView ;
1011import org .lowcoder .api .home .SessionUserService ;
1112import org .lowcoder .api .usermanagement .view .AddMemberRequest ;
1213import org .lowcoder .api .usermanagement .view .UpdateRoleRequest ;
14+ import org .lowcoder .domain .application .service .ApplicationRecordServiceImpl ;
1315import org .lowcoder .domain .application .service .ApplicationService ;
1416import org .lowcoder .domain .datasource .model .Datasource ;
1517import org .lowcoder .domain .datasource .service .DatasourceService ;
4042import org .lowcoder .infra .event .groupmember .GroupMemberRoleUpdateEvent ;
4143import org .lowcoder .infra .event .user .UserLoginEvent ;
4244import org .lowcoder .infra .event .user .UserLogoutEvent ;
45+ import org .lowcoder .infra .util .TupleUtils ;
4346import org .lowcoder .plugin .api .event .LowcoderEvent .EventType ;
4447import org .lowcoder .sdk .constants .Authentication ;
4548import org .lowcoder .sdk .util .LocaleUtils ;
@@ -65,6 +68,7 @@ public class BusinessEventPublisher {
6568 private final ApplicationService applicationService ;
6669 private final DatasourceService datasourceService ;
6770 private final ResourcePermissionService resourcePermissionService ;
71+ private final ApplicationRecordServiceImpl applicationRecordServiceImpl ;
6872
6973 public Mono <Void > publishFolderCommonEvent (String folderId , String folderName , EventType eventType ) {
7074
@@ -93,13 +97,14 @@ public Mono<Void> publishFolderCommonEvent(String folderId, String folderName, E
9397 });
9498 }
9599
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 ) {
97101 return applicationService .findByIdWithoutDsl (applicationId )
98102 .map (application -> {
99103 ApplicationInfoView applicationInfoView = ApplicationInfoView .builder ()
100104 .applicationId (applicationId )
101105 .name (application .getName ())
102106 .folderId (folderId )
107+ .folderIdFrom (folderIdFrom )
103108 .build ();
104109 return ApplicationView .builder ()
105110 .applicationInfoView (applicationInfoView )
@@ -125,21 +130,48 @@ public Mono<Void> publishApplicationCommonEvent(ApplicationView applicationView,
125130 .map (Optional ::of )
126131 .onErrorReturn (Optional .empty ());
127132 }))
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 )
128142 .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 )
129154 .doOnNext (tuple -> {
130155 OrgMember orgMember = tuple .getT1 ().getT1 ();
131156 Optional <Folder > optional = tuple .getT1 ().getT2 ();
157+ Optional <Folder > optionalFrom = tuple .getT1 ().getT3 ();
132158 String token = tuple .getT2 ();
159+ String category = tuple .getT3 ().getLeft ();
160+ String description = tuple .getT3 ().getRight ();
133161 ApplicationInfoView applicationInfoView = applicationView .getApplicationInfoView ();
134162 ApplicationCommonEvent event = ApplicationCommonEvent .builder ()
135163 .orgId (orgMember .getOrgId ())
136164 .userId (orgMember .getUserId ())
137165 .applicationId (applicationInfoView .getApplicationId ())
138166 .applicationGid (applicationInfoView .getApplicationGid ())
139167 .applicationName (applicationInfoView .getName ())
168+ .applicationCategory (category )
169+ .applicationDescription (description )
140170 .type (eventType )
141171 .folderId (optional .map (Folder ::getId ).orElse (null ))
142172 .folderName (optional .map (Folder ::getName ).orElse (null ))
173+ .oldFolderId (optionalFrom .map (Folder ::getId ).orElse (null ))
174+ .oldFolderName (optionalFrom .map (Folder ::getName ).orElse (null ))
143175 .isAnonymous (anonymous )
144176 .sessionHash (Hashing .sha512 ().hashString (token , StandardCharsets .UTF_8 ).toString ())
145177 .build ();
0 commit comments