2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 European Software Marketing Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.babel.xml.generator.model;
23 import java.util.Collections;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Properties;
28 import org.onap.aai.babel.xml.generator.data.ArtifactType;
29 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
30 import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
31 import org.onap.aai.babel.xml.generator.types.ModelType;
32 import org.onap.aai.babel.xml.generator.types.ModelWidget;
34 public abstract class Widget extends Model {
36 public static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND = "Cannot generate artifacts. Widget configuration not found for %s";
39 SERVICE, VF, VFC, VSERVER, VOLUME, FLAVOR, TENANT, VOLUME_GROUP, LINT, L3_NET, VFMODULE, IMAGE, OAM_NETWORK, ALLOTTED_RESOURCE, TUNNEL_XCONNECT;
42 private Set<String> keys = new HashSet<>();
51 public static Widget getWidget(Type type) {
54 return new ServiceWidget();
56 return new VfWidget();
58 return new VfcWidget();
60 return new VServerWidget();
62 return new VolumeWidget();
64 return new FlavorWidget();
66 return new TenantWidget();
68 return new VolumeGroupWidget();
70 return new LIntfWidget();
72 return new L3NetworkWidget();
74 return new VfModuleWidget();
76 return new ImageWidget();
78 return new OamNetwork();
79 case ALLOTTED_RESOURCE:
80 return new AllotedResourceWidget();
82 return new TunnelXconnectWidget();
88 public String getId() {
89 Properties properties = WidgetConfigurationUtil.getConfig();
90 String id = properties.getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
92 throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
93 ArtifactType.AAI.name() + ".model-version-id." + getName()));
98 public ModelType getType() {
99 ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
100 return widgetModel.type();
103 public String getName() {
104 ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
105 return widgetModel.name();
109 * Get Widget Id from properties file.
111 * @return - Widget Id
114 public String getWidgetId() {
115 Properties properties = WidgetConfigurationUtil.getConfig();
116 String id = properties.getProperty(ArtifactType.AAI.name() + ".model-invariant-id." + getName());
118 throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
119 ArtifactType.AAI.name() + ".model-invariant-id." + getName()));
125 public int hashCode() {
126 return getId().hashCode();
130 public Type getWidgetType() {
139 * @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) {
163 * @return the boolean
165 public boolean memberOf(List<String> keys) {
169 return !Collections.disjoint(this.keys, keys);
173 * All instances used boolean.
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();
186 public boolean addResource(Resource resource) {
187 throw new IllegalAccessException(Model.GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
191 public boolean addWidget(Widget widget) {