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 static org.onap.aai.babel.xml.generator.data.GeneratorConstants.GENERATOR_AAI_CONFIGLPROP_NOT_FOUND;
25 import java.util.Collections;
26 import java.util.HashSet;
27 import java.util.List;
28 import java.util.Properties;
30 import org.onap.aai.babel.xml.generator.data.ArtifactType;
31 import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
32 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
33 import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
34 import org.onap.aai.babel.xml.generator.types.ModelType;
35 import org.onap.aai.babel.xml.generator.types.ModelWidget;
37 public abstract class Widget extends Model {
39 private Set<String> keys = new HashSet<>();
44 * @param type the type
47 public static Widget getWidget(Type type) {
51 return new ServiceWidget();
53 return new VfWidget();
55 return new VfcWidget();
57 return new VServerWidget();
59 return new VolumeWidget();
61 return new FlavorWidget();
63 return new TenantWidget();
65 return new VolumeGroupWidget();
67 return new LIntfWidget();
69 return new L3NetworkWidget();
71 return new VfModuleWidget();
73 return new ImageWidget();
75 return new OamNetwork();
76 case ALLOTTED_RESOURCE:
77 return new AllotedResourceWidget();
79 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(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() {
140 * @return the boolean
143 public boolean equals(Object obj) {
144 if (obj instanceof Widget) {
145 if (getId().equals(((Widget) obj).getId())) {
146 ((Widget) obj).keys.addAll(this.keys);
155 public void addKey(String key) {
162 * @param keys the keys
163 * @return the boolean
165 public boolean memberOf(List<String> keys) {
169 return !Collections.disjoint(this.keys, keys);
173 * All instances used boolean.
175 * @param collection the collection
176 * @return the boolean
178 public boolean allInstancesUsed(Set<String> collection) {
179 Set<String> keyCopy = new HashSet<>(keys);
180 keyCopy.removeAll(collection);
181 return keyCopy.isEmpty();
185 public boolean addResource(Resource resource) {
186 throw new IllegalAccessException(GeneratorConstants.GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
190 public boolean addWidget(Widget widget) {