Skip to content

Commit 2e73aca

Browse files
Thomasrludomikula
authored andcommitted
Add sharing details to events APPLICATION_SHARING_CHANGE
1 parent e007719 commit 2e73aca

File tree

7 files changed

+164
-21
lines changed

7 files changed

+164
-21
lines changed

server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/event/AbstractEvent.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.lowcoder.infra.event;
22

3+
import com.fasterxml.jackson.annotation.JsonInclude;
34
import lombok.Getter;
45
import lombok.Setter;
56
import lombok.experimental.SuperBuilder;
@@ -57,7 +58,16 @@ public void populateDetails(ContextView contextView) {
5758
try {
5859
f.setAccessible(Boolean.TRUE);
5960
value = f.get(this);
60-
details.put(f.getName(), value);
61+
JsonInclude jsonInclude = f.getAnnotation(JsonInclude.class);
62+
if (jsonInclude != null && jsonInclude.value() == JsonInclude.Include.NON_NULL) {
63+
// Include only if value is not null
64+
if (value != null) {
65+
details.put(f.getName(), value);
66+
}
67+
} else {
68+
// Include regardless of value
69+
details.put(f.getName(), value);
70+
}
6171
} catch (Exception e) {
6272
}
6373

server/api-service/lowcoder-infra/src/main/java/org/lowcoder/infra/event/ApplicationCommonEvent.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.lowcoder.infra.event;
22

33

4+
import com.fasterxml.jackson.annotation.JsonInclude;
45
import jakarta.annotation.Nullable;
56
import lombok.Getter;
67
import lombok.experimental.SuperBuilder;
@@ -18,20 +19,33 @@ public class ApplicationCommonEvent extends AbstractEvent {
1819
private final String applicationDescription;
1920
private final EventType type;
2021
@Nullable
22+
@JsonInclude(JsonInclude.Include.NON_NULL)
2123
private final String folderId;
2224
@Nullable
25+
@JsonInclude(JsonInclude.Include.NON_NULL)
2326
private final String folderName;
2427
@Nullable
28+
@JsonInclude(JsonInclude.Include.NON_NULL)
2529
private final String oldFolderId;
2630
@Nullable
31+
@JsonInclude(JsonInclude.Include.NON_NULL)
2732
private final String oldFolderName;
33+
@JsonInclude(JsonInclude.Include.NON_NULL)
2834
private final String permissionId;
35+
@JsonInclude(JsonInclude.Include.NON_NULL)
2936
private final String role;
37+
@JsonInclude(JsonInclude.Include.NON_NULL)
3038
private final Set<String> userIds;
39+
@JsonInclude(JsonInclude.Include.NON_NULL)
3140
private final Set<String> groupIds;
41+
@JsonInclude(JsonInclude.Include.NON_NULL)
3242
private final String shareType;
43+
@JsonInclude(JsonInclude.Include.NON_NULL)
3344
private final String tag;
45+
@JsonInclude(JsonInclude.Include.NON_NULL)
3446
private final String commitMessage;
47+
@JsonInclude(JsonInclude.Include.NON_NULL)
48+
private final Object sharingDetails;
3549

3650
@Override
3751
public EventType getEventType() {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.lowcoder.infra.event;
2+
3+
4+
import jakarta.annotation.Nullable;
5+
import lombok.Getter;
6+
import lombok.experimental.SuperBuilder;
7+
8+
@Getter
9+
@SuperBuilder
10+
public class BundleCommonEvent extends AbstractEvent {
11+
12+
private final String bundleId;
13+
private final String bundleGid;
14+
private final String bundleName;
15+
private final String bundleCategory;
16+
private final String bundleDescription;
17+
private final EventType type;
18+
@Nullable
19+
private final String folderId;
20+
@Nullable
21+
private final String folderName;
22+
@Nullable
23+
private final String oldFolderId;
24+
@Nullable
25+
private final String oldFolderName;
26+
27+
@Override
28+
public EventType getEventType() {
29+
return type;
30+
}
31+
}

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/application/ApplicationController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ public Mono<ResponseView<Boolean>> setApplicationPublicToAll(@PathVariable Strin
270270
@RequestBody ApplicationPublicToAllRequest request) {
271271
return gidService.convertApplicationIdToObjectId(applicationId).flatMap(appId ->
272272
applicationApiService.setApplicationPublicToAll(appId, request.publicToAll())
273-
.delayUntil(__ -> businessEventPublisher.publishApplicationSharingEvent(applicationId, "PublicToAll"))
273+
.delayUntil(__ -> applicationApiService.getApplicationPermissions(appId)
274+
.flatMap(applicationPermissionView -> businessEventPublisher.publishApplicationSharingEvent(applicationId, "PublicToAll", applicationPermissionView)))
274275
.map(ResponseView::success));
275276
}
276277

@@ -279,7 +280,8 @@ public Mono<ResponseView<Boolean>> setApplicationPublicToMarketplace(@PathVariab
279280
@RequestBody ApplicationPublicToMarketplaceRequest request) {
280281
return gidService.convertApplicationIdToObjectId(applicationId).flatMap(appId ->
281282
applicationApiService.setApplicationPublicToMarketplace(appId, request)
282-
.delayUntil(__ -> businessEventPublisher.publishApplicationSharingEvent(applicationId, "PublicToMarketplace"))
283+
.delayUntil(__ -> applicationApiService.getApplicationPermissions(appId)
284+
.flatMap(applicationPermissionView -> businessEventPublisher.publishApplicationSharingEvent(applicationId, "PublicToMarketplace", applicationPermissionView)))
283285
.map(ResponseView::success));
284286
}
285287

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

Lines changed: 29 additions & 17 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.jetbrains.annotations.NotNull;
54
import org.lowcoder.api.bundle.view.BundleInfoView;
65
import org.lowcoder.api.bundle.view.BundlePermissionView;
76
import org.lowcoder.api.bundle.view.MarketplaceBundleInfoView;
@@ -20,12 +19,12 @@
2019
import org.springframework.web.bind.annotation.RequestBody;
2120
import org.springframework.web.bind.annotation.RequestParam;
2221
import org.springframework.web.bind.annotation.RestController;
23-
import reactor.core.publisher.Flux;
2422
import reactor.core.publisher.Mono;
2523

2624
import java.util.List;
2725

2826
import static org.lowcoder.api.util.Pagination.fluxToPageResponseView;
27+
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.*;
2928
import static org.lowcoder.sdk.exception.BizError.INVALID_PARAMETER;
3029
import static org.lowcoder.sdk.util.ExceptionUtils.ofError;
3130

@@ -43,16 +42,31 @@ public class BundleController implements BundleEndpoints
4342
@Override
4443
public Mono<ResponseView<BundleInfoView>> create(@RequestBody CreateBundleRequest bundle) {
4544
return bundleApiService.create(bundle)
46-
//TODO [thomasr]: add new method to BusinessEventPublisher(jar file)
47-
// .delayUntil(f -> businessEventPublisher.publishBundleCommonEvent(f.getBundleId(), f.getName(), EventType.BUNDLE_CREATE))
45+
.delayUntil(f -> businessEventPublisher.publishBundleCommonEvent(f, BUNDLE_CREATE))
4846
.map(ResponseView::success);
4947
}
5048

5149
@Override
5250
public Mono<ResponseView<Void>> delete(@PathVariable("id") String bundleId) {
5351
return gidService.convertBundleIdToObjectId(bundleId).flatMap(objectId ->
5452
bundleApiService.delete(objectId)
55-
// .delayUntil(f -> businessEventPublisher.publishBundleCommonEvent(f.getId(), f.getName(), EventType.BUNDLE_DELETE))
53+
.delayUntil(f -> businessEventPublisher.publishBundleCommonEvent(
54+
BundleInfoView.builder()
55+
.bundleGid(f.getGid())
56+
.editingBundleDSL(f.getEditingBundleDSL())
57+
.image(f.getImage())
58+
.title(f.getTitle())
59+
.description(f.getDescription())
60+
.name(f.getName())
61+
.publicToMarketplace(f.isPublicToMarketplace())
62+
.publicToAll(f.isPublicToAll())
63+
.agencyProfile(f.agencyProfile())
64+
.createTime(f.getCreatedAt())
65+
.createBy(f.getCreatedBy())
66+
.createAt(f.getCreatedAt().toEpochMilli())
67+
.publishedBundleDSL(f.getPublishedBundleDSL())
68+
.category(f.getCategory())
69+
.build(), BUNDLE_DELETE))
5670
.then(Mono.fromSupplier(() -> ResponseView.success(null))));
5771
}
5872

@@ -63,11 +77,10 @@ public Mono<ResponseView<Void>> delete(@PathVariable("id") String bundleId) {
6377
public Mono<ResponseView<BundleInfoView>> update(@RequestBody Bundle bundle) {
6478
return bundleService.findById(bundle.getId())
6579
.zipWhen(__ -> bundleApiService.update(bundle))
66-
// .delayUntil(tuple2 -> {
67-
// Bundle old = tuple2.getT1();
68-
// return businessEventPublisher.publishBundleCommonEvent(bundle.getId(), old.getName() + " => " + bundle.getName(),
69-
// EventType.BUNDLE_UPDATE);
70-
// })
80+
.delayUntil(tuple2 -> {
81+
Bundle old = tuple2.getT1();
82+
return businessEventPublisher.publishBundleCommonEvent(tuple2.getT2(), BUNDLE_UPDATE);
83+
})
7184
.map(tuple2 -> ResponseView.success(tuple2.getT2()));
7285
}
7386

@@ -81,15 +94,15 @@ public Mono<ResponseView<BundleInfoView>> publish(@PathVariable String bundleId)
8194
public Mono<ResponseView<Boolean>> recycle(@PathVariable String bundleId) {
8295
return gidService.convertBundleIdToObjectId(bundleId).flatMap(objectId ->
8396
bundleApiService.recycle(objectId)
84-
// .delayUntil(__ -> businessEventPublisher.publishBundleCommonEvent(bundleId, null, BUNDLE_RECYCLED))
97+
.delayUntil(__ -> businessEventPublisher.publishBundleCommonEvent(bundleId, null, null, BUNDLE_RECYCLED))
8598
.map(ResponseView::success));
8699
}
87100

88101
@Override
89102
public Mono<ResponseView<Boolean>> restore(@PathVariable String bundleId) {
90103
return gidService.convertBundleIdToObjectId(bundleId).flatMap(objectId ->
91104
bundleApiService.restore(objectId)
92-
// .delayUntil(__ -> businessEventPublisher.publishBundleCommonEvent(bundleId, null, BUNDLE_RESTORE))
105+
.delayUntil(__ -> businessEventPublisher.publishBundleCommonEvent(bundleId, null, null, BUNDLE_RESTORE))
93106
.map(ResponseView::success));
94107
}
95108

@@ -120,8 +133,7 @@ public Mono<ResponseView<Void>> moveApp(@PathVariable("id") String applicationId
120133
gidService.convertBundleIdToObjectId(toBundleId).flatMap(objectIdTo ->
121134
gidService.convertApplicationIdToObjectId(applicationId).flatMap(appId ->
122135
bundleApiService.moveApp(appId, objectIdFrom, objectIdTo)
123-
//TODO: Event Type not defined yet
124-
// .then(businessEventPublisher.publishBundleCommonEvent(applicationLikeId, targetBundleId, BUNDLE_MOVE))
136+
.then(businessEventPublisher.publishBundleCommonEvent(applicationId, fromBundleId, toBundleId, APPLICATION_MOVE))
125137
.then(Mono.fromSupplier(() -> ResponseView.success(null))))));
126138
}
127139

@@ -188,23 +200,23 @@ public Mono<ResponseView<BundlePermissionView>> getBundlePermissions(@PathVariab
188200
public Mono<ResponseView<BundleInfoView>> getPublishedBundle(@PathVariable String bundleId) {
189201
return gidService.convertBundleIdToObjectId(bundleId).flatMap(objectId ->
190202
bundleApiService.getPublishedBundle(objectId, BundleRequestType.PUBLIC_TO_ALL)
191-
// .delayUntil(bundleView -> businessEventPublisher.publishBundleCommonEvent(bundleView, BUNDLE_VIEW))
203+
.delayUntil(bundleView -> businessEventPublisher.publishBundleCommonEvent(bundleView, BUNDLE_VIEW))
192204
.map(ResponseView::success));
193205
}
194206

195207
@Override
196208
public Mono<ResponseView<BundleInfoView>> getPublishedMarketPlaceBundle(@PathVariable String bundleId) {
197209
return gidService.convertBundleIdToObjectId(bundleId).flatMap(objectId ->
198210
bundleApiService.getPublishedBundle(objectId, BundleRequestType.PUBLIC_TO_MARKETPLACE)
199-
// .delayUntil(bundleView -> businessEventPublisher.publishBundleCommonEvent(bundleView, BUNDLE_VIEW))
211+
.delayUntil(bundleView -> businessEventPublisher.publishBundleCommonEvent(bundleView, BUNDLE_VIEW))
200212
.map(ResponseView::success));
201213
}
202214

203215
@Override
204216
public Mono<ResponseView<BundleInfoView>> getAgencyProfileBundle(@PathVariable String bundleId) {
205217
return gidService.convertBundleIdToObjectId(bundleId).flatMap(objectId ->
206218
bundleApiService.getPublishedBundle(objectId, BundleRequestType.AGENCY_PROFILE)
207-
// .delayUntil(bundleView -> businessEventPublisher.publishBundleCommonEvent(bundleView, BUNDLE_VIEW))
219+
.delayUntil(bundleView -> businessEventPublisher.publishBundleCommonEvent(bundleView, BUNDLE_VIEW))
208220
.map(ResponseView::success));
209221
}
210222

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class BundleInfoView {
2727
private final Long createAt;
2828
private final String createBy;
2929
private final String folderId;
30+
private final String folderIdFrom;
3031
private final Boolean publicToAll;
3132
private final Boolean publicToMarketplace;
3233
private final Boolean agencyProfile;

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/util/BusinessEventPublisher.java

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import org.apache.commons.lang3.StringUtils;
88
import org.apache.commons.lang3.tuple.Pair;
99
import org.lowcoder.api.application.view.ApplicationInfoView;
10+
import org.lowcoder.api.application.view.ApplicationPermissionView;
1011
import org.lowcoder.api.application.view.ApplicationPublishRequest;
1112
import org.lowcoder.api.application.view.ApplicationView;
13+
import org.lowcoder.api.bundle.view.BundleInfoView;
1214
import org.lowcoder.api.home.SessionUserService;
1315
import org.lowcoder.api.usermanagement.view.AddMemberRequest;
1416
import org.lowcoder.api.usermanagement.view.UpdateRoleRequest;
@@ -243,7 +245,7 @@ public Mono<Void> publishApplicationPermissionEvent(String applicationId, Set<St
243245
}
244246

245247

246-
public Mono<Void> publishApplicationSharingEvent(String applicationId, String shareType) {
248+
public Mono<Void> publishApplicationSharingEvent(String applicationId, String shareType, ApplicationPermissionView applicationPermissionView) {
247249
return sessionUserService.isAnonymousUser()
248250
.flatMap(anonymous -> {
249251
if (anonymous) {
@@ -270,6 +272,7 @@ public Mono<Void> publishApplicationSharingEvent(String applicationId, String sh
270272
.applicationCategory(category)
271273
.applicationDescription(description)
272274
.type(EventType.APPLICATION_SHARING_CHANGE)
275+
.sharingDetails(applicationPermissionView)
273276
.shareType(shareType)
274277
.isAnonymous(anonymous)
275278
.sessionHash(Hashing.sha512().hashString(token, StandardCharsets.UTF_8).toString())
@@ -382,6 +385,76 @@ public Mono<Void> publishApplicationVersionChangeEvent(String applicationId, Str
382385
}
383386

384387

388+
public Mono<Void> publishBundleCommonEvent(BundleInfoView bundleInfoView, EventType eventType) {
389+
return sessionUserService.isAnonymousUser()
390+
.flatMap(anonymous -> {
391+
if (anonymous) {
392+
return Mono.empty();
393+
}
394+
return sessionUserService.getVisitorOrgMemberCache()
395+
.zipWith(Mono.defer(() -> {
396+
String folderId = bundleInfoView.getFolderId();
397+
if (StringUtils.isBlank(folderId)) {
398+
return Mono.just(Optional.<Folder> empty());
399+
}
400+
return folderService.findById(folderId)
401+
.map(Optional::of)
402+
.onErrorReturn(Optional.empty());
403+
}))
404+
.zipWith(Mono.defer(() -> {
405+
String folderId = bundleInfoView.getFolderIdFrom();
406+
if (StringUtils.isBlank(folderId)) {
407+
return Mono.just(Optional.<Folder> empty());
408+
}
409+
return folderService.findById(folderId)
410+
.map(Optional::of)
411+
.onErrorReturn(Optional.empty());
412+
}), TupleUtils::merge)
413+
.zipWith(sessionUserService.getVisitorToken())
414+
.flatMap(tuple -> {
415+
OrgMember orgMember = tuple.getT1().getT1();
416+
Optional<Folder> optional = tuple.getT1().getT2();
417+
Optional<Folder> optionalFrom = tuple.getT1().getT3();
418+
String token = tuple.getT2();
419+
ApplicationCommonEvent event = ApplicationCommonEvent.builder()
420+
.orgId(orgMember.getOrgId())
421+
.userId(orgMember.getUserId())
422+
.applicationId(bundleInfoView.getBundleId())
423+
.applicationGid(bundleInfoView.getBundleGid())
424+
.applicationName(bundleInfoView.getName())
425+
.type(eventType)
426+
.folderId(optional.map(Folder::getId).orElse(null))
427+
.folderName(optional.map(Folder::getName).orElse(null))
428+
.oldFolderId(optionalFrom.map(Folder::getId).orElse(null))
429+
.oldFolderName(optionalFrom.map(Folder::getName).orElse(null))
430+
.isAnonymous(anonymous)
431+
.sessionHash(Hashing.sha512().hashString(token, StandardCharsets.UTF_8).toString())
432+
.build();
433+
return Mono.deferContextual(contextView -> {
434+
event.populateDetails(contextView);
435+
applicationEventPublisher.publishEvent(event);
436+
return Mono.empty();
437+
}).then();
438+
})
439+
.then()
440+
.onErrorResume(throwable -> {
441+
log.error("publishBundleCommonEvent error. {}, {}", bundleInfoView, eventType, throwable);
442+
return Mono.empty();
443+
});
444+
});
445+
}
446+
447+
public Mono<Void> publishBundleCommonEvent(String bundleId, @Nullable String folderIdFrom, @Nullable String folderIdTo, EventType eventType) {
448+
return applicationService.findByIdWithoutDsl(bundleId)
449+
.map(application -> BundleInfoView.builder()
450+
.bundleId(bundleId)
451+
.name(application.getName())
452+
.folderId(folderIdTo)
453+
.folderIdFrom(folderIdFrom)
454+
.build())
455+
.flatMap(bundleInfoView -> publishBundleCommonEvent(bundleInfoView, eventType));
456+
}
457+
385458
public Mono<Void> publishUserLoginEvent(String source) {
386459
return sessionUserService.getVisitorOrgMember().zipWith(sessionUserService.getVisitorToken())
387460
.delayUntil(tuple -> {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy