2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright (c) 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=========================================================
22 package org.onap.aai.babel.xml.generator.model;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.HashSet;
28 import java.util.Properties;
30 import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
31 import org.onap.aai.babel.xml.generator.data.ArtifactType;
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;
36 public class Widget extends Model {
38 public static final String GENERATOR_AAI_CONFIGLPROP_NOT_FOUND =
39 "Cannot generate artifacts. Widget configuration not found for %s";
42 SERVICE, VF, VFC, VSERVER, VOLUME, FLAVOR, TENANT, VOLUME_GROUP, LINT, L3_NET, VFMODULE, IMAGE, OAM_NETWORK, ALLOTTED_RESOURCE, TUNNEL_XCONNECT, CONFIGURATION, CR, INSTANCE_GROUP;
45 private Set<String> keys = new HashSet<>();
47 protected String name;
49 protected boolean deleteFlag = false;
51 public Widget(Type widgetType, String name, boolean deleteFlag) {
54 this.deleteFlag = deleteFlag;
61 * @throws XmlArtifactGenerationException
63 public Widget(Widget baseWidget) throws XmlArtifactGenerationException {
64 this(baseWidget.getWidgetType(), baseWidget.getName(), baseWidget.getDeleteFlag());
65 if (type == Type.VSERVER) {
66 widgets.add(getWidget(Type.FLAVOR));
67 widgets.add(getWidget(Type.IMAGE));
68 widgets.add(getWidget(Type.TENANT));
69 widgets.add(getWidget(Type.VFC));
78 * @return a new widget of the specified type
79 * @throws XmlArtifactGenerationException
80 * if there is no configuration defined for the specified type
82 public static Widget getWidget(Type type) throws XmlArtifactGenerationException {
83 Widget widget = WidgetConfigurationUtil.createWidgetFromType(type);
85 throw new XmlArtifactGenerationException("No widget type is defined for " + type);
91 public boolean isResource() {
95 public String getId() {
96 String id = WidgetConfigurationUtil.getConfig()
97 .getProperty(ArtifactType.AAI.name() + ".model-version-id." + getName());
99 throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
100 ArtifactType.AAI.name() + ".model-version-id." + getName()));
105 public ModelType getType() {
106 return ModelType.WIDGET;
109 public String getName() {
114 * Get Widget Id from properties file.
116 * @return - Widget Id
119 public String getWidgetId() {
120 Properties properties = WidgetConfigurationUtil.getConfig();
121 String id = properties.getProperty(ArtifactType.AAI.name() + ".model-invariant-id." + getName());
123 throw new IllegalArgumentException(String.format(GENERATOR_AAI_CONFIGLPROP_NOT_FOUND,
124 ArtifactType.AAI.name() + ".model-invariant-id." + getName()));
130 public int hashCode() {
131 return getId().hashCode();
135 public Type getWidgetType() {
140 * Equals method that compares Widget IDs.
143 * the Widget object to compare
144 * @return whether or not obj is equal to this Widget
147 public boolean equals(Object obj) {
148 boolean isEqual = false;
149 if (obj instanceof Widget) {
150 Widget other = (Widget) obj;
151 if (getId().equals(other.getId())) {
152 other.keys.addAll(this.keys);
159 public void addKey(String key) {
164 * Determine whether one or more keys belonging to this Widget appear in the specified Collection.
168 * @return the boolean
170 public boolean memberOf(Collection<String> keys) {
174 return !Collections.disjoint(this.keys, keys);
178 public boolean addResource(Resource resource) {
179 throw new IllegalAccessException(Model.GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
183 public boolean addWidget(Widget widget) {
184 if (getWidgetType() == Type.VSERVER) {
185 return widgets.add(widget);
191 public Map<String, Object> getProperties() {
192 return Collections.emptyMap();
196 public String toString() {
197 return getName() + " Widget keys=" + keys + ", resources=" + resources + ", widgets=" + widgets;
201 public boolean getDeleteFlag() {