Skip to content

Commit 1212bd3

Browse files
committed
Make content gen more configurable, fix NPE in DocRefCell
1 parent adab028 commit 1212bd3

File tree

12 files changed

+516
-187
lines changed

12 files changed

+516
-187
lines changed

stroom-config/stroom-config-app/src/test/resources/stroom/config/app/expected.yaml

+8-7
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ appConfig:
9393
- "Assigned"
9494
- "Closed"
9595
autoContentCreation:
96-
additionalGroupSuffix: " (sandbox)"
96+
additionalGroupTemplate: "grp-${accountid}-sandbox"
9797
createAsSubjectId: "Administrators"
9898
createAsType: "GROUP"
99-
destinationExplorerPath: "/Feeds"
99+
destinationExplorerPathTemplate: "/Feeds/${accountid}"
100100
enabled: false
101+
groupTemplate: "grp-${accountid}"
101102
templateMatchFields:
102103
- "accountid"
103104
- "accountname"
@@ -792,16 +793,16 @@ appConfig:
792793
feedNameTemplate: "${accountid}-${component}-${format}-${schema}"
793794
metaTypes:
794795
- "Context"
795-
- "Raw Reference"
796+
- "Detections"
797+
- "Error"
796798
- "Events"
799+
- "Meta Data"
797800
- "Raw Events"
801+
- "Raw Reference"
802+
- "Records"
798803
- "Reference"
799-
- "Error"
800804
- "Test Events"
801805
- "Test Reference"
802-
- "Detections"
803-
- "Meta Data"
804-
- "Records"
805806
receiptPolicyUuid: null
806807
x509CertificateDnHeader: "X-SSL-CLIENT-S-DN"
807808
x509CertificateHeader: "X-SSL-CERT"

stroom-core-client/src/main/java/stroom/data/client/presenter/DocRefCell.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,12 @@ public DocRefCell<T> build() {
379379
if (docRef == null) {
380380
return SafeHtmlUtils.EMPTY_SAFE_HTML;
381381
} else {
382-
return SafeHtmlUtils.fromString(docRef.getDisplayValue(GwtNullSafe.requireNonNullElse(
382+
final String displayValue = docRef.getDisplayValue(GwtNullSafe.requireNonNullElse(
383383
displayType,
384-
displayType)));
384+
DisplayType.AUTO));
385+
return GwtNullSafe.isNonBlankString(displayValue)
386+
? SafeHtmlUtils.fromString(displayValue)
387+
: SafeHtmlUtils.EMPTY_SAFE_HTML;
385388
}
386389
};
387390
}

stroom-core/src/main/java/stroom/core/receive/AutoContentCreationConfig.java

+64-50
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import stroom.meta.api.StandardHeaderArguments;
44
import stroom.security.shared.User;
55
import stroom.util.NullSafe;
6+
import stroom.util.collections.CollectionUtil;
67
import stroom.util.shared.AbstractConfig;
78
import stroom.util.shared.DocPath;
89
import stroom.util.shared.IsStroomConfig;
@@ -18,27 +19,28 @@
1819
import jakarta.validation.constraints.NotBlank;
1920
import jakarta.validation.constraints.NotNull;
2021

21-
import java.util.Collections;
2222
import java.util.HashSet;
2323
import java.util.Set;
24-
import java.util.TreeSet;
25-
import java.util.stream.Collectors;
2624

2725

2826
@JsonPropertyOrder(alphabetic = true)
2927
public class AutoContentCreationConfig
3028
extends AbstractConfig
3129
implements IsStroomConfig {
3230

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";
3535

3636
@JsonProperty
3737
private final boolean enabled;
3838
@JsonProperty
39-
private final String destinationExplorerPath;
39+
private final String destinationExplorerPathTemplate;
4040
@JsonProperty
41-
private final String additionalGroupSuffix;
41+
private final String groupTemplate;
42+
@JsonProperty
43+
private final String additionalGroupTemplate;
4244
@JsonProperty
4345
private final String createAsSubjectId;
4446
@JsonProperty
@@ -48,45 +50,51 @@ public class AutoContentCreationConfig
4850

4951
public AutoContentCreationConfig() {
5052
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)
5256
.toString();
53-
additionalGroupSuffix = " (sandbox)";
57+
groupTemplate = DEFAULT_GROUP_TEMPLATE;
58+
additionalGroupTemplate = DEFAULT_ADDITIONAL_GROUP_TEMPLATE;
5459
createAsSubjectId = User.ADMINISTRATORS_GROUP_SUBJECT_ID;
5560
createAsType = UserType.GROUP;
5661
// TreeSet to ensure consistent order in the serialised json
5762
// Make all lower case as expression matching is case-sense on field name and we
5863
// can't be sure what case is used in the receipt headers.
59-
templateMatchFields = normaliseFields(Set.of(
64+
templateMatchFields = CollectionUtil.asUnmodifiabledConsistentOrderSet(normaliseFields(Set.of(
6065
StandardHeaderArguments.FEED,
6166
StandardHeaderArguments.ACCOUNT_ID,
6267
StandardHeaderArguments.ACCOUNT_NAME,
6368
StandardHeaderArguments.COMPONENT,
6469
StandardHeaderArguments.FORMAT,
6570
StandardHeaderArguments.SCHEMA,
66-
StandardHeaderArguments.SCHEMA_VERSION));
71+
StandardHeaderArguments.SCHEMA_VERSION)));
6772
}
6873

6974
@JsonCreator
7075
public AutoContentCreationConfig(
7176
@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,
7480
@JsonProperty("createAsSubjectId") final String createAsSubjectId,
7581
@JsonProperty("createAsType") final UserType createAsType,
7682
@JsonProperty("templateMatchFields") final Set<String> templateMatchFields) {
7783

7884
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;
8188
this.createAsSubjectId = createAsSubjectId;
8289
this.createAsType = createAsType;
8390
this.templateMatchFields = normaliseFields(templateMatchFields);
8491
}
8592

8693
private AutoContentCreationConfig(Builder builder) {
8794
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;
9098
this.createAsSubjectId = builder.createAsSubjectId;
9199
this.createAsType = builder.createAsType;
92100
this.templateMatchFields = normaliseFields(builder.templateMatchFields);
@@ -103,24 +111,32 @@ public boolean isEnabled() {
103111

104112
@NotBlank
105113
@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 " +
107115
"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;
111127
}
112128

113129
@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;
119135
}
120136

121137
@NotNull
122138
@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. " +
124140
"This user/group must have the permission to create all content required. It will also be the " +
125141
"'run as' user for created pipeline processor filters.")
126142
public String getCreateAsSubjectId() {
@@ -145,10 +161,10 @@ public Set<String> getTemplateMatchFields() {
145161
@JsonIgnore
146162
@ValidationMethod(message = "destinationPath must be an absolute path.")
147163
public boolean isDestinationPathValid() {
148-
if (destinationExplorerPath == null) {
164+
if (destinationExplorerPathTemplate == null) {
149165
return true;
150166
} else {
151-
final DocPath docPath = DocPath.fromParts(destinationExplorerPath);
167+
final DocPath docPath = DocPath.fromParts(destinationExplorerPathTemplate);
152168
return docPath.isAbsolute();
153169
}
154170
}
@@ -160,25 +176,16 @@ public static Builder builder() {
160176
public Builder copy() {
161177
return new Builder()
162178
.enabled(enabled)
163-
.destinationPath(destinationExplorerPath)
164-
.additionalGroupSuffix(additionalGroupSuffix)
179+
.destinationPathTemplate(destinationExplorerPathTemplate)
180+
.groupTemplate(groupTemplate)
181+
.additionalGroupTemplate(additionalGroupTemplate)
165182
.createAsSubjectId(createAsSubjectId)
166183
.createAsType(createAsType)
167184
.templateMatchFields(templateMatchFields);
168185
}
169186

170187
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());
182189
}
183190

184191

@@ -188,8 +195,9 @@ private static Set<String> normaliseFields(final Set<String> fields) {
188195
public static class Builder {
189196

190197
private boolean enabled;
191-
private String destinationPath;
192-
private String additionalGroupSuffix;
198+
private String destinationExplorerPathTemplate;
199+
private String groupTemplate;
200+
private String additionalGroupTemplate;
193201
private String createAsSubjectId;
194202
private UserType createAsType;
195203
private Set<String> templateMatchFields;
@@ -199,13 +207,18 @@ public Builder enabled(boolean enabled) {
199207
return this;
200208
}
201209

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;
204217
return this;
205218
}
206219

207-
public Builder additionalGroupSuffix(String additionalGroupSuffix) {
208-
this.additionalGroupSuffix = additionalGroupSuffix;
220+
public Builder additionalGroupTemplate(String additionalGroupSuffix) {
221+
this.additionalGroupTemplate = additionalGroupSuffix;
209222
return this;
210223
}
211224

@@ -235,8 +248,9 @@ public Builder addTemplateMatchFields(String templateMatchField) {
235248
public Builder copy() {
236249
return new Builder()
237250
.enabled(this.enabled)
238-
.destinationPath(this.destinationPath)
239-
.additionalGroupSuffix(this.additionalGroupSuffix)
251+
.destinationPathTemplate(this.destinationExplorerPathTemplate)
252+
.groupTemplate(this.groupTemplate)
253+
.additionalGroupTemplate(this.additionalGroupTemplate)
240254
.createAsSubjectId(this.createAsSubjectId)
241255
.createAsType(this.createAsType)
242256
.templateMatchFields(this.templateMatchFields);

0 commit comments

Comments
 (0)