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 com.google.common.collect.ImmutableMap;
25 import java.util.Collections;
26 import java.util.List;
28 import java.util.Optional;
29 import java.util.stream.Collectors;
30 import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException;
31 import org.onap.aai.babel.xml.generator.types.ModelType;
33 public class Resource extends Model {
35 private WidgetType type;
36 private boolean deleteFlag;
37 private ModelType modelType = ModelType.RESOURCE;
38 private Map<String, Object> properties = Collections.emptyMap();
40 Widget vserver = null;
41 boolean addlintf = false;
42 boolean addvolume = false;
45 public Resource(WidgetType type, boolean deleteFlag) {
47 this.deleteFlag = deleteFlag;
55 public Resource(Resource baseResource) {
56 this(baseResource.getWidgetType(), baseResource.getDeleteFlag());
57 setModelType(baseResource.getModelType());
61 public int hashCode() {
62 final String uuid = getModelNameVersionId();
63 return uuid == null ? 0 : uuid.hashCode();
67 public boolean equals(Object obj) {
68 if (obj instanceof Resource) {
69 return getModelNameVersionId().equals(((Resource) obj).getModelNameVersionId());
75 public boolean getDeleteFlag() {
79 public void setProperties(Map<String, Object> properties) {
80 this.properties = properties;
83 public Map<String, Object> getProperties() {
87 public void setModelType(ModelType type) {
88 this.modelType = type;
91 public ModelType getModelType() {
95 public void setMembers(List<String> members) {
96 this.members = members;
104 * @return the boolean
105 * @throws XmlArtifactGenerationException
108 public boolean addWidget(Widget widget) throws XmlArtifactGenerationException {
109 if (type == WidgetType.valueOf("VFMODULE")) {
110 if (widget.memberOf(members)) {
111 if (vserver == null && widget.hasWidgetType("VSERVER")) {
112 addVserverWidget(widget);
113 } else if (widget.hasWidgetType("LINT")) {
114 return addLIntfWidget(widget);
115 } else if (widget.hasWidgetType("VOLUME")) {
116 addVolumeWidget(widget);
119 if (!widget.hasWidgetType("OAM_NETWORK")) {
120 return widgets.add(widget);
125 return widgets.add(widget);
130 public WidgetType getWidgetType() {
135 public String getModelTypeName() {
140 public String toString() {
141 return ImmutableMap.<String, String>builder() //
142 .put("Resource", Optional.ofNullable(getModelId()).orElse("null")) //
143 .put("widget type", getWidgetType().toString()) //
144 .put("deleteFlag", Boolean.toString(deleteFlag)) //
145 .put("modelType", modelType.toString()) //
146 .put("properties", properties.toString()) //
147 .put("vserver", Optional.ofNullable(vserver).map(Widget::toString).orElse("null")) //
148 .put("addlintf", Boolean.toString(addlintf)) //
149 .put("addvolume", Boolean.toString(addvolume)) //
150 .put("members", Optional.ofNullable(members).map(List::toString).orElse("null")) //
151 .build().entrySet().stream() //
152 .map(e -> e.getKey() + "=" + e.getValue()) //
153 .collect(Collectors.joining(", "));
156 private void addVolumeWidget(Widget widget) {
157 if (vserver != null) {
158 vserver.addWidget(widget);
168 private boolean addLIntfWidget(Widget widget) {
169 if (vserver != null) {
170 vserver.addWidget(widget);
178 private void addVserverWidget(Widget widget) throws XmlArtifactGenerationException {
181 vserver.addWidget(Widget.createWidget("LINT"));
184 vserver.addWidget(Widget.createWidget("VOLUME"));