Replaced all tabs with spaces in java and pom.xml
[so.git] / adapters / mso-catalog-db-adapter / src / main / java / org / onap / so / adapters / catalogdb / catalogrest / QueryVfModule.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.adapters.catalogdb.catalogrest;
22
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import javax.xml.bind.annotation.XmlRootElement;
28 import org.onap.so.db.catalog.beans.HeatEnvironment;
29 import org.onap.so.db.catalog.beans.VfModuleCustomization;
30
31 @XmlRootElement(name = "vfModules")
32 public class QueryVfModule extends CatalogQuery {
33     private List<VfModuleCustomization> vfModules;
34     private static final String TEMPLATE = "\t{\n" + "\t\t\"modelInfo\"               : { \n"
35             + "\t\t\t\"modelName\"              : <MODEL_NAME>,\n"
36             + "\t\t\t\"modelUuid\"              : <MODEL_UUID>,\n"
37             + "\t\t\t\"modelInvariantUuid\"     : <MODEL_INVARIANT_ID>,\n"
38             + "\t\t\t\"modelVersion\"           : <MODEL_VERSION>,\n"
39             + "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>\n" + "\t\t},"
40             + "\t\t\"isBase\"                 : <IS_BASE>,\n" + "\t\t\"vfModuleLabel\"          : <VF_MODULE_LABEL>,\n"
41             + "\t\t\"initialCount\"           : <INITIAL_COUNT>,\n"
42             + "\t\t\"hasVolumeGroup\"           : <HAS_VOLUME_GROUP>\n" + "\t}";
43
44     public QueryVfModule() {
45         super();
46         vfModules = new ArrayList<>();
47     }
48
49     public QueryVfModule(List<VfModuleCustomization> vlist) {
50         vfModules = new ArrayList<>();
51         if (vlist != null) {
52             for (VfModuleCustomization o : vlist) {
53                 if (logger.isDebugEnabled())
54                     logger.debug(o.toString());
55                 vfModules.add(o);
56             }
57         }
58     }
59
60     public List<VfModuleCustomization> getVfModule() {
61         return this.vfModules;
62     }
63
64     public void setVfModule(List<VfModuleCustomization> v) {
65         this.vfModules = v;
66     }
67
68     @Override
69     public String toString() {
70         StringBuilder sb = new StringBuilder();
71
72         boolean first = true;
73         int i = 1;
74         for (VfModuleCustomization o : vfModules) {
75             sb.append(i).append("\t");
76             if (!first)
77                 sb.append("\n");
78             first = false;
79             sb.append(o);
80         }
81         return sb.toString();
82     }
83
84     @Override
85     public String JSON2(boolean isArray, boolean isEmbed) {
86         StringBuilder sb = new StringBuilder();
87         if (!isEmbed && isArray)
88             sb.append("{ ");
89         if (isArray)
90             sb.append("\"vfModules\": [");
91         Map<String, String> valueMap = new HashMap<>();
92         String sep = "";
93         boolean first = true;
94
95         for (VfModuleCustomization o : vfModules) {
96             if (first)
97                 sb.append("\n");
98             first = false;
99
100             boolean vfNull = o.getVfModule() == null ? true : false;
101             boolean hasVolumeGroup = false;
102             HeatEnvironment envt = o.getVolumeHeatEnv();
103             if (envt != null) {
104                 hasVolumeGroup = true;
105             }
106
107             put(valueMap, "MODEL_NAME", vfNull ? null : o.getVfModule().getModelName());
108             put(valueMap, "MODEL_UUID", vfNull ? null : o.getVfModule().getModelUUID());
109             put(valueMap, "MODEL_INVARIANT_ID", vfNull ? null : o.getVfModule().getModelInvariantUUID());
110             put(valueMap, "MODEL_VERSION", vfNull ? null : o.getVfModule().getModelVersion());
111             put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID());
112             put(valueMap, "IS_BASE", vfNull ? false : o.getVfModule().getIsBase() ? true : false);
113             put(valueMap, "VF_MODULE_LABEL", o.getLabel());
114             put(valueMap, "INITIAL_COUNT", o.getInitialCount());
115             put(valueMap, "HAS_VOLUME_GROUP", new Boolean(hasVolumeGroup));
116
117             sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
118             sep = ",\n";
119         }
120         if (!first)
121             sb.append("\n");
122         if (isArray)
123             sb.append("]");
124         if (!isEmbed && isArray)
125             sb.append("}");
126         return sb.toString();
127     }
128 }