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, CONFIGURATION;
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();
84 return new ConfigurationWidget();
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(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
95 ArtifactType.AAI.name() + ".model-version-id." + getName()));
100 public ModelType getType() {
101 ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
102 return widgetModel.type();
105 public String getName() {
106 ModelWidget widgetModel = this.getClass().getAnnotation(ModelWidget.class);
107 return widgetModel.name();
111 * Get Widget Id from properties file.
113 * @return - Widget Id
116 public String getWidgetId() {
117 Properties properties = WidgetConfigurationUtil.getConfig();
118 String id = properties.getProperty(ArtifactType.AAI.name() + ".model-invariant-id." + getName());
120 throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
121 ArtifactType.AAI.name() + ".model-invariant-id." + getName()));
127 public int hashCode() {
128 return getId().hashCode();
132 public Type getWidgetType() {
141 * @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) {
165 * @return the boolean
167 public boolean memberOf(List<String> keys) {
171 return !Collections.disjoint(this.keys, keys);
175 * All instances used boolean.
179 * @return the boolean
181 public boolean allInstancesUsed(Set<String> collection) {
182 Set<String> keyCopy = new HashSet<>(keys);
183 keyCopy.removeAll(collection);
184 return keyCopy.isEmpty();
188 public boolean addResource(Resource resource) {
189 throw new IllegalAccessException(Model.GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
193 public boolean addWidget(Widget widget) {