2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.mso.adapters.catalogdb.catalogrest;
22 import org.openecomp.mso.db.catalog.beans.VfModule;
23 import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
24 import org.jboss.resteasy.annotations.providers.NoJackson;
26 import javax.xml.bind.annotation.XmlRootElement;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
32 @XmlRootElement(name = "vfModules")
34 public class QueryVfModule extends CatalogQuery {
35 private List<VfModuleCustomization> vfModules;
36 private final String template =
38 // "\t{ \"vfModule\" : { \n"+
39 "\t\t\"modelInfo\" : { \n"+
40 "\t\t\t\"modelName\" : <MODEL_NAME>,\n"+
41 "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n"+
42 "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+
43 "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+
44 "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>\n"+
46 "\t\t\"isBase\" : <IS_BASE>,\n"+
47 "\t\t\"vfModuleLabel\" : <VF_MODULE_LABEL>,\n"+
48 "\t\t\"initialCount\" : <INITIAL_COUNT>,\n"+
49 "\t\t\"hasVolumeGroup\" : <HAS_VOLUME_GROUP>\n"+
53 public QueryVfModule() { super(); vfModules = new ArrayList<>(); }
54 public QueryVfModule(List<VfModuleCustomization> vlist) {
55 LOGGER.debug ("QueryVfModule:");
56 vfModules = new ArrayList<>();
58 for (VfModuleCustomization o : vlist) {
59 LOGGER.debug ("-- o is a vfModules ----");
60 LOGGER.debug (o.toString());
62 LOGGER.debug ("-------------------");
67 public List<VfModuleCustomization> getVfModule(){ return this.vfModules; }
68 public void setVfModule(List<VfModuleCustomization> v) { this.vfModules = v; }
71 public String toString () {
72 StringBuilder buf = new StringBuilder();
76 for (VfModuleCustomization o : vfModules) {
78 if (!first) buf.append("\n"); first = false;
81 return buf.toString();
85 public String JSON2(boolean isArray, boolean x) {
86 StringBuilder buf = new StringBuilder();
87 if (isArray) buf.append("\"vfModules\": [");
88 Map<String, String> valueMap = new HashMap<>();
92 for (VfModuleCustomization o : vfModules) {
93 if (first) buf.append("\n"); first = false;
95 boolean vfNull = o.getVfModule() == null ? true : false;
96 boolean hasVolumeGroup = false;
97 String envt = o.getHeatEnvironmentArtifactUuid();
98 if (envt != null && !"".equals(envt)) {
99 hasVolumeGroup = true;
102 put(valueMap, "MODEL_NAME", vfNull ? null : o.getVfModule().getModelName());
103 put(valueMap, "MODEL_UUID", vfNull ? null : o.getVfModule().getModelUUID());
104 put(valueMap, "MODEL_INVARIANT_ID", vfNull ? null : o.getVfModule().getModelInvariantUuid());
105 put(valueMap, "MODEL_VERSION", vfNull ? null : o.getVfModule().getVersion());
106 put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid());
107 put(valueMap, "IS_BASE", vfNull ? false : new Boolean(o.getVfModule().isBase()? true: false));
108 put(valueMap, "VF_MODULE_LABEL", o.getLabel());
109 put(valueMap, "INITIAL_COUNT", o.getInitialCount());
110 put(valueMap, "HAS_VOLUME_GROUP", new Boolean(hasVolumeGroup));
112 buf.append(sep+ this.setTemplate(template, valueMap));
115 if (!first) buf.append("\n");
116 if (isArray) buf.append("]");
117 return buf.toString();