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();
84 modelToBeReturned = null;
88 toscaType = toscaType.substring(0, toscaType.lastIndexOf("."));
91 return modelToBeReturned;
94 public abstract boolean addResource(Resource resource);
96 public abstract boolean addWidget(Widget resource);
99 * Gets widget version id.
101 * @return the widget version id
103 public String getWidgetId() {
104 org.openecomp.sdc.generator.aai.types.Model model =
105 this.getClass().getAnnotation(org.openecomp.sdc.generator.aai.types.Model.class);
106 return Widget.getWidget(model.widget()).getId();
112 * @return the invariant id
114 public String getWidgetInvariantId() {
115 org.openecomp.sdc.generator.aai.types.Model model =
116 this.getClass().getAnnotation(org.openecomp.sdc.generator.aai.types.Model.class);
117 return Widget.getWidget(model.widget()).getWidgetId();
123 * @return the delete flag
125 public boolean getDeleteFlag() {
126 org.openecomp.sdc.generator.aai.types.Model model =
127 this.getClass().getAnnotation(org.openecomp.sdc.generator.aai.types.Model.class);
128 return model.dataDeleteFlag();
134 * @return the cardinality
136 public Cardinality getCardinality() {
137 org.openecomp.sdc.generator.aai.types.Model model =
138 this.getClass().getAnnotation(org.openecomp.sdc.generator.aai.types.Model.class);
139 return model.cardinality();
142 public abstract Widget.Type getWidgetType();
144 public String getModelId() {
152 * @return the model type
154 public ModelType getModelType() {
156 if (this instanceof Service) {
157 return ModelType.SERVICE;
158 } else if (this instanceof Resource) {
159 return ModelType.RESOURCE;
160 } else if (this instanceof Widget) {
161 return ModelType.WIDGET;
167 public String getModelName() {
172 public String getModelVersion() {
177 public String getModelNameVersionId() {
179 return modelNameVersionId;
182 public String getModelDescription() {
184 return modelDescription;
188 * Populate model identification information.
190 * @param modelIdentInfo the model ident info
192 public void populateModelIdentificationInformation(Map<String, String> modelIdentInfo) {
193 Iterator<String> iter = modelIdentInfo.keySet().iterator();
195 while (iter.hasNext()) {
196 switch (property = iter.next()) {
198 case "vfModuleModelInvariantUUID":
199 case "serviceInvariantUUID":
200 case "resourceInvariantUUID":
201 case "invariantUUID":
202 case "providing_service_invariant_uuid":
203 modelId = modelIdentInfo.get(property);
205 case "vfModuleModelUUID":
209 case "providing_service_uuid":
210 modelNameVersionId = modelIdentInfo.get(property);
212 case "vfModuleModelVersion":
213 case "serviceVersion":
214 case "resourceversion":
216 modelVersion = modelIdentInfo.get(property);
218 case "vfModuleModelName":
222 modelName = modelIdentInfo.get(property);
224 case "serviceDescription":
225 case "resourceDescription":
226 case "vf_module_description":
228 modelDescription = modelIdentInfo.get(property);
230 case "providing_service_name":
231 modelName = modelIdentInfo.get(property);
232 modelDescription = modelIdentInfo.get(property);
244 public Set<Resource> getResources() {
248 public Set<Widget> getWidgets() {
252 private void checkSupported() throws IllegalAccessException {
253 if (this instanceof Widget) {
254 throw new IllegalAccessException(GeneratorConstants
255 .GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);