Re-implement model type value for Resource Mapping
[aai/babel.git] / src / main / java / org / onap / aai / babel / xml / generator / model / Model.java
index 3c407bd..c67d67f 100644 (file)
@@ -18,6 +18,7 @@
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.babel.xml.generator.model;
 
 import java.util.Collections;
@@ -29,9 +30,7 @@ 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.error.IllegalAccessException;
 import org.onap.aai.babel.xml.generator.model.Widget.Type;
-import org.onap.aai.babel.xml.generator.types.ModelType;
 
 public abstract class Model {
 
@@ -110,10 +109,10 @@ public abstract class Model {
     protected Set<Widget> widgets = new HashSet<>();
 
     /**
-     * Gets the object (model) corresponding to the supplied TOSCA type.
+     * Gets the Resource Model corresponding to the supplied TOSCA type.
      *
      * @param toscaType
-     *     the tosca type
+     *            the tosca type
      * @return the model for the type, or null
      */
     public static Resource getModelFor(String toscaType) {
@@ -142,9 +141,9 @@ public abstract class Model {
      * information.
      *
      * @param toscaType
-     *     the TOSCA type
+     *            the TOSCA type
      * @param metaDataType
-     *     the type from the TOSCA metadata
+     *            the type from the TOSCA metadata
      * @return the model for the type, or null
      */
     public static Resource getModelFor(String toscaType, String metaDataType) {
@@ -157,15 +156,15 @@ public abstract class Model {
         }
     }
 
-    public abstract boolean addResource(Resource resource);
-
     public abstract boolean addWidget(Widget resource) throws XmlArtifactGenerationException;
 
     public abstract Widget.Type getWidgetType();
 
-    public abstract Map<String, Object> getProperties();
+    public abstract String getModelTypeName();
 
-    public abstract boolean isResource();
+    public boolean addResource(Resource resource) {
+        return resources.add(resource);
+    }
 
     /**
      * Gets delete flag.
@@ -181,7 +180,6 @@ public abstract class Model {
     }
 
     public String getModelId() {
-        checkSupported();
         return modelId;
     }
 
@@ -194,32 +192,14 @@ public abstract class Model {
     }
 
     public String getModelNameVersionId() {
-        checkSupported();
         return modelNameVersionId;
     }
 
-    /**
-     * Gets model type.
-     *
-     * @return the model type
-     */
-    public ModelType getModelType() {
-        if (this instanceof Service) {
-            return ModelType.SERVICE;
-        } else if (this instanceof Resource) {
-            return ModelType.RESOURCE;
-        } else if (this instanceof Widget) {
-            return ModelType.WIDGET;
-        } else {
-            return null;
-        }
-    }
-
     /**
      * Gets widget version id.
      *
      * @return the widget version id
-     * @throws XmlArtifactGenerationException 
+     * @throws XmlArtifactGenerationException
      */
     public String getWidgetId() throws XmlArtifactGenerationException {
         return Widget.getWidget(getWidgetType()).getId();
@@ -229,17 +209,17 @@ public abstract class Model {
      * Gets invariant id.
      *
      * @return the invariant id
-     * @throws XmlArtifactGenerationException 
+     * @throws XmlArtifactGenerationException
      */
     public String getWidgetInvariantId() throws XmlArtifactGenerationException {
         return Widget.getWidget(getWidgetType()).getWidgetId();
     }
-    
+
     /**
      * Populate model identification information.
      *
      * @param modelIdentInfo
-     *     the model ident info
+     *            the model ident info
      */
     public void populateModelIdentificationInformation(Map<String, String> modelIdentInfo) {
         Iterator<String> iter = modelIdentInfo.keySet().iterator();
@@ -265,10 +245,9 @@ public abstract class Model {
         return widgets;
     }
 
-    private void checkSupported() {
-        if (this instanceof Widget) {
-            throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
-        }
+    @Override
+    public String toString() {
+        return "Model [type=" + getModelTypeName() + ", name=" + getModelName() + "]";
     }
 
 }