diff options
author | Michael Lando <ml636r@att.com> | 2017-04-06 16:20:54 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-04-06 16:20:54 +0000 |
commit | 5fedaea41630b553c68b60a6442e703f11ea12f3 (patch) | |
tree | 509b0fa32a70295cf606499262b7ac2884fb9552 /jython-tosca-parser/src/main/java/org | |
parent | 6e74314df1333835c319ed167ff16fba204c5e42 (diff) | |
parent | 9fc2ad8285866c5d45391f9c9f4f49a87a36763a (diff) |
Merge "[SDC-8] implementing the tosca stubs"
Diffstat (limited to 'jython-tosca-parser/src/main/java/org')
14 files changed, 123 insertions, 27 deletions
diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java index a6f9868..5a928e0 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java @@ -2,12 +2,15 @@ package org.openecomp.sdc.toscaparser.api; import static com.google.common.collect.ImmutableList.toImmutableList; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; import org.openecomp.sdc.toscaparser.api.elements.StatefulEntityType; +import org.openecomp.sdc.toscaparser.jython.JyCapability; import org.openecomp.sdc.toscaparser.jython.JyEntityTemplate; +import org.openecomp.sdc.toscaparser.jython.JyProperty; import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects.ToStringHelper; @@ -36,17 +39,19 @@ public abstract class EntityTemplate { } public List<Property> getProperties() { - return jyEntityTemplate.getJyProperties() + List<JyProperty> jyProperties = jyEntityTemplate.getJyProperties(); + return jyProperties != null ? jyProperties .stream() .map(Property::new) - .collect(toImmutableList()); + .collect(toImmutableList()) : new ArrayList<>(); } public List<Capability> getCapabilities() { - return jyEntityTemplate.getJyCapabilities() + List<JyCapability> jyCapabilities = jyEntityTemplate.getJyCapabilities(); + return jyCapabilities != null ? jyCapabilities .stream() .map(Capability::new) - .collect(toImmutableList()); + .collect(toImmutableList()) : new ArrayList<>(); } public List<Map<String, Map<String, Object>>> getRequirements() { diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java index 65f6857..0fa0d9c 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java @@ -1,10 +1,32 @@ package org.openecomp.sdc.toscaparser.api; +import java.util.List; + import org.openecomp.sdc.toscaparser.jython.JyGroup; +import com.google.common.base.MoreObjects.ToStringHelper; + public class Group extends EntityTemplate { + private final JyGroup jyGroup; + public Group(JyGroup jyGroup) { super(jyGroup); + this.jyGroup = jyGroup; + } + + public List<String> getMembers(){ + return jyGroup.getJyMembers(); } + + public Metadata getMetadata(){ + return jyGroup.getJyMetadata() != null ? new Metadata(jyGroup.getJyMetadata()) : null; + } + + @Override + protected ToStringHelper toStringHelper() { + return super.toStringHelper() + .add("members", getMembers()) + .add("metadata", getMetadata()); + } } diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Metadata.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Metadata.java new file mode 100644 index 0000000..4fa3646 --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Metadata.java @@ -0,0 +1,28 @@ +package org.openecomp.sdc.toscaparser.api;
+
+import java.util.Map;
+
+import com.google.common.base.MoreObjects;
+
+public class Metadata {
+
+ private final Map<String, Object> metadataMap;
+
+ public Metadata(Map<String, Object> metadataMap) {
+ this.metadataMap = metadataMap;
+ }
+
+ public String getValue(String key) {
+ return !isEmpty() ? String.valueOf(this.metadataMap.get(key)) : null;
+ }
+
+ private boolean isEmpty() {
+ return this.metadataMap == null || this.metadataMap.size() == 0;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("metadataMap", metadataMap).toString();
+ }
+}
diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java index d8cac9e..3592a69 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java @@ -1,8 +1,7 @@ package org.openecomp.sdc.toscaparser.api; -import java.util.Map; - import org.openecomp.sdc.toscaparser.jython.JyNodeTemplate; +import org.openecomp.sdc.toscaparser.jython.JySubstitutionMappings; import com.google.common.base.MoreObjects.ToStringHelper; @@ -15,13 +14,19 @@ public class NodeTemplate extends EntityTemplate { this.jyNodeTemplate = jyNodeTemplate; } - public Map<String, String> getMetadata() { - return jyNodeTemplate.getJyMetadata(); + public Metadata getMetadata() { + return jyNodeTemplate.getJyMetadata() != null ? new Metadata(jyNodeTemplate.getJyMetadata()) : null; + } + + public SubstitutionMappings getSubstitutionMappings(){ + JySubstitutionMappings jySubstitutionMappings = jyNodeTemplate.getJySubstitutionMappings(); + return jySubstitutionMappings != null ? new SubstitutionMappings(jySubstitutionMappings) : null; } @Override protected ToStringHelper toStringHelper() { return super.toStringHelper() - .add("metadata", getMetadata()); + .add("metadata", getMetadata()) + .add("substitutionMappings", getSubstitutionMappings()); } } diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java index 526a0e3..30de2a8 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java @@ -2,12 +2,15 @@ package org.openecomp.sdc.toscaparser.api; import static com.google.common.collect.ImmutableList.toImmutableList; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import org.openecomp.sdc.toscaparser.api.elements.NodeType; import org.openecomp.sdc.toscaparser.api.parameters.Input; +import org.openecomp.sdc.toscaparser.jython.JyGroup; import org.openecomp.sdc.toscaparser.jython.JySubstitutionMappings; +import org.openecomp.sdc.toscaparser.jython.parameters.JyInput; import com.google.common.base.MoreObjects; @@ -25,12 +28,21 @@ public class SubstitutionMappings { .map(NodeTemplate::new) .collect(toImmutableList()); } + + public List<Group> getGroups() { + List<JyGroup> jyGroups = jySubstitutionMappings.getJyGroups(); + return jyGroups != null ? jyGroups + .stream() + .map(Group::new) + .collect(toImmutableList()) : new ArrayList<>(); + } public List<Input> getInputs() { - return jySubstitutionMappings.getJyInputs() + List<JyInput> jyInputs = jySubstitutionMappings.getJyInputs(); + return jyInputs != null ? jyInputs .stream() .map(Input::new) - .collect(toImmutableList()); + .collect(toImmutableList()) : new ArrayList<>(); } public NodeType getNodeDefinition() { diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java index 5c9db48..0d0dd10 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java @@ -2,13 +2,17 @@ package org.openecomp.sdc.toscaparser.api; import static com.google.common.collect.ImmutableList.toImmutableList; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; import org.openecomp.sdc.toscaparser.api.parameters.Input; +import org.openecomp.sdc.toscaparser.jython.JyGroup; +import org.openecomp.sdc.toscaparser.jython.JyNodeTemplate; import org.openecomp.sdc.toscaparser.jython.JySubstitutionMappings; import org.openecomp.sdc.toscaparser.jython.JyTopologyTemplate; +import org.openecomp.sdc.toscaparser.jython.parameters.JyInput; import com.google.common.base.MoreObjects; @@ -25,24 +29,27 @@ public class TopologyTemplate { } public List<NodeTemplate> getNodeTemplates() { - return jyTopologyTemplate.getJyNodeTemplates() + List<JyNodeTemplate> jyNodeTemplates = jyTopologyTemplate.getJyNodeTemplates(); + return jyNodeTemplates != null ? jyNodeTemplates .stream() .map(NodeTemplate::new) - .collect(toImmutableList()); + .collect(toImmutableList()) : new ArrayList<>(); } public List<Input> getInputs() { - return jyTopologyTemplate.getJyInputs() + List<JyInput> jyInputs = jyTopologyTemplate.getJyInputs(); + return jyInputs != null ? jyInputs .stream() .map(Input::new) - .collect(toImmutableList()); + .collect(toImmutableList()) : new ArrayList<>(); } public List<Group> getGroups() { - return jyTopologyTemplate.getJyGroups() + List<JyGroup> jyGroups = jyTopologyTemplate.getJyGroups(); + return jyGroups != null ? jyGroups .stream() .map(Group::new) - .collect(toImmutableList()); + .collect(toImmutableList()) : new ArrayList<>(); } public SubstitutionMappings getSubstitutionMappings() { @@ -50,7 +57,7 @@ public class TopologyTemplate { return jySubstitutionMappings != null ? new SubstitutionMappings(jySubstitutionMappings) : null; } - public Map<String, String> getMetadata() { + public Metadata getMetadata() { return jyTopologyTemplate.getJyMetadata(); } diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java index abf1b53..0aaafff 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java @@ -23,6 +23,10 @@ public class ToscaTemplate { public String getVersion() { return jyToscaTemplate.getJyVersion(); } + + public Metadata getMetadata() { + return jyToscaTemplate.getJyMetadata() != null ? new Metadata(jyToscaTemplate.getJyMetadata()) : null; + } public String getDescription() { return jyToscaTemplate.getJyDescription(); @@ -37,7 +41,7 @@ public class ToscaTemplate { } public List<TopologyTemplate> getNestedTopologyTemplates() { - return jyToscaTemplate.getNestedTopologyTemplates() + return jyToscaTemplate.getJyNestedTopologyTemplates() .stream() .map(TopologyTemplate::new) .collect(toImmutableList()); @@ -53,6 +57,7 @@ public class ToscaTemplate { .add("version", getVersion()) .add("description", getDescription()) .add("topologyTemplate", topologyTemplate) + .add("nestedTopologyTemplates", getNestedTopologyTemplates()) .toString(); } }
\ No newline at end of file diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java index 0b9ad7d..2339bb4 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java @@ -22,8 +22,6 @@ public class Input { return jyInput.getJyType(); } - - public boolean isRequired() { return jyInput.isJyRequired(); } @@ -31,6 +29,10 @@ public class Input { public String getDescription() { return jyInput.getJyDescription(); } + + public Object getDefault() { + return jyInput.getJyDefault(); + } @Override public String toString() { @@ -39,6 +41,7 @@ public class Input { .add("type", getType()) .add("required", isRequired()) .add("description", getDescription()) + .add("default", getDefault()) .toString(); } } diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyGroup.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyGroup.java index c155dc6..e12a31e 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyGroup.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyGroup.java @@ -1,5 +1,10 @@ package org.openecomp.sdc.toscaparser.jython; -public interface JyGroup extends JyEntityTemplate { +import java.util.List; +import java.util.Map; +public interface JyGroup extends JyEntityTemplate { + + List<String> getJyMembers(); + Map<String, Object> getJyMetadata(); } diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyNodeTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyNodeTemplate.java index a837137..620cc1c 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyNodeTemplate.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyNodeTemplate.java @@ -4,5 +4,6 @@ import java.util.Map; public interface JyNodeTemplate extends JyEntityTemplate { - Map<String, String> getJyMetadata(); + Map<String, Object> getJyMetadata(); + JySubstitutionMappings getJySubstitutionMappings(); } diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JySubstitutionMappings.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JySubstitutionMappings.java index bd95cdc..1130e8c 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JySubstitutionMappings.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JySubstitutionMappings.java @@ -9,5 +9,6 @@ public interface JySubstitutionMappings { List<JyNodeTemplate> getJyNodeTemplates(); List<JyInput> getJyInputs(); + List<JyGroup> getJyGroups(); JyNodeType getJyNodeDefinition(); } diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyTopologyTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyTopologyTemplate.java index 9cdc38b..d16ef5c 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyTopologyTemplate.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyTopologyTemplate.java @@ -1,8 +1,8 @@ package org.openecomp.sdc.toscaparser.jython; import java.util.List; -import java.util.Map; +import org.openecomp.sdc.toscaparser.api.Metadata; import org.openecomp.sdc.toscaparser.jython.parameters.JyInput; public interface JyTopologyTemplate { @@ -12,5 +12,5 @@ public interface JyTopologyTemplate { List<JyInput> getJyInputs(); List<JyGroup> getJyGroups(); JySubstitutionMappings getJySubstitutionMappings(); - Map<String, String> getJyMetadata(); + Metadata getJyMetadata(); } diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyToscaTemplate.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyToscaTemplate.java index 7cba568..a2180c7 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyToscaTemplate.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/JyToscaTemplate.java @@ -1,12 +1,14 @@ package org.openecomp.sdc.toscaparser.jython; import java.util.List; +import java.util.Map; public interface JyToscaTemplate { String getJyVersion(); String getJyDescription(); List<JyNodeTemplate> getJyNodeTemplates(); - List<JyTopologyTemplate> getNestedTopologyTemplates(); + List<JyTopologyTemplate> getJyNestedTopologyTemplates(); JyTopologyTemplate getJyTopologyTemplate(); + Map<String, Object> getJyMetadata(); } diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/parameters/JyInput.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/parameters/JyInput.java index 253805b..c1614ce 100644 --- a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/parameters/JyInput.java +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/jython/parameters/JyInput.java @@ -4,7 +4,7 @@ public interface JyInput { String getJyName(); String getJyType(); - String getJyDefault(); + Object getJyDefault(); boolean isJyRequired(); String getJyDescription(); } |