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 org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
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;
33 public class Widget extends Model {
35 private Set<String> keys = new HashSet<>();
37 protected String name;
38 protected WidgetType type;
39 protected boolean deleteFlag = false;
41 private String modelInvariantId;
42 private String modelVersionId;
44 public Widget(WidgetType widgetType, String name, boolean deleteFlag, String modelInvariantId, String modelVersionId) {
47 this.deleteFlag = deleteFlag;
48 this.modelInvariantId = modelInvariantId;
49 this.modelVersionId = modelVersionId;
56 * @throws XmlArtifactGenerationException
57 * if there is no widget mapping defined for any of the VSERVER child types
59 public Widget(Widget baseWidget) throws XmlArtifactGenerationException {
60 this(baseWidget.getWidgetType(), baseWidget.getName(), baseWidget.getDeleteFlag(), baseWidget.getWidgetId(), baseWidget.getId());
61 if (this.hasWidgetType("VSERVER")) {
62 widgets.add(createWidget("FLAVOR"));
63 widgets.add(createWidget("IMAGE"));
64 widgets.add(createWidget("TENANT"));
65 widgets.add(createWidget("VFC"));
70 * Creates a new widget of the specified type.
73 * String value of the Widget Type
74 * @return a new widget of the specified type
75 * @throws XmlArtifactGenerationException
76 * if the configured widget mappings do not support the specified type
78 public static Widget createWidget(String type) throws XmlArtifactGenerationException {
79 Widget widget = WidgetConfigurationUtil.createWidgetFromType(type);
81 throw new XmlArtifactGenerationException("No widget type is defined for " + type);
87 * Creates a new widget of the specified type.
91 * @return a new widget of the specified type
92 * @throws XmlArtifactGenerationException
93 * if there is no configuration defined for the specified type
95 public static Widget createWidget(WidgetType type) throws XmlArtifactGenerationException {
96 return createWidget(type.toString());
99 public String getId() {
100 return modelVersionId;
103 public ModelType getType() {
104 return ModelType.WIDGET;
107 public String getName() {
112 * Get Widget Id from properties file.
114 * @return - Widget Id
117 public String getWidgetId() {
118 return modelInvariantId;
122 public int hashCode() {
123 return getId().hashCode();
127 public WidgetType getWidgetType() {
132 * Equals method that compares Widget IDs.
135 * the Widget object to compare
136 * @return whether or not obj is equal to this Widget
139 public boolean equals(Object obj) {
140 boolean isEqual = false;
141 if (obj instanceof Widget) {
142 Widget other = (Widget) obj;
143 if (getId().equals(other.getId())) {
144 other.keys.addAll(this.keys);
151 public void addKey(String key) {
156 * Determine whether one or more keys belonging to this Widget appear in the specified Collection.
160 * @return the boolean
162 public boolean memberOf(Collection<String> keys) {
166 return !Collections.disjoint(this.keys, keys);
170 public boolean addResource(Resource resource) {
171 throw new IllegalAccessException(Model.GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
175 public boolean addWidget(Widget widget) {
176 if (getWidgetType() == WidgetType.valueOf("VSERVER")) {
177 return widgets.add(widget);
183 public String toString() {
184 return getName() + " Widget keys=" + keys + ", resources=" + resources + ", widgets=" + widgets;
188 public boolean getDeleteFlag() {
193 public String getModelTypeName() {
194 throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
198 public String getModelId() {
199 throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);
203 public String getModelNameVersionId() {
204 throw new IllegalAccessException(GENERATOR_AAI_ERROR_UNSUPPORTED_WIDGET_OPERATION);