X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fxml%2Fgenerator%2Fmodel%2FModel.java;h=12f1ac8ef9785de92f8c9e33724d5340a92f74a8;hb=fbd05f86edf3e4710ab454780581f0ee40e152f6;hp=d4da6df69686f4edb23b28f7c484ceea569802e8;hpb=979d62dc51a6e25ebab8d1d3751b8cac6d062893;p=aai%2Fbabel.git diff --git a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java index d4da6df..12f1ac8 100644 --- a/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java +++ b/src/main/java/org/onap/aai/babel/xml/generator/model/Model.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2019 European Software Marketing Ltd. + * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2017-2019 European Software Marketing Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.babel.xml.generator.model; import java.util.Collections; @@ -27,10 +28,9 @@ import java.util.Iterator; import java.util.Map; 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 { @@ -99,9 +99,9 @@ public abstract class Model { public abstract void populate(Model model, String value); } - private String modelId; + private String modelId; // model-invariant-id private String modelName; - private String modelNameVersionId; + private String modelNameVersionId; // model-version-id private String modelVersion; private String modelDescription; @@ -109,10 +109,10 @@ public abstract class Model { protected Set 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) { @@ -141,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) { @@ -156,15 +156,15 @@ public abstract class Model { } } - public abstract boolean addResource(Resource resource); - - public abstract boolean addWidget(Widget resource); + public abstract boolean addWidget(Widget resource) throws XmlArtifactGenerationException; public abstract Widget.Type getWidgetType(); - public abstract Map getProperties(); + public abstract String getModelTypeName(); - public abstract boolean isResource(); + public boolean addResource(Resource resource) { + return resources.add(resource); + } /** * Gets delete flag. @@ -172,9 +172,7 @@ public abstract class Model { * @return the delete flag */ public boolean getDeleteFlag() { - org.onap.aai.babel.xml.generator.types.Model model = - this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class); - return model.dataDeleteFlag(); + return true; } public String getModelDescription() { @@ -182,7 +180,6 @@ public abstract class Model { } public String getModelId() { - checkSupported(); return modelId; } @@ -195,54 +192,34 @@ 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 */ - public String getWidgetId() { - org.onap.aai.babel.xml.generator.types.Model model = - this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class); - return Widget.getWidget(model.widget()).getId(); + public String getWidgetId() throws XmlArtifactGenerationException { + return Widget.getWidget(getWidgetType()).getId(); } /** * Gets invariant id. * * @return the invariant id + * @throws XmlArtifactGenerationException */ - public String getWidgetInvariantId() { - org.onap.aai.babel.xml.generator.types.Model model = - this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class); - return Widget.getWidget(model.widget()).getWidgetId(); + 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 modelIdentInfo) { Iterator iter = modelIdentInfo.keySet().iterator(); @@ -268,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() + "]"; } }