diff options
Diffstat (limited to 'jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api')
14 files changed, 507 insertions, 0 deletions
diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Capability.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Capability.java new file mode 100644 index 0000000..1359c36 --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Capability.java @@ -0,0 +1,38 @@ +package org.openecomp.sdc.toscaparser.api; + +import static com.google.common.collect.ImmutableList.toImmutableList; + +import java.util.List; +import java.util.Objects; + +import org.openecomp.sdc.toscaparser.jython.JyCapability; + +import com.google.common.base.MoreObjects; + +public class Capability { + + private final JyCapability jyCapability; + + public Capability(JyCapability jyCapability) { + this.jyCapability = Objects.requireNonNull(jyCapability); + } + + public String getName() { + return jyCapability.getJyName(); + } + + public List<Property> getProperties() { + return jyCapability.getJyProperties() + .stream() + .map(Property::new) + .collect(toImmutableList()); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("name", getName()) + .add("properties", getProperties()) + .toString(); + } +} 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 new file mode 100644 index 0000000..a6f9868 --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java @@ -0,0 +1,70 @@ +package org.openecomp.sdc.toscaparser.api; + +import static com.google.common.collect.ImmutableList.toImmutableList; + +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.JyEntityTemplate; + +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; + +public abstract class EntityTemplate { + + private final JyEntityTemplate jyEntityTemplate; + private final StatefulEntityType statefulEntityType; + + public EntityTemplate(JyEntityTemplate jyEntityTemplate) { + this.jyEntityTemplate = Objects.requireNonNull(jyEntityTemplate); + StatefulEntityTypeFactory statefulEntityTypeFactory = new StatefulEntityTypeFactory(); + statefulEntityType = statefulEntityTypeFactory.create(jyEntityTemplate.getJyTypeDefinition()); + } + + public String getName() { + return jyEntityTemplate.getJyName(); + } + + public String getDescription() { + return jyEntityTemplate.getJyDescription(); + } + + public StatefulEntityType getTypeDefinition() { + return statefulEntityType; + } + + public List<Property> getProperties() { + return jyEntityTemplate.getJyProperties() + .stream() + .map(Property::new) + .collect(toImmutableList()); + } + + public List<Capability> getCapabilities() { + return jyEntityTemplate.getJyCapabilities() + .stream() + .map(Capability::new) + .collect(toImmutableList()); + } + + public List<Map<String, Map<String, Object>>> getRequirements() { + return jyEntityTemplate.getJyRequirements(); + } + + protected ToStringHelper toStringHelper() { + return MoreObjects.toStringHelper(this) + .add("name", getName()) + .add("description", getDescription()) + .add("typeDefinition", getTypeDefinition()) + .add("properties", getProperties()) + .add("capabilities", getCapabilities()) + .add("requirements", getRequirements()); + } + + @Override + public String toString() { + return toStringHelper().toString(); + } +} 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 new file mode 100644 index 0000000..65f6857 --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Group.java @@ -0,0 +1,10 @@ +package org.openecomp.sdc.toscaparser.api; + +import org.openecomp.sdc.toscaparser.jython.JyGroup; + +public class Group extends EntityTemplate { + + public Group(JyGroup jyGroup) { + super(jyGroup); + } +} 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 new file mode 100644 index 0000000..047a421 --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java @@ -0,0 +1,10 @@ +package org.openecomp.sdc.toscaparser.api; + +import org.openecomp.sdc.toscaparser.jython.JyNodeTemplate; + +public class NodeTemplate extends EntityTemplate { + + public NodeTemplate(JyNodeTemplate jyNodeTemplate) { + super(jyNodeTemplate); + } +} diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Property.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Property.java new file mode 100644 index 0000000..c52efb6 --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/Property.java @@ -0,0 +1,48 @@ +package org.openecomp.sdc.toscaparser.api; + +import java.util.Objects; + +import org.openecomp.sdc.toscaparser.jython.JyProperty; +import org.openecomp.sdc.toscaparser.utils.PythonUtils; + +import com.google.common.base.MoreObjects; + +public class Property { + + private final JyProperty jyProperty; + + public Property(JyProperty jyProperty) { + this.jyProperty = Objects.requireNonNull(jyProperty); + } + + public String getName() { + return jyProperty.getJyName(); + } + + public Object getValue() { + return PythonUtils.cast(jyProperty.getJyValue(), jyProperty.getJyValueClassName()); + } + + public String getType() { + return jyProperty.getJyType(); + } + + public boolean isRequired() { + return jyProperty.isJyRequired(); + } + + public String getDescription() { + return jyProperty.getJyDescription(); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("name", getName()) + .add("type", getType()) + .add("required", isRequired()) + .add("description", getDescription()) + .add("value", getValue()) + .toString(); + } +} diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/StatefulEntityTypeFactory.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/StatefulEntityTypeFactory.java new file mode 100644 index 0000000..554450a --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/StatefulEntityTypeFactory.java @@ -0,0 +1,28 @@ +package org.openecomp.sdc.toscaparser.api; + +import org.openecomp.sdc.toscaparser.api.elements.GroupType; +import org.openecomp.sdc.toscaparser.api.elements.NodeType; +import org.openecomp.sdc.toscaparser.api.elements.StatefulEntityType; +import org.openecomp.sdc.toscaparser.jython.elements.JyGroupType; +import org.openecomp.sdc.toscaparser.jython.elements.JyNodeType; +import org.openecomp.sdc.toscaparser.jython.elements.JyStatefulEntityType; + +public class StatefulEntityTypeFactory { + + public StatefulEntityType create(JyStatefulEntityType jyStatefulEntityType) { + String jyClassName = jyStatefulEntityType.getJyClassName(); + StatefulEntityType statefulEntityType; + switch (jyClassName) { + case "NodeType": + statefulEntityType = new NodeType((JyNodeType) jyStatefulEntityType); + break; + case "GroupType": + statefulEntityType = new GroupType((JyGroupType) jyStatefulEntityType); + break; + default: + throw new UnsupportedOperationException(jyClassName + " is not supported!"); + } + + return statefulEntityType; + } +}
\ No newline at end of file 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 new file mode 100644 index 0000000..526a0e3 --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java @@ -0,0 +1,48 @@ +package org.openecomp.sdc.toscaparser.api; + +import static com.google.common.collect.ImmutableList.toImmutableList; + +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.JySubstitutionMappings; + +import com.google.common.base.MoreObjects; + +public class SubstitutionMappings { + + private final JySubstitutionMappings jySubstitutionMappings; + + public SubstitutionMappings(JySubstitutionMappings jySubstitutionMappings) { + this.jySubstitutionMappings = Objects.requireNonNull(jySubstitutionMappings); + } + + public List<NodeTemplate> getNodeTemplates() { + return jySubstitutionMappings.getJyNodeTemplates() + .stream() + .map(NodeTemplate::new) + .collect(toImmutableList()); + } + + public List<Input> getInputs() { + return jySubstitutionMappings.getJyInputs() + .stream() + .map(Input::new) + .collect(toImmutableList()); + } + + public NodeType getNodeDefinition() { + return new NodeType(jySubstitutionMappings.getJyNodeDefinition()); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("nodeTemplates", getNodeTemplates()) + .add("inputs", getInputs()) + .add("nodeDefinition", getNodeDefinition()) + .toString(); + } +} 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 new file mode 100644 index 0000000..1769455 --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java @@ -0,0 +1,62 @@ +package org.openecomp.sdc.toscaparser.api; + +import static com.google.common.collect.ImmutableList.toImmutableList; + +import java.util.List; +import java.util.Objects; + +import org.openecomp.sdc.toscaparser.api.parameters.Input; +import org.openecomp.sdc.toscaparser.jython.JySubstitutionMappings; +import org.openecomp.sdc.toscaparser.jython.JyTopologyTemplate; + +import com.google.common.base.MoreObjects; + +public class TopologyTemplate { + + private final JyTopologyTemplate jyTopologyTemplate; + + public TopologyTemplate(JyTopologyTemplate jyTopologyTemplate) { + this.jyTopologyTemplate = Objects.requireNonNull(jyTopologyTemplate); + } + + public String getDescription() { + return jyTopologyTemplate.getJyDescription(); + } + + public List<NodeTemplate> getNodeTemplates() { + return jyTopologyTemplate.getJyNodeTemplates() + .stream() + .map(NodeTemplate::new) + .collect(toImmutableList()); + } + + public List<Input> getInputs() { + return jyTopologyTemplate.getJyInputs() + .stream() + .map(Input::new) + .collect(toImmutableList()); + } + + public List<Group> getGroups() { + return jyTopologyTemplate.getJyGroups() + .stream() + .map(Group::new) + .collect(toImmutableList()); + } + + public SubstitutionMappings getSubstitutionMappings() { + JySubstitutionMappings jySubstitutionMappings = jyTopologyTemplate.getJySubstitutionMappings(); + return jySubstitutionMappings != null ? new SubstitutionMappings(jySubstitutionMappings) : null; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("description", getDescription()) + .add("inputs", getInputs()) + .add("nodeTemplates", getNodeTemplates()) + .add("groups", getGroups()) + .add("substitutionMappings", getSubstitutionMappings()) + .toString(); + } +} 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 new file mode 100644 index 0000000..97563fb --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplate.java @@ -0,0 +1,49 @@ +package org.openecomp.sdc.toscaparser.api; + +import java.util.List; +import java.util.Objects; + +import org.openecomp.sdc.toscaparser.api.parameters.Input; +import org.openecomp.sdc.toscaparser.jython.JyToscaTemplate; + +import com.google.common.base.MoreObjects; + +public class ToscaTemplate { + + private final JyToscaTemplate jyToscaTemplate; + private final TopologyTemplate topologyTemplate; + + public ToscaTemplate(JyToscaTemplate jyToscaTemplate, TopologyTemplate topologyTemplate) { + this.jyToscaTemplate = Objects.requireNonNull(jyToscaTemplate); + this.topologyTemplate = Objects.requireNonNull(topologyTemplate); + } + + public String getVersion() { + return jyToscaTemplate.getJyVersion(); + } + + public String getDescription() { + return jyToscaTemplate.getJyDescription(); + } + + public TopologyTemplate getTopologyTemplate() { + return topologyTemplate; + } + + public List<NodeTemplate> getNodeTemplates() { + return topologyTemplate.getNodeTemplates(); + } + + public List<Input> getInputs() { + return topologyTemplate.getInputs(); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("version", getVersion()) + .add("description", getDescription()) + .add("topologyTemplate", topologyTemplate) + .toString(); + } +}
\ No newline at end of file diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplateFactory.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplateFactory.java new file mode 100644 index 0000000..553c56b --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/ToscaTemplateFactory.java @@ -0,0 +1,14 @@ +package org.openecomp.sdc.toscaparser.api; + +import java.util.Objects; + +import org.openecomp.sdc.toscaparser.jython.JyToscaTemplate; + +public class ToscaTemplateFactory { + + public ToscaTemplate create(JyToscaTemplate jyToscaTemplate) { + Objects.requireNonNull(jyToscaTemplate); + TopologyTemplate topologyTemplate = new TopologyTemplate(jyToscaTemplate.getJyTopologyTemplate()); + return new ToscaTemplate(jyToscaTemplate, topologyTemplate); + } +}
\ No newline at end of file diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/elements/GroupType.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/elements/GroupType.java new file mode 100644 index 0000000..8e0bedf --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/elements/GroupType.java @@ -0,0 +1,30 @@ +package org.openecomp.sdc.toscaparser.api.elements; + +import org.openecomp.sdc.toscaparser.jython.elements.JyGroupType; + +import com.google.common.base.MoreObjects.ToStringHelper; + +public class GroupType extends StatefulEntityType { + + private final JyGroupType jyGroupType; + + public GroupType(JyGroupType jyGroupType) { + super(jyGroupType); + this.jyGroupType = jyGroupType; + } + + public String getVersion() { + return jyGroupType.getJyVersion(); + } + + public String getDescription() { + return jyGroupType.getJyDescription(); + } + + @Override + protected ToStringHelper toStringHelper() { + return super.toStringHelper() + .add("version", getVersion()) + .add("description", getDescription()); + } +} diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/elements/NodeType.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/elements/NodeType.java new file mode 100644 index 0000000..69bd9ba --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/elements/NodeType.java @@ -0,0 +1,27 @@ +package org.openecomp.sdc.toscaparser.api.elements; + +import java.util.List; + +import org.openecomp.sdc.toscaparser.jython.elements.JyNodeType; + +import com.google.common.base.MoreObjects.ToStringHelper; + +public class NodeType extends StatefulEntityType { + + private final JyNodeType jyNodeType; + + public NodeType(JyNodeType jyNodeType) { + super(jyNodeType); + this.jyNodeType = jyNodeType; + } + + public List<?> getRequirements() { + return jyNodeType.getJyRequirements(); + } + + @Override + protected ToStringHelper toStringHelper() { + return super.toStringHelper() + .add("requirements", getRequirements()); + } +} diff --git a/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/elements/StatefulEntityType.java b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/elements/StatefulEntityType.java new file mode 100644 index 0000000..32661b5 --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/elements/StatefulEntityType.java @@ -0,0 +1,31 @@ +package org.openecomp.sdc.toscaparser.api.elements; + +import java.util.Objects; + +import org.openecomp.sdc.toscaparser.jython.elements.JyStatefulEntityType; + +import com.google.common.base.MoreObjects; +import com.google.common.base.MoreObjects.ToStringHelper; + +public abstract class StatefulEntityType { + + private final JyStatefulEntityType jyStatefulEntityType; + + public StatefulEntityType(JyStatefulEntityType jyStatefulEntityType) { + this.jyStatefulEntityType = Objects.requireNonNull(jyStatefulEntityType); + } + + public String getType() { + return jyStatefulEntityType.getJyType(); + } + + protected ToStringHelper toStringHelper() { + return MoreObjects.toStringHelper(this) + .add("type", getType()); + } + + @Override + public String toString() { + return toStringHelper().toString(); + } +} 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 new file mode 100644 index 0000000..b700c47 --- /dev/null +++ b/jython-tosca-parser/src/main/java/org/openecomp/sdc/toscaparser/api/parameters/Input.java @@ -0,0 +1,42 @@ +package org.openecomp.sdc.toscaparser.api.parameters; + +import java.util.Objects; + +import org.openecomp.sdc.toscaparser.jython.parameters.JyInput; + +import com.google.common.base.MoreObjects; + +public class Input { + + private final JyInput jyInput; + + public Input(JyInput jyInput) { + this.jyInput = Objects.requireNonNull(jyInput); + } + + public String getName() { + return jyInput.getJyName(); + } + + public String getType() { + return jyInput.getJyType(); + } + + public boolean isRequired() { + return jyInput.isJyRequired(); + } + + public String getDescription() { + return jyInput.getJyDescription(); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("name", getName()) + .add("type", getType()) + .add("required", isRequired()) + .add("description", getDescription()) + .toString(); + } +} |