11
11
import lombok .extern .jackson .Jacksonized ;
12
12
import org .apache .commons .collections4 .MapUtils ;
13
13
import org .apache .commons .lang3 .BooleanUtils ;
14
+ import org .lowcoder .domain .application .ApplicationUtil ;
15
+ import org .lowcoder .domain .application .service .ApplicationRecordService ;
14
16
import org .lowcoder .domain .query .model .ApplicationQuery ;
15
17
import org .lowcoder .sdk .exception .BizError ;
16
18
import org .lowcoder .sdk .exception .BizException ;
19
21
import org .springframework .data .annotation .Transient ;
20
22
import org .springframework .data .mongodb .core .mapping .Document ;
21
23
import org .springframework .util .StringUtils ;
24
+ import reactor .core .publisher .Mono ;
22
25
23
26
import java .time .Instant ;
24
27
import java .util .*;
@@ -41,7 +44,6 @@ public class Application extends HasIdAndAuditing {
41
44
private Integer applicationType ;
42
45
private ApplicationStatus applicationStatus ;
43
46
44
- private Map <String , Object > publishedApplicationDSL ;
45
47
private Map <String , Object > editingApplicationDSL ;
46
48
47
49
@ Setter
@@ -63,7 +65,6 @@ public Application(
63
65
@ JsonProperty ("name" ) String name ,
64
66
@ JsonProperty ("applicationType" ) Integer applicationType ,
65
67
@ JsonProperty ("applicationStatus" ) ApplicationStatus applicationStatus ,
66
- @ JsonProperty ("publishedApplicationDSL" ) Map <String , Object > publishedApplicationDSL ,
67
68
@ JsonProperty ("editingApplicationDSL" ) Map <String , Object > editingApplicationDSL ,
68
69
@ JsonProperty ("publicToAll" ) Boolean publicToAll ,
69
70
@ JsonProperty ("publicToMarketplace" ) Boolean publicToMarketplace ,
@@ -76,7 +77,6 @@ public Application(
76
77
this .name = name ;
77
78
this .applicationType = applicationType ;
78
79
this .applicationStatus = applicationStatus ;
79
- this .publishedApplicationDSL = publishedApplicationDSL ;
80
80
this .publicToAll = publicToAll ;
81
81
this .publicToMarketplace = publicToMarketplace ;
82
82
this .agencyProfile = agencyProfile ;
@@ -87,43 +87,28 @@ public Application(
87
87
88
88
@ Transient
89
89
private final Supplier <Set <ApplicationQuery >> editingQueries =
90
- memoize (() -> Optional . ofNullable (editingApplicationDSL )
90
+ memoize (() -> ofNullable (editingApplicationDSL )
91
91
.map (map -> map .get ("queries" ))
92
92
.map (queries -> JsonUtils .fromJsonSet (JsonUtils .toJson (queries ), ApplicationQuery .class ))
93
93
.orElse (Collections .emptySet ()));
94
94
95
- @ Transient
96
- private final Supplier <Set <ApplicationQuery >> liveQueries =
97
- memoize (() -> JsonUtils .fromJsonSet (JsonUtils .toJson (getLiveApplicationDsl ().get ("queries" )), ApplicationQuery .class ));
98
-
99
95
@ Transient
100
96
private final Supplier <Set <String >> editingModules = memoize (() -> getDependentModulesFromDsl (editingApplicationDSL ));
101
97
102
- @ Transient
103
- private final Supplier <Set <String >> liveModules = memoize (() -> getDependentModulesFromDsl (getLiveApplicationDsl ()));
104
-
105
- @ Transient
106
- private final Supplier <Object > liveContainerSize = memoize (() -> {
107
- if (ApplicationType .APPLICATION .getValue () == getApplicationType ()) {
108
- return null ;
109
- }
110
- return getContainerSizeFromDSL (getLiveApplicationDsl ());
111
- });
112
-
113
98
public Set <ApplicationQuery > getEditingQueries () {
114
99
return editingQueries .get ();
115
100
}
116
101
117
- public Set <ApplicationQuery > getLiveQueries () {
118
- return liveQueries . get ();
102
+ public Mono < Set <ApplicationQuery >> getLiveQueries (ApplicationRecordService applicationRecordService ) {
103
+ return getLiveApplicationDsl ( applicationRecordService ). mapNotNull ( liveApplicationDSL -> JsonUtils . fromJsonSet ( JsonUtils . toJson ( liveApplicationDSL . get ("queries" )), ApplicationQuery . class ) );
119
104
}
120
105
121
106
public Set <String > getEditingModules () {
122
107
return editingModules .get ();
123
108
}
124
109
125
- public Set <String > getLiveModules () {
126
- return liveModules . get ( );
110
+ public Mono < Set <String >> getLiveModules (ApplicationRecordService applicationRecordService ) {
111
+ return getLiveApplicationDsl ( applicationRecordService ). map ( ApplicationUtil :: getDependentModulesFromDsl );
127
112
}
128
113
129
114
public boolean isPublicToAll () {
@@ -138,23 +123,25 @@ public boolean agencyProfile() {
138
123
return BooleanUtils .toBooleanDefaultIfNull (agencyProfile , false );
139
124
}
140
125
141
- public ApplicationQuery getQueryByViewModeAndQueryId (boolean isViewMode , String queryId ) {
142
- return ( isViewMode ? getLiveQueries () : getEditingQueries ())
126
+ public Mono < ApplicationQuery > getQueryByViewModeAndQueryId (boolean isViewMode , String queryId , ApplicationRecordService applicationRecordService ) {
127
+ return getLiveQueries ( applicationRecordService ). map ( liveQueries -> ( isViewMode ? liveQueries : getEditingQueries ())
143
128
.stream ()
144
129
.filter (query -> queryId .equals (query .getId ()) || queryId .equals (query .getGid ()))
145
130
.findFirst ()
146
- .orElseThrow (() -> new BizException (BizError .QUERY_NOT_FOUND , "LIBRARY_QUERY_NOT_FOUND" ));
131
+ .orElseThrow (() -> new BizException (BizError .QUERY_NOT_FOUND , "LIBRARY_QUERY_NOT_FOUND" ))) ;
147
132
}
148
133
149
134
/**
150
135
* all published dsl will be kept in a list in the future
151
136
*/
152
137
@ Transient
153
138
@ JsonIgnore
154
- public Map <String , Object > getLiveApplicationDsl () {
155
- var dsl = MapUtils .isEmpty (publishedApplicationDSL ) ? editingApplicationDSL : publishedApplicationDSL ;
156
- if (dsl == null ) dsl = new HashMap <>();
157
- return dsl ;
139
+ public Mono <Map <String , Object >> getLiveApplicationDsl (ApplicationRecordService applicationRecordService ) {
140
+ return applicationRecordService .getLatestRecordByApplicationId (this .getId ()).map (applicationRecord -> {
141
+ Map <String , Object > dsl = applicationRecord == null ? editingApplicationDSL : applicationRecord .getApplicationDSL ();
142
+ if (dsl == null ) dsl = new HashMap <>();
143
+ return dsl ;
144
+ });
158
145
}
159
146
160
147
public String getOrganizationId () {
@@ -193,12 +180,17 @@ public String getCategory() {
193
180
194
181
public Map <String , Object > getEditingApplicationDSLOrNull () {return editingApplicationDSL ; }
195
182
196
- public Object getLiveContainerSize () {
197
- return liveContainerSize .get ();
183
+ public Mono <Object > getLiveContainerSize (ApplicationRecordService applicationRecordService ) {
184
+ return getLiveApplicationDsl (applicationRecordService ).flatMap (dsl -> {
185
+ if (ApplicationType .APPLICATION .getValue () == getApplicationType ()) {
186
+ return Mono .empty ();
187
+ }
188
+ return Mono .just (getContainerSizeFromDSL (dsl ));
189
+ });
198
190
}
199
191
200
- public Map <String , Object > getPublishedApplicationDSL () {
201
- return publishedApplicationDSL ;
192
+ public Mono < Map <String , Object >> getPublishedApplicationDSL (ApplicationRecordService applicationRecordService ) {
193
+ return applicationRecordService . getLatestRecordByApplicationId ( this . getId ()). map ( ApplicationRecord :: getApplicationDSL ) ;
202
194
}
203
195
204
196
}
0 commit comments