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=========================================================
21 package org.onap.so.adapters.catalogdb.catalogrest;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
28 import javax.xml.bind.annotation.XmlRootElement;
30 import org.onap.so.db.catalog.beans.HeatEnvironment;
31 import org.onap.so.db.catalog.beans.VfModuleCustomization;
33 @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 sb = new StringBuilder();
76 for (VfModuleCustomization o : vfModules) {
77 sb.append(i).append("\t");
78 if (!first) sb.append("\n"); first = false;
85 public String JSON2(boolean isArray, boolean isEmbed) {
86 StringBuilder sb = new StringBuilder();
87 if (!isEmbed && isArray) sb.append("{ ");
88 if (isArray) sb.append("\"vfModules\": [");
89 Map<String, String> valueMap = new HashMap<>();
93 for (VfModuleCustomization o : vfModules) {
94 if (first) sb.append("\n"); first = false;
96 boolean vfNull = o.getVfModule() == null ? true : false;
97 boolean hasVolumeGroup = false;
98 HeatEnvironment envt = o.getVolumeHeatEnv();
100 hasVolumeGroup = true;
103 put(valueMap, "MODEL_NAME", vfNull ? null : o.getVfModule().getModelName());
104 put(valueMap, "MODEL_UUID", vfNull ? null : o.getVfModule().getModelUUID());
105 put(valueMap, "MODEL_INVARIANT_ID", vfNull ? null : o.getVfModule().getModelInvariantUUID());
106 put(valueMap, "MODEL_VERSION", vfNull ? null : o.getVfModule().getModelVersion());
107 put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID());
108 put(valueMap, "IS_BASE", vfNull ? false : o.getVfModule().getIsBase() ? true : false);
109 put(valueMap, "VF_MODULE_LABEL", o.getLabel());
110 put(valueMap, "INITIAL_COUNT", o.getInitialCount());
111 put(valueMap, "HAS_VOLUME_GROUP", new Boolean(hasVolumeGroup));
113 sb.append(sep).append(this.setTemplate(template, valueMap));
116 if (!first) sb.append("\n");
117 if (isArray) sb.append("]");
118 if (!isEmbed && isArray) sb.append("}");
119 return sb.toString();