Skip to content

Commit 58f13a4

Browse files
Thomasludomikula
Thomas
authored andcommitted
Add Bundle DSP
1 parent 4b4f61d commit 58f13a4

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/bundle/model/Bundle.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.lowcoder.sdk.models.HasIdAndAuditing;
1010
import org.springframework.data.mongodb.core.mapping.Document;
1111

12+
import java.util.Map;
13+
1214
@Getter
1315
@Setter
1416
@Document
@@ -23,7 +25,11 @@ public class Bundle extends HasIdAndAuditing {
2325
private String category;
2426
private String image;
2527
private BundleStatus bundleStatus;
28+
2629
private Boolean publicToAll;
2730
private Boolean publicToMarketplace;
2831
private Boolean agencyProfile;
32+
33+
private Map<String, Object> editingBundleDSL;
34+
private Map<String, Object> publishedBundleDSL;
2935
}

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/BundleApiServiceImpl.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
import org.lowcoder.api.permission.PermissionHelper;
1717
import org.lowcoder.api.permission.view.PermissionItemView;
1818
import org.lowcoder.api.usermanagement.OrgDevChecker;
19+
import org.lowcoder.domain.application.model.Application;
1920
import org.lowcoder.domain.application.model.ApplicationStatus;
2021
import org.lowcoder.domain.application.model.ApplicationType;
22+
import org.lowcoder.domain.application.repository.ApplicationRepository;
2123
import org.lowcoder.domain.application.service.ApplicationServiceImpl;
2224
import org.lowcoder.domain.bundle.model.*;
25+
import org.lowcoder.domain.bundle.repository.BundleRepository;
2326
import org.lowcoder.domain.bundle.service.BundleElementRelationService;
2427
import org.lowcoder.domain.bundle.service.BundleNode;
2528
import org.lowcoder.domain.bundle.service.BundleService;
@@ -47,6 +50,7 @@
4750
import java.util.*;
4851
import java.util.function.Function;
4952
import java.util.function.ToLongFunction;
53+
import java.util.stream.Collectors;
5054

5155
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
5256
import static org.lowcoder.domain.bundle.model.BundleStatus.NORMAL;
@@ -72,6 +76,8 @@ public class BundleApiServiceImpl implements BundleApiService {
7276
private final OrganizationService organizationService;
7377
private final FolderApiService folderApiService;
7478
private final ApplicationServiceImpl applicationServiceImpl;
79+
private final ApplicationRepository applicationRepository;
80+
private final BundleRepository bundleRepository;
7581

7682
@Override
7783
public Mono<BundleInfoView> create(CreateBundleRequest createBundleRequest) {
@@ -262,11 +268,27 @@ public Mono<Void> moveApp(String applicationId, String fromBundleId, String toBu
262268
if (StringUtils.isBlank(toBundleId)) {
263269
return Mono.empty();
264270
}
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));
266280
})
267281
.then();
268282
}
269283

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+
270292
/**
271293
* @param applicationId app id to add
272294
* @param toBundleId bundle id to add app to
@@ -283,7 +305,9 @@ public Mono<Void> addApp(String applicationId, String toBundleId) {
283305
if (StringUtils.isBlank(toBundleId)) {
284306
return Mono.empty();
285307
}
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));
287311
})
288312
.then();
289313
}
@@ -344,6 +368,8 @@ public Mono<BundleInfoView> getPublishedBundle(String bundleId, BundleRequestTyp
344368
.category(bundle.getCategory())
345369
.description(bundle.getDescription())
346370
.image(bundle.getImage())
371+
// .editingBundleDSL(bundle.getEditingBundleDSL())
372+
.publishedBundleDSL(bundle.getPublishedBundleDSL())
347373
.publicToMarketplace(bundle.getPublicToMarketplace())
348374
.publicToAll(bundle.getPublicToAll())
349375
.agencyProfile(bundle.getAgencyProfile())

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/bundle/view/BundleInfoView.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.time.Instant;
1010
import java.util.List;
11+
import java.util.Map;
1112

1213
@Getter
1314
@Setter
@@ -31,7 +32,8 @@ public class BundleInfoView {
3132
private boolean isVisible;
3233
private boolean isManageable;
3334

34-
private List<ApplicationInfoView> subApplications;
35+
private Map<String, Object> editingBundleDSL;
36+
private Map<String, Object> publishedBundleDSL;
3537

3638
private final Instant createTime;
3739

0 commit comments

Comments
 (0)