2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.generator.aai.model;
23 import org.openecomp.sdc.generator.aai.types.Cardinality;
24 import org.openecomp.sdc.generator.aai.types.ModelType;
25 import org.openecomp.sdc.generator.data.GeneratorConstants;
26 import org.openecomp.sdc.generator.error.IllegalAccessException;
28 import java.util.HashSet;
29 import java.util.Iterator;
33 public abstract class Model {
35 protected Set<Resource> resources = new HashSet<>();
36 protected Set<Widget> widgets = new HashSet<>();
37 private String modelId;
38 private String modelName;
39 private ModelType modelType;
40 private String modelVersion;
41 private String modelNameVersionId;
42 private String modelDescription;
47 * @param toscaType the tosca type
48 * @return the model for
50 public static Model getModelFor(String toscaType) {
52 Model modelToBeReturned = null;
53 while (toscaType != null && toscaType.lastIndexOf(".") != -1 && modelToBeReturned == null) {
57 case "org.openecomp.resource.vf.allottedResource":
58 modelToBeReturned = new AllotedResource();
60 case "org.openecomp.resource.vfc.AllottedResource":
61 modelToBeReturned = new ProvidingService();
63 case "org.openecomp.resource.vfc":
64 modelToBeReturned = new VServerWidget();
66 case "org.openecomp.resource.cp":
67 case "org.openecomp.cp":
68 modelToBeReturned = new LIntfWidget();
70 case "org.openecomp.resource.vl":
71 modelToBeReturned = new L3Network();
73 case "org.openecomp.resource.vf":
74 modelToBeReturned = new VirtualFunction();
76 case "org.openecomp.groups.vfmodule":
77 case "org.openecomp.groups.VfModule":
78 modelToBeReturned = new VfModule();
80 case "org.openecomp.resource.vfc.nodes.heat.cinder":
81 modelToBeReturned = new VolumeWidget();
83 case "org.openecomp.resource.pnf":
84 modelToBeReturned = new PnfResource();
87 modelToBeReturned = null;
91 toscaType = toscaType.substring(0, toscaType.lastIndexOf("."));
94 return modelToBeReturned;
97 public abstract boolean addResource(Resource resource);
99 public abstract boolean addWidget(Widget resource);
102 * Gets widget version id.
104 * @return the widget version id
106 public String getWidgetId() {
107 org.openecomp.sdc.generator.aai.types.Model model =
108 this.getClass().getAnnotation(org.openecomp.sdc.generator.aai.types.Model.class);
109 return Widget.getWidget(model.widget()).getId();
115 * @return the invariant id
117 public String getWidgetInvariantId() {
118 org.openecomp.sdc.generator.aai.types.Model model =
119 this.getClass().getAnnotation(org.openecomp.sdc.generator.aai.types.Model.class);
120 return Widget.getWidget(model.widget()).getWidgetId();
126 * @return the delete flag
128 public boolean getDeleteFlag() {
129 org.openecomp.sdc.generator.aai.types.Model model =
130 this.getClass().getAnnotation(org.openecomp.sdc.generator.aai.types.Model.class);
131 return model.dataDeleteFlag();
137 * @return the cardinality
139 public Cardinality getCardinality() {
140 org.openecomp.sdc.generator.aai.types.Model model =
141 this.getClass().getAnnotation(org.openecomp.sdc.generator.aai.types.Model.class);
142 return model.cardinality();
145 public abstract Widget.Type getWidgetType();
147 public String getModelId() {
155 * @return the model type
157 public ModelType getModelType() {
159 if (this instanceof Service) {
160 return ModelType.SERVICE;
161 } else if (this instanceof Resource) {
162 return ModelType.RESOURCE;
163 } else if (this instanceof Widget) {
164 return ModelType.WIDGET;
170 public String getModelName() {
175 public String getModelVersion() {
180 public String getModelNameVersionId() {
182 return modelNameVersionId;
185 public String getModelDescription() {
187 return modelDescription;
191 * Populate model identification information.
193 * @param modelIdentInfo the model ident info
195 public void populateModelIdentificationInformation(Map<String, String> modelIdentInfo) {
196 Iterator<String> iter = modelIdentInfo.keySet().iterator();
198 while (iter.hasNext()) {
199 switch (property = iter.next()) {
201 case "vfModuleModelInvariantUUID":
202 case "serviceInvariantUUID":
203 case "resourceInvariantUUID":
204 case "invariantUUID":
205 case "providing_service_invariant_uuid":
206 modelId = modelIdentInfo.get(property);
208 case "vfModuleModelUUID":
212 case "providing_service_uuid":
213 modelNameVersionId = modelIdentInfo.get(property);
215 case "vfModuleModelVersion":
216 case "serviceVersion":
217 case "resourceversion":
219 modelVersion = modelIdentInfo.get(property);
221 case "vfModuleModelName":
225 modelName = modelIdentInfo.get(property);
227 case "serviceDescription":
228 case "resourceDescription":
229 case "vf_module_description":
231 modelDescription = modelIdentInfo.get(property);
233 case "providing_service_name":
234 modelName = modelIdentInfo.get(property);
235 modelDescription = modelIdentInfo.get(property);
247 public Set<Resource> getResources() {
251 public Set<Widget> getWidgets() {
255 private void checkSupported() throws IllegalAccessException {
256 if (this instanceof Widget) {
257 throw new IllegalAccessException(GeneratorConstants
258 .GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);