16
16
import org .lowcoder .api .permission .PermissionHelper ;
17
17
import org .lowcoder .api .permission .view .PermissionItemView ;
18
18
import org .lowcoder .api .usermanagement .OrgDevChecker ;
19
+ import org .lowcoder .domain .application .model .Application ;
19
20
import org .lowcoder .domain .application .model .ApplicationStatus ;
20
21
import org .lowcoder .domain .application .model .ApplicationType ;
22
+ import org .lowcoder .domain .application .repository .ApplicationRepository ;
21
23
import org .lowcoder .domain .application .service .ApplicationServiceImpl ;
22
24
import org .lowcoder .domain .bundle .model .*;
25
+ import org .lowcoder .domain .bundle .repository .BundleRepository ;
23
26
import org .lowcoder .domain .bundle .service .BundleElementRelationService ;
24
27
import org .lowcoder .domain .bundle .service .BundleNode ;
25
28
import org .lowcoder .domain .bundle .service .BundleService ;
47
50
import java .util .*;
48
51
import java .util .function .Function ;
49
52
import java .util .function .ToLongFunction ;
53
+ import java .util .stream .Collectors ;
50
54
51
55
import static org .apache .commons .collections4 .CollectionUtils .isNotEmpty ;
52
56
import static org .lowcoder .domain .bundle .model .BundleStatus .NORMAL ;
@@ -72,6 +76,8 @@ public class BundleApiServiceImpl implements BundleApiService {
72
76
private final OrganizationService organizationService ;
73
77
private final FolderApiService folderApiService ;
74
78
private final ApplicationServiceImpl applicationServiceImpl ;
79
+ private final ApplicationRepository applicationRepository ;
80
+ private final BundleRepository bundleRepository ;
75
81
76
82
@ Override
77
83
public Mono <BundleInfoView > create (CreateBundleRequest createBundleRequest ) {
@@ -262,11 +268,27 @@ public Mono<Void> moveApp(String applicationId, String fromBundleId, String toBu
262
268
if (StringUtils .isBlank (toBundleId )) {
263
269
return Mono .empty ();
264
270
}
265
- return bundleElementRelationService .create (toBundleId , applicationId );
271
+ return bundleService .findById (fromBundleId ).map (bundle -> {
272
+ var map = bundle .getEditingBundleDSL ();
273
+ if (map == null ) map = new HashMap <>();
274
+ ((List <Application >) map .computeIfAbsent ("applications" , k -> new ArrayList <>())).removeIf (app -> app .getId () == applicationId );
275
+ bundle .setEditingBundleDSL (map );
276
+ return bundle ;
277
+ }).map (bundle -> applicationRepository .findById (applicationId )
278
+ .flatMap (newapplication -> addAppToBundle (bundle , newapplication )))
279
+ .then (bundleElementRelationService .create (toBundleId , applicationId ));
266
280
})
267
281
.then ();
268
282
}
269
283
284
+ private Mono <Bundle > addAppToBundle (Bundle bundle , Application newapplication ) {
285
+ var map = bundle .getEditingBundleDSL ();
286
+ if (map == null ) map = new HashMap <>();
287
+ ((List <Application >) map .computeIfAbsent ("applications" , k -> new ArrayList <>())).add (newapplication );
288
+ bundle .setEditingBundleDSL (map );
289
+ return bundleRepository .save (bundle );
290
+ }
291
+
270
292
/**
271
293
* @param applicationId app id to add
272
294
* @param toBundleId bundle id to add app to
@@ -283,7 +305,9 @@ public Mono<Void> addApp(String applicationId, String toBundleId) {
283
305
if (StringUtils .isBlank (toBundleId )) {
284
306
return Mono .empty ();
285
307
}
286
- return bundleElementRelationService .create (toBundleId , applicationId );
308
+ return bundleService .findById (toBundleId ).map (bundle -> applicationRepository .findById (applicationId )
309
+ .flatMap (newapplication -> addAppToBundle (bundle , newapplication )))
310
+ .then (bundleElementRelationService .create (toBundleId , applicationId ));
287
311
})
288
312
.then ();
289
313
}
@@ -344,6 +368,8 @@ public Mono<BundleInfoView> getPublishedBundle(String bundleId, BundleRequestTyp
344
368
.category (bundle .getCategory ())
345
369
.description (bundle .getDescription ())
346
370
.image (bundle .getImage ())
371
+ // .editingBundleDSL(bundle.getEditingBundleDSL())
372
+ .publishedBundleDSL (bundle .getPublishedBundleDSL ())
347
373
.publicToMarketplace (bundle .getPublicToMarketplace ())
348
374
.publicToAll (bundle .getPublicToAll ())
349
375
.agencyProfile (bundle .getAgencyProfile ())
0 commit comments