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();
79 case "org.openecomp.nodes.PortMirroringConfiguration":
80 modelToBeReturned = new Configuration();
83 modelToBeReturned = null;
86 typePrefix = typePrefix.substring(0, typePrefix.lastIndexOf('.'));
89 return modelToBeReturned;
92 public abstract boolean addResource(Resource resource);
94 public abstract boolean addWidget(Widget resource);
97 * Gets widget version id.
99 * @return the widget version id
101 public String getWidgetId() {
102 org.onap.aai.babel.xml.generator.types.Model model =
103 this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
104 return Widget.getWidget(model.widget()).getId();
110 * @return the invariant id
112 public String getWidgetInvariantId() {
113 org.onap.aai.babel.xml.generator.types.Model model =
114 this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
115 return Widget.getWidget(model.widget()).getWidgetId();
121 * @return the delete flag
123 public boolean getDeleteFlag() {
124 org.onap.aai.babel.xml.generator.types.Model model =
125 this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
126 return model.dataDeleteFlag();
132 * @return the cardinality
134 public Cardinality getCardinality() {
135 org.onap.aai.babel.xml.generator.types.Model model =
136 this.getClass().getAnnotation(org.onap.aai.babel.xml.generator.types.Model.class);
137 return model.cardinality();
140 public abstract Widget.Type getWidgetType();
142 public String getModelId() {
150 * @return the model type
152 public ModelType getModelType() {
153 if (this instanceof Service) {
154 return ModelType.SERVICE;
155 } else if (this instanceof Resource) {
156 return ModelType.RESOURCE;
157 } else if (this instanceof Widget) {
158 return ModelType.WIDGET;
164 public String getModelName() {
168 public String getModelVersion() {
172 public String getModelNameVersionId() {
174 return modelNameVersionId;
177 public String getModelDescription() {
178 return modelDescription;
182 * Populate model identification information.
184 * @param modelIdentInfo the model ident info
186 public void populateModelIdentificationInformation(Map<String, String> modelIdentInfo) {
187 Iterator<String> iter = modelIdentInfo.keySet().iterator();
189 while (iter.hasNext()) {
190 property = iter.next();
192 case "vfModuleModelInvariantUUID":
193 case "serviceInvariantUUID":
194 case "resourceInvariantUUID":
195 case "invariantUUID":
196 case "providing_service_invariant_uuid":
197 modelId = modelIdentInfo.get(property);
199 case "vfModuleModelUUID":
203 case "providing_service_uuid":
204 modelNameVersionId = modelIdentInfo.get(property);
206 case "vfModuleModelVersion":
207 case "serviceVersion":
208 case "resourceversion":
210 modelVersion = modelIdentInfo.get(property);
212 case "vfModuleModelName":
216 modelName = modelIdentInfo.get(property);
218 case "serviceDescription":
219 case "resourceDescription":
220 case "vf_module_description":
222 modelDescription = modelIdentInfo.get(property);
224 case "providing_service_name":
225 modelName = modelIdentInfo.get(property);
226 modelDescription = modelIdentInfo.get(property);
234 public void setModelVersion(String modelVersion) {
235 this.modelVersion = modelVersion;
238 public Set<Resource> getResources() {
242 public Set<Widget> getWidgets() {
246 private void checkSupported() {
247 if (this instanceof Widget) {
248 throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);