Extend service model
[aai/babel.git] / src / main / java / org / onap / aai / babel / xml / generator / model / Model.java
index 12f1ac8..c33127e 100644 (file)
@@ -30,7 +30,6 @@ import java.util.Optional;
 import java.util.Set;
 import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
-import org.onap.aai.babel.xml.generator.model.Widget.Type;
 
 public abstract class Model {
 
@@ -68,6 +67,12 @@ public abstract class Model {
                 model.modelDescription = value;
             }
         },
+        ORCHESTRATION_TYPE("instantiationType"){
+            @Override
+            public void populate(Model model, String value) {
+                model.instantiationType = value;
+            }
+        },
         NAME_AND_DESCRIPTION("providing_service_name") {
             @Override
             public void populate(Model model, String value) {
@@ -104,7 +109,7 @@ public abstract class Model {
     private String modelNameVersionId; // model-version-id
     private String modelVersion;
     private String modelDescription;
-
+    private String instantiationType;
     protected Set<Resource> resources = new HashSet<>();
     protected Set<Widget> widgets = new HashSet<>();
 
@@ -148,9 +153,9 @@ public abstract class Model {
      */
     public static Resource getModelFor(String toscaType, String metaDataType) {
         if ("Configuration".equals(metaDataType)) {
-            return new Resource(Type.CONFIGURATION, true);
+            return new Resource(WidgetType.valueOf("CONFIGURATION"), true);
         } else if ("CR".equals(metaDataType)) {
-            return new Resource(Type.CR, true);
+            return new Resource(WidgetType.valueOf("CR"), true);
         } else {
             return getModelFor(toscaType);
         }
@@ -158,10 +163,24 @@ public abstract class Model {
 
     public abstract boolean addWidget(Widget resource) throws XmlArtifactGenerationException;
 
-    public abstract Widget.Type getWidgetType();
+    /**
+     * @return the Widget Type of this model.
+     */
+    public abstract WidgetType getWidgetType();
 
     public abstract String getModelTypeName();
 
+    /**
+     * Check whether the model's Widget Type matches the supplied type.
+     *
+     * @param type
+     *            the Widget Type to compare
+     * @return true if the Widget Type of this model matches the supplied type
+     */
+    public boolean hasWidgetType(String type) {
+        return getWidgetType() == WidgetType.valueOf(type);
+    }
+
     public boolean addResource(Resource resource) {
         return resources.add(resource);
     }
@@ -195,6 +214,10 @@ public abstract class Model {
         return modelNameVersionId;
     }
 
+    public String getInstantiationType() {
+        return instantiationType;
+    }
+
     /**
      * Gets widget version id.
      *
@@ -202,7 +225,7 @@ public abstract class Model {
      * @throws XmlArtifactGenerationException
      */
     public String getWidgetId() throws XmlArtifactGenerationException {
-        return Widget.getWidget(getWidgetType()).getId();
+        return Widget.createWidget(getWidgetType()).getId();
     }
 
     /**
@@ -212,7 +235,7 @@ public abstract class Model {
      * @throws XmlArtifactGenerationException
      */
     public String getWidgetInvariantId() throws XmlArtifactGenerationException {
-        return Widget.getWidget(getWidgetType()).getWidgetId();
+        return Widget.createWidget(getWidgetType()).getWidgetId();
     }
 
     /**
@@ -222,6 +245,9 @@ public abstract class Model {
      *            the model ident info
      */
     public void populateModelIdentificationInformation(Map<String, String> modelIdentInfo) {
+        if (modelIdentInfo == null) {
+            return;
+        }
         Iterator<String> iter = modelIdentInfo.keySet().iterator();
         String property;
         while (iter.hasNext()) {