Skip to content

Commit 481f162

Browse files
Thomasludomikula
Thomas
authored andcommitted
Fix issues add/move app
add test case for getPublishedBundle
1 parent 58f13a4 commit 481f162

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,15 @@ public Mono<Void> moveApp(String applicationId, String fromBundleId, String toBu
268268
if (StringUtils.isBlank(toBundleId)) {
269269
return Mono.empty();
270270
}
271-
return bundleService.findById(fromBundleId).map(bundle -> {
271+
return bundleService.findById(fromBundleId).flatMap(bundle -> {
272272
var map = bundle.getEditingBundleDSL();
273273
if(map == null) map = new HashMap<>();
274-
((List<Application>) map.computeIfAbsent("applications", k-> new ArrayList<>())).removeIf(app -> app.getId() == applicationId);
274+
((List<Application>) map.computeIfAbsent("applications", k-> new ArrayList<>())).removeIf(app -> app.getId().equals(applicationId));
275275
bundle.setEditingBundleDSL(map);
276-
return bundle;
277-
}).map(bundle -> applicationRepository.findById(applicationId)
276+
return bundleRepository.save(bundle);
277+
})
278+
.then(bundleRepository.findById(toBundleId))
279+
.flatMap(bundle -> applicationRepository.findById(applicationId)
278280
.flatMap(newapplication -> addAppToBundle(bundle, newapplication)))
279281
.then(bundleElementRelationService.create(toBundleId, applicationId));
280282
})
@@ -305,7 +307,7 @@ public Mono<Void> addApp(String applicationId, String toBundleId) {
305307
if (StringUtils.isBlank(toBundleId)) {
306308
return Mono.empty();
307309
}
308-
return bundleService.findById(toBundleId).map(bundle -> applicationRepository.findById(applicationId)
310+
return bundleService.findById(toBundleId).flatMap(bundle -> applicationRepository.findById(applicationId)
309311
.flatMap(newapplication-> addAppToBundle(bundle, newapplication)))
310312
.then(bundleElementRelationService.create(toBundleId, applicationId));
311313
})
@@ -368,7 +370,6 @@ public Mono<BundleInfoView> getPublishedBundle(String bundleId, BundleRequestTyp
368370
.category(bundle.getCategory())
369371
.description(bundle.getDescription())
370372
.image(bundle.getImage())
371-
// .editingBundleDSL(bundle.getEditingBundleDSL())
372373
.publishedBundleDSL(bundle.getPublishedBundleDSL())
373374
.publicToMarketplace(bundle.getPublicToMarketplace())
374375
.publicToAll(bundle.getPublicToAll())

server/api-service/lowcoder-server/src/test/java/org/lowcoder/api/bundle/BundleApiServiceImplTest.java

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.junit.runner.RunWith;
55
import org.lowcoder.api.bundle.view.BundleInfoView;
66
import org.lowcoder.api.home.SessionUserServiceImpl;
7+
import org.lowcoder.domain.bundle.model.BundleRequestType;
78
import org.lowcoder.domain.organization.model.MemberRole;
89
import org.lowcoder.domain.organization.model.OrgMember;
910
import org.springframework.beans.factory.annotation.Autowired;
@@ -117,24 +118,31 @@ public void moveAddAppTest() {
117118
"image",
118119
null));
119120

120-
StepVerifier.create(Mono.zip(bundleInfoViewMono, bundleInfoViewMono2))
121-
.assertNext(tuple2 -> {
121+
Mono<Void> testMono = Mono.zip(bundleInfoViewMono, bundleInfoViewMono2)
122+
.flatMap(tuple2 -> {
122123
var bundleInfoView = tuple2.getT1();
123124
var bundleInfoView2 = tuple2.getT2();
124-
//And then add app01 to created bundle
125-
StepVerifier.create(bundleApiService.addApp("app01", bundleInfoView.getBundleId()))
126-
.verifyComplete();
127-
//or move bundle
128-
StepVerifier.create(bundleApiService.moveApp("app01", bundleInfoView.getBundleId(), bundleInfoView2.getBundleId()))
129-
.verifyComplete();
130-
//Try no dev user to add app to bundle
131-
when(sessionUserService.getVisitorId()).thenReturn(Mono.just("user01"));
132-
when(sessionUserService.getVisitorOrgMemberCache()).thenReturn(Mono.just(new OrgMember("org01", "user01", MemberRole.MEMBER, "NORMAL", 0)));
133-
StepVerifier.create(bundleApiService.addApp("app01", bundleInfoView.getBundleId()))
134-
.expectError();
135-
StepVerifier.create(bundleApiService.moveApp("app01", bundleInfoView.getBundleId(), bundleInfoView2.getBundleId()))
136-
.expectError();
137-
})
125+
126+
return bundleApiService.addApp("app01", bundleInfoView.getBundleId())
127+
.then(bundleApiService.moveApp("app01", bundleInfoView.getBundleId(), bundleInfoView2.getBundleId()))
128+
.then(Mono.fromRunnable(() -> {
129+
// Try a no-dev user to add app to bundle
130+
when(sessionUserService.getVisitorId()).thenReturn(Mono.just("user01"));
131+
when(sessionUserService.getVisitorOrgMemberCache()).thenReturn(Mono.just(new OrgMember("org01", "user01", MemberRole.MEMBER, "NORMAL", 0)));
132+
}))
133+
.then(bundleApiService.addApp("app01", bundleInfoView.getBundleId()).onErrorResume(e -> Mono.empty()))
134+
.then(bundleApiService.moveApp("app01", bundleInfoView.getBundleId(), bundleInfoView2.getBundleId()).onErrorResume(e -> Mono.empty()))
135+
//Get published bundle
136+
.then(bundleApiService.getPublishedBundle(bundleInfoView2.getBundleId(), BundleRequestType.PUBLIC_TO_ALL))
137+
.doOnNext(bundle -> {
138+
//should have no published dsl since not yet published
139+
assertNotNull(bundle.getBundleId());
140+
assertNull(bundle.getPublishedBundleDSL());
141+
})
142+
.then();
143+
});
144+
145+
StepVerifier.create(testMono)
138146
.verifyComplete();
139147
}
140148
}

0 commit comments

Comments
 (0)