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.onap.sdc.generator.aai.model;
23 import org.onap.sdc.generator.aai.types.Cardinality;
24 import org.onap.sdc.generator.aai.types.ModelType;
25 import org.onap.sdc.generator.data.GeneratorConstants;
26 import org.onap.sdc.generator.error.IllegalAccessException;
28 import java.util.HashSet;
32 public abstract class Model {
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;
45 * @param toscaType the tosca type
46 * @return the model for
48 public static Model getModelFor(String toscaType) {
50 Model modelToBeReturned = null;
51 while (isModelNotSet(toscaType, modelToBeReturned)) {
55 case "org.openecomp.resource.vf.allottedResource":
56 modelToBeReturned = new AllotedResource();
58 case "org.openecomp.resource.vfc.AllottedResource":
59 modelToBeReturned = new ProvidingService();
61 case "org.openecomp.resource.vfc":
62 modelToBeReturned = new VServerWidget();
64 case "org.openecomp.resource.cp":
65 case "org.openecomp.cp":
66 modelToBeReturned = new LIntfWidget();
68 case "org.openecomp.resource.vl":
69 modelToBeReturned = new L3Network();
71 case "org.openecomp.resource.vf":
72 modelToBeReturned = new VirtualFunction();
74 case "org.openecomp.groups.vfmodule":
75 case "org.openecomp.groups.VfModule":
76 modelToBeReturned = new VfModule();
78 case "org.openecomp.resource.vfc.nodes.heat.cinder":
79 modelToBeReturned = new VolumeWidget();
82 modelToBeReturned = null;
86 toscaType = toscaType.substring(0, toscaType.lastIndexOf("."));
89 return modelToBeReturned;
93 public abstract boolean addResource(Resource resource);
95 public abstract boolean addWidget(Widget resource);
98 * Gets widget version id.
100 * @return the widget version id
102 public String getWidgetId() {
103 org.onap.sdc.generator.aai.types.Model model =
104 this.getClass().getAnnotation(org.onap.sdc.generator.aai.types.Model.class);
105 return Widget.getWidget(model.widget()).getId();
111 * @return the invariant id
113 public String getWidgetInvariantId() {
114 org.onap.sdc.generator.aai.types.Model model =
115 this.getClass().getAnnotation(org.onap.sdc.generator.aai.types.Model.class);
116 return Widget.getWidget(model.widget()).getWidgetId();
122 * @return the delete flag
124 public boolean getDeleteFlag() {
125 org.onap.sdc.generator.aai.types.Model model =
126 this.getClass().getAnnotation(org.onap.sdc.generator.aai.types.Model.class);
127 return model.dataDeleteFlag();
133 * @return the cardinality
135 public Cardinality getCardinality() {
136 org.onap.sdc.generator.aai.types.Model model =
137 this.getClass().getAnnotation(org.onap.sdc.generator.aai.types.Model.class);
138 return model.cardinality();
141 public abstract Widget.Type getWidgetType();
143 public String getModelId() {
151 * @return the model type
153 public ModelType getModelType() {
154 if (this instanceof Service) {
155 return ModelType.SERVICE;
156 } else if (this instanceof Resource) {
157 return ModelType.RESOURCE;
158 } else if (this instanceof Widget) {
159 return ModelType.WIDGET;
165 public String getModelName() {
169 public String getModelVersion() {
173 public String getModelNameVersionId() {
175 return modelNameVersionId;
178 public String getModelDescription() {
179 return modelDescription;
183 * Populate model identification information.
185 * @param modelIdentInfo the model ident info
187 public void populateModelIdentificationInformation(Map<String, String> modelIdentInfo) {
188 for (Map.Entry<String,String> entry : modelIdentInfo.entrySet()) {
189 String property=entry.getKey();
192 case "vfModuleModelInvariantUUID":
193 case "serviceInvariantUUID":
194 case "resourceInvariantUUID":
195 case "invariantUUID":
196 case "providing_service_invariant_uuid":
197 modelId = entry.getValue();
199 case "vfModuleModelUUID":
203 case "providing_service_uuid":
204 modelNameVersionId = entry.getValue();
206 case "vfModuleModelVersion":
207 case "serviceVersion":
208 case "resourceversion":
210 modelVersion = entry.getValue();
212 case "vfModuleModelName":
216 modelName = entry.getValue();
218 case "serviceDescription":
219 case "resourceDescription":
220 case "vf_module_description":
222 modelDescription = entry.getValue();
224 case "providing_service_name":
225 modelName = entry.getValue();
226 modelDescription = entry.getValue();
237 public Set<Resource> getResources() {
241 public Set<Widget> getWidgets() {
245 private void checkSupported() {
246 if (this instanceof Widget) {
247 throw new IllegalAccessException(GeneratorConstants
248 .GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
252 private static boolean isModelNotSet(String toscaType, Model modelToBeReturned) {
253 return toscaType != null && toscaType.lastIndexOf(".") != -1 && modelToBeReturned == null;