AT&T 1712 and 1802 release code
[so.git] / adapters / mso-catalog-db-adapter / src / main / java / org / openecomp / mso / 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 package org.openecomp.mso.adapters.catalogdb.catalogrest;
21
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import javax.xml.bind.annotation.XmlRootElement;
28
29 import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
30
31 @XmlRootElement(name = "vfModules")
32 public class QueryVfModule extends CatalogQuery {
33         private List<VfModuleCustomization> vfModules;
34         private final String template =
35                 "\t{\n"+
36 //              "\t{ \"vfModule\"               : { \n"+
37                 "\t\t\"modelInfo\"               : { \n"+
38                         "\t\t\t\"modelName\"              : <MODEL_NAME>,\n"+
39                         "\t\t\t\"modelUuid\"              : <MODEL_UUID>,\n"+
40                         "\t\t\t\"modelInvariantUuid\"     : <MODEL_INVARIANT_ID>,\n"+
41                         "\t\t\t\"modelVersion\"           : <MODEL_VERSION>,\n"+
42                         "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>\n"+
43                         "\t\t},"+
44                         "\t\t\"isBase\"                 : <IS_BASE>,\n"+
45                         "\t\t\"vfModuleLabel\"          : <VF_MODULE_LABEL>,\n"+
46                         "\t\t\"initialCount\"           : <INITIAL_COUNT>,\n"+
47                         "\t\t\"hasVolumeGroup\"           : <HAS_VOLUME_GROUP>\n"+
48                 "\t}";
49 //              "\t}}";
50
51         public QueryVfModule() { super(); vfModules = new ArrayList<>(); }
52         public QueryVfModule(List<VfModuleCustomization> vlist) { 
53                 LOGGER.debug ("QueryVfModule:");
54                 vfModules = new ArrayList<>();
55                 if (vlist != null) {
56                         for (VfModuleCustomization o : vlist) {
57                         LOGGER.debug ("-- o is a  vfModules ----");
58                         LOGGER.debug (o.toString());
59                         vfModules.add(o);
60                         LOGGER.debug ("-------------------");
61                 }
62         }
63         }
64
65         public List<VfModuleCustomization> getVfModule(){ return this.vfModules; }
66         public void setVfModule(List<VfModuleCustomization> v) { this.vfModules = v; }
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) sb.append("\n"); first = false;
77                         sb.append(o);
78                 }
79                 return sb.toString();
80     }
81
82         @Override
83         public String JSON2(boolean isArray, boolean x) {
84                 StringBuilder sb = new StringBuilder();
85                 if (isArray) sb.append("\"vfModules\": [");
86                 Map<String, String> valueMap = new HashMap<>();
87                 String sep = "";
88                 boolean first = true;
89
90                 for (VfModuleCustomization o : vfModules) {
91                         if (first) sb.append("\n"); first = false;
92
93                         boolean vfNull = o.getVfModule() == null ? true : false;
94                         boolean hasVolumeGroup = false;
95                         String envt = o.getHeatEnvironmentArtifactUuid();
96                         if (envt != null && !"".equals(envt)) {
97                                 hasVolumeGroup = true;
98                         }
99
100                     put(valueMap, "MODEL_NAME",               vfNull ? null : o.getVfModule().getModelName());
101                     put(valueMap, "MODEL_UUID",               vfNull ? null : o.getVfModule().getModelUUID());
102                     put(valueMap, "MODEL_INVARIANT_ID",       vfNull ? null : o.getVfModule().getModelInvariantUuid());
103                     put(valueMap, "MODEL_VERSION",            vfNull ? null : o.getVfModule().getVersion());
104                     put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid());
105                         put(valueMap, "IS_BASE", vfNull ? false : o.getVfModule().isBase() ? true : false);
106                         put(valueMap, "VF_MODULE_LABEL",          o.getLabel());
107                     put(valueMap, "INITIAL_COUNT",            o.getInitialCount());
108                     put(valueMap, "HAS_VOLUME_GROUP", hasVolumeGroup);
109
110             sb.append(sep).append(this.setTemplate(template, valueMap));
111             sep = ",\n";
112                 }
113                 if (!first) sb.append("\n");
114                 if (isArray) sb.append("]");
115                 return sb.toString();
116         }
117 }