Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6cff307

Browse files
Thomasrludomikula
Thomasr
authored andcommitted
Added before/after detail of library query update event
1 parenteefe884 commit6cff307

File tree

4 files changed

+70
-16
lines changed

4 files changed

+70
-16
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class LibraryQueryEvent extends AbstractEvent {
1010
privateStringid;
1111
privateStringname;
1212
privateEventTypeeventType;
13+
privateStringoldName;
1314

1415
@Override
1516
publicEventTypegetEventType() {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
packageorg.lowcoder.infra.event;
2+
3+
importlombok.Getter;
4+
importlombok.experimental.SuperBuilder;
5+
6+
@Getter
7+
@SuperBuilder
8+
publicclassLibraryQueryPublishEventextendsAbstractEvent {
9+
10+
privateStringid;
11+
privateStringoldVersion;
12+
privateStringnewVersion;
13+
privateEventTypeeventType;
14+
15+
@Override
16+
publicEventTypegetEventType() {
17+
returneventType;
18+
}
19+
}

‎server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/query/LibraryQueryController.java

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

33
importjava.util.List;
44

5+
importorg.lowcoder.api.datasource.UpsertDatasourceRequest;
56
importorg.lowcoder.api.framework.view.PageResponseView;
67
importorg.lowcoder.api.framework.view.ResponseView;
78
importorg.lowcoder.api.query.view.LibraryQueryAggregateView;
@@ -11,7 +12,10 @@
1112
importorg.lowcoder.api.query.view.UpsertLibraryQueryRequest;
1213
importorg.lowcoder.api.util.BusinessEventPublisher;
1314
importorg.lowcoder.api.util.GidService;
15+
importorg.lowcoder.domain.datasource.model.Datasource;
1416
importorg.lowcoder.domain.query.model.LibraryQuery;
17+
importorg.lowcoder.domain.query.model.LibraryQueryRecord;
18+
importorg.lowcoder.domain.query.service.LibraryQueryRecordService;
1519
importorg.lowcoder.domain.query.service.LibraryQueryService;
1620
importorg.lowcoder.plugin.api.event.LowcoderEvent.EventType;
1721
importorg.springframework.beans.factory.annotation.Autowired;
@@ -22,8 +26,10 @@
2226

2327
importreactor.core.publisher.Flux;
2428
importreactor.core.publisher.Mono;
29+
importreactor.util.function.Tuple2;
2530

2631
importstaticorg.lowcoder.api.util.Pagination.fluxToPageResponseView;
32+
importstaticorg.lowcoder.plugin.api.event.LowcoderEvent.EventType.DATA_SOURCE_UPDATE;
2733

2834
@RestController
2935
publicclassLibraryQueryControllerimplementsLibraryQueryEndpoints
@@ -37,6 +43,8 @@ public class LibraryQueryController implements LibraryQueryEndpoints
3743
privateBusinessEventPublisherbusinessEventPublisher;
3844
@Autowired
3945
privateGidServicegidService;
46+
@Autowired
47+
privateLibraryQueryRecordServicelibraryQueryRecordService;
4048

4149
@Override
4250
publicMono<ResponseView<List<LibraryQueryAggregateView>>>dropDownList(@RequestParam(required =false,defaultValue ="")Stringname) {
@@ -64,16 +72,20 @@ public Mono<ResponseView<LibraryQueryView>> create(@RequestBody LibraryQuery lib
6472
returnlibraryQueryApiService.create(libraryQuery)
6573
.delayUntil(libraryQueryView ->
6674
businessEventPublisher.publishLibraryQueryEvent(libraryQueryView.id(),libraryQueryView.name(),
67-
EventType.LIBRARY_QUERY_CREATE))
75+
EventType.LIBRARY_QUERY_CREATE,null))
6876
.map(ResponseView::success);
6977
}
7078

7179
@Override
7280
publicMono<ResponseView<Boolean>>update(@PathVariableStringlibraryQueryId,
73-
@RequestBodyUpsertLibraryQueryRequestupsertLibraryQueryRequest) {
81+
@RequestBodyUpsertLibraryQueryRequestrequest) {
7482
returngidService.convertLibraryQueryIdToObjectId(libraryQueryId).flatMap(objectId ->
75-
libraryQueryApiService.update(objectId,upsertLibraryQueryRequest)
76-
.map(ResponseView::success));
83+
libraryQueryService.getById(objectId).flatMap(orgLibraryQuery ->
84+
libraryQueryApiService.update(objectId,request)
85+
.zipWith(libraryQueryService.getById(objectId))
86+
.delayUntil(tuple ->businessEventPublisher.publishLibraryQueryEvent(tuple.getT2().getId(),tuple.getT2().getName(),EventType.LIBRARY_QUERY_UPDATE,orgLibraryQuery.getName()))
87+
.map(Tuple2::getT1)
88+
.map(ResponseView::success)));
7789
}
7890

7991
@Override
@@ -82,18 +94,19 @@ public Mono<ResponseView<Boolean>> delete(@PathVariable String libraryQueryId) {
8294
libraryQueryService.getById(objectId)
8395
.delayUntil(__ ->libraryQueryApiService.delete(objectId))
8496
.delayUntil(libraryQuery ->businessEventPublisher.publishLibraryQueryEvent(libraryQuery.getId(),libraryQuery.getName(),
85-
EventType.LIBRARY_QUERY_DELETE))
97+
EventType.LIBRARY_QUERY_DELETE,libraryQuery.getName()))
8698
.thenReturn(ResponseView.success(true)));
8799
}
88100

89101
@Override
90102
publicMono<ResponseView<LibraryQueryRecordMetaView>>publish(@PathVariableStringlibraryQueryId,
91103
@RequestBodyLibraryQueryPublishRequestlibraryQueryPublishRequest) {
92104
returngidService.convertLibraryQueryIdToObjectId(libraryQueryId).flatMap(objectId ->
93-
libraryQueryApiService.publish(objectId,libraryQueryPublishRequest)
94-
.delayUntil(__ ->libraryQueryService.getById(objectId)
95-
.flatMap(libraryQuery ->businessEventPublisher.publishLibraryQuery(libraryQuery,EventType.LIBRARY_QUERY_PUBLISH)))
96-
.map(ResponseView::success));
105+
libraryQueryRecordService.getLatestRecordByLibraryQueryId(objectId).map(LibraryQueryRecord::getTag).defaultIfEmpty("").flatMap(oldVersion ->
106+
libraryQueryApiService.publish(objectId,libraryQueryPublishRequest)
107+
.delayUntil(__ ->libraryQueryService.getById(objectId)
108+
.flatMap(libraryQuery ->businessEventPublisher.publishLibraryQueryPublishEvent(libraryQueryId,oldVersion.isEmpty()?null:oldVersion,libraryQueryPublishRequest.tag(),EventType.LIBRARY_QUERY_PUBLISH)))
109+
.map(ResponseView::success)));
97110
}
98111

99112
}

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929
importorg.lowcoder.domain.query.model.LibraryQuery;
3030
importorg.lowcoder.domain.user.model.User;
3131
importorg.lowcoder.domain.user.service.UserService;
32-
importorg.lowcoder.infra.event.ApplicationCommonEvent;
33-
importorg.lowcoder.infra.event.FolderCommonEvent;
34-
importorg.lowcoder.infra.event.LibraryQueryEvent;
35-
importorg.lowcoder.infra.event.QueryExecutionEvent;
32+
importorg.lowcoder.infra.event.*;
3633
importorg.lowcoder.infra.event.datasource.DatasourceEvent;
3734
importorg.lowcoder.infra.event.datasource.DatasourcePermissionEvent;
3835
importorg.lowcoder.infra.event.group.GroupCreateEvent;
@@ -766,11 +763,34 @@ public Mono<Void> publishDatasourcePermissionEvent(String datasourceId,
766763
});
767764
}
768765

769-
publicMono<Void>publishLibraryQuery(LibraryQuerylibraryQuery,EventTypeeventType) {
770-
returnpublishLibraryQueryEvent(libraryQuery.getId(),libraryQuery.getName(),eventType);
766+
publicMono<Void>publishLibraryQueryPublishEvent(Stringid,StringoldVersion,StringnewVersion,EventTypeeventType) {
767+
returnsessionUserService.getVisitorOrgMemberCache()
768+
.zipWith(sessionUserService.getVisitorToken())
769+
.flatMap(tuple -> {
770+
LibraryQueryPublishEventevent =LibraryQueryPublishEvent.builder()
771+
.id(id)
772+
.oldVersion(oldVersion)
773+
.newVersion(newVersion)
774+
.eventType(eventType)
775+
.userId(tuple.getT1().getUserId())
776+
.orgId(tuple.getT1().getOrgId())
777+
.isAnonymous(Authentication.isAnonymousUser(tuple.getT1().getUserId()))
778+
.sessionHash(Hashing.sha512().hashString(tuple.getT2(),StandardCharsets.UTF_8).toString())
779+
.build();
780+
returnMono.deferContextual(contextView -> {
781+
event.populateDetails(contextView);
782+
applicationEventPublisher.publishEvent(event);
783+
returnMono.<Void>empty();
784+
});
785+
})
786+
.then()
787+
.onErrorResume(throwable -> {
788+
log.error("publishLibraryQueryPublishEvent error.",throwable);
789+
returnMono.empty();
790+
});
771791
}
772792

773-
publicMono<Void>publishLibraryQueryEvent(Stringid,Stringname,EventTypeeventType) {
793+
publicMono<Void>publishLibraryQueryEvent(Stringid,Stringname,EventTypeeventType,StringoldName) {
774794
returnsessionUserService.getVisitorOrgMemberCache()
775795
.zipWith(sessionUserService.getVisitorToken())
776796
.flatMap(tuple -> {
@@ -779,6 +799,7 @@ public Mono<Void> publishLibraryQueryEvent(String id, String name, EventType eve
779799
.orgId(tuple.getT1().getOrgId())
780800
.id(id)
781801
.name(name)
802+
.oldName(oldName)
782803
.eventType(eventType)
783804
.isAnonymous(Authentication.isAnonymousUser(tuple.getT1().getUserId()))
784805
.sessionHash(Hashing.sha512().hashString(tuple.getT2(),StandardCharsets.UTF_8).toString())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp