3
3
import stroom .meta .api .StandardHeaderArguments ;
4
4
import stroom .security .shared .User ;
5
5
import stroom .util .NullSafe ;
6
+ import stroom .util .collections .CollectionUtil ;
6
7
import stroom .util .shared .AbstractConfig ;
7
8
import stroom .util .shared .DocPath ;
8
9
import stroom .util .shared .IsStroomConfig ;
18
19
import jakarta .validation .constraints .NotBlank ;
19
20
import jakarta .validation .constraints .NotNull ;
20
21
21
- import java .util .Collections ;
22
22
import java .util .HashSet ;
23
23
import java .util .Set ;
24
- import java .util .TreeSet ;
25
- import java .util .stream .Collectors ;
26
24
27
25
28
26
@ JsonPropertyOrder (alphabetic = true )
29
27
public class AutoContentCreationConfig
30
28
extends AbstractConfig
31
29
implements IsStroomConfig {
32
30
33
- public static final String DEFAULT_DESTINATION_PATH_PART = "Feeds" ;
34
- public static final String DEFAULT_TEMPLATES_PATH_PART = "Content Templates" ;
31
+ public static final String DEFAULT_DESTINATION_BASE_PART = "Feeds" ;
32
+ public static final String DEFAULT_DESTINATION_SUB_DIR_PART = "${accountid}" ;
33
+ public static final String DEFAULT_GROUP_TEMPLATE = "grp-${accountid}" ;
34
+ public static final String DEFAULT_ADDITIONAL_GROUP_TEMPLATE = "grp-${accountid}-sandbox" ;
35
35
36
36
@ JsonProperty
37
37
private final boolean enabled ;
38
38
@ JsonProperty
39
- private final String destinationExplorerPath ;
39
+ private final String destinationExplorerPathTemplate ;
40
40
@ JsonProperty
41
- private final String additionalGroupSuffix ;
41
+ private final String groupTemplate ;
42
+ @ JsonProperty
43
+ private final String additionalGroupTemplate ;
42
44
@ JsonProperty
43
45
private final String createAsSubjectId ;
44
46
@ JsonProperty
@@ -48,45 +50,51 @@ public class AutoContentCreationConfig
48
50
49
51
public AutoContentCreationConfig () {
50
52
enabled = false ;
51
- destinationExplorerPath = DocPath .fromParts (DEFAULT_DESTINATION_PATH_PART )
53
+ destinationExplorerPathTemplate = DocPath .fromParts (
54
+ DEFAULT_DESTINATION_BASE_PART ,
55
+ DEFAULT_DESTINATION_SUB_DIR_PART )
52
56
.toString ();
53
- additionalGroupSuffix = " (sandbox)" ;
57
+ groupTemplate = DEFAULT_GROUP_TEMPLATE ;
58
+ additionalGroupTemplate = DEFAULT_ADDITIONAL_GROUP_TEMPLATE ;
54
59
createAsSubjectId = User .ADMINISTRATORS_GROUP_SUBJECT_ID ;
55
60
createAsType = UserType .GROUP ;
56
61
// TreeSet to ensure consistent order in the serialised json
57
62
// Make all lower case as expression matching is case-sense on field name and we
58
63
// can't be sure what case is used in the receipt headers.
59
- templateMatchFields = normaliseFields (Set .of (
64
+ templateMatchFields = CollectionUtil . asUnmodifiabledConsistentOrderSet ( normaliseFields (Set .of (
60
65
StandardHeaderArguments .FEED ,
61
66
StandardHeaderArguments .ACCOUNT_ID ,
62
67
StandardHeaderArguments .ACCOUNT_NAME ,
63
68
StandardHeaderArguments .COMPONENT ,
64
69
StandardHeaderArguments .FORMAT ,
65
70
StandardHeaderArguments .SCHEMA ,
66
- StandardHeaderArguments .SCHEMA_VERSION ));
71
+ StandardHeaderArguments .SCHEMA_VERSION ))) ;
67
72
}
68
73
69
74
@ JsonCreator
70
75
public AutoContentCreationConfig (
71
76
@ JsonProperty ("enabled" ) final boolean enabled ,
72
- @ JsonProperty ("destinationExplorerPath" ) final String destinationExplorerPath ,
73
- @ JsonProperty ("additionalGroupSuffix" ) final String additionalGroupSuffix ,
77
+ @ JsonProperty ("destinationExplorerPathTemplate" ) final String destinationExplorerPathTemplate ,
78
+ @ JsonProperty ("groupTemplate" ) final String groupTemplate ,
79
+ @ JsonProperty ("additionalGroupTemplate" ) final String additionalGroupTemplate ,
74
80
@ JsonProperty ("createAsSubjectId" ) final String createAsSubjectId ,
75
81
@ JsonProperty ("createAsType" ) final UserType createAsType ,
76
82
@ JsonProperty ("templateMatchFields" ) final Set <String > templateMatchFields ) {
77
83
78
84
this .enabled = enabled ;
79
- this .destinationExplorerPath = destinationExplorerPath ;
80
- this .additionalGroupSuffix = additionalGroupSuffix ;
85
+ this .destinationExplorerPathTemplate = destinationExplorerPathTemplate ;
86
+ this .groupTemplate = NullSafe .nonBlankStringElse (groupTemplate , DEFAULT_GROUP_TEMPLATE );
87
+ this .additionalGroupTemplate = additionalGroupTemplate ;
81
88
this .createAsSubjectId = createAsSubjectId ;
82
89
this .createAsType = createAsType ;
83
90
this .templateMatchFields = normaliseFields (templateMatchFields );
84
91
}
85
92
86
93
private AutoContentCreationConfig (Builder builder ) {
87
94
this .enabled = builder .enabled ;
88
- this .destinationExplorerPath = builder .destinationPath ;
89
- this .additionalGroupSuffix = builder .additionalGroupSuffix ;
95
+ this .destinationExplorerPathTemplate = builder .destinationExplorerPathTemplate ;
96
+ this .groupTemplate = builder .groupTemplate ;
97
+ this .additionalGroupTemplate = builder .additionalGroupTemplate ;
90
98
this .createAsSubjectId = builder .createAsSubjectId ;
91
99
this .createAsType = builder .createAsType ;
92
100
this .templateMatchFields = normaliseFields (builder .templateMatchFields );
@@ -103,24 +111,32 @@ public boolean isEnabled() {
103
111
104
112
@ NotBlank
105
113
@ JsonPropertyDescription (
106
- "The path to a folder in the Stroom explorer tree where Stroom will auto-create " +
114
+ "The templated path to a folder in the Stroom explorer tree where Stroom will auto-create " +
107
115
"content. If it doesn't exist it will be created. Content will be created in a sub-folder of this " +
108
- "folder with a name derived from the system name of the received data." )
109
- public String getDestinationExplorerPath () {
110
- return destinationExplorerPath ;
116
+ "folder with a name derived from the system name of the received data. By default this is " +
117
+ "'Feeds/${accountid}'." )
118
+ public String getDestinationExplorerPathTemplate () {
119
+ return destinationExplorerPathTemplate ;
120
+ }
121
+
122
+ @ JsonPropertyDescription (
123
+ "When Stroom auto-creates a feed, it will create a user group with a " +
124
+ "name derived from this template. Default value is 'grp-${accountid}'." )
125
+ public String getGroupTemplate () {
126
+ return groupTemplate ;
111
127
}
112
128
113
129
@ JsonPropertyDescription (
114
- "If set, when Stroom auto-creates a feed, it will create an addition user group with " +
115
- "name '<system name><additionalGroupSuffix>' . This is in addition to creating a user group " +
116
- "called '<system name>'. If not set, only the latter user group will be created." )
117
- public String getAdditionalGroupSuffix () {
118
- return additionalGroupSuffix ;
130
+ "If set, when Stroom auto-creates a feed, it will create an additional user group with a " +
131
+ "name derived from this template . This is in addition to the user group defined by 'groupTemplate'. " +
132
+ "If not set, only the latter user group will be created. Default value is 'grp-${accountid}-sandbox' ." )
133
+ public String getAdditionalGroupTemplate () {
134
+ return additionalGroupTemplate ;
119
135
}
120
136
121
137
@ NotNull
122
138
@ JsonPropertyDescription (
123
- "The subjectId of the user/group who will be the owner of any auto-created content. " +
139
+ "The subjectId of the user/group who the auto-created content will be created by . " +
124
140
"This user/group must have the permission to create all content required. It will also be the " +
125
141
"'run as' user for created pipeline processor filters." )
126
142
public String getCreateAsSubjectId () {
@@ -145,10 +161,10 @@ public Set<String> getTemplateMatchFields() {
145
161
@ JsonIgnore
146
162
@ ValidationMethod (message = "destinationPath must be an absolute path." )
147
163
public boolean isDestinationPathValid () {
148
- if (destinationExplorerPath == null ) {
164
+ if (destinationExplorerPathTemplate == null ) {
149
165
return true ;
150
166
} else {
151
- final DocPath docPath = DocPath .fromParts (destinationExplorerPath );
167
+ final DocPath docPath = DocPath .fromParts (destinationExplorerPathTemplate );
152
168
return docPath .isAbsolute ();
153
169
}
154
170
}
@@ -160,25 +176,16 @@ public static Builder builder() {
160
176
public Builder copy () {
161
177
return new Builder ()
162
178
.enabled (enabled )
163
- .destinationPath (destinationExplorerPath )
164
- .additionalGroupSuffix (additionalGroupSuffix )
179
+ .destinationPathTemplate (destinationExplorerPathTemplate )
180
+ .groupTemplate (groupTemplate )
181
+ .additionalGroupTemplate (additionalGroupTemplate )
165
182
.createAsSubjectId (createAsSubjectId )
166
183
.createAsType (createAsType )
167
184
.templateMatchFields (templateMatchFields );
168
185
}
169
186
170
187
private static Set <String > normaliseFields (final Set <String > fields ) {
171
- // TreeSet to ensure consistent order in the serialised json
172
- // Make all lower case as expression matching is case-sense on field name and we
173
- // can't be sure what case is used in the receipt headers.
174
- if (NullSafe .isEmptyCollection (fields )) {
175
- return Collections .emptySet ();
176
- } else {
177
- return Collections .unmodifiableNavigableSet (NullSafe .stream (fields )
178
- .map (String ::trim )
179
- .map (String ::toLowerCase )
180
- .collect (Collectors .toCollection (TreeSet ::new )));
181
- }
188
+ return CollectionUtil .cleanItems (fields , s -> s .trim ().toLowerCase ());
182
189
}
183
190
184
191
@@ -188,8 +195,9 @@ private static Set<String> normaliseFields(final Set<String> fields) {
188
195
public static class Builder {
189
196
190
197
private boolean enabled ;
191
- private String destinationPath ;
192
- private String additionalGroupSuffix ;
198
+ private String destinationExplorerPathTemplate ;
199
+ private String groupTemplate ;
200
+ private String additionalGroupTemplate ;
193
201
private String createAsSubjectId ;
194
202
private UserType createAsType ;
195
203
private Set <String > templateMatchFields ;
@@ -199,13 +207,18 @@ public Builder enabled(boolean enabled) {
199
207
return this ;
200
208
}
201
209
202
- public Builder destinationPath (String destinationPath ) {
203
- this .destinationPath = destinationPath ;
210
+ public Builder destinationPathTemplate (String destinationPathTemplate ) {
211
+ this .destinationExplorerPathTemplate = destinationPathTemplate ;
212
+ return this ;
213
+ }
214
+
215
+ public Builder groupTemplate (String groupTemplate ) {
216
+ this .groupTemplate = groupTemplate ;
204
217
return this ;
205
218
}
206
219
207
- public Builder additionalGroupSuffix (String additionalGroupSuffix ) {
208
- this .additionalGroupSuffix = additionalGroupSuffix ;
220
+ public Builder additionalGroupTemplate (String additionalGroupSuffix ) {
221
+ this .additionalGroupTemplate = additionalGroupSuffix ;
209
222
return this ;
210
223
}
211
224
@@ -235,8 +248,9 @@ public Builder addTemplateMatchFields(String templateMatchField) {
235
248
public Builder copy () {
236
249
return new Builder ()
237
250
.enabled (this .enabled )
238
- .destinationPath (this .destinationPath )
239
- .additionalGroupSuffix (this .additionalGroupSuffix )
251
+ .destinationPathTemplate (this .destinationExplorerPathTemplate )
252
+ .groupTemplate (this .groupTemplate )
253
+ .additionalGroupTemplate (this .additionalGroupTemplate )
240
254
.createAsSubjectId (this .createAsSubjectId )
241
255
.createAsType (this .createAsType )
242
256
.templateMatchFields (this .templateMatchFields );
0 commit comments