2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 European Software Marketing Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.babel.xml.generator.model;
23 import java.util.HashSet;
24 import java.util.Iterator;
27 import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
28 import org.onap.aai.babel.xml.generator.types.Cardinality;
29 import org.onap.aai.babel.xml.generator.types.ModelType;
31 public abstract class Model {
32 public static final String GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION = "Operation Not Supported for Widgets";
34 protected Set<Resource> resources = new HashSet<>();
35 protected Set<Widget> widgets = new HashSet<>();
36 private String modelId;
37 private String modelName;
38 private String modelVersion;
39 private String modelNameVersionId;
40 private String modelDescription;
43 * Gets the object (model) corresponding to the supplied TOSCA type.
45 * @param toscaType the tosca type
46 * @return the model for the type, or null
48 public static Model getModelFor(String toscaType) {
49 Model modelToBeReturned = null;
50 String typePrefix = toscaType;
51 while (modelToBeReturned == null && typePrefix != null && typePrefix.lastIndexOf('.') != -1) {
53 case "org.openecomp.resource.vf.allottedResource":
54 modelToBeReturned = new AllotedResource();
56 case "org.openecomp.resource.vfc.AllottedResource":
57 modelToBeReturned = new ProvidingService();
59 case "org.openecomp.resource.vfc":
60 modelToBeReturned = new VServerWidget();
62 case "org.openecomp.resource.cp":
63 case "org.openecomp.cp":
64 modelToBeReturned = new LIntfWidget();
66 case "org.openecomp.resource.vl":
67 modelToBeReturned = new L3Network();
69 case "org.openecomp.resource.vf":
70 modelToBeReturned = new VirtualFunction();
72 case "org.openecomp.groups.vfmodule":
73 case "org.openecomp.groups.VfModule":
74 modelToBeReturned = new VfModule();
76 case "org.openecomp.resource.vfc.nodes.heat.cinder":
77 modelToBeReturned = new VolumeWidget();
80 modelToBeReturned = null;
83 typePrefix = typePrefix.substring(0, typePrefix.lastIndexOf('.'));
86 return modelToBeReturned;
89 public abstract boolean addResource(Resource resource);
91 public abstract boolean addWidget(Widget resource);
94 * Gets widget version id.
96 * @return the widget version id
98 public String getWidgetId() {
99 org.onap.aai.babel.xml.generator.types.Model model =
100 this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
101 return Widget.getWidget(model.widget()).getId();
107 * @return the invariant id
109 public String getWidgetInvariantId() {
110 org.onap.aai.babel.xml.generator.types.Model model =
111 this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
112 return Widget.getWidget(model.widget()).getWidgetId();
118 * @return the delete flag
120 public boolean getDeleteFlag() {
121 org.onap.aai.babel.xml.generator.types.Model model =
122 this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
123 return model.dataDeleteFlag();
129 * @return the cardinality
131 public Cardinality getCardinality() {
132 org.onap.aai.babel.xml.generator.types.Model model =
133 this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
134 return model.cardinality();
137 public abstract Widget.Type getWidgetType();
139 public String getModelId() {
147 * @return the model type
149 public ModelType getModelType() {
150 if (this instanceof Service) {
151 return ModelType.SERVICE;
152 } else if (this instanceof Resource) {
153 return ModelType.RESOURCE;
154 } else if (this instanceof Widget) {
155 return ModelType.WIDGET;
161 public String getModelName() {
165 public String getModelVersion() {
169 public String getModelNameVersionId() {
171 return modelNameVersionId;
174 public String getModelDescription() {
175 return modelDescription;
179 * Populate model identification information.
181 * @param modelIdentInfo the model ident info
183 public void populateModelIdentificationInformation(Map<String, String> modelIdentInfo) {
184 Iterator<String> iter = modelIdentInfo.keySet().iterator();
186 while (iter.hasNext()) {
187 property = iter.next();
189 case "vfModuleModelInvariantUUID":
190 case "serviceInvariantUUID":
191 case "resourceInvariantUUID":
192 case "invariantUUID":
193 case "providing_service_invariant_uuid":
194 modelId = modelIdentInfo.get(property);
196 case "vfModuleModelUUID":
200 case "providing_service_uuid":
201 modelNameVersionId = modelIdentInfo.get(property);
203 case "vfModuleModelVersion":
204 case "serviceVersion":
205 case "resourceversion":
207 modelVersion = modelIdentInfo.get(property);
209 case "vfModuleModelName":
213 modelName = modelIdentInfo.get(property);
215 case "serviceDescription":
216 case "resourceDescription":
217 case "vf_module_description":
219 modelDescription = modelIdentInfo.get(property);
221 case "providing_service_name":
222 modelName = modelIdentInfo.get(property);
223 modelDescription = modelIdentInfo.get(property);
231 public void setModelVersion(String modelVersion) {
232 this.modelVersion = modelVersion;
235 public Set<Resource> getResources() {
239 public Set<Widget> getWidgets() {
243 private void checkSupported() {
244 if (this instanceof Widget) {
245 throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);