summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionDeserializer.java16
-rw-r--r--src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionTypeEnum.java2
-rw-r--r--src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseAction.java184
-rw-r--r--src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseCopyAction.java53
-rw-r--r--src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/DateFormatterAction.java4
-rw-r--r--src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/LogEventAction.java20
-rw-r--r--src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/LogTextAction.java41
-rw-r--r--src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapAction.java4
-rw-r--r--src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ReplaceTextAction.java24
-rw-r--r--src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/Rule.java6
-rw-r--r--src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/UnaryFieldAction.java161
11 files changed, 323 insertions, 192 deletions
diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionDeserializer.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionDeserializer.java
index 84884ee..9732035 100644
--- a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionDeserializer.java
+++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionDeserializer.java
@@ -6,7 +6,7 @@ import java.lang.reflect.Type;
public class ActionDeserializer implements JsonDeserializer<BaseAction> {
@Override
- public BaseAction deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
+ public BaseAction deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
String action;
try {
action = json.getAsJsonObject().get("actionType").getAsString();
@@ -14,8 +14,9 @@ public class ActionDeserializer implements JsonDeserializer<BaseAction> {
throw new JsonParseException("Missing information : action type");
}
ActionTypeEnum actionTypeEnum = ActionTypeEnum.getTypeByName(action);
- if (null == actionTypeEnum)
+ if (null == actionTypeEnum) {
throw new JsonParseException("Undefined action type: " + action);
+ }
Type clazz = getActionClassByActionTypeEnum(actionTypeEnum);
return new Gson().fromJson(json, clazz);
}
@@ -26,8 +27,17 @@ public class ActionDeserializer implements JsonDeserializer<BaseAction> {
return MapAction.class;
case DATE_FORMATTER:
return DateFormatterAction.class;
+ case LOG_EVENT:
+ return LogEventAction.class;
+ case LOG_TEXT:
+ return LogTextAction.class;
+ case CLEAR:
+ return UnaryFieldAction.class;
+ case REPLACE_TEXT:
+ return ReplaceTextAction.class;
default:
- return BaseAction.class;
+ // suitable for copy/regex/concat
+ return BaseCopyAction.class;
}
}
diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionTypeEnum.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionTypeEnum.java
index 4538da5..6b66195 100644
--- a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionTypeEnum.java
+++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ActionTypeEnum.java
@@ -3,7 +3,7 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor;
import java.util.Arrays;
public enum ActionTypeEnum {
- COPY("copy"), MAP("map"), CONCAT("concat"), DATE_FORMATTER("dateFormatter");
+ COPY("copy"), MAP("map"), CONCAT("concat"), DATE_FORMATTER("dateFormatter"), LOG_EVENT("logEvent"), LOG_TEXT("logText"), CLEAR("clear"), REPLACE_TEXT("replaceText");
private String type;
diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseAction.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseAction.java
index ce9db27..a27e790 100644
--- a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseAction.java
+++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseAction.java
@@ -1,23 +1,13 @@
package org.onap.sdc.dcae.composition.restmodels.ruleeditor;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
-import java.util.Objects;
-import java.util.stream.Collectors;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.util.CollectionUtils;
-
-public class BaseAction {
+public abstract class BaseAction {
private String actionType;
- private From from;
- private String target;
// UI generated id
private String id;
-
public String getId() {
return id;
}
@@ -34,179 +24,11 @@ public class BaseAction {
this.actionType = actionType;
}
- public String getTarget() {
- return target;
- }
-
- public void setTarget(String target) {
- this.target = target;
- }
-
- public From getFrom() {
- return from;
- }
-
- public void setFrom(From from) {
- this.from = from;
- }
-
- public void setFrom(String from) {
- this.from = new From(from);
- }
-
- public void setFrom(List<String> from) {
- this.from = new From(from);
- }
-
- public void setFrom(String from, String regex) {
- this.from = new From(from, regex);
- }
-
- protected class FromField {
- private String value;
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- FromField(String value){
- setValue(value);
- }
-
- private FromField(){}
-
- private boolean isReference(){
- return StringUtils.isNoneBlank(value) && value.startsWith("${") && value.endsWith("}");
- }
-
- private String stripedReference() {
- return value.substring(2, value.length()-1);
- }
-
- boolean referencesTarget(String target) {
- return isReference() && target.equals(stripedReference());
- }
-
- @Override
- public boolean equals(Object obj) {
- return obj == this || !(null == obj || getClass() != obj.getClass()) && Objects.equals(value, ((FromField)obj).value);
- }
-
- @Override
- public int hashCode(){
- return Objects.hash(this.value);
- }
- }
-
- protected class From extends FromField {
-
- private String regex;
- // UI state of the regex field
- private String state;
- private List<FromField> values;
-
- public String getRegex() {
- return regex;
- }
-
- public void setRegex(String regex) {
- this.regex = regex;
- }
-
- public String getState() {
- return state;
- }
-
- public void setState(String state) {
- this.state = state;
- }
-
- public List<FromField> getValues() {
- return values;
- }
-
- public void setValues(List<FromField> values) {
- this.values = values;
- }
-
- protected From(String value, String regex){
- super(value);
- setRegex(regex);
- }
-
- protected From(List<String> valuesList) {
- List<FromField> allValues = valuesList.stream().map(FromField::new).collect(Collectors.toList());
- setValues(allValues);
- }
-
- protected From(String value){
- super(value);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
- if (null == obj || getClass() != obj.getClass())
- return false;
- From other = (From) obj;
- return Objects.equals(regex, other.regex)
- && Objects.equals(state, other.state)
- && Objects.equals(values, other.values);
- }
-
- @Override
- public int hashCode(){
- return Objects.hash(this.regex,this.state,this.values);
- }
-
- }
-
public boolean hasDependencies(Collection<BaseAction> allActions) {
return allActions.stream().anyMatch(this::referencesTarget);
}
- public String getFromValue() {
- return null == from ? null: StringUtils.isNoneBlank(from.getValue()) ? from.getValue() : StringUtils.join(getFromValues(), "");
- }
-
- public List<String> getFromValues() {
- return null == from || CollectionUtils.isEmpty(from.values) ? new ArrayList<>() : from.values.stream().map(FromField::getValue).collect(Collectors.toList());
- }
-
- public String getRegexValue() {
- return from.getRegex();
- }
-
- public boolean referencesTarget(BaseAction other) {
- return from.referencesTarget(other.strippedTarget()) ||
- other != this && !CollectionUtils.isEmpty(from.values) && from.values.stream().anyMatch(p -> p.referencesTarget(other.strippedTarget()));
- }
-
- String strippedTarget() {
- return target.startsWith("${") && target.endsWith("}") ? target.substring(2, target.length()-1) : target;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
- if (null == obj || getClass() != obj.getClass())
- return false;
- BaseAction other = (BaseAction) obj;
- return Objects.equals(actionType, other.actionType)
- && Objects.equals(target, other.target)
- && Objects.equals(id, other.id)
- && Objects.equals(from, other.from);
- }
-
- @Override
- public int hashCode(){
- return Objects.hash(this.actionType,this.from,this.id,this.target);
- }
+ public abstract boolean referencesTarget(BaseAction other);
+ public abstract String strippedTarget();
}
diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseCopyAction.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseCopyAction.java
new file mode 100644
index 0000000..58a40ce
--- /dev/null
+++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseCopyAction.java
@@ -0,0 +1,53 @@
+package org.onap.sdc.dcae.composition.restmodels.ruleeditor;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.util.CollectionUtils;
+
+import java.util.Objects;
+
+public class BaseCopyAction extends UnaryFieldAction {
+
+ private String target;
+
+ public String getTarget() {
+ return target;
+ }
+
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+
+ public String getFromValue() {
+ if(null == getFrom()) {
+ return null;
+ }
+ return StringUtils.isNoneBlank(getFrom().getValue()) ? getFrom().getValue() : StringUtils.join(getFromValues(), "");
+ }
+
+
+ public String getRegexValue() {
+ return getFrom().getRegex();
+ }
+
+ public boolean referencesTarget(BaseAction other) {
+ return getFrom().referencesTarget(other.strippedTarget()) ||
+ other != this && !CollectionUtils.isEmpty(getFrom().getValues()) && getFrom().getValues().stream().anyMatch(p -> p.referencesTarget(other.strippedTarget()));
+ }
+
+ public String strippedTarget() {
+ return target.startsWith("${") && target.endsWith("}") ? target.substring(2, target.length()-1) : target;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return super.equals(obj) && Objects.equals(target, ((BaseCopyAction)obj).target);
+
+ }
+
+ @Override
+ public int hashCode(){
+ return Objects.hash(this.target);
+ }
+
+}
diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/DateFormatterAction.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/DateFormatterAction.java
index 6a66a5a..d6900f9 100644
--- a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/DateFormatterAction.java
+++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/DateFormatterAction.java
@@ -1,8 +1,6 @@
package org.onap.sdc.dcae.composition.restmodels.ruleeditor;
-import com.google.gson.annotations.SerializedName;
-
-public class DateFormatterAction extends BaseAction {
+public class DateFormatterAction extends BaseCopyAction {
private DateFormatter dateFormatter = new DateFormatter();
diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/LogEventAction.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/LogEventAction.java
new file mode 100644
index 0000000..49b9ed3
--- /dev/null
+++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/LogEventAction.java
@@ -0,0 +1,20 @@
+package org.onap.sdc.dcae.composition.restmodels.ruleeditor;
+
+public class LogEventAction extends BaseAction {
+
+ private LogEvent logEvent;
+
+ private class LogEvent {
+ private String title;
+ }
+
+ public String getTitle() {
+ return logEvent.title;
+ }
+
+ public boolean referencesTarget(BaseAction other){
+ return false;
+ }
+
+ public String strippedTarget(){return "";}
+}
diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/LogTextAction.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/LogTextAction.java
new file mode 100644
index 0000000..643bc62
--- /dev/null
+++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/LogTextAction.java
@@ -0,0 +1,41 @@
+package org.onap.sdc.dcae.composition.restmodels.ruleeditor;
+
+
+public class LogTextAction extends BaseAction {
+
+ private LogText logText;
+
+ private class LogText {
+ private String name;
+ private String level;
+ private String text;
+ }
+
+ public String getName() {
+ return logText.name;
+ }
+
+ public String getLevel() {
+ return logText.level;
+ }
+
+ public String getText() {
+ return logText.text;
+ }
+
+ public void setLogText(String name, String level, String text) {
+ LogText logTextInput = new LogText();
+ logTextInput.name = name;
+ logTextInput.level = level;
+ logTextInput.text = text;
+ this.logText = logTextInput;
+ }
+
+ //TODO the text field supports ${} notation - should we check if it references another action target?
+ public boolean referencesTarget(BaseAction other){
+ return false;
+ }
+
+ public String strippedTarget(){return "";}
+
+}
diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapAction.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapAction.java
index b7988f4..a75eff4 100644
--- a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapAction.java
+++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MapAction.java
@@ -6,7 +6,7 @@ import java.util.stream.Collectors;
import com.google.gson.annotations.SerializedName;
-public class MapAction extends BaseAction {
+public class MapAction extends BaseCopyAction {
private Transform map;
@@ -85,7 +85,7 @@ public class MapAction extends BaseAction {
}
- public Map<String, String> transformToMap() throws IllegalStateException {
+ public Map<String, String> transformToMap() {
return getMap().getValues().stream().collect(Collectors.toMap(UIHashMap::getKey, UIHashMap::getValue));
}
diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ReplaceTextAction.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ReplaceTextAction.java
new file mode 100644
index 0000000..599a956
--- /dev/null
+++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ReplaceTextAction.java
@@ -0,0 +1,24 @@
+package org.onap.sdc.dcae.composition.restmodels.ruleeditor;
+
+public class ReplaceTextAction extends UnaryFieldAction {
+
+ private ReplaceText replaceText;
+
+ private class ReplaceText {
+ private String find;
+ private String replace;
+ }
+
+ public String getFind() {
+ return replaceText.find;
+ }
+
+ public String getReplace() {
+ return replaceText.replace;
+ }
+
+ public String getFromValue() {
+ return getFrom().getValue();
+ }
+
+}
diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/Rule.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/Rule.java
index b65fdf0..d573657 100644
--- a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/Rule.java
+++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/Rule.java
@@ -86,10 +86,12 @@ public class Rule {
@Override
public boolean equals(Object obj) {
- if (obj == this)
+ if (obj == this) {
return true;
- if (null == obj || getClass() != obj.getClass())
+ }
+ if (null == obj || getClass() != obj.getClass()) {
return false;
+ }
Rule other = (Rule) obj;
return Objects.equals(version, other.version) &&
Objects.equals(description, other.description) &&
diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/UnaryFieldAction.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/UnaryFieldAction.java
new file mode 100644
index 0000000..17146ec
--- /dev/null
+++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/UnaryFieldAction.java
@@ -0,0 +1,161 @@
+package org.onap.sdc.dcae.composition.restmodels.ruleeditor;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+public class UnaryFieldAction extends BaseAction {
+
+ private From from;
+
+ public From getFrom() {
+ return from;
+ }
+
+ public void setFrom(From from) {
+ this.from = from;
+ }
+
+ public void setFrom(String from) {
+ this.from = new From(from);
+ }
+
+ public void setFrom(List<String> from) {
+ this.from = new From(from);
+ }
+
+ public void setFrom(String from, String regex) {
+ this.from = new From(from, regex);
+ }
+
+ protected class FromField {
+ private String value;
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ FromField(String value){
+ setValue(value);
+ }
+
+ private FromField(){}
+
+ private boolean isReference(){
+ return StringUtils.isNoneBlank(value) && value.startsWith("${") && value.endsWith("}");
+ }
+
+ private String stripedReference() {
+ return value.substring(2, value.length()-1);
+ }
+
+ boolean referencesTarget(String target) {
+ return isReference() && target.equals(stripedReference());
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj == this || !(null == obj || getClass() != obj.getClass()) && Objects.equals(value, ((FromField)obj).value);
+ }
+
+ @Override
+ public int hashCode(){
+ return Objects.hash(this.value);
+ }
+ }
+
+ protected class From extends FromField {
+
+ private String regex;
+ // UI state of the regex field
+ private String state;
+ private List<FromField> values;
+
+ public String getRegex() {
+ return regex;
+ }
+
+ public void setRegex(String regex) {
+ this.regex = regex;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public void setState(String state) {
+ this.state = state;
+ }
+
+ public List<FromField> getValues() {
+ return values;
+ }
+
+ public void setValues(List<FromField> values) {
+ this.values = values;
+ }
+
+ protected From(String value, String regex){
+ super(value);
+ setRegex(regex);
+ }
+
+ protected From(List<String> valuesList) {
+ List<FromField> allValues = valuesList.stream().map(FromField::new).collect(Collectors.toList());
+ setValues(allValues);
+ }
+
+ protected From(String value){
+ super(value);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (null == obj || getClass() != obj.getClass()) {
+ return false;
+ }
+ From other = (From) obj;
+ return Objects.equals(regex, other.regex)
+ && Objects.equals(state, other.state)
+ && Objects.equals(values, other.values);
+ }
+
+ @Override
+ public int hashCode(){
+ return Objects.hash(this.regex,this.state,this.values);
+ }
+
+ }
+
+ public List<String> getFromValues() {
+ return null == from || CollectionUtils.isEmpty(from.values) ? new ArrayList<>() : from.values.stream().map(FromField::getValue).collect(Collectors.toList());
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj == this || !(null == obj || getClass() != obj.getClass()) && Objects.equals(from, ((UnaryFieldAction)obj).from);
+ }
+
+ @Override
+ public int hashCode(){
+ return Objects.hash(this.from);
+ }
+
+
+ public boolean referencesTarget(BaseAction other){
+ return false;
+ }
+
+ public String strippedTarget(){return "";}
+}