diff options
author | Eran (ev672n), Vosk <ev672n@att.com> | 2018-08-06 16:01:12 +0300 |
---|---|---|
committer | Eran (ev672n), Vosk <ev672n@att.com> | 2018-08-06 16:01:12 +0300 |
commit | eaa5b3f6732881ba860ef2ecbf4a97a0973c1352 (patch) | |
tree | 2e7ae8baaf407e554aeee2c2573973ea93bece5a /src | |
parent | 5fa2d09daac160c62e3619a5b017e966950bf2dd (diff) |
Changing the dcae property code
Updating DCAE- property code for Dockerizing the DCAE-CI code
Change-Id: I5cc138ded2a9b82c80758f826e270329bf0e400b
Issue-ID: SDC-1604
Signed-off-by: Eran (ev672n), Vosk <ev672n@att.com>
Diffstat (limited to 'src')
23 files changed, 1021 insertions, 108 deletions
diff --git a/src/main/java/org/onap/sdc/dcae/composition/model/Model.java b/src/main/java/org/onap/sdc/dcae/composition/model/Model.java index 9c24602..adcd1bd 100644 --- a/src/main/java/org/onap/sdc/dcae/composition/model/Model.java +++ b/src/main/java/org/onap/sdc/dcae/composition/model/Model.java @@ -24,7 +24,7 @@ public class Model { private String name; @SerializedName("id") @Expose - private Integer id; + private String id; public String getItemId() { return itemId; @@ -66,11 +66,11 @@ public class Model { this.name = name; } - public Integer getId() { + public String getId() { return id; } - public void setId(Integer id) { + public void setId(String id) { this.id = id; } diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/canvas/DcaeComponentCatalog.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/canvas/DcaeComponentCatalog.java new file mode 100644 index 0000000..aeb4e6c --- /dev/null +++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/canvas/DcaeComponentCatalog.java @@ -0,0 +1,59 @@ +package org.onap.sdc.dcae.composition.restmodels.canvas; + +import org.onap.sdc.dcae.composition.restmodels.sdc.Resource; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class DcaeComponentCatalog { + + private List<SubCategoryFolder> elements; + + public List<SubCategoryFolder> getElements() { + return elements; + } + + public void setElements(List<SubCategoryFolder> elements) { + this.elements = elements; + } + + public static class SubCategoryFolder { + //TODO name and itemId are assigned identical values consider removing one + private String name; + private String itemId; + private List<Resource> items; + + public String getName() { + return name; + } + + public String getItemId() { + return itemId; + } + + public List<Resource> getItems() { + return items; + } + + public void setName(String name) { + this.name = name; + } + + public void setItemId(String itemId) { + this.itemId = itemId; + } + + public void setItems(List<Resource> items) { + this.items = items; + } + + public SubCategoryFolder(){} + + public SubCategoryFolder(String subcategory, List<Resource> resources) { + this.name = subcategory; + this.itemId = subcategory; + this.items = resources; + } + } +} 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 9732035..b8bfae5 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 @@ -32,9 +32,16 @@ public class ActionDeserializer implements JsonDeserializer<BaseAction> { case LOG_TEXT: return LogTextAction.class; case CLEAR: + case CLEAR_NSF: return UnaryFieldAction.class; case REPLACE_TEXT: return ReplaceTextAction.class; + case HP_METRIC: + return HpMetricAction.class; + case STRING_TRANSFORM: + return StringTransformAction.class; + case TOPO_SEARCH: + return TopoSearchAction.class; default: // 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 6b66195..30d0da4 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,18 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; import java.util.Arrays; public enum ActionTypeEnum { - COPY("copy"), MAP("map"), CONCAT("concat"), DATE_FORMATTER("dateFormatter"), LOG_EVENT("logEvent"), LOG_TEXT("logText"), CLEAR("clear"), REPLACE_TEXT("replaceText"); + COPY("copy"), + MAP("map"), + CONCAT("concat"), + DATE_FORMATTER("dateFormatter"), + LOG_EVENT("logEvent"), + LOG_TEXT("logText"), + CLEAR("clear"), + REPLACE_TEXT("replaceText"), + CLEAR_NSF("clearNSF"), + HP_METRIC("hpMetric"), + STRING_TRANSFORM("stringTransform"), + TOPO_SEARCH("topologySearch"); 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 a27e790..78c66b0 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,6 +1,9 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; +import org.apache.commons.lang3.StringUtils; + import java.util.Collection; +import java.util.Objects; public abstract class BaseAction { @@ -31,4 +34,101 @@ public abstract class BaseAction { public abstract boolean referencesTarget(BaseAction other); public abstract String strippedTarget(); + + @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(id, other.id) && Objects.equals(actionType, other.actionType); + } + + @Override + public int hashCode() { + return Objects.hash(id, actionType); + } + + class FromField { + private String value; + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + FromField(String value){ + setValue(value); + } + + FromField(){} + + private boolean isReference(){ + return StringUtils.isNoneBlank(value) && value.startsWith("${") && value.endsWith("}"); + } + + private String strippedReference() { + return value.substring(2, value.length()-1); + } + + boolean referencesTarget(String target) { + return isReference() && target.equals(strippedReference()); + } + + @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); + } + } + + class UIHashMap { + private String key; + private String value; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (null == obj || getClass() != obj.getClass()) { + return false; + } + UIHashMap other = (UIHashMap) obj; + return Objects.equals(key, other.key) && Objects.equals(value, other.value); + } + + @Override + public int hashCode(){ + return Objects.hash(key, value); + } + + } } diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseCondition.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseCondition.java index 60a9778..dd10b9b 100644 --- a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseCondition.java +++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/BaseCondition.java @@ -1,5 +1,7 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; +import java.util.Objects; + public abstract class BaseCondition { // UI evaluation fields @@ -7,5 +9,44 @@ public abstract class BaseCondition { private String name; private String id; + public String getLevel() { + return level; + } + + public String getName() { + return name; + } + + public String getId() { + return id; + } + + public void setLevel(String level) { + this.level = level; + } + + public void setName(String name) { + this.name = name; + } + + public void setId(String id) { + this.id = id; + } + public abstract boolean referencesTarget(String target); + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (null == obj || getClass() != obj.getClass()) { + return false; + } + BaseCondition other = (BaseCondition) obj; + return Objects.equals(id, other.id) && Objects.equals(level, other.level) && Objects.equals(name, other.name); + } + + @Override + public abstract int hashCode(); } 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 index 58a40ce..bf2b2b7 100644 --- 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 @@ -18,23 +18,26 @@ public class BaseCopyAction extends UnaryFieldAction { } - public String getFromValue() { + public String fromValue() { if(null == getFrom()) { return null; } - return StringUtils.isNoneBlank(getFrom().getValue()) ? getFrom().getValue() : StringUtils.join(getFromValues(), ""); + return StringUtils.isNoneBlank(getFrom().getValue()) ? getFrom().getValue() : StringUtils.join(fromValues(), ""); } - public String getRegexValue() { + public String regexValue() { return getFrom().getRegex(); } + //using 'other != this' rather than '!this.equals(other)' because technically it is possible to have two identical actions that are not the same action + @Override 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())); } + @Override public String strippedTarget() { return target.startsWith("${") && target.endsWith("}") ? target.substring(2, target.length()-1) : target; } @@ -42,7 +45,6 @@ public class BaseCopyAction extends UnaryFieldAction { @Override public boolean equals(Object obj) { return super.equals(obj) && Objects.equals(target, ((BaseCopyAction)obj).target); - } @Override diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/Condition.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/Condition.java index 5f037a6..ea5850d 100644 --- a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/Condition.java +++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/Condition.java @@ -1,13 +1,16 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.stream.Stream; public class Condition extends BaseCondition { protected String left; protected String operator; - protected List<String> right; + protected List<String> right = new ArrayList<>(); + protected boolean emptyIsAssigned; public String getLeft() { return left; @@ -33,6 +36,14 @@ public class Condition extends BaseCondition { this.right = right; } + public boolean isEmptyIsAssigned() { + return emptyIsAssigned; + } + + public void setEmptyIsAssigned(boolean emptyIsAssigned) { + this.emptyIsAssigned = emptyIsAssigned; + } + @Override public boolean referencesTarget(String target) { @@ -42,6 +53,19 @@ public class Condition extends BaseCondition { .anyMatch(target::equals); } + @Override + public boolean equals(Object obj) { + return super.equals(obj) && Objects.equals(left, ((Condition)obj).left) && + Objects.equals(operator, ((Condition)obj).operator) && + Objects.equals(right, ((Condition)obj).right) && + emptyIsAssigned == ((Condition)obj).emptyIsAssigned; + } + + @Override + public int hashCode(){ + return Objects.hash(left, operator, right, emptyIsAssigned); + } + private String strippedReference(String value) { return value.substring(2, value.length()-1); } @@ -50,5 +74,6 @@ public class Condition extends BaseCondition { return value.startsWith("${") && value.endsWith("}"); } + } diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ConditionDeserializer.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ConditionDeserializer.java index b14c3b1..e7757c1 100644 --- a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ConditionDeserializer.java +++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ConditionDeserializer.java @@ -7,11 +7,12 @@ import java.lang.reflect.Type; public class ConditionDeserializer implements JsonDeserializer<BaseCondition> { @Override - public BaseCondition deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + public BaseCondition deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { Type clazz = Condition.class; JsonElement type = json.getAsJsonObject().get("type"); - if(null != type && !type.isJsonNull()) + if(null != type && !type.isJsonNull()) { clazz = ConditionGroup.class; + } return context.deserialize(json, clazz); } } diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ConditionGroup.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ConditionGroup.java index c8ddc9d..cf132ef 100644 --- a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ConditionGroup.java +++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/ConditionGroup.java @@ -1,6 +1,7 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; import java.util.List; +import java.util.Objects; public class ConditionGroup extends BaseCondition { @@ -28,4 +29,15 @@ public class ConditionGroup extends BaseCondition { return children.stream().anyMatch(c -> c.referencesTarget(target)); } + @Override + public boolean equals(Object obj) { + return super.equals(obj) && Objects.equals(type, ((ConditionGroup)obj).type) && + Objects.equals(children, ((ConditionGroup)obj).children); + } + + @Override + public int hashCode(){ + return Objects.hash(type, children); + } + } 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 d6900f9..b291862 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,5 +1,7 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; +import java.util.Objects; + public class DateFormatterAction extends BaseCopyAction { private DateFormatter dateFormatter = new DateFormatter(); @@ -12,7 +14,7 @@ public class DateFormatterAction extends BaseCopyAction { this.dateFormatter = dateFormatter; } - private class DateFormatter{ + private class DateFormatter { private String fromFormat; private String toFormat; private String fromTimezone; @@ -49,9 +51,26 @@ public class DateFormatterAction extends BaseCopyAction { public void setToTimezone(String toTimezone) { this.toTimezone = toTimezone; } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (null == obj || getClass() != obj.getClass()) { + return false; + } + DateFormatter other = (DateFormatter) obj; + return Objects.equals(fromFormat, other.fromFormat) && Objects.equals(fromTimezone, other.fromTimezone) && Objects.equals(toFormat, other.toFormat) && Objects.equals(toTimezone, other.toTimezone); + } + + @Override + public int hashCode(){ + return Objects.hash(fromFormat, fromTimezone, toFormat, toTimezone); + } } - public String getFromFormat() { + public String fromFormat() { return dateFormatter.fromFormat; } @@ -59,7 +78,7 @@ public class DateFormatterAction extends BaseCopyAction { this.dateFormatter.fromFormat = fromFormat; } - public String getToFormat() { + public String toFormat() { return dateFormatter.toFormat; } @@ -67,7 +86,7 @@ public class DateFormatterAction extends BaseCopyAction { this.dateFormatter.toFormat = toFormat; } - public String getFromTz() { + public String fromTz() { return dateFormatter.fromTimezone; } @@ -75,11 +94,21 @@ public class DateFormatterAction extends BaseCopyAction { this.dateFormatter.fromTimezone = fromTz; } - public String getToTz() { + public String toTz() { return dateFormatter.toTimezone; } public void setToTz(String toTz) { this.dateFormatter.toTimezone = toTz; } + + @Override + public boolean equals(Object obj) { + return super.equals(obj) && Objects.equals(dateFormatter, ((DateFormatterAction)obj).dateFormatter); + } + + @Override + public int hashCode(){ + return Objects.hash(dateFormatter); + } } diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/HpMetricAction.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/HpMetricAction.java new file mode 100644 index 0000000..f8b2513 --- /dev/null +++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/HpMetricAction.java @@ -0,0 +1,32 @@ +package org.onap.sdc.dcae.composition.restmodels.ruleeditor; + +import java.util.Objects; + +public class HpMetricAction extends BaseAction { + + private String selectedHpMetric; + + public String getSelectedHpMetric() { + return selectedHpMetric; + } + + public void setSelectedHpMetric(String selectedHpMetric) { + this.selectedHpMetric = selectedHpMetric; + } + + public boolean referencesTarget(BaseAction other){ + return false; + } + + public String strippedTarget(){return "";} + + @Override + public boolean equals(Object obj) { + return super.equals(obj) && Objects.equals(selectedHpMetric, ((HpMetricAction)obj).selectedHpMetric); + } + + @Override + public int hashCode() { + return Objects.hash(selectedHpMetric); + } +} 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 index 49b9ed3..e3ccd44 100644 --- 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 @@ -1,14 +1,34 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; +import java.util.Objects; + public class LogEventAction extends BaseAction { private LogEvent logEvent; private class LogEvent { private String title; + + public String getTitle() { + return title; + } + + @Override + public boolean equals(Object obj) { + return obj == this || !(null == obj || getClass() != obj.getClass()) && title.equals(((LogEvent)obj).title); + } + + @Override + public int hashCode(){ + return Objects.hash(title); + } + } + + public LogEvent getLogEvent() { + return logEvent; } - public String getTitle() { + public String logTitle() { return logEvent.title; } @@ -17,4 +37,14 @@ public class LogEventAction extends BaseAction { } public String strippedTarget(){return "";} + + @Override + public boolean equals(Object obj) { + return super.equals(obj) && Objects.equals(logEvent, ((LogEventAction)obj).logEvent); + } + + @Override + public int hashCode(){ + return Objects.hash(logEvent); + } } 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 index 643bc62..16d2a9a 100644 --- 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 @@ -1,5 +1,6 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; +import java.util.Objects; public class LogTextAction extends BaseAction { @@ -9,17 +10,50 @@ public class LogTextAction extends BaseAction { private String name; private String level; private String text; + + public String getName() { + return name; + } + + public String getLevel() { + return level; + } + + public String getText() { + return text; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (null == obj || getClass() != obj.getClass()) { + return false; + } + LogText other = (LogText) obj; + return Objects.equals(name, other.name) && Objects.equals(level, other.level) && Objects.equals(text, other.text); + } + + @Override + public int hashCode(){ + return Objects.hash(name, level, text); + } } - public String getName() { + public LogText getLogText() { + return logText; + } + + public String logName() { return logText.name; } - public String getLevel() { + public String logLevel() { return logText.level; } - public String getText() { + public String logText() { return logText.text; } @@ -38,4 +72,14 @@ public class LogTextAction extends BaseAction { public String strippedTarget(){return "";} + @Override + public boolean equals(Object obj) { + return super.equals(obj) && Objects.equals(logText, ((LogTextAction)obj).logText); + } + + @Override + public int hashCode(){ + return Objects.hash(logText); + } + } 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 a75eff4..7790737 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 @@ -2,8 +2,10 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.google.gson.annotations.SerializedName; public class MapAction extends BaseCopyAction { @@ -18,6 +20,7 @@ public class MapAction extends BaseCopyAction { this.map = map; } + @JsonIgnore public List<UIHashMap> getMapValues() { return null == map? null : map.values; } @@ -26,6 +29,7 @@ public class MapAction extends BaseCopyAction { return null != map && map.haveDefault; } + @JsonIgnore public String getMapDefaultValue() { return null == map? null : map.defaultValue; } @@ -61,26 +65,22 @@ public class MapAction extends BaseCopyAction { this.values = values; } - } - - private class UIHashMap { - private String key; - private String value; - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - public String getValue() { - return value; + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (null == obj || getClass() != obj.getClass()) { + return false; + } + Transform other = (Transform) obj; + return Objects.equals(defaultValue, other.defaultValue) && Objects.equals(haveDefault, other.haveDefault) && Objects.equals(values, other.values); } - public void setValue(String value) { - this.value = value; + @Override + public int hashCode(){ + return Objects.hash(defaultValue, haveDefault, values); } } @@ -89,4 +89,15 @@ public class MapAction extends BaseCopyAction { return getMap().getValues().stream().collect(Collectors.toMap(UIHashMap::getKey, UIHashMap::getValue)); } + + @Override + public boolean equals(Object obj) { + return super.equals(obj) && Objects.equals(map, ((MapAction) obj).map); + } + + @Override + public int hashCode(){ + return Objects.hash(map); + } + } diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MappingRules.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MappingRules.java index ca24d57..2fc8258 100644 --- a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MappingRules.java +++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MappingRules.java @@ -2,13 +2,38 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; + +import com.fasterxml.jackson.annotation.JsonIgnore; import com.google.gson.Gson; public class MappingRules { + private String version; private String eventType; + //US405978 set notifyOID + private String notifyId; + //US420764 support phases configuration + private String entryPhase; + private String publishPhase; private Map<String, Rule> rules = new LinkedHashMap<>(); + public String getEntryPhase() { + return entryPhase; + } + + public void setEntryPhase(String entryPhase) { + this.entryPhase = entryPhase; + } + + public String getPublishPhase() { + return publishPhase; + } + + public void setPublishPhase(String publishPhase) { + this.publishPhase = publishPhase; + } + public Map<String, Rule> getRules() { return rules; } @@ -33,6 +58,13 @@ public class MappingRules { this.eventType = eventType; } + public String getNotifyId() { + return notifyId; + } + + public void setNotifyId(String notifyId) { + this.notifyId = notifyId; + } public MappingRules(Rule rule) { version = rule.getVersion(); @@ -40,21 +72,27 @@ public class MappingRules { addOrReplaceRule(rule); } + protected MappingRules(){} + public void addOrReplaceRule(Rule rule) { rule.generateUid(); rules.put(rule.getUid(), rule); + //US405978 set notifyOID + notifyId = rule.getNotifyId(); + //US420764 support phases configuration + entryPhase = rule.getEntryPhase(); + publishPhase = rule.getPublishPhase(); } public boolean ruleExists(Rule rule) { return rules.containsKey(rule.getUid()); } - + @JsonIgnore public boolean isEmpty() { return rules.isEmpty(); } - public Rule removeRule(String ruleUid) { return rules.remove(ruleUid); } @@ -67,4 +105,26 @@ public class MappingRules { return new Gson().toJson(this).getBytes(); } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (null == obj || getClass() != obj.getClass()) { + return false; + } + MappingRules other = (MappingRules) obj; + return Objects.equals(version, other.version) && Objects.equals(eventType, other.eventType) && Objects.equals(rules, other.rules) && globalTranslationFieldsEqual(other); + + } + + private boolean globalTranslationFieldsEqual(MappingRules other) { + return Objects.equals(notifyId, other.notifyId) && Objects.equals(entryPhase, other.entryPhase) && Objects.equals(publishPhase, other.publishPhase); + } + + @Override + public int hashCode() { + return Objects.hash(version, notifyId, eventType, rules, entryPhase, publishPhase); + } } diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MappingRulesResponse.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MappingRulesResponse.java new file mode 100644 index 0000000..8087aa3 --- /dev/null +++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/MappingRulesResponse.java @@ -0,0 +1,20 @@ +package org.onap.sdc.dcae.composition.restmodels.ruleeditor; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + +import java.util.List; + +@JsonInclude(Include.NON_NULL) +public class MappingRulesResponse extends MappingRules { + + private List<EventTypeDefinitionUI> schema; + + public List<EventTypeDefinitionUI> getSchema() { + return schema; + } + + public void setSchema(List<EventTypeDefinitionUI> schema) { + this.schema = schema; + } +} 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 index 599a956..5594d73 100644 --- 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 @@ -1,5 +1,7 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; +import java.util.Objects; + public class ReplaceTextAction extends UnaryFieldAction { private ReplaceText replaceText; @@ -7,18 +9,57 @@ public class ReplaceTextAction extends UnaryFieldAction { private class ReplaceText { private String find; private String replace; + + public String getFind() { + return find; + } + + public String getReplace() { + return replace; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (null == obj || getClass() != obj.getClass()) { + return false; + } + ReplaceText other = (ReplaceText) obj; + return Objects.equals(find, other.find) && Objects.equals(replace, other.replace); + } + + @Override + public int hashCode(){ + return Objects.hash(find, replace); + } } - public String getFind() { + public ReplaceText getReplaceText() { + return replaceText; + } + + public String find() { return replaceText.find; } - public String getReplace() { + public String replace() { return replaceText.replace; } - public String getFromValue() { + public String fromValue() { return getFrom().getValue(); } + @Override + public boolean equals(Object obj) { + return super.equals(obj) && Objects.equals(replaceText, ((ReplaceTextAction)obj).replaceText); + } + + @Override + public int hashCode(){ + return Objects.hash(replaceText); + } + } 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 d573657..60e58df 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 @@ -1,5 +1,6 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import org.apache.commons.lang3.StringUtils; @@ -8,15 +9,47 @@ import java.util.*; import java.util.stream.Collectors; public class Rule { + + private static Gson gson = new GsonBuilder().serializeNulls().create(); + private String version; private String eventType; + // US405978 set notifyOID + private String notifyId; private String description; private String uid; - private String phase = "phase_1"; //placeholder + private String phase; private BaseCondition condition; private List<BaseAction> actions; + // US420764 support phases configuration + private String entryPhase; //global translation value + private String publishPhase; //global translation value + // US427299 phase grouping + private String groupId; //rules can be grouped into phase units. the global entry phase calls runPhase on phase_1, phase_1 on phase_2, etc. - private static Gson gson = new GsonBuilder().serializeNulls().create(); + public String getEntryPhase() { + return entryPhase; + } + + public void setEntryPhase(String entryPhase) { + this.entryPhase = entryPhase; + } + + public String getPublishPhase() { + return publishPhase; + } + + public void setPublishPhase(String publishPhase) { + this.publishPhase = publishPhase; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } public String getVersion() { return version; @@ -67,6 +100,14 @@ public class Rule { this.description = description; } + public String getNotifyId() { + return notifyId; + } + + public void setNotifyId(String notifyId) { + this.notifyId = notifyId; + } + public BaseCondition getCondition() { return condition; } @@ -75,9 +116,10 @@ public class Rule { this.condition = condition; } - public void generateUid() { - if(StringUtils.isBlank(uid)) + void generateUid() { + if(StringUtils.isBlank(uid)) { uid = UUID.randomUUID().toString(); + } } public String toJson() { @@ -93,23 +135,40 @@ public class Rule { return false; } Rule other = (Rule) obj; - return Objects.equals(version, other.version) && - Objects.equals(description, other.description) && - Objects.equals(eventType, other.eventType) && - Objects.equals(uid, other.uid) && - Objects.equals(phase, other.phase) && + return globalFieldsEqual(other) && localFieldsEqual(other) && Objects.equals(condition, other.condition) && Objects.equals(actions, other.actions); } + private boolean localFieldsEqual(Rule other) { + return Objects.equals(description, other.description) && Objects.equals(uid, other.uid) && groupFieldsEqual(other); + } + + private boolean globalFieldsEqual(Rule other) { + return Objects.equals(version, other.version) && Objects.equals(eventType, other.eventType) && globalMutableFieldsEqual(other); + } + + private boolean globalMutableFieldsEqual(Rule other) { + return Objects.equals(notifyId, other.notifyId) && Objects.equals(entryPhase, other.entryPhase) && Objects.equals(publishPhase, other.publishPhase); + } + + private boolean groupFieldsEqual(Rule other) { + return Objects.equals(phase, other.phase) && Objects.equals(groupId, other.groupId); + } + @Override public int hashCode(){ - return Objects.hash(this.version,this.description,this.eventType,this.uid,this.phase,this.condition,this.actions); + return Objects.hash(this.version,this.description,this.notifyId,this.eventType,this.uid,this.phase,this.condition,this.actions,this.entryPhase,this.publishPhase,this.groupId); } + public boolean referencesOtherRule(Rule other){ - return other != this && actions.stream().anyMatch(p -> p.hasDependencies(other.actions)) || - isConditionalRule() && other.actions.stream().map(BaseAction::strippedTarget).anyMatch(t -> condition.referencesTarget(t)); + return sameGroupId(other) && (actions.stream().anyMatch(p -> p.hasDependencies(other.actions)) || + isConditionalRule() && other.actions.stream().map(BaseAction::strippedTarget).anyMatch(t -> condition.referencesTarget(t))); + } + + private boolean sameGroupId(Rule other) { + return !equals(other) && Objects.equals(groupId, other.groupId); } @@ -121,7 +180,7 @@ public class Rule { public List<BaseAction> findDependencies(List<Rule> others) { return others.stream() - .filter(r -> r != this) + .filter(r -> !equals(r)) .map(this::findDependencies) .flatMap(List::stream) .collect(Collectors.toList()); @@ -131,6 +190,7 @@ public class Rule { return allRules.stream().anyMatch(this::referencesOtherRule); } + @JsonIgnore public boolean isConditionalRule() { return null != condition; } diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/StringTransformAction.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/StringTransformAction.java new file mode 100644 index 0000000..66db1bd --- /dev/null +++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/StringTransformAction.java @@ -0,0 +1,97 @@ +package org.onap.sdc.dcae.composition.restmodels.ruleeditor; + +import org.apache.commons.lang3.StringUtils; + +import java.util.Arrays; +import java.util.Objects; + +public class StringTransformAction extends BaseCopyAction { + + private StringTransform stringTransform; + + public StringTransform getStringTransform() { + return stringTransform; + } + + public void setStringTransform(StringTransform stringTransform) { + this.stringTransform = stringTransform; + } + + public String startValue() { + return stringTransform.startValue; + } + + public String targetCase() { + return stringTransform.targetCase; + } + + public boolean trim() { + return stringTransform.isTrimString; + } + + private class StringTransform { + + private String startValue; + private String targetCase; + private boolean isTrimString; + + public String getStartValue() { + return startValue; + } + + public void setStartValue(String startValue) { + this.startValue = startValue; + } + + public boolean hasIsTrimString() { + return isTrimString; + } + + public void setIsTrimString(boolean isTrimString) { + this.isTrimString = isTrimString; + } + + public String getTargetCase() { + return targetCase; + } + + public void setTargetCase(String targetCase) { + this.targetCase = targetCase; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (null == obj || getClass() != obj.getClass()) { + return false; + } + StringTransform other = (StringTransform) obj; + return Objects.equals(isTrimString, other.isTrimString) && Objects.equals(startValue, other.startValue) && Objects.equals(targetCase, other.targetCase); + } + + @Override + public int hashCode(){ + return Objects.hash(this.targetCase,this.startValue,this.isTrimString); + } + + } + + @Override + public boolean referencesTarget(BaseAction other) { + // startValue is expected to look something like "${event.otherFields.otherSiteId}${event.otherFields.otherSiteInst}${event.commonEventHeader.sourceName}" + String[] references = StringUtils.substringsBetween(startValue(), "${", "}"); + return null != references && Arrays.asList(references).contains(other.strippedTarget()); + } + + @Override + public boolean equals(Object obj) { + return super.equals(obj) && Objects.equals(stringTransform, ((StringTransformAction)obj).stringTransform); + } + + @Override + public int hashCode(){ + return Objects.hash(this.stringTransform); + } +} diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/TopoSearchAction.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/TopoSearchAction.java new file mode 100644 index 0000000..b2a3960 --- /dev/null +++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/TopoSearchAction.java @@ -0,0 +1,191 @@ +package org.onap.sdc.dcae.composition.restmodels.ruleeditor; + +import org.apache.commons.lang3.StringUtils; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +public class TopoSearchAction extends BaseAction { + + private TopoSearch search; + + private class TopoSearch { + + private String searchField; + private String searchValue; + private Condition searchFilter; + private String radio; + private Enrich enrich; + private List<UIHashMap> updates; + + public String getSearchField() { + return searchField; + } + + public void setSearchField(String searchField) { + this.searchField = searchField; + } + + public String getSearchValue() { + return searchValue; + } + + public void setSearchValue(String searchValue) { + this.searchValue = searchValue; + } + + public Condition getSearchFilter() { + return searchFilter; + } + + public void setSearchFilter(Condition searchFilter) { + this.searchFilter = searchFilter; + } + + public String getRadio() { + return radio; + } + + public void setRadio(String radio) { + this.radio = radio; + } + + public Enrich getEnrich() { + return enrich; + } + + public void setEnrich(Enrich enrich) { + this.enrich = enrich; + } + + public List<UIHashMap> getUpdates() { + return updates; + } + + public void setUpdates(List<UIHashMap> updates) { + this.updates = updates; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (null == obj || getClass() != obj.getClass()) { + return false; + } + TopoSearch other = (TopoSearch) obj; + return searchEquals(other) && Objects.equals(searchFilter, other.searchFilter) && Objects.equals(enrich, other.enrich) && Objects.equals(updates, other.updates); + } + + @Override + public int hashCode() { + return Objects.hash(searchField, searchValue, searchFilter, enrich, radio, updates); + } + + private boolean searchEquals(TopoSearch other) { + return Objects.equals(searchField, other.searchField) && Objects.equals(searchValue, other.searchValue) && Objects.equals(radio, other.radio); + } + } + + private class Enrich { + + private List<FromField> fields; + private String prefix; + + public List<FromField> getFields() { + return fields; + } + + public void setFields(List<FromField> fields) { + this.fields = fields; + } + + public String getPrefix() { + return prefix; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (null == obj || getClass() != obj.getClass()) { + return false; + } + Enrich other = (Enrich) obj; + return Objects.equals(fields, other.fields) && Objects.equals(prefix, other.prefix); + } + + @Override + public int hashCode() { + return Objects.hash(fields, prefix); + } + } + + public String searchField() { + return search.searchField; + } + + public String searchValue() { + return search.searchValue; + } + + public Condition searchFilter() { + return search.searchFilter; + } + + public List<String> enrichFields() { + return search.enrich.fields.stream().map(FromField::getValue).collect(Collectors.toList()); + } + + public String enrichPrefix() { + return search.enrich.prefix; + } + + public List<UIHashMap> updates() { + return search.updates; + } + + public boolean doEnrich() { + return !"updates".equalsIgnoreCase(search.radio); + } + + public boolean conditionalSearch(){ + return null != search.searchFilter; + } + + public Map<String, String> updatesMap() { + return updates().stream().collect(Collectors.toMap(UIHashMap::getKey, UIHashMap::getValue)); + } + + + @Override + public boolean referencesTarget(BaseAction other) { + String strippedTarget = other.strippedTarget(); + String strippedReference = StringUtils.substringBetween(searchValue(), "${", "}"); + return null != strippedReference && strippedReference.equals(strippedTarget) || conditionalSearch() && searchFilter().referencesTarget(strippedTarget); + } + + //TODO enhance to targets plural + @Override + public String strippedTarget() { + return ""; + } + + @Override + public boolean equals(Object obj) { + return super.equals(obj) && Objects.equals(search, ((TopoSearchAction)obj).search); + } + + @Override + public int hashCode() { + return Objects.hash(search); + } +} diff --git a/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/TranslateRequest.java b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/TranslateRequest.java new file mode 100644 index 0000000..b363c6d --- /dev/null +++ b/src/main/java/org/onap/sdc/dcae/composition/restmodels/ruleeditor/TranslateRequest.java @@ -0,0 +1,79 @@ +package org.onap.sdc.dcae.composition.restmodels.ruleeditor; + + +public class TranslateRequest { + + private String vfcmtUuid; + private String dcaeCompLabel; + private String nid; + private String configParam; + private String notifyId; + //US420764 support phases configuration + private String entryPhase; + private String publishPhase; + + + public TranslateRequest(String vfcmtUuid, String dcaeCompLabel, String nid, String configParam, String notifyId) { + this.vfcmtUuid = vfcmtUuid; + this.dcaeCompLabel = dcaeCompLabel; + this.nid = nid; + this.configParam = configParam; + this.notifyId = notifyId; + } + + public String getVfcmtUuid() { + return vfcmtUuid; + } + + public void setVfcmtUuid(String vfcmtUuid) { + this.vfcmtUuid = vfcmtUuid; + } + + public String getDcaeCompLabel() { + return dcaeCompLabel; + } + + public void setDcaeCompLabel(String dcaeCompLabel) { + this.dcaeCompLabel = dcaeCompLabel; + } + + public String getNid() { + return nid; + } + + public void setNid(String nid) { + this.nid = nid; + } + + public String getConfigParam() { + return configParam; + } + + public void setConfigParam(String configParam) { + this.configParam = configParam; + } + + public String getNotifyId() { + return notifyId; + } + + public void setNotifyId(String notifyId) { + this.notifyId = notifyId; + } + + public String getEntryPhase() { + return entryPhase; + } + + public void setEntryPhase(String entryPhase) { + this.entryPhase = entryPhase; + } + + public String getPublishPhase() { + return publishPhase; + } + + public void setPublishPhase(String publishPhase) { + this.publishPhase = publishPhase; + } +} 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 index 17146ec..c13d101 100644 --- 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 @@ -1,6 +1,5 @@ package org.onap.sdc.dcae.composition.restmodels.ruleeditor; -import org.apache.commons.lang3.StringUtils; import org.springframework.util.CollectionUtils; import java.util.ArrayList; @@ -32,46 +31,6 @@ public class UnaryFieldAction extends BaseAction { 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; @@ -119,16 +78,9 @@ public class UnaryFieldAction extends BaseAction { @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); + return super.equals(obj) && Objects.equals(regex, ((From) obj).regex) + && Objects.equals(state, ((From) obj).state) + && Objects.equals(values, ((From) obj).values); } @Override @@ -138,13 +90,13 @@ public class UnaryFieldAction extends BaseAction { } - public List<String> getFromValues() { + public List<String> fromValues() { 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); + return super.equals(obj) && Objects.equals(from, ((UnaryFieldAction)obj).from); } @Override @@ -158,4 +110,13 @@ public class UnaryFieldAction extends BaseAction { } public String strippedTarget(){return "";} + + public String regexState() { + return from.state; + } + + public void regexState(String state) { + from.state = state; + } } + |