Skip to content

Commit 7b86625

Browse files
Thomasludomikula
Thomas
authored andcommitted
Add two API
- /api/bundles/addApp - /api/bundles/moveApp
1 parent e7a58b0 commit 7b86625

File tree

8 files changed

+77
-20
lines changed

8 files changed

+77
-20
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public interface BundleElementRelationService {
1111
Mono<Boolean> deleteByBundleIds(List<String> bundleIds);
1212

1313
Mono<Boolean> deleteByElementId(String elementId);
14+
Mono<Boolean> deleteByBundleIdAndElementId(String bundleId, String elementId);
1415

1516
Mono<Void> create(String bundleId, String elementId);
1617

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public Mono<Boolean> deleteByElementId(String elementId) {
2828
return biRelationService.removeAllBiRelationsByTargetId(BUNDLE_ELEMENT, elementId);
2929
}
3030

31+
@Override
32+
public Mono<Boolean> deleteByBundleIdAndElementId(String bundleId, String elementId) {
33+
return biRelationService.removeAllBiRelationsBySourceIdAndTargetId(BUNDLE_ELEMENT, bundleId, elementId);
34+
}
35+
3136
@Override
3237
public Mono<Void> create(String bundleId, String elementId) {
3338
return biRelationService.getBySourceId(BUNDLE_ELEMENT, bundleId)

server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/birelation/BiRelationService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Mono<Boolean> updateRelation(BiRelationBizType bizType, String sourceId, String
4545

4646
Mono<Boolean> removeAllBiRelationsByTargetId(BiRelationBizType bizType, String targetId);
4747

48+
Mono<Boolean> removeAllBiRelationsBySourceIdAndTargetId(BiRelationBizType bizType, String sourceId, String targetId);
49+
4850
Mono<Boolean> removeAllBiRelations(BiRelationBizType bizType, List<String> sourceIds);
4951

5052
Mono<BiRelation> getBiRelation(BiRelationBizType bizType, String sourceId, String targetId);

server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/birelation/BiRelationServiceImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ public Mono<Boolean> removeAllBiRelationsByTargetId(BiRelationBizType bizType, S
143143
return mongoUpsertHelper.remove(query, BiRelation.class);
144144
}
145145

146+
@Override
147+
public Mono<Boolean> removeAllBiRelationsBySourceIdAndTargetId(BiRelationBizType bizType, String sourceId, String targetId) {
148+
Query query = new Query();
149+
query.addCriteria(where(BIZ_TYPE).is(bizType));
150+
query.addCriteria(where(SOURCE_ID).is(sourceId));
151+
query.addCriteria(where(TARGET_ID).is(targetId));
152+
return mongoUpsertHelper.remove(query, BiRelation.class);
153+
}
154+
146155
@Override
147156
public Mono<Boolean> removeAllBiRelations(BiRelationBizType bizType, List<String> sourceIds) {
148157
Query query = new Query();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import jakarta.annotation.Nonnull;
44
import jakarta.annotation.Nullable;
5-
import org.lowcoder.api.application.ApplicationEndpoints;
65
import org.lowcoder.api.bundle.view.BundleInfoView;
76
import org.lowcoder.api.bundle.view.BundlePermissionView;
87
import org.lowcoder.domain.application.model.ApplicationType;
@@ -11,7 +10,6 @@
1110
import org.lowcoder.domain.permission.model.ResourceAction;
1211
import org.lowcoder.domain.permission.model.ResourcePermission;
1312
import org.lowcoder.domain.permission.model.ResourceRole;
14-
import org.lowcoder.sdk.config.dynamic.Conf;
1513
import reactor.core.publisher.Flux;
1614
import reactor.core.publisher.Mono;
1715

@@ -35,7 +33,9 @@ public interface BundleApiService {
3533

3634
Mono<BundleInfoView> update(Bundle bundle);
3735

38-
Mono<Void> move(String applicationLikeId, @Nullable String targetBundled);
36+
Mono<Void> moveApp(String applicationId, String fromBundled, String toBundleId);
37+
38+
Mono<Void> addApp(String applicationId, String toBundleId);
3939

4040
Flux<?> getElements(@Nullable String bundleId, @Nullable ApplicationType applicationType);
4141

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import lombok.RequiredArgsConstructor;
66
import org.apache.commons.collections4.CollectionUtils;
77
import org.apache.commons.lang3.StringUtils;
8-
import org.lowcoder.api.application.ApplicationEndpoints;
98
import org.lowcoder.api.bundle.BundleEndpoints.CreateBundleRequest;
109
import org.lowcoder.api.application.view.ApplicationInfoView;
1110
import org.lowcoder.api.application.view.ApplicationPermissionView;
@@ -259,21 +258,44 @@ public Mono<BundleInfoView> update(Bundle bundle) {
259258
}
260259

261260
/**
262-
* @param targetBundleId null means root bundle
261+
* @param applicationId app id to move
262+
* @param fromBundleId bundle id to remove app from
263+
* @param toBundleId bundle id to move app to
263264
*/
264265
@Override
265-
public Mono<Void> move(String applicationLikeId, @Nullable String targetBundleId) {
266+
public Mono<Void> moveApp(String applicationId, String fromBundleId, String toBundleId) {
266267
return sessionUserService.getVisitorId()
267268
// check permissions
268-
.delayUntil(userId -> resourcePermissionService.checkResourcePermissionWithError(userId, applicationLikeId,
269+
.delayUntil(userId -> resourcePermissionService.checkResourcePermissionWithError(userId, applicationId,
269270
ResourceAction.MANAGE_APPLICATIONS))
270271
// remove old relations
271-
.then(bundleElementRelationService.deleteByElementId(applicationLikeId))
272+
.then(bundleElementRelationService.deleteByBundleIdAndElementId(fromBundleId, applicationId))
272273
.flatMap(b -> {
273-
if (StringUtils.isBlank(targetBundleId)) {
274+
if (StringUtils.isBlank(toBundleId)) {
274275
return Mono.empty();
275276
}
276-
return bundleElementRelationService.create(targetBundleId, applicationLikeId);
277+
return bundleElementRelationService.create(toBundleId, applicationId);
278+
})
279+
.then();
280+
}
281+
282+
/**
283+
* @param applicationId app id to add
284+
* @param toBundleId bundle id to add app to
285+
*/
286+
@Override
287+
public Mono<Void> addApp(String applicationId, String toBundleId) {
288+
return sessionUserService.getVisitorId()
289+
// check permissions
290+
.delayUntil(userId -> resourcePermissionService.checkResourcePermissionWithError(userId, applicationId,
291+
ResourceAction.MANAGE_APPLICATIONS))
292+
// remove old relations
293+
.then(bundleElementRelationService.deleteByBundleIdAndElementId(toBundleId, applicationId))
294+
.flatMap(b -> {
295+
if (StringUtils.isBlank(toBundleId)) {
296+
return Mono.empty();
297+
}
298+
return bundleElementRelationService.create(toBundleId, applicationId);
277299
})
278300
.then();
279301
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.lowcoder.api.bundle;
22

33
import lombok.RequiredArgsConstructor;
4-
import org.lowcoder.api.application.ApplicationEndpoints;
54
import org.lowcoder.api.bundle.view.BundleInfoView;
65
import org.lowcoder.api.bundle.view.BundlePermissionView;
76
import org.lowcoder.api.bundle.view.MarketplaceBundleInfoView;
@@ -98,14 +97,22 @@ public Mono<ResponseView<List<?>>> getElements(@RequestParam(value = "id", requi
9897
}
9998

10099
@Override
101-
public Mono<ResponseView<Void>> move(@PathVariable("id") String applicationLikeId,
102-
@RequestParam(value = "targetBundleId", required = false) String targetBundleId) {
103-
return bundleApiService.move(applicationLikeId, targetBundleId)
100+
public Mono<ResponseView<Void>> moveApp(@PathVariable("id") String applicationId,
101+
@RequestParam(value = "fromBundleId") String fromBundleId,
102+
@RequestParam(value = "toBundleId") String toBundleId) {
103+
return bundleApiService.moveApp(applicationId, fromBundleId, toBundleId)
104104
//TODO: Event Type not defined yet
105105
// .then(businessEventPublisher.publishBundleCommonEvent(applicationLikeId, targetBundleId, BUNDLE_MOVE))
106106
.then(Mono.fromSupplier(() -> ResponseView.success(null)));
107107
}
108108

109+
@Override
110+
public Mono<ResponseView<Void>> addApp(@PathVariable("id") String applicationId,
111+
@RequestParam(value = "toBundleId") String toBundleId) {
112+
return bundleApiService.addApp(applicationId, toBundleId)
113+
.then(Mono.fromSupplier(() -> ResponseView.success(null)));
114+
}
115+
109116
@Override
110117
public Mono<ResponseView<Void>> reorder(@PathVariable("bundleId") String bundleId,
111118
@RequestParam(value = "elementIds", required = true) List<String> elementIds) {

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import io.swagger.v3.oas.annotations.Operation;
55
import jakarta.annotation.Nullable;
66
import org.apache.commons.lang3.BooleanUtils;
7-
import org.lowcoder.api.application.ApplicationEndpoints;
87
import org.lowcoder.api.bundle.view.BundleInfoView;
98
import org.lowcoder.api.bundle.view.BundlePermissionView;
109
import org.lowcoder.api.bundle.view.MarketplaceBundleInfoView;
@@ -126,13 +125,25 @@ public Mono<ResponseView<List<?>>> getElements(@RequestParam(value = "id", requi
126125

127126
@Operation(
128127
tags = TAG_BUNDLE_MANAGEMENT,
129-
operationId = "moveBundle",
130-
summary = "Move Bundle",
128+
operationId = "moveApp",
129+
summary = "Move App to Bundle",
131130
description = "Relocate an application to a different bundle in Lowcoder using its unique ID."
132131
)
133-
@PutMapping("/move/{id}")
134-
public Mono<ResponseView<Void>> move(@PathVariable("id") String applicationLikeId,
135-
@RequestParam(value = "targetBundleId", required = false) String targetBundleId);
132+
@PutMapping("/moveApp/{id}")
133+
public Mono<ResponseView<Void>> moveApp(@PathVariable("id") String applicationId,
134+
@RequestParam(value = "fromBundleId") String fromBundleId,
135+
@RequestParam(value = "toBundleId") String toBundleId);
136+
137+
@Operation(
138+
tags = TAG_BUNDLE_MANAGEMENT,
139+
operationId = "addApp",
140+
summary = "Add App to Bundle",
141+
description = "Add an application to a bundle in Lowcoder using its unique ID."
142+
)
143+
144+
@PutMapping("/addApp/{id}")
145+
public Mono<ResponseView<Void>> addApp(@PathVariable("id") String applicationId,
146+
@RequestParam(value = "toBundleId") String toBundleId);
136147

137148
@Operation(
138149
tags = TAG_BUNDLE_MANAGEMENT,

0 commit comments

Comments
 (0)