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 java.util.Collections;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Properties;
29 import org.onap.sdc.generator.aai.types.ModelType;
30 import org.onap.sdc.generator.aai.types.ModelWidget;
31 import org.onap.sdc.generator.data.ArtifactType;
32 import org.onap.sdc.generator.data.GeneratorConstants;
33 import org.onap.sdc.generator.data.WidgetConfigurationUtil;
34 import org.onap.sdc.generator.error.IllegalAccessException;
36 public abstract class Widget extends Model {
38 private Set<String> keys = new HashSet<>();
43 * @param type the type
46 public static Widget getWidget(Type type) {
50 return new ServiceWidget();
52 return new VfWidget();
54 return new VfcWidget();
56 return new VServerWidget();
58 return new VolumeWidget();
60 return new FlavorWidget();
62 return new TenantWidget();
64 return new VolumeGroupWidget();
66 return new LIntfWidget();
68 return new L3NetworkWidget();
70 return new VfModuleWidget();
72 return new ImageWidget();
74 return new OamNetwork();
75 case ALLOTTED_RESOURCE:
76 return new AllotedResourceWidget();
78 return new TunnelXconnectWidget();
90 public String getId() {
91 Properties properties = WidgetConfigurationUtil.getConfig();
92 String id = properties.getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
94 throw new IllegalArgumentException(String.format(
95 GeneratorConstants.GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
96 ArtifactType.AAI.name() + ".model-version-id." + getName()));
101 public ModelType getType() {
102 ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
103 return widgetModel.type();
106 public String getName() {
107 ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
108 return widgetModel.name();
112 * Get Widget Id from properties file.
113 * @return - Widget Id
115 public String getWidgetId() {
116 Properties properties = WidgetConfigurationUtil.getConfig();
117 String id = properties.getProperty(ArtifactType.AAI.name() + ".model-invariant-id."
120 throw new IllegalArgumentException(String.format(
121 GeneratorConstants.GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
122 ArtifactType.AAI.name() + ".model-invariant-id." + getName()));
127 public int hashCode() {
128 return getId().hashCode();
132 public Type getWidgetType() {
140 * @return the boolean
142 public boolean equals(Object obj) {
143 if (obj instanceof Widget) {
144 if (getId().equals(((Widget) obj).getId())) {
145 ((Widget) obj).keys.addAll(this.keys);
154 public void addKey(String key) {
161 * @param keys the keys
162 * @return the boolean
164 public boolean memberOf(List<String> keys) {
168 return !Collections.disjoint(this.keys, keys);
172 * All instances used boolean.
174 * @param collection the collection
175 * @return the boolean
177 public boolean allInstancesUsed(Set<String> collection) {
178 Set<String> keyCopy = new HashSet<>(keys);
179 keyCopy.removeAll(collection);
180 return keyCopy.isEmpty();
183 public boolean addResource(Resource resource) {
184 throw new IllegalAccessException(GeneratorConstants
185 .GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
188 public boolean addWidget(Widget widget) {
193 SERVICE, VF, VFC, VSERVER, VOLUME, FLAVOR, TENANT, VOLUME_GROUP, LINT, L3_NET, VFMODULE, IMAGE,
194 OAM_NETWORK,ALLOTTED_RESOURCE,TUNNEL_XCONNECT