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 static org.openecomp.sdc.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLPROP_NOT_FOUND;
25 import org.openecomp.sdc.generator.aai.types.ModelType;
26 import org.openecomp.sdc.generator.aai.types.ModelWidget;
27 import org.openecomp.sdc.generator.data.ArtifactType;
28 import org.openecomp.sdc.generator.data.GeneratorConstants;
29 import org.openecomp.sdc.generator.data.WidgetConfigurationUtil;
30 import org.openecomp.sdc.generator.error.IllegalAccessException;
32 import java.util.Collections;
33 import java.util.HashSet;
34 import java.util.List;
35 import java.util.Properties;
38 public abstract class Widget extends Model {
40 private Set<String> keys = new HashSet<>();
45 * @param type the type
48 public static Widget getWidget(Type type) {
52 return new ServiceWidget();
54 return new VfWidget();
56 return new VfcWidget();
58 return new VServerWidget();
60 return new VolumeWidget();
62 return new FlavorWidget();
64 return new TenantWidget();
66 return new VolumeGroupWidget();
68 return new LIntfWidget();
70 return new L3NetworkWidget();
72 return new VfModuleWidget();
74 return new ImageWidget();
76 return new OamNetwork();
77 case ALLOTTED_RESOURCE:
78 return new AllotedResourceWidget();
80 return new TunnelXconnectWidget();
82 return new PnfWidget();
94 public String getId() {
95 Properties properties = WidgetConfigurationUtil.getConfig();
96 String id = properties.getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
98 throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
99 ArtifactType.AAI.name() + ".model-version-id." + getName()));
104 public ModelType getType() {
105 ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
106 return widgetModel.type();
109 public String getName() {
110 ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
111 return widgetModel.name();
115 * Get Widget Id from properties file.
116 * @return - Widget Id
118 public String getWidgetId() {
119 Properties properties = WidgetConfigurationUtil.getConfig();
120 String id = properties.getProperty(ArtifactType.AAI.name() + ".model-invariant-id."
123 throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
124 ArtifactType.AAI.name() + ".model-invariant-id." + getName()));
129 public int hashCode() {
130 return getId().hashCode();
134 public Type getWidgetType() {
142 * @return the boolean
144 public boolean equals(Object obj) {
145 if (obj instanceof Widget) {
146 if (getId().equals(((Widget) obj).getId())) {
147 ((Widget) obj).keys.addAll(this.keys);
156 public void addKey(String key) {
163 * @param keys the keys
164 * @return the boolean
166 public boolean memberOf(List<String> keys) {
170 return !Collections.disjoint(this.keys, keys);
174 * All instances used boolean.
176 * @param collection the collection
177 * @return the boolean
179 public boolean allInstancesUsed(Set<String> collection) {
180 Set<String> keyCopy = new HashSet<>(keys);
181 keyCopy.removeAll(collection);
182 return keyCopy.isEmpty();
185 public boolean addResource(Resource resource) {
186 throw new IllegalAccessException(GeneratorConstants
187 .GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
190 public boolean addWidget(Widget widget) {
195 SERVICE, VF, VFC, VSERVER, VOLUME, FLAVOR, TENANT, VOLUME_GROUP, LINT, L3_NET, VFMODULE, IMAGE,
196 OAM_NETWORK,ALLOTTED_RESOURCE,TUNNEL_XCONNECT, PNF