1
1
package org .lowcoder .api .bundle ;
2
2
3
3
import lombok .RequiredArgsConstructor ;
4
- import org .jetbrains .annotations .NotNull ;
5
4
import org .lowcoder .api .bundle .view .BundleInfoView ;
6
5
import org .lowcoder .api .bundle .view .BundlePermissionView ;
7
6
import org .lowcoder .api .bundle .view .MarketplaceBundleInfoView ;
20
19
import org .springframework .web .bind .annotation .RequestBody ;
21
20
import org .springframework .web .bind .annotation .RequestParam ;
22
21
import org .springframework .web .bind .annotation .RestController ;
23
- import reactor .core .publisher .Flux ;
24
22
import reactor .core .publisher .Mono ;
25
23
26
24
import java .util .List ;
27
25
28
26
import static org .lowcoder .api .util .Pagination .fluxToPageResponseView ;
27
+ import static org .lowcoder .plugin .api .event .LowcoderEvent .EventType .*;
29
28
import static org .lowcoder .sdk .exception .BizError .INVALID_PARAMETER ;
30
29
import static org .lowcoder .sdk .util .ExceptionUtils .ofError ;
31
30
@@ -43,16 +42,31 @@ public class BundleController implements BundleEndpoints
43
42
@ Override
44
43
public Mono <ResponseView <BundleInfoView >> create (@ RequestBody CreateBundleRequest bundle ) {
45
44
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 ))
48
46
.map (ResponseView ::success );
49
47
}
50
48
51
49
@ Override
52
50
public Mono <ResponseView <Void >> delete (@ PathVariable ("id" ) String bundleId ) {
53
51
return gidService .convertBundleIdToObjectId (bundleId ).flatMap (objectId ->
54
52
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 ))
56
70
.then (Mono .fromSupplier (() -> ResponseView .success (null ))));
57
71
}
58
72
@@ -63,11 +77,10 @@ public Mono<ResponseView<Void>> delete(@PathVariable("id") String bundleId) {
63
77
public Mono <ResponseView <BundleInfoView >> update (@ RequestBody Bundle bundle ) {
64
78
return bundleService .findById (bundle .getId ())
65
79
.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
+ })
71
84
.map (tuple2 -> ResponseView .success (tuple2 .getT2 ()));
72
85
}
73
86
@@ -81,15 +94,15 @@ public Mono<ResponseView<BundleInfoView>> publish(@PathVariable String bundleId)
81
94
public Mono <ResponseView <Boolean >> recycle (@ PathVariable String bundleId ) {
82
95
return gidService .convertBundleIdToObjectId (bundleId ).flatMap (objectId ->
83
96
bundleApiService .recycle (objectId )
84
- // .delayUntil(__ -> businessEventPublisher.publishBundleCommonEvent(bundleId, null, BUNDLE_RECYCLED))
97
+ .delayUntil (__ -> businessEventPublisher .publishBundleCommonEvent (bundleId , null , null , BUNDLE_RECYCLED ))
85
98
.map (ResponseView ::success ));
86
99
}
87
100
88
101
@ Override
89
102
public Mono <ResponseView <Boolean >> restore (@ PathVariable String bundleId ) {
90
103
return gidService .convertBundleIdToObjectId (bundleId ).flatMap (objectId ->
91
104
bundleApiService .restore (objectId )
92
- // .delayUntil(__ -> businessEventPublisher.publishBundleCommonEvent(bundleId, null, BUNDLE_RESTORE))
105
+ .delayUntil (__ -> businessEventPublisher .publishBundleCommonEvent (bundleId , null , null , BUNDLE_RESTORE ))
93
106
.map (ResponseView ::success ));
94
107
}
95
108
@@ -120,8 +133,7 @@ public Mono<ResponseView<Void>> moveApp(@PathVariable("id") String applicationId
120
133
gidService .convertBundleIdToObjectId (toBundleId ).flatMap (objectIdTo ->
121
134
gidService .convertApplicationIdToObjectId (applicationId ).flatMap (appId ->
122
135
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 ))
125
137
.then (Mono .fromSupplier (() -> ResponseView .success (null ))))));
126
138
}
127
139
@@ -188,23 +200,23 @@ public Mono<ResponseView<BundlePermissionView>> getBundlePermissions(@PathVariab
188
200
public Mono <ResponseView <BundleInfoView >> getPublishedBundle (@ PathVariable String bundleId ) {
189
201
return gidService .convertBundleIdToObjectId (bundleId ).flatMap (objectId ->
190
202
bundleApiService .getPublishedBundle (objectId , BundleRequestType .PUBLIC_TO_ALL )
191
- // .delayUntil(bundleView -> businessEventPublisher.publishBundleCommonEvent(bundleView, BUNDLE_VIEW))
203
+ .delayUntil (bundleView -> businessEventPublisher .publishBundleCommonEvent (bundleView , BUNDLE_VIEW ))
192
204
.map (ResponseView ::success ));
193
205
}
194
206
195
207
@ Override
196
208
public Mono <ResponseView <BundleInfoView >> getPublishedMarketPlaceBundle (@ PathVariable String bundleId ) {
197
209
return gidService .convertBundleIdToObjectId (bundleId ).flatMap (objectId ->
198
210
bundleApiService .getPublishedBundle (objectId , BundleRequestType .PUBLIC_TO_MARKETPLACE )
199
- // .delayUntil(bundleView -> businessEventPublisher.publishBundleCommonEvent(bundleView, BUNDLE_VIEW))
211
+ .delayUntil (bundleView -> businessEventPublisher .publishBundleCommonEvent (bundleView , BUNDLE_VIEW ))
200
212
.map (ResponseView ::success ));
201
213
}
202
214
203
215
@ Override
204
216
public Mono <ResponseView <BundleInfoView >> getAgencyProfileBundle (@ PathVariable String bundleId ) {
205
217
return gidService .convertBundleIdToObjectId (bundleId ).flatMap (objectId ->
206
218
bundleApiService .getPublishedBundle (objectId , BundleRequestType .AGENCY_PROFILE )
207
- // .delayUntil(bundleView -> businessEventPublisher.publishBundleCommonEvent(bundleView, BUNDLE_VIEW))
219
+ .delayUntil (bundleView -> businessEventPublisher .publishBundleCommonEvent (bundleView , BUNDLE_VIEW ))
208
220
.map (ResponseView ::success ));
209
221
}
210
222
0 commit comments