This is an automated email from the ASF dual-hosted git repository.
riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new 7905969 [STREAMPIPES-275] Support more static properties in templates
new 32bb1f2 Merge branch 'dev' of github.com:apache/incubator-streampipes
into dev
7905969 is described below
commit 7905969020455caf8204e5f8844deb31ec28ea2b
Author: Dominik Riemer <[email protected]>
AuthorDate: Mon Feb 22 22:21:44 2021 +0100
[STREAMPIPES-275] Support more static properties in templates
---
.../template/PipelineElementTemplateConfig.java | 8 ++
.../template/PipelineElementTemplateHandler.java | 7 +-
.../template/PipelineElementTemplateVisitor.java | 95 ++++++++++++++++------
.../pipeline-element-template-generator.ts | 54 +++++++++++-
4 files changed, 136 insertions(+), 28 deletions(-)
diff --git
a/streampipes-model/src/main/java/org/apache/streampipes/model/template/PipelineElementTemplateConfig.java
b/streampipes-model/src/main/java/org/apache/streampipes/model/template/PipelineElementTemplateConfig.java
index 6354106..3c01bcf 100644
---
a/streampipes-model/src/main/java/org/apache/streampipes/model/template/PipelineElementTemplateConfig.java
+++
b/streampipes-model/src/main/java/org/apache/streampipes/model/template/PipelineElementTemplateConfig.java
@@ -30,9 +30,17 @@ public class PipelineElementTemplateConfig {
this.value = value;
}
+ public static PipelineElementTemplateConfig from(Object value) {
+ return new PipelineElementTemplateConfig(value);
+ }
+
public PipelineElementTemplateConfig() {
}
+ private PipelineElementTemplateConfig(Object value) {
+ this.value = value;
+ }
+
public boolean isEditable() {
return editable;
}
diff --git
a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineElementTemplateHandler.java
b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineElementTemplateHandler.java
index 1f74717..97881fa 100644
---
a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineElementTemplateHandler.java
+++
b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineElementTemplateHandler.java
@@ -20,6 +20,9 @@ package org.apache.streampipes.manager.template;
import org.apache.streampipes.model.base.InvocableStreamPipesEntity;
import org.apache.streampipes.model.template.PipelineElementTemplate;
+import java.util.HashMap;
+import java.util.Map;
+
public abstract class PipelineElementTemplateHandler<T extends
InvocableStreamPipesEntity> {
protected T pipelineElement;
@@ -36,7 +39,9 @@ public abstract class PipelineElementTemplateHandler<T
extends InvocableStreamPi
}
public T applyTemplateOnPipelineElement() {
- PipelineElementTemplateVisitor visitor = new
PipelineElementTemplateVisitor(template);
+ Map<String, Object> configs = new HashMap<>();
+ template.getTemplateConfigs().forEach((key, value) -> configs.put(key,
value.getValue()));
+ PipelineElementTemplateVisitor visitor = new
PipelineElementTemplateVisitor(configs);
pipelineElement.getStaticProperties().forEach(config ->
config.accept(visitor));
if (overwriteNameAndDescription) {
diff --git
a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineElementTemplateVisitor.java
b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineElementTemplateVisitor.java
index 11c9583..1cd97d1 100644
---
a/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineElementTemplateVisitor.java
+++
b/streampipes-pipeline-management/src/main/java/org/apache/streampipes/manager/template/PipelineElementTemplateVisitor.java
@@ -18,18 +18,18 @@
package org.apache.streampipes.manager.template;
import org.apache.streampipes.model.staticproperty.*;
-import org.apache.streampipes.model.template.PipelineElementTemplate;
-import org.apache.streampipes.model.template.PipelineElementTemplateConfig;
+import org.apache.streampipes.model.util.Cloner;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class PipelineElementTemplateVisitor implements StaticPropertyVisitor {
- private Map<String, PipelineElementTemplateConfig> configs;
+ private final Map<String, Object> configs;
- public PipelineElementTemplateVisitor(PipelineElementTemplate template) {
- this.configs = template.getTemplateConfigs();
+ public PipelineElementTemplateVisitor(Map<String, Object> configs) {
+ this.configs = configs;
}
@Override
@@ -44,37 +44,48 @@ public class PipelineElementTemplateVisitor implements
StaticPropertyVisitor {
@Override
public void visit(CodeInputStaticProperty codeInputStaticProperty) {
-
+ if (hasKey(codeInputStaticProperty)) {
+ codeInputStaticProperty.setValue(getAsString(codeInputStaticProperty));
+ }
}
@Override
public void visit(CollectionStaticProperty collectionStaticProperty) {
-
+ if (hasKey(collectionStaticProperty)) {
+ List<Map<String, Object>> values = getAsList(collectionStaticProperty,
"members");
+ collectionStaticProperty.setMembers(new ArrayList<>());
+ values.forEach(v -> {
+ StaticProperty sp = new
Cloner().staticProperty(collectionStaticProperty.getStaticPropertyTemplate());
+ PipelineElementTemplateVisitor visitor = new
PipelineElementTemplateVisitor(v);
+ sp.accept(visitor);
+ collectionStaticProperty.getMembers().add(sp);
+ });
+ }
}
@Override
public void visit(ColorPickerStaticProperty colorPickerStaticProperty) {
if (hasKey(colorPickerStaticProperty)) {
-
colorPickerStaticProperty.setSelectedColor(getStringValue(colorPickerStaticProperty));
+
colorPickerStaticProperty.setSelectedColor(getAsString(colorPickerStaticProperty));
}
}
@Override
public void visit(DomainStaticProperty domainStaticProperty) {
-
+ // TODO - not used anywhere anymore
}
@Override
public void visit(FileStaticProperty fileStaticProperty) {
if (hasKey(fileStaticProperty)) {
- fileStaticProperty.setLocationPath(getStringValue(fileStaticProperty));
+ fileStaticProperty.setLocationPath(getAsString(fileStaticProperty));
}
}
@Override
public void visit(FreeTextStaticProperty freeTextStaticProperty) {
if (hasKey(freeTextStaticProperty)) {
- freeTextStaticProperty.setValue(getStringValue(freeTextStaticProperty));
+ freeTextStaticProperty.setValue(getAsString(freeTextStaticProperty));
}
}
@@ -96,31 +107,51 @@ public class PipelineElementTemplateVisitor implements
StaticPropertyVisitor {
@Override
public void visit(OneOfStaticProperty oneOfStaticProperty) {
if (hasKey(oneOfStaticProperty)) {
- String value = getStringValue(oneOfStaticProperty);
- oneOfStaticProperty.getOptions().forEach(option -> {
- option.setSelected(option.getName().equals(value));
- });
+ String value = getAsString(oneOfStaticProperty);
+ oneOfStaticProperty.getOptions().forEach(option ->
+ option.setSelected(option.getName().equals(value)));
}
}
@Override
public void visit(SecretStaticProperty secretStaticProperty) {
-
+ if (hasKey(secretStaticProperty)) {
+ secretStaticProperty.setEncrypted(true);
+ secretStaticProperty.setValue(getAsString(secretStaticProperty));
+ }
}
@Override
public void visit(StaticPropertyAlternative staticPropertyAlternative) {
-
+ if (hasKey(staticPropertyAlternative)) {
+ Map<String, Object> values = getAsMap(staticPropertyAlternative);
+ StaticProperty property = staticPropertyAlternative.getStaticProperty();
+
staticPropertyAlternative.setSelected(Boolean.parseBoolean(String.valueOf(values.get("selected"))));
+ PipelineElementTemplateVisitor visitor = new
PipelineElementTemplateVisitor(getAsMap(values, "staticProperty"));
+ property.accept(visitor);
+ }
}
@Override
public void visit(StaticPropertyAlternatives staticPropertyAlternatives) {
-
+ if (hasKey(staticPropertyAlternatives)) {
+ Map<String, Object> values = getAsMap(staticPropertyAlternatives,
"alternatives");
+ staticPropertyAlternatives.getAlternatives().forEach((alternative) -> {
+ PipelineElementTemplateVisitor visitor = new
PipelineElementTemplateVisitor(values);
+ alternative.accept(visitor);
+ });
+ }
}
@Override
public void visit(StaticPropertyGroup staticPropertyGroup) {
-
+ if (hasKey(staticPropertyGroup)) {
+ Map<String, Object> values = getAsMap(staticPropertyGroup);
+ staticPropertyGroup.getStaticProperties().forEach((group) -> {
+ PipelineElementTemplateVisitor visitor = new
PipelineElementTemplateVisitor(getAsMap(values, "staticProperties"));
+ group.accept(visitor);
+ });
+ }
}
@Override
@@ -128,15 +159,31 @@ public class PipelineElementTemplateVisitor implements
StaticPropertyVisitor {
}
- private String getStringValue(StaticProperty sp) {
- return String.valueOf(getValue(sp));
- }
-
private Object getValue(StaticProperty sp) {
- return configs.get(sp.getInternalName()).getValue();
+ return ((Map<String, Object>)
configs.get(sp.getInternalName())).get("value");
}
private boolean hasKey(StaticProperty sp) {
return configs.containsKey(sp.getInternalName());
}
+
+ private String getAsString(StaticProperty sp) {
+ return configs.get(sp.getInternalName()).toString();
+ }
+
+ private Map<String, Object> getAsMap(StaticProperty sp) {
+ return (Map<String, Object>) configs.get(sp.getInternalName());
+ }
+
+ private Map<String, Object> getAsMap(StaticProperty sp, String subkey) {
+ return (Map<String, Object>) getAsMap(sp).get(subkey);
+ }
+
+ private Map<String, Object> getAsMap(Map<String, Object> map, String key) {
+ return (Map<String, Object>) map.get(key);
+ }
+
+ private List<Map<String, Object>> getAsList(StaticProperty sp, String key) {
+ return (List<Map<String, Object>>) getAsMap(sp).get(key);
+ }
}
diff --git
a/ui/src/app/editor/components/pipeline-element-template-config/pipeline-element-template-generator.ts
b/ui/src/app/editor/components/pipeline-element-template-config/pipeline-element-template-generator.ts
index f09a834..95dbc3f 100644
---
a/ui/src/app/editor/components/pipeline-element-template-config/pipeline-element-template-generator.ts
+++
b/ui/src/app/editor/components/pipeline-element-template-config/pipeline-element-template-generator.ts
@@ -18,8 +18,15 @@
import {
AnyStaticProperty,
+ CodeInputStaticProperty,
+ CollectionStaticProperty,
ColorPickerStaticProperty,
- FreeTextStaticProperty, OneOfStaticProperty, SecretStaticProperty,
+ FileStaticProperty,
+ FreeTextStaticProperty,
+ OneOfStaticProperty, Pipeline,
+ SecretStaticProperty,
+ StaticPropertyAlternative,
+ StaticPropertyAlternatives, StaticPropertyGroup,
StaticPropertyUnion
} from "../../../core-model/gen/streampipes-model";
@@ -33,13 +40,54 @@ export class PipelineElementTemplateGenerator {
if (this.sp instanceof FreeTextStaticProperty) {
return this.sp.value;
} else if (this.sp instanceof OneOfStaticProperty) {
- return this.sp.options.find(o => o.selected).name;
+ return this.sp.options.find(o => o.selected) ? this.sp.options.find(o =>
o.selected).name : "";
} else if (this.sp instanceof ColorPickerStaticProperty) {
return this.sp.selectedColor;
} else if (this.sp instanceof SecretStaticProperty) {
- return undefined;
+ return {encrypted: this.sp.encrypted, value: this.sp.value};
} else if (this.sp instanceof AnyStaticProperty) {
return this.sp.options.filter(o => o.selected).map(o => o.name);
+ } else if (this.sp instanceof CodeInputStaticProperty) {
+ return this.sp.value;
+ } else if (this.sp instanceof CollectionStaticProperty) {
+ return {
+ members: this.addListEntry(this.sp.members)
+ };
+ } else if (this.sp instanceof FileStaticProperty) {
+ return this.sp.locationPath;
+ } else if (this.sp instanceof StaticPropertyAlternatives) {
+ return {
+ alternatives: this.addNestedEntry(this.sp.alternatives)
+ };
+ } else if (this.sp instanceof StaticPropertyAlternative) {
+ return {
+ selected: this.sp.selected,
+ staticProperty: this.addNestedEntry([this.sp.staticProperty])
+ };
+ } else if (this.sp instanceof StaticPropertyGroup) {
+ return { staticProperties:
this.addNestedEntry(this.sp.staticProperties)};
}
}
+
+ addEntry(sp: StaticPropertyUnion) {
+ let entry = {};
+ entry[sp.internalName] = new
PipelineElementTemplateGenerator(sp).toTemplateValue();
+ return entry;
+ }
+
+ addListEntry(staticProperties: Array<StaticPropertyUnion>) {
+ let values = [];
+ staticProperties.forEach(sp => {
+ values.push(this.addEntry(sp));
+ });
+ return values;
+ }
+
+ addNestedEntry(staticProperties: Array<StaticPropertyUnion>) {
+ let entry = {};
+ staticProperties.forEach(sp => {
+ entry[sp.internalName] = new
PipelineElementTemplateGenerator(sp).toTemplateValue();
+ });
+ return entry;
+ }
}