e5fa14376b8153d42ffe3e404430df0456159be6
[so.git] /
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
28 import javax.xml.bind.annotation.XmlRootElement;
29
30 import org.onap.so.db.catalog.beans.HeatEnvironment;
31 import org.onap.so.db.catalog.beans.VfModuleCustomization;
32
33 @XmlRootElement(name = "vfModules")
34 public class QueryVfModule extends CatalogQuery {
35         private List<VfModuleCustomization> vfModules;
36         private final String template =
37                 "\t{\n"+
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"+
45                         "\t\t},"+
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"+
50                 "\t}";
51 //              "\t}}";
52
53         public QueryVfModule() { super(); vfModules = new ArrayList<>(); }
54         public QueryVfModule(List<VfModuleCustomization> vlist) { 
55                 LOGGER.debug ("QueryVfModule:");
56                 vfModules = new ArrayList<>();
57                 if (vlist != null) {
58                         for (VfModuleCustomization o : vlist) {
59                         LOGGER.debug ("-- o is a  vfModules ----");
60                         LOGGER.debug (o.toString());
61                         vfModules.add(o);
62                         LOGGER.debug ("-------------------");
63                 }
64         }
65         }
66
67         public List<VfModuleCustomization> getVfModule(){ return this.vfModules; }
68         public void setVfModule(List<VfModuleCustomization> v) { this.vfModules = v; }
69
70         @Override
71         public String toString () {
72                 StringBuilder sb = new StringBuilder();
73
74                 boolean first = true;
75                 int i = 1;
76                 for (VfModuleCustomization o : vfModules) {
77                         sb.append(i).append("\t");
78                         if (!first) sb.append("\n"); 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) sb.append("{ ");
88                 if (isArray) sb.append("\"vfModules\": [");
89                 Map<String, String> valueMap = new HashMap<>();
90                 String sep = "";
91                 boolean first = true;
92
93                 for (VfModuleCustomization o : vfModules) {
94                         if (first) sb.append("\n"); first = false;
95
96                         boolean vfNull = o.getVfModule() == null ? true : false;
97                         boolean hasVolumeGroup = false;
98                         HeatEnvironment envt = o.getVolumeHeatEnv();
99                         if (envt != null) {
100                                 hasVolumeGroup = true;
101                         }
102
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));
112
113             sb.append(sep).append(this.setTemplate(template, valueMap));
114             sep = ",\n";
115                 }
116                 if (!first) sb.append("\n");
117                 if (isArray) sb.append("]");
118                 if (!isEmbed && isArray) sb.append("}");
119                 return sb.toString();
120         }
121 }