[SDC-243] jtosca for port mirroring
authorPavel Aharoni <pa0916@att.com>
Mon, 21 Aug 2017 18:28:48 +0000 (21:28 +0300)
committerPavel Aharoni <pa0916@att.com>
Mon, 21 Aug 2017 18:28:48 +0000 (21:28 +0300)
Change-Id: I4218eb219a2c7d5061a52753f285474bdba0b6cf
Signed-off-by: Pavel Aharoni <pa0916@att.com>
14 files changed:
pom.xml
src/main/java/org/openecomp/sdc/toscaparser/api/CapabilityAssignment.java [moved from src/main/java/org/openecomp/sdc/toscaparser/api/Capability.java with 76% similarity]
src/main/java/org/openecomp/sdc/toscaparser/api/CapabilityAssignments.java [new file with mode: 0644]
src/main/java/org/openecomp/sdc/toscaparser/api/EntityTemplate.java
src/main/java/org/openecomp/sdc/toscaparser/api/NodeTemplate.java
src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignment.java [new file with mode: 0644]
src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignments.java [new file with mode: 0644]
src/main/java/org/openecomp/sdc/toscaparser/api/SubstitutionMappings.java
src/main/java/org/openecomp/sdc/toscaparser/api/TopologyTemplate.java
src/main/java/org/openecomp/sdc/toscaparser/api/elements/Metadata.java
src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetAttribute.java
src/main/java/org/openecomp/sdc/toscaparser/api/functions/GetProperty.java
src/main/resources/TOSCA_definition_1_0.yaml
src/main/resources/extensions/nfv/TOSCA_nfv_definition_1_0.yaml

diff --git a/pom.xml b/pom.xml
index 6485d2b..31c6b64 100644 (file)
--- a/pom.xml
+++ b/pom.xml
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
-       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">\r
-       <modelVersion>4.0.0</modelVersion>\r
-\r
-       <groupId>org.openecomp.sdc.jtosca</groupId>\r
-       <artifactId>jtosca</artifactId>\r
-       <version>1.1.3-SNAPSHOT</version>\r
-\r
-       <properties>\r
-\r
-               <!-- ==================== -->\r
-               <!-- Generic properties -->\r
-               <!-- ==================== -->\r
-               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\r
-\r
-               <!-- ==================== -->\r
-               <!-- Versions -->\r
-               <!-- ==================== -->\r
-               <!-- Global project version -->\r
-\r
-               <!-- Dependencies projects version -->\r
-               <sonar.skipDesign>true</sonar.skipDesign>\r
-               <sonar.projectBaseDir>${project.basedir}</sonar.projectBaseDir>\r
-               <sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>\r
-               <nexus.proxy>https://nexus.onap.org</nexus.proxy>\r
-               <sitePath>/content/sites/site/org/openecomp/sdc/jtosca/${project.version}</sitePath>\r
-               <snapshots.path>snapshots</snapshots.path>\r
-               <releases.path>releases</releases.path>\r
-               <!--<staging.profile.id>176c31dfe190a</staging.profile.id> -->\r
-\r
-       </properties>\r
-\r
-       <dependencies>\r
-               <!-- YAML parser -->\r
-               <dependency>\r
-                       <groupId>org.yaml</groupId>\r
-                       <artifactId>snakeyaml</artifactId>\r
-                       <version>1.14</version>\r
-                       <scope>compile</scope>\r
-               </dependency>\r
-\r
-               <dependency>\r
-                       <groupId>org.slf4j</groupId>\r
-                       <artifactId>slf4j-api</artifactId>\r
-                       <version>1.7.25</version>\r
-               </dependency>\r
-\r
-               <!-- <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> \r
-                       <version>1.1.2</version> <scope>test</scope> </dependency> -->\r
-\r
-               <dependency>\r
-                       <groupId>junit</groupId>\r
-                       <artifactId>junit</artifactId>\r
-                       <version>4.12</version>\r
-               </dependency>\r
-       </dependencies>\r
-\r
-       <reporting>\r
-               <plugins>\r
-                       <plugin>\r
-                               <groupId>org.apache.maven.plugins</groupId>\r
-                               <artifactId>maven-javadoc-plugin</artifactId>\r
-                               <version>2.10.4</version>\r
-                               <configuration>\r
-                                       <failOnError>false</failOnError>\r
-                                       <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>\r
-                                       <docletArtifact>\r
-                                               <groupId>org.umlgraph</groupId>\r
-                                               <artifactId>umlgraph</artifactId>\r
-                                               <version>5.6</version>\r
-                                       </docletArtifact>\r
-                                       <additionalparam>-views</additionalparam>\r
-                                       <useStandardDocletOptions>true</useStandardDocletOptions>\r
-                               </configuration>\r
-                       </plugin>\r
-               </plugins>\r
-       </reporting>\r
-\r
-       <build>\r
-               <plugins>\r
-                       <plugin>\r
-                               <groupId>org.apache.maven.plugins</groupId>\r
-                               <artifactId>maven-site-plugin</artifactId>\r
-                               <version>3.4</version>\r
-                               <dependencies>\r
-                                       <dependency>\r
-                                               <groupId>org.apache.maven.wagon</groupId>\r
-                                               <artifactId>wagon-webdav-jackrabbit</artifactId>\r
-                                               <version>2.10</version>\r
-                                       </dependency>\r
-                               </dependencies>\r
-                       </plugin>\r
-\r
-                       <plugin>\r
-                               <groupId>org.jacoco</groupId>\r
-                               <artifactId>jacoco-maven-plugin</artifactId>\r
-                               <version>0.7.8</version>\r
-                               <executions>\r
-                                       <!-- Unit-Tests -->\r
-                                       <execution>\r
-                                               <id>prepare-agent</id>\r
-                                               <goals>\r
-                                                       <goal>prepare-agent</goal>\r
-                                               </goals>\r
-                                               <configuration>\r
-                                                       <destFile>${sonar.jacoco.reportPath}</destFile>\r
-                                               </configuration>\r
-                                       </execution>\r
-                               </executions>\r
-                       </plugin>\r
-\r
-                       <!-- Staging Plugin -->\r
-                       <plugin>\r
-                               <groupId>org.sonatype.plugins</groupId>\r
-                               <artifactId>nexus-staging-maven-plugin</artifactId>\r
-                               <version>1.6.7</version>\r
-                               <extensions>true</extensions>\r
-                               <configuration>\r
-                                       <nexusUrl>${nexus.proxy}</nexusUrl>\r
-                                       <stagingProfileId>${staging.profile.id}</stagingProfileId>\r
-                                       <serverId>ecomp-staging</serverId>\r
-                               </configuration>\r
-                       </plugin>\r
-\r
-                       <plugin>\r
-                               <groupId>org.apache.maven.plugins</groupId>\r
-                               <artifactId>maven-compiler-plugin</artifactId>\r
-                               <version>2.5.1</version>\r
-                               <inherited>true</inherited>\r
-                               <configuration>\r
-                                       <source>1.8</source>\r
-                                       <target>1.8</target>\r
-                               </configuration>\r
-                       </plugin>\r
-                       <plugin>\r
-                               <groupId>org.apache.maven.plugins</groupId>\r
-                               <artifactId>maven-javadoc-plugin</artifactId>\r
-                               <version>2.10.3</version>\r
-                               <configuration />\r
-                       </plugin>\r
-                       <plugin>\r
-                               <groupId>org.codehaus.mojo</groupId>\r
-                               <artifactId>license-maven-plugin</artifactId>\r
-                               <version>1.10</version>\r
-                               <configuration>\r
-                                       <addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>\r
-                                       <processStartTag>============LICENSE_START=======================================================</processStartTag>\r
-                                       <processEndTag>============LICENSE_END=========================================================</processEndTag>\r
-                                       <sectionDelimiter>================================================================================</sectionDelimiter>\r
-                                       <licenseName>apache_v2</licenseName>\r
-                                       <inceptionYear>2017</inceptionYear>\r
-                                       <organizationName>AT&amp;T Intellectual Property. All rights\r
-                                               reserved.</organizationName>\r
-                                       <projectName>jtosca</projectName>\r
-                                       <canUpdateCopyright>true</canUpdateCopyright>\r
-                                       <canUpdateDescription>true</canUpdateDescription>\r
-                                       <canUpdateLicense>true</canUpdateLicense>\r
-                                       <emptyLineAfterHeader>true</emptyLineAfterHeader>\r
-                                       <verbose>false</verbose>\r
-                                       <includes>\r
-                                               <include>**/*.java</include>\r
-                                       </includes>\r
-                               </configuration>\r
-                               <executions>\r
-                                       <execution>\r
-                                               <id>first</id>\r
-                                               <goals>\r
-                                                       <goal>update-file-header</goal>\r
-                                               </goals>\r
-                                               <!--phase>process-sources</phase -->\r
-                                       </execution>\r
-                               </executions>\r
-                       </plugin>\r
-               </plugins>\r
-       </build>\r
-\r
-       <repositories>\r
-               <repository>\r
-                       <id>central</id>\r
-                       <name>Official Maven repository</name>\r
-                       <url>http://repo2.maven.org/maven2/</url>\r
-               </repository>\r
-               <repository>\r
-                       <id>ecomp-releases</id>\r
-                       <name>Release Repository</name>\r
-                       <url>${nexus.proxy}/content/repositories/releases/</url>\r
-               </repository>\r
-               <repository>\r
-                       <id>ecomp-staging</id>\r
-                       <name>Staging Repository</name>\r
-                       <url>${nexus.proxy}/content/repositories/staging/</url>\r
-               </repository>\r
-       </repositories>\r
-\r
-       <distributionManagement>\r
-               <repository>\r
-                       <id>ecomp-releases</id>\r
-                       <name>Release Repository</name>\r
-                       <url>${nexus.proxy}/content/repositories/${releases.path}/</url>\r
-               </repository>\r
-               <snapshotRepository>\r
-                       <id>ecomp-snapshots</id>\r
-                       <name>Snapshot Repository</name>\r
-                       <url>${nexus.proxy}/content/repositories/${snapshots.path}/</url>\r
-               </snapshotRepository>\r
-               <site>\r
-                       <id>ecomp-site</id>\r
-                       <url>dav:${nexus.proxy}${sitePath}</url>\r
-               </site>\r
-       </distributionManagement>\r
-\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+       <modelVersion>4.0.0</modelVersion>
+
+       <groupId>org.openecomp.sdc.jtosca</groupId>
+       <artifactId>jtosca</artifactId>
+       <version>1.1.10-SNAPSHOT</version>
+       <properties>
+
+               <!-- ==================== -->
+               <!-- Generic properties -->
+               <!-- ==================== -->
+               <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+               <!-- ==================== -->
+               <!-- Versions -->
+               <!-- ==================== -->
+               <!-- Global project version -->
+
+               <!-- Dependencies projects version -->
+               <sonar.skipDesign>true</sonar.skipDesign>
+               <sonar.projectBaseDir>${project.basedir}</sonar.projectBaseDir>
+               <sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
+               <nexus.proxy>https://nexus.onap.org</nexus.proxy>
+               <sitePath>/content/sites/site/org/openecomp/sdc/jtosca/${project.version}</sitePath>
+               <snapshots.path>snapshots</snapshots.path>
+               <releases.path>releases</releases.path>
+               <!--<staging.profile.id>176c31dfe190a</staging.profile.id> -->
+
+       </properties>
+
+       <dependencies>
+               <!-- YAML parser -->
+               <dependency>
+                       <groupId>org.yaml</groupId>
+                       <artifactId>snakeyaml</artifactId>
+                       <version>1.14</version>
+                       <scope>compile</scope>
+               </dependency>
+
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-api</artifactId>
+                       <version>1.7.25</version>
+               </dependency>
+
+               <!-- <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> 
+                       <version>1.1.2</version> <scope>test</scope> </dependency> -->
+
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <version>4.12</version>
+               </dependency>
+       </dependencies>
+
+       <reporting>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-javadoc-plugin</artifactId>
+                               <version>2.10.4</version>
+                               <configuration>
+                                       <failOnError>false</failOnError>
+                                       <doclet>org.umlgraph.doclet.UmlGraphDoc</doclet>
+                                       <docletArtifact>
+                                               <groupId>org.umlgraph</groupId>
+                                               <artifactId>umlgraph</artifactId>
+                                               <version>5.6</version>
+                                       </docletArtifact>
+                                       <additionalparam>-views</additionalparam>
+                                       <useStandardDocletOptions>true</useStandardDocletOptions>
+                               </configuration>
+                       </plugin>
+               </plugins>
+       </reporting>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-site-plugin</artifactId>
+                               <version>3.4</version>
+                               <dependencies>
+                                       <dependency>
+                                               <groupId>org.apache.maven.wagon</groupId>
+                                               <artifactId>wagon-webdav-jackrabbit</artifactId>
+                                               <version>2.10</version>
+                                       </dependency>
+                               </dependencies>
+                       </plugin>
+
+                       <plugin>
+                               <groupId>org.jacoco</groupId>
+                               <artifactId>jacoco-maven-plugin</artifactId>
+                               <version>0.7.8</version>
+                               <executions>
+                                       <!-- Unit-Tests -->
+                                       <execution>
+                                               <id>prepare-agent</id>
+                                               <goals>
+                                                       <goal>prepare-agent</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <destFile>${sonar.jacoco.reportPath}</destFile>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
+
+                       <!-- Staging Plugin -->
+                       <plugin>
+                               <groupId>org.sonatype.plugins</groupId>
+                               <artifactId>nexus-staging-maven-plugin</artifactId>
+                               <version>1.6.7</version>
+                               <extensions>true</extensions>
+                               <configuration>
+                                       <nexusUrl>${nexus.proxy}</nexusUrl>
+                                       <stagingProfileId>${staging.profile.id}</stagingProfileId>
+                                       <serverId>ecomp-staging</serverId>
+                               </configuration>
+                       </plugin>
+
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-compiler-plugin</artifactId>
+                               <version>2.5.1</version>
+                               <inherited>true</inherited>
+                               <configuration>
+                                       <source>1.8</source>
+                                       <target>1.8</target>
+                               </configuration>
+                       </plugin>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-javadoc-plugin</artifactId>
+                               <version>2.10.3</version>
+                               <configuration />
+                       </plugin>
+                       <plugin>
+                               <groupId>org.codehaus.mojo</groupId>
+                               <artifactId>license-maven-plugin</artifactId>
+                               <version>1.10</version>
+                               <configuration>
+                                       <addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
+                                       <processStartTag>============LICENSE_START=======================================================</processStartTag>
+                                       <processEndTag>============LICENSE_END=========================================================</processEndTag>
+                                       <sectionDelimiter>================================================================================</sectionDelimiter>
+                                       <licenseName>apache_v2</licenseName>
+                                       <inceptionYear>2017</inceptionYear>
+                                       <organizationName>AT&amp;T Intellectual Property. All rights
+                                               reserved.</organizationName>
+                                       <projectName>jtosca</projectName>
+                                       <canUpdateCopyright>true</canUpdateCopyright>
+                                       <canUpdateDescription>true</canUpdateDescription>
+                                       <canUpdateLicense>true</canUpdateLicense>
+                                       <emptyLineAfterHeader>true</emptyLineAfterHeader>
+                                       <verbose>false</verbose>
+                                       <includes>
+                                               <include>**/*.java</include>
+                                       </includes>
+                               </configuration>
+                               <executions>
+                                       <execution>
+                                               <id>first</id>
+                                               <goals>
+                                                       <goal>update-file-header</goal>
+                                               </goals>
+                                               <!--phase>process-sources</phase -->
+                                       </execution>
+                               </executions>
+                       </plugin>
+               </plugins>
+       </build>
+
+       <repositories>
+               <repository>
+                       <id>central</id>
+                       <name>Official Maven repository</name>
+                       <url>http://repo2.maven.org/maven2/</url>
+               </repository>
+               <repository>
+                       <id>ecomp-releases</id>
+                       <name>Release Repository</name>
+                       <url>${nexus.proxy}/content/repositories/releases/</url>
+               </repository>
+               <repository>
+                       <id>ecomp-staging</id>
+                       <name>Staging Repository</name>
+                       <url>${nexus.proxy}/content/repositories/staging/</url>
+               </repository>
+       </repositories>
+
+       <distributionManagement>
+               <repository>
+                       <id>ecomp-releases</id>
+                       <name>Release Repository</name>
+                       <url>${nexus.proxy}/content/repositories/${releases.path}/</url>
+               </repository>
+               <snapshotRepository>
+                       <id>ecomp-snapshots</id>
+                       <name>Snapshot Repository</name>
+                       <url>${nexus.proxy}/content/repositories/${snapshots.path}/</url>
+               </snapshotRepository>
+               <site>
+                       <id>ecomp-site</id>
+                       <url>dav:${nexus.proxy}${sitePath}</url>
+               </site>
+       </distributionManagement>
+
 </project>
\ No newline at end of file
@@ -7,20 +7,24 @@ import java.util.Map;
 import org.openecomp.sdc.toscaparser.api.elements.CapabilityTypeDef;
 import org.openecomp.sdc.toscaparser.api.elements.PropertyDef;
 
-public class Capability {
+public class CapabilityAssignment {
        
        private String name;
        private LinkedHashMap<String,Object> _properties;
        private CapabilityTypeDef _definition;
 
-       public Capability(String cname, 
-                                         LinkedHashMap<String,Object> cproperties,
-                                        CapabilityTypeDef cdefinition) {
+       public CapabilityAssignment(String cname,
+                                                               LinkedHashMap<String,Object> cproperties,
+                                                               CapabilityTypeDef cdefinition) {
                name = cname;
                _properties = cproperties;
                _definition = cdefinition;
        }
-       
+
+       /**
+        * Get the properties list for capability
+        * @return list of property objects for capability
+        */
        public ArrayList<Property> getPropertiesObjects() {
                // Return a list of property objects
                ArrayList<Property> properties = new ArrayList<Property>();
@@ -41,7 +45,11 @@ public class Capability {
                }
                return properties;
        }
-       
+
+       /**
+        * Get the map of properties
+        * @return map of all properties contains dictionary of property name and property object
+        */
        public LinkedHashMap<String,Property> getProperties() {
         // Return a dictionary of property name-object pairs
                LinkedHashMap<String,Property> npps = new LinkedHashMap<>();
@@ -51,6 +59,11 @@ public class Capability {
                return npps;
        }
 
+       /**
+        * Get the property value by name
+        * @param pname - the property name for capability
+        * @return the property value for this name
+        */
        public Object getPropertyValue(String pname) {
         // Return the value of a given property name
                LinkedHashMap<String,Property> props = getProperties();
@@ -60,22 +73,34 @@ public class Capability {
         return null;
        }
 
+       /**
+        * Get the name for capability
+        * @return the name for capability
+        */
         public String getName() {
                 return name;
         }
-        
+
+       /**
+        * Get the definition for capability
+        * @return CapabilityTypeDef - contain definition for capability
+        */
         public CapabilityTypeDef getDefinition() {
                 return _definition;
         }
-        
-        // setter
+
+       /**
+        * Set the property for capability
+        * @param pname - the property name for capability to set
+        * @param pvalue - the property valiue for capability to set
+        */
         public void setProperty(String pname,Object pvalue) {
                 _properties.put(pname,pvalue);
         }
 
     @Override
     public String toString() {
-        return "Capability{" +
+        return "CapabilityAssignment{" +
                 "name='" + name + '\'' +
                 ", _properties=" + _properties +
                 ", _definition=" + _definition +
@@ -88,7 +113,7 @@ public class Capability {
 from toscaparser.properties import Property
 
 
-class Capability(object):
+class CapabilityAssignment(object):
     '''TOSCA built-in capabilities type.'''
 
     def __init__(self, name, properties, definition):
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/CapabilityAssignments.java b/src/main/java/org/openecomp/sdc/toscaparser/api/CapabilityAssignments.java
new file mode 100644 (file)
index 0000000..3397960
--- /dev/null
@@ -0,0 +1,51 @@
+package org.openecomp.sdc.toscaparser.api;
+
+import org.openecomp.sdc.toscaparser.api.CapabilityAssignment;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class CapabilityAssignments {
+
+    private Map<String,CapabilityAssignment> capabilityAssignments;
+
+    public CapabilityAssignments(Map<String,CapabilityAssignment> capabilityAssignments) {
+        this.capabilityAssignments = capabilityAssignments != null ? new HashMap<>(capabilityAssignments) : new HashMap<>();
+    }
+
+    /**
+     * Get all capability assignments for node template.<br>
+     * This object can be either the original one, holding all capability assignments for this node template,or a filtered one, holding a filtered subset.<br>
+     * @return list of capability assignments for the node template. <br>
+     * If there are no capability assignments, empty list is returned.
+     */
+    public List<CapabilityAssignment> getAll() {
+        return new ArrayList<>(capabilityAssignments.values());
+    }
+
+    /**
+     * Filter capability assignments by capability tosca type.
+     * @param type - The tosca type of capability assignments.
+     * @return CapabilityAssignments object, containing capability assignments of this type.<br>
+     * If no such found, filtering will result in an empty collection.
+     */
+    public CapabilityAssignments getCapabilitiesByType(String type) {
+        Map<String,CapabilityAssignment> capabilityAssignmentsMap = capabilityAssignments.entrySet().stream()
+                .filter(cap -> cap.getValue().getDefinition().getType().equals(type)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+
+        return new CapabilityAssignments(capabilityAssignmentsMap);
+    }
+
+    /**
+     * Get capability assignment by capability name.
+     * @param name - The name of capability assignment
+     * @return capability assignment with this name, or null if no such capability assignment was found.
+     */
+    public CapabilityAssignment getCapabilityByName(String name) {
+        return capabilityAssignments.get(name);
+    }
+
+}
index e896905..9220dac 100644 (file)
@@ -2,9 +2,9 @@ package org.openecomp.sdc.toscaparser.api;
 
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
 import org.openecomp.sdc.toscaparser.api.elements.*;
 import org.openecomp.sdc.toscaparser.api.utils.ThreadLocalsHolder;
 
@@ -47,8 +47,8 @@ public abstract class EntityTemplate {
        protected StatefulEntityType typeDefinition;
        private ArrayList<Property> _properties;
        private ArrayList<InterfacesDef> _interfaces; 
-       private ArrayList<Object> _requirements;
-       private ArrayList<Capability> _capabilities;
+       private ArrayList<RequirementAssignment> _requirements;
+       private ArrayList<CapabilityAssignment> _capabilities;
 
        // dummy constructor for subclasses that don't want super
        public EntityTemplate() {
@@ -151,18 +151,40 @@ public abstract class EntityTemplate {
     }
     
      @SuppressWarnings("unchecked")
-       public ArrayList<Object> getRequirements() {
+       public RequirementAssignments getRequirements() {
        if(_requirements == null) {
-               _requirements = new ArrayList<Object>();
-               Object ob = ((EntityType)typeDefinition).getValue(REQUIREMENTS,entityTpl,false);
-               if(ob != null) {
-                       _requirements.addAll((ArrayList<Object>)ob);
-               }
-                               
+               _requirements = _createRequirements();
        }
-       return _requirements;
+       return new RequirementAssignments(_requirements);
     }
 
+    private ArrayList<RequirementAssignment> _createRequirements() {
+               ArrayList<RequirementAssignment> reqs = new ArrayList<>();
+               ArrayList<Map<String, Object>> requirements = (ArrayList<Map<String, Object>>)
+                               typeDefinition.getValue(REQUIREMENTS,entityTpl,false);
+               if(requirements == null) {
+                       requirements = new ArrayList<>();
+               }
+               for (Map<String, Object> req: requirements) {
+                       for(String reqName: req.keySet()) {
+                               Object reqItem = req.get(reqName);
+                               if(reqItem instanceof LinkedHashMap) {
+                                       Object rel = ((LinkedHashMap<String,Object>)reqItem).get("relationship");
+//                                     LinkedHashMap relationship = rel instanceof LinkedHashMap ? (LinkedHashMap) rel : null;
+                                       String nodeName = ((LinkedHashMap<String,Object>)reqItem).get("node").toString();
+                                       Object capability = ((LinkedHashMap<String,Object>)reqItem).get("capability");
+                                       String capabilityString = capability != null ? capability.toString() : null;
+
+                                       reqs.add(new RequirementAssignment(reqName, nodeName, capabilityString, rel));
+                               } else if (reqItem instanceof String) { //short notation
+                                       String nodeName = String.valueOf(reqItem);
+                                       reqs.add(new RequirementAssignment(reqName, nodeName));
+                               }
+                       }
+               }
+               return reqs;
+       }
+
     public ArrayList<Property> getPropertiesObjects() {
         // Return properties objects for this template
         if(_properties ==null) {
@@ -192,7 +214,7 @@ public abstract class EntityTemplate {
        return _interfaces;
     }
     
-    public ArrayList<Capability> getCapabilitiesObjects() {
+    public ArrayList<CapabilityAssignment> getCapabilitiesObjects() {
         // Return capabilities objects for this template
        if(_capabilities == null) {
                _capabilities = _createCapabilities();
@@ -201,12 +223,12 @@ public abstract class EntityTemplate {
        
     }
     
-    public LinkedHashMap<String,Capability> getCapabilities() {
-       LinkedHashMap<String,Capability> caps = new LinkedHashMap<String,Capability>();
-       for(Capability cap: getCapabilitiesObjects()) {
+    public CapabilityAssignments getCapabilities() {
+       LinkedHashMap<String,CapabilityAssignment> caps = new LinkedHashMap<String,CapabilityAssignment>();
+       for(CapabilityAssignment cap: getCapabilitiesObjects()) {
                caps.put(cap.getName(),cap);
        }
-       return caps;
+       return new CapabilityAssignments(caps);
     }
 
     public boolean isDerivedFrom(String typeStr) {
@@ -226,8 +248,8 @@ public abstract class EntityTemplate {
     }
     
     @SuppressWarnings("unchecked")
-       private ArrayList<Capability> _createCapabilities() {
-       ArrayList<Capability> capability = new ArrayList<Capability>();
+       private ArrayList<CapabilityAssignment> _createCapabilities() {
+       ArrayList<CapabilityAssignment> capability = new ArrayList<CapabilityAssignment>();
                LinkedHashMap<String,Object> caps = (LinkedHashMap<String,Object>)
                                                        ((EntityType)typeDefinition).getValue(CAPABILITIES,entityTpl,true);
                if(caps != null) {
@@ -257,7 +279,7 @@ public abstract class EntityTemplate {
                                        if(pp != null) {
                                                properties.putAll(pp);
                                        }
-                    Capability cap = new Capability(name, properties, c);
+                    CapabilityAssignment cap = new CapabilityAssignment(name, properties, c);
                     capability.add(cap);
                                }
                        }
@@ -292,7 +314,7 @@ public abstract class EntityTemplate {
        for(Map.Entry<String,Object> me: capabilities.entrySet()) {
                String cap = me.getKey();
                        LinkedHashMap<String,Object> props = (LinkedHashMap<String,Object>)me.getValue();
-               Capability capability = getCapability(cap);
+               CapabilityAssignment capability = getCapability(cap);
                if(capability == null) {
                        continue;
                }
@@ -485,15 +507,11 @@ public abstract class EntityTemplate {
        return interfaces;
     }
     
-       public Capability getCapability(String name) {
+       public CapabilityAssignment getCapability(String name) {
         // Provide named capability
        // :param name: name of capability
         // :return: capability object if found, None otherwise
-       LinkedHashMap<String,Capability> caps = getCapabilities();
-       if(caps != null) {
-               return caps.get(name);
-       }
-       return null;
+               return getCapabilities().getCapabilityByName(name);
     }
     
        // getter
@@ -666,7 +684,7 @@ class EntityTemplate(object):
                     if 'properties' in props and props['properties']:
                         properties.update(props['properties'])
 
-                    cap = Capability(name, properties, c)
+                    cap = CapabilityAssignment(name, properties, c)
                     capability.append(cap)
         return capability
 
index 11db32b..6606068 100644 (file)
@@ -2,6 +2,7 @@ package org.openecomp.sdc.toscaparser.api;
 
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.openecomp.sdc.toscaparser.api.elements.*;
@@ -46,17 +47,14 @@ public class NodeTemplate extends EntityTemplate {
        @SuppressWarnings("unchecked")
        public LinkedHashMap<RelationshipType,NodeTemplate> getRelationships() {
                if(_relationships.isEmpty()) {
-                       ArrayList<Object> requires = getRequirements();
-                       if(requires != null && requires instanceof ArrayList) {
-                               for(Object ro: requires) {
-                                       LinkedHashMap<String,Object> r = (LinkedHashMap<String,Object>)ro;
-                                       for(Map.Entry<String,Object> me: r.entrySet()) {
-                                               LinkedHashMap<RelationshipType,NodeTemplate> explicit = _getExplicitRelationship(r,me.getValue());
-                                               if(explicit != null) {
-                                                       // _relationships.putAll(explicit)...
-                                                       for(Map.Entry<RelationshipType,NodeTemplate> ee: explicit.entrySet()) {
-                                                               _relationships.put(ee.getKey(), ee.getValue());
-                                                       }
+                       List<RequirementAssignment> requires = getRequirements().getAll();
+                       if(requires != null && requires instanceof List) {
+                               for(RequirementAssignment r: requires) {
+                                       LinkedHashMap<RelationshipType,NodeTemplate> explicit = _getExplicitRelationship(r);
+                                       if(explicit != null) {
+                                               // _relationships.putAll(explicit)...
+                                               for(Map.Entry<RelationshipType,NodeTemplate> ee: explicit.entrySet()) {
+                                                       _relationships.put(ee.getKey(), ee.getValue());
                                                }
                                        }
                                }
@@ -66,7 +64,7 @@ public class NodeTemplate extends EntityTemplate {
        }
 
        @SuppressWarnings("unchecked")
-       private LinkedHashMap<RelationshipType,NodeTemplate> _getExplicitRelationship(LinkedHashMap<String,Object> req,Object value) {
+       private LinkedHashMap<RelationshipType,NodeTemplate> _getExplicitRelationship(RequirementAssignment req) {
         // Handle explicit relationship
 
         // For example,
@@ -75,13 +73,7 @@ public class NodeTemplate extends EntityTemplate {
         //     relationship: tosca.relationships.HostedOn
                
                LinkedHashMap<RelationshipType,NodeTemplate> explicitRelation = new LinkedHashMap<RelationshipType,NodeTemplate>();
-               String node;
-               if(value instanceof LinkedHashMap) {
-                       node = (String)((LinkedHashMap<String,Object>)value).get("node");
-               }
-               else {
-                       node = (String)value;
-               }
+               String node = req.getNodeTemplateName();
                
                if(node != null && !node.isEmpty()) {
             //msg = _('Lookup by TOSCA types is not supported. '
@@ -105,35 +97,33 @@ public class NodeTemplate extends EntityTemplate {
                     return null;
                        }
                        NodeTemplate relatedTpl = new NodeTemplate(node,templates,customDef,null,null);
-                       Object relationship = null;
+                       Object relationship = req.getRelationship();
                        String relationshipString = null;
-                       if(value instanceof LinkedHashMap) {
-                               relationship = ((LinkedHashMap<String,Object>)value).get("relationship");
-                               // here relationship can be a string or a LHM with 'type':<relationship>
-                       }
-            // check if its type has relationship defined
+//                     // here relationship can be a string or a LHM with 'type':<relationship>
+
+                       // check if its type has relationship defined
                        if(relationship == null) {
                                ArrayList<Object> parentReqs = ((NodeType)typeDefinition).getAllRequirements();
                                if(parentReqs == null) {
                     ThreadLocalsHolder.getCollector().appendException("ValidationError: parent_req is null");
                                }
                                else {
-                                       for(String key: req.keySet()) {
-                                               boolean bFoundRel = false;
+//                                     for(String key: req.keySet()) {
+//                                             boolean bFoundRel = false;
                                                for(Object rdo: parentReqs) {
                                                        LinkedHashMap<String,Object> reqDict = (LinkedHashMap<String,Object>)rdo;
-                                                       LinkedHashMap<String,Object> relDict = (LinkedHashMap<String,Object>)reqDict.get(key);
+                                                       LinkedHashMap<String,Object> relDict = (LinkedHashMap<String,Object>)reqDict.get(req.getName());
                                                        if(relDict != null) {
                                                                relationship = relDict.get("relationship");
                                                                //BUG-python??? need to break twice?
-                                                               bFoundRel = true;
+//                                                             bFoundRel = true;
                                                                break;
                                                        }
                                                }
-                                               if(bFoundRel) {
-                                                       break;
-                                               }
-                                       }
+//                                             if(bFoundRel) {
+//                                                     break;
+//                                             }
+//                                     }
                                }
                        }
                        
@@ -208,8 +198,9 @@ public class NodeTemplate extends EntityTemplate {
        }
 
        @SuppressWarnings("unchecked")
-       private void _addRelationshipTemplate(LinkedHashMap<String,Object> requirement, String rtype, NodeTemplate source) {
-               LinkedHashMap<String,Object> req = (LinkedHashMap<String,Object>)CopyUtils.copyLhmOrAl(requirement);
+       private void _addRelationshipTemplate(RequirementAssignment requirement, String rtype, NodeTemplate source) {
+               LinkedHashMap<String,Object> req = new LinkedHashMap<>();
+               req.put("relationship", CopyUtils.copyLhmOrAl(requirement.getRelationship()));
                req.put("type",rtype);
                RelationshipTemplate tpl = new RelationshipTemplate(req, rtype, customDef, this, source);
                relationshipTpl.add(tpl);
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignment.java b/src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignment.java
new file mode 100644 (file)
index 0000000..799a8ee
--- /dev/null
@@ -0,0 +1,85 @@
+package org.openecomp.sdc.toscaparser.api;
+
+import java.util.Map;
+
+public class RequirementAssignment {
+
+    private String name;
+    private String nodeName;
+    private String capabilityName;
+    private Object relationship;
+
+    public RequirementAssignment(String reqName, String nodeName) {
+        this.name = reqName;
+        this.nodeName = nodeName;
+    }
+
+    public RequirementAssignment(String reqName, String nodeName, String capabilityName) {
+        this.name = reqName;
+        this.nodeName = nodeName;
+        this.capabilityName = capabilityName;
+    }
+
+    public RequirementAssignment(String reqName, String nodeName, String capabilityName, Object relationship) {
+        this.name = reqName;
+        this.nodeName = nodeName;
+        this.capabilityName = capabilityName;
+        this.relationship = relationship;
+    }
+
+    /**
+     * Get the name for requirement assignment.
+     * @return the name for requirement assignment.
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Set the name for requirement
+     * @param name - the name for requirement to set
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * Get the node name for requirement assignment.
+     * @return the node name for requirement
+     */
+    public String getNodeTemplateName() {
+        return nodeName;
+    }
+
+    /**
+     * Set the node name for requirement
+     * @param nodeName - the node name for requirement to set
+     */
+    public void setNodeTemplateName(String nodeName) {
+        this.nodeName = nodeName;
+    }
+
+    /**
+     * Get the capability name for requirement assignment.
+     * @return the capability name for requirement
+     */
+    public String getCapabilityName() {
+        return capabilityName;
+    }
+
+    /**
+     * Set the capability name for requirement assignment.
+     * @param capabilityName - the capability name for requirement to set
+     */
+    public void setCapabilityName(String capabilityName) {
+        this.capabilityName = capabilityName;
+    }
+
+    /**
+     * Get the relationship object for requirement
+     * @return the relationship object for requirement
+     */
+    public Object getRelationship() {
+        return relationship;
+    }
+}
diff --git a/src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignments.java b/src/main/java/org/openecomp/sdc/toscaparser/api/RequirementAssignments.java
new file mode 100644 (file)
index 0000000..7991f3c
--- /dev/null
@@ -0,0 +1,39 @@
+package org.openecomp.sdc.toscaparser.api;
+
+import org.openecomp.sdc.toscaparser.api.RequirementAssignment;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class RequirementAssignments {
+
+    private List<RequirementAssignment> requirementAssignmentList;
+
+    public RequirementAssignments(List<RequirementAssignment> requirementAssignments) {
+        this.requirementAssignmentList = requirementAssignments != null ? new ArrayList<>(requirementAssignments) : new ArrayList<>();
+    }
+
+    /**
+     * Get all requirement assignments for Node Template.<br>
+     * This object can be either the original one, holding all requirement assignments for this node template,or a filtered one, holding a filtered subset.<br>
+     * @return list of requirement assignments for the node template. <br>
+     * If there are no requirement assignments, empty list is returned.
+     */
+    public List<RequirementAssignment> getAll() {
+        return new ArrayList<>(requirementAssignmentList);
+    }
+
+    /**
+     * Filter requirement assignments by requirement name.
+     * @param reqName - The name of requirement
+     * @return RequirementAssignments object, containing requirement assignments of this type.<br>
+     * If no such found, filtering will result in an empty collection.
+     */
+    public RequirementAssignments getRequirementsByName(String reqName) {
+        List<RequirementAssignment> requirementAssignments = requirementAssignmentList.stream()
+                .filter(req -> req.getName().equals(reqName)).collect(Collectors.toList());
+
+        return new RequirementAssignments(requirementAssignments);
+    }
+}
index b9c2238..a68f9fb 100644 (file)
@@ -1,10 +1,7 @@
 package org.openecomp.sdc.toscaparser.api;
 
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
+import java.util.*;
 
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
 import org.openecomp.sdc.toscaparser.api.elements.NodeType;
 import org.openecomp.sdc.toscaparser.api.elements.PropertyDef;
 import org.openecomp.sdc.toscaparser.api.parameters.Input;
@@ -217,13 +214,13 @@ public class SubstitutionMappings {
         // The capabilities must be in node template which be mapped.
                LinkedHashMap<String,Object> tplsCapabilities = 
                                (LinkedHashMap<String,Object>)subMappingDef.get(CAPABILITIES);
-               LinkedHashMap<String,Capability> nodeCapabilities = null;
+               List<CapabilityAssignment> nodeCapabilities = null;
                if(subMappedNodeTemplate != null) {
-                       nodeCapabilities = subMappedNodeTemplate.getCapabilities();
+                       nodeCapabilities = subMappedNodeTemplate.getCapabilities().getAll();
                }
                if(nodeCapabilities != null) {
-                       for(String cap: nodeCapabilities.keySet()) {
-                               if(tplsCapabilities != null && tplsCapabilities.get(cap) == null) {
+                       for(CapabilityAssignment cap: nodeCapabilities) {
+                               if(tplsCapabilities != null && tplsCapabilities.get(cap.getName()) == null) {
                        ; //pass
                        // ExceptionCollector.appendException(
                        //    UnknownFieldError(what='SubstitutionMappings',
@@ -241,15 +238,13 @@ public class SubstitutionMappings {
         // The requirements must be in node template which be mapped.
                LinkedHashMap<String,Object> tplsRequirements = 
                                (LinkedHashMap<String,Object>)subMappingDef.get(REQUIREMENTS);
-               ArrayList<Object> nodeRequirements = null;
+               List<RequirementAssignment> nodeRequirements = null;
                if(subMappedNodeTemplate != null) {
-                       nodeRequirements = subMappedNodeTemplate.getRequirements();
+                       nodeRequirements = subMappedNodeTemplate.getRequirements().getAll();
                }
                if(nodeRequirements != null) {
-                       for(Object ro: nodeRequirements) {
-                               ArrayList<String> al = new ArrayList<String>(
-                                               ((LinkedHashMap<String,Object>)ro).keySet());
-                               String cap = al.get(0);
+                       for(RequirementAssignment ro: nodeRequirements) {
+                               String cap = ro.getName();
                                if(tplsRequirements != null && tplsRequirements.get(cap) == null) {
                        ; //pass
                        // ExceptionCollector.appendException(
index 709dc81..afedfdb 100644 (file)
@@ -1,11 +1,7 @@
 package org.openecomp.sdc.toscaparser.api;
 
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import java.util.*;
 
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
 import org.openecomp.sdc.toscaparser.api.elements.InterfacesDef;
 import org.openecomp.sdc.toscaparser.api.elements.NodeType;
 import org.openecomp.sdc.toscaparser.api.elements.RelationshipType;
@@ -415,27 +411,20 @@ public class TopologyTemplate {
                                        }
                                }
                        }
-                       if(nt.getRequirements() != null &&
-                                       nt.getRequirements() instanceof ArrayList) {
-                               for(Object oreq: nt.getRequirements()) {
-                                       LinkedHashMap<String,Object> req = (LinkedHashMap<String,Object>)oreq;
-                                       LinkedHashMap<String,Object> rel = req;
-                                       for(String reqName: req.keySet()) {
-                                               Object reqItem = req.get(reqName);
-                                               if(reqItem instanceof LinkedHashMap) {
-                                                       Object t = ((LinkedHashMap<String,Object>)reqItem).get("relationship");
-                                                       // it can be a string or a LHM...
-                                                       if(t instanceof LinkedHashMap) {
-                                                               rel = (LinkedHashMap<String,Object>)t;
-                                                       }
-                                                       else {
-                                                               // we set it to null to fail the next test
-                                                               // and avoid the get("proprties")
-                                                               rel = null;
-                                                       }
-                                                       break;
-                                               }
-                                       }
+                       if(nt.getRequirements() != null) {
+                               for(RequirementAssignment req: nt.getRequirements().getAll()) {
+                                               LinkedHashMap<String,Object> rel;
+                                               Object t = req.getRelationship();
+                                               // it can be a string or a LHM...
+                                               if(t instanceof LinkedHashMap) {
+                                                       rel = (LinkedHashMap<String,Object>)t;
+                                               }
+                                               else {
+                                                       // we set it to null to fail the next test
+                                                       // and avoid the get("proprties")
+                                                       rel = null;
+                                               }
+
                                        if(rel != null && rel.get("properties") != null) {
                                                LinkedHashMap<String,Object> relprops = 
                                                                (LinkedHashMap<String,Object>)rel.get("properties");
@@ -448,7 +437,7 @@ public class TopologyTemplate {
                                }
                        }
                        if(nt.getCapabilitiesObjects() != null) {
-                               for(Capability cap: nt.getCapabilitiesObjects()) {
+                               for(CapabilityAssignment cap: nt.getCapabilitiesObjects()) {
                                        if(cap.getPropertiesObjects() != null) {
                                                for(Property prop: cap.getPropertiesObjects()) {
                                                        Object propvalue = Function.getFunction(this,nt,prop.getValue(), resolveGetInput);
index 6cf84a5..b153876 100644 (file)
@@ -1,36 +1,34 @@
 package org.openecomp.sdc.toscaparser.api.elements;
 
+import java.util.AbstractMap;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 public class Metadata {
        
        private final Map<String, Object> metadataMap;
 
        public Metadata(Map<String, Object> metadataMap) {
-        this.metadataMap = metadataMap;
+        this.metadataMap = metadataMap != null ? metadataMap : new HashMap<>();
     }
 
        public String getValue(String key)  {
-               return !isEmpty() ? String.valueOf(this.metadataMap.get(key)) : null;
-       }
-       
-       public Map<String, Object> getPropertyMap()  {
-               if(metadataMap == null){
-                       return null;
-               }
-               return new HashMap<>(metadataMap);
-       }
-       
-       public void setValue(String key, Object value)  {
-               if (!isEmpty())  {
-                       this.metadataMap.put(key, value);
+
+               Object obj = this.metadataMap.get(key);
+               if (obj != null){
+                       return String.valueOf(obj);
                }
+               return null;
        }
 
-
-       private boolean isEmpty() {
-               return this.metadataMap == null || this.metadataMap.size() == 0;
+       /**
+        * Get all properties of a Metadata object.<br>
+        * This object represents the "metadata" section of some entity.
+        * @return all properties of this Metadata, as a key-value.
+        */
+       public Map<String, String> getAllProperties()  {
+               return metadataMap.entrySet().stream().map(e-> new AbstractMap.SimpleEntry<String, String>(e.getKey(), String.valueOf(e.getValue()))).collect(Collectors.toMap(Map.Entry::getKey,Map.Entry::getValue));
        }
 
        @Override
index 549073b..8a3d0b6 100644 (file)
@@ -4,7 +4,6 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 
 import org.openecomp.sdc.toscaparser.api.*;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
 import org.openecomp.sdc.toscaparser.api.elements.AttributeDef;
 import org.openecomp.sdc.toscaparser.api.elements.CapabilityTypeDef;
 import org.openecomp.sdc.toscaparser.api.elements.DataType;
@@ -164,22 +163,17 @@ public class GetAttribute extends Function {
                if(nodeTemplate != null) {
                LinkedHashMap<String,Object> hostedOnRel = 
                                (LinkedHashMap<String,Object>)EntityType.TOSCA_DEF.get(HOSTED_ON);
-                       for(Object ro: nodeTemplate.getRequirements()) {
-                               if(ro != null && ro instanceof LinkedHashMap) {
-                                       LinkedHashMap<String,Object> r = (LinkedHashMap<String,Object>)ro;
-                                       for(String requirement: r.keySet()) {
-                                               String targetName = (String)r.get(requirement);
-                                               NodeTemplate targetNode = _findNodeTemplate(targetName);
-                                               NodeType targetType = (NodeType)targetNode.getTypeDefinition();
-                                               for(CapabilityTypeDef capability: targetType.getCapabilitiesObjects()) {
+                       for(RequirementAssignment r: nodeTemplate.getRequirements().getAll()) {
+                               String targetName = r.getNodeTemplateName();
+                               NodeTemplate targetNode = _findNodeTemplate(targetName);
+                               NodeType targetType = (NodeType)targetNode.getTypeDefinition();
+                               for(CapabilityTypeDef capability: targetType.getCapabilitiesObjects()) {
 //                                                     if(((ArrayList<String>)hostedOnRel.get("valid_target_types")).contains(capability.getType())) {
-                                                       if(capability.inheritsFrom((ArrayList<String>)hostedOnRel.get("valid_target_types"))) {
-                                                               if(_attributeExistsInType(targetType)) {
-                                                                       return targetNode;
-                                                               }
-                                                               return _findHostContainingAttribute(targetName);
-                                                       }
+                                       if(capability.inheritsFrom((ArrayList<String>)hostedOnRel.get("valid_target_types"))) {
+                                               if(_attributeExistsInType(targetType)) {
+                                                       return targetNode;
                                                }
+                                               return _findHostContainingAttribute(targetName);
                                        }
                                }
                        }
@@ -246,16 +240,11 @@ public class GetAttribute extends Function {
 
                NodeTemplate nodeTpl = _findNodeTemplate((String)args.get(0));
            // Find attribute in node template's requirements
-               for(Object ro: nodeTpl.getRequirements()) {
-                       if(ro != null && ro instanceof LinkedHashMap) {
-                               LinkedHashMap<String,Object> r = (LinkedHashMap<String,Object>)ro;
-                               for(String req: r.keySet()) {
-                                       String nodeName = (String)r.get(req);
-                                       if(req.equals(reqOrCap)) {
-                                               NodeTemplate nodeTemplate = _findNodeTemplate(nodeName);
-                       return _getCapabilityAttribute(nodeTemplate,req,attrName);
-                                       }
-                               }
+               for(RequirementAssignment r: nodeTpl.getRequirements().getAll()) {
+                       String nodeName = r.getNodeTemplateName();
+                       if(r.getName().equals(reqOrCap)) {
+                               NodeTemplate nodeTemplate = _findNodeTemplate(nodeName);
+                               return _getCapabilityAttribute(nodeTemplate,r.getName(),attrName);
                        }
                }
            // If requirement was not found, look in node template's capabilities
@@ -266,9 +255,9 @@ public class GetAttribute extends Function {
                                                                                  String capabilityName,
                                                                                  String attrName) {
            // Gets a node template capability attribute
-           LinkedHashMap<String,Capability> caps = nodeTemplate.getCapabilities();
-           if(caps != null && caps.keySet().contains(capabilityName)) {
-               Capability cap = caps.get(capabilityName);
+               CapabilityAssignment cap = nodeTemplate.getCapabilities().getCapabilityByName(capabilityName);
+
+           if(cap != null) {
                AttributeDef attribute = null;
                LinkedHashMap<String,AttributeDef> attrs =
                                cap.getDefinition().getAttributesDef();
@@ -283,7 +272,7 @@ public class GetAttribute extends Function {
                return attribute;
            }
            String msg = String.format(
-               "Requirement/Capability \"%s\" referenced from node template \"%s\" was not found in node template \"%s\"",
+               "Requirement/CapabilityAssignment \"%s\" referenced from node template \"%s\" was not found in node template \"%s\"",
                capabilityName,((NodeTemplate)context).getName(),nodeTemplate.getName());
            ThreadLocalsHolder.getCollector().appendException("KeyError: " + msg);
                return null;                                                                      
@@ -518,7 +507,7 @@ def _get_capability_attribute(self,
                                               'ntpl1': node_template.name,
                                               'ntpl2': self.context.name}))
         return attribute
-    msg = _('Requirement/Capability "{0}" referenced from node template '
+    msg = _('Requirement/CapabilityAssignment "{0}" referenced from node template '
             '"{1}" was not found in node template "{2}".').format(
                 capability_name,
                 self.context.name,
index 71420e8..41495bc 100644 (file)
@@ -4,7 +4,6 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 
 import org.openecomp.sdc.toscaparser.api.*;
-import org.openecomp.sdc.toscaparser.api.common.ExceptionCollector;
 import org.openecomp.sdc.toscaparser.api.elements.CapabilityTypeDef;
 import org.openecomp.sdc.toscaparser.api.elements.EntityType;
 import org.openecomp.sdc.toscaparser.api.elements.NodeType;
@@ -105,17 +104,12 @@ public class GetProperty extends Function {
                return null;
         }
            // look for property in node template's requirements
-           for(Object r: nodeTpl.getRequirements()) {
-               if(r instanceof LinkedHashMap) {
-                       LinkedHashMap<String,Object> rlist = (LinkedHashMap<String,Object>)r;
-                       for(String req: rlist.keySet()) {
-                               String nodeName = (String)rlist.get(req);
-                               if(req.equals(reqOrCap)) {
-                                       NodeTemplate nodeTemplate = _findNodeTemplate(nodeName);
-                               return _getCapabilityProperty(nodeTemplate,req,propertyName,true);
-                               }
-                       }
-               }
+           for(RequirementAssignment req: nodeTpl.getRequirements().getAll()) {
+                       String nodeName = req.getNodeTemplateName();
+                       if(req.getName().equals(reqOrCap)) {
+                               NodeTemplate nodeTemplate = _findNodeTemplate(nodeName);
+                               return _getCapabilityProperty(nodeTemplate,req.getName(),propertyName,true);
+                       }
            }           
                // If requirement was not found, look in node template's capabilities
                return _getCapabilityProperty(nodeTpl,reqOrCap,propertyName,true);
@@ -128,9 +122,8 @@ public class GetProperty extends Function {
                
            // Gets a node template capability property
                Object property = null;
-               LinkedHashMap<String,Capability> caps = nodeTemplate.getCapabilities();
-               if(caps != null && caps.get(capabilityName) != null) {
-                       Capability cap = caps.get(capabilityName);
+               CapabilityAssignment cap = nodeTemplate.getCapabilities().getCapabilityByName(capabilityName);
+               if(cap != null) {
                        LinkedHashMap<String,Property> props = cap.getProperties();
                if(props != null && props.get(propertyName) != null) {
                    property = ((Property)props.get(propertyName)).getValue();
@@ -144,7 +137,7 @@ public class GetProperty extends Function {
                }
                if(throwErrors) {
                    ThreadLocalsHolder.getCollector().appendException(String.format(
-                       "KeyError: Requirement/Capability \"%s\" referenced from node template \"%s\" was not found in node template \"%s\"",
+                       "KeyError: Requirement/CapabilityAssignment \"%s\" referenced from node template \"%s\" was not found in node template \"%s\"",
                        capabilityName,((NodeTemplate)context).getName(),nodeTemplate.getName()));
                }
                
@@ -262,30 +255,26 @@ public class GetProperty extends Function {
            NodeTemplate nodeTemplate = _findNodeTemplate(nodeTemplateName);
            LinkedHashMap<String,Object> hostedOnRel = (LinkedHashMap<String,Object>)
                                                                                                        EntityType.TOSCA_DEF.get(HOSTED_ON);
-           for(Object r: nodeTemplate.getRequirements()) {
-               if(r instanceof LinkedHashMap) {
-                       LinkedHashMap<String,Object> rlist = (LinkedHashMap<String,Object>)r;
-                       for(String requirement: rlist.keySet()) {
-                               String targetName = (String)rlist.get(requirement);
-                               NodeTemplate targetNode = _findNodeTemplate(targetName);
-                               NodeType targetType = (NodeType)targetNode.getTypeDefinition();
-                       for(CapabilityTypeDef capDef: targetType.getCapabilitiesObjects()) {
-                               if(capDef.inheritsFrom((ArrayList<String>)hostedOnRel.get("valid_target_types"))) {
-                                       if(_propertyExistsInType(targetType)) {
-                                               return targetNode;
-                                       }
-                               // If requirement was not found, look in node
-                               // template's capabilities
-                               if(args.size() > 2 && 
-                                       _getCapabilityProperty(targetNode,(String)args.get(1),(String)args.get(2),false) != null) {
-                                               return targetNode;
-                                       }
-
-                                       return _findHostContainingProperty(targetName);
-                               }
-                       }
-                       }
-               }
+           for(RequirementAssignment requirement: nodeTemplate.getRequirements().getAll()) {
+                       String targetName = requirement.getNodeTemplateName();
+                       NodeTemplate targetNode = _findNodeTemplate(targetName);
+                       NodeType targetType = (NodeType)targetNode.getTypeDefinition();
+                       for(CapabilityTypeDef capDef: targetType.getCapabilitiesObjects()) {
+                               if(capDef.inheritsFrom((ArrayList<String>)hostedOnRel.get("valid_target_types"))) {
+                                       if(_propertyExistsInType(targetType)) {
+                                               return targetNode;
+                                       }
+                                       // If requirement was not found, look in node
+                                       // template's capabilities
+                                       if(args.size() > 2 &&
+                                               _getCapabilityProperty(targetNode,(String)args.get(1),(String)args.get(2),false) != null) {
+                                               return targetNode;
+                                       }
+
+                                       return _findHostContainingProperty(targetName);
+                               }
+                       }
+
            }
            return null;
        }
@@ -466,7 +455,7 @@ def _get_capability_property(self,
                                               'ntpl1': node_template.name,
                                               'ntpl2': self.context.name}))
         return property
-    msg = _('Requirement/Capability "{0}" referenced from node template '
+    msg = _('Requirement/CapabilityAssignment "{0}" referenced from node template '
             '"{1}" was not found in node template "{2}".').format(
                 capability_name,
                 self.context.name,
index 554b7b6..c5a4d0f 100644 (file)
@@ -13,7 +13,7 @@
 ##########################################################################
 # The content of this file reflects TOSCA Simple Profile in YAML version
 # 1.0.0. It describes the definition for TOSCA types including Node Type,
-# Relationship Type, Capability Type and Interfaces.
+# Relationship Type, CapabilityAssignment Type and Interfaces.
 ##########################################################################
 tosca_definitions_version: tosca_simple_yaml_1_0
 
@@ -489,8 +489,8 @@ relationship_types:
     valid_target_types: [ tosca.capabilities.network.Bindable ]
 
 ##########################################################################
-# Capability Type.
-# A Capability Type is a reusable entity that describes a kind of
+# CapabilityAssignment Type.
+# A CapabilityAssignment Type is a reusable entity that describes a kind of
 # capability that a Node Type can declare to expose.
 ##########################################################################
 capability_types:
index 365d70e..8b08837 100644 (file)
@@ -13,7 +13,7 @@
 ##########################################################################
 # The content of this file reflects TOSCA NFV Profile in YAML version
 # 1.0.0. It describes the definition for TOSCA NFV types including Node Type,
-# Relationship Type, Capability Type and Interfaces.
+# Relationship Type, CapabilityAssignment Type and Interfaces.
 ##########################################################################
 tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
 
@@ -139,8 +139,8 @@ relationship_types:
     valid_target_types: [ tosca.capabilities.nfv.Forwarder]
 
 ##########################################################################
-# Capability Type.
-# A Capability Type is a reusable entity that describes a kind of
+# CapabilityAssignment Type.
+# A CapabilityAssignment Type is a reusable entity that describes a kind of
 # capability that a Node Type can declare to expose.
 ##########################################################################