2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2019 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.Collection;
24 import java.util.Collections;
25 import java.util.HashSet;
27 import java.util.Properties;
29 import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
30 import org.onap.aai.babel.xml.generator.data.ArtifactType;
31 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
32 import org.onap.aai.babel.xml.generator.error.IllegalAccessException;
33 import org.onap.aai.babel.xml.generator.types.ModelType;
35 public class Widget extends Model {
37 public static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND =
38 "Cannot generate artifacts. Widget configuration not found for %s";
41 SERVICE, VF, VFC, VSERVER, VOLUME, FLAVOR, TENANT, VOLUME_GROUP, LINT, L3_NET, VFMODULE, IMAGE, OAM_NETWORK, ALLOTTED_RESOURCE, TUNNEL_XCONNECT, CONFIGURATION, CR, INSTANCE_GROUP;
44 private Set<String> keys = new HashSet<>();
46 protected String name;
48 protected boolean deleteFlag = false;
50 public Widget(Type widgetType, String name, boolean deleteFlag) {
53 this.deleteFlag = deleteFlag;
60 * @throws XmlArtifactGenerationException
62 public Widget(Widget baseWidget) throws XmlArtifactGenerationException {
63 this(baseWidget.getWidgetType(), baseWidget.getName(), baseWidget.getDeleteFlag());
64 if (type == Type.VSERVER) {
65 widgets.add(getWidget(Type.FLAVOR));
66 widgets.add(getWidget(Type.IMAGE));
67 widgets.add(getWidget(Type.TENANT));
68 widgets.add(getWidget(Type.VFC));
77 * @return a new widget of the specified type
78 * @throws XmlArtifactGenerationException
79 * if there is no configuration defined for the specified type
81 public static Widget getWidget(Type type) throws XmlArtifactGenerationException {
82 Widget widget = WidgetConfigurationUtil.createWidgetFromType(type);
84 throw new XmlArtifactGenerationException("No widget type is defined for " + type);
90 public boolean isResource() {
94 public String getId() {
95 String id = WidgetConfigurationUtil.getConfig()
96 .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 return ModelType.WIDGET;
108 public String getName() {
113 * Get Widget Id from properties file.
115 * @return - Widget Id
118 public String getWidgetId() {
119 Properties properties = WidgetConfigurationUtil.getConfig();
120 String id = properties.getProperty(ArtifactType.AAI.name() + ".model-invariant-id." + getName());
122 throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
123 ArtifactType.AAI.name() + ".model-invariant-id." + getName()));
129 public int hashCode() {
130 return getId().hashCode();
134 public Type getWidgetType() {
139 * Equals method that compares Widget IDs.
142 * the Widget object to compare
143 * @return whether or not obj is equal to this Widget
146 public boolean equals(Object obj) {
147 boolean isEqual = false;
148 if (obj instanceof Widget) {
149 Widget other = (Widget) obj;
150 if (getId().equals(other.getId())) {
151 other.keys.addAll(this.keys);
158 public void addKey(String key) {
163 * Determine whether one or more keys belonging to this Widget appear in the specified Collection.
167 * @return the boolean
169 public boolean memberOf(Collection<String> keys) {
173 return !Collections.disjoint(this.keys, keys);
177 public boolean addResource(Resource resource) {
178 throw new IllegalAccessException(Model.GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
182 public boolean addWidget(Widget widget) {
183 if (getWidgetType() == Type.VSERVER) {
184 return widgets.add(widget);
190 public Map<String, Object> getProperties() {
191 return Collections.emptyMap();
195 public String toString() {
196 return getName() + " Widget keys=" + keys + ", resources=" + resources + ", widgets=" + widgets;
200 public boolean getDeleteFlag() {