873a8dbe1bd8ec61809300215ba7f1296a00a8a8
[so.git] / adapters / mso-catalog-db-adapter / src / main / java / org / openecomp / mso / adapters / catalogdb / catalogrest / QueryVfModule.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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 org.openecomp.mso.db.catalog.beans.VfModule;
23 import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
24 import org.jboss.resteasy.annotations.providers.NoJackson;
25
26 import javax.xml.bind.annotation.XmlRootElement;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 @XmlRootElement(name = "vfModules")
33 @NoJackson
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<VfModuleCustomization>(); }
54         public QueryVfModule(List<VfModuleCustomization> vlist) { 
55                 LOGGER.debug ("QueryVfModule:");
56                 vfModules = new ArrayList<VfModuleCustomization>();
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                 StringBuffer buf = new StringBuffer();
73
74                 boolean first = true;
75                 int i = 1;
76                 for (VfModuleCustomization o : vfModules) {
77                         buf.append(i+"\t");
78                         if (!first) buf.append("\n"); first = false;
79                         buf.append(o);
80                 }
81                 return buf.toString();
82     }
83
84         @Override
85         public String JSON2(boolean isArray, boolean x) {
86                 StringBuffer buf = new StringBuffer();
87                 if (isArray) buf.append("\"vfModules\": [");
88                 Map<String, String> valueMap = new HashMap<String, String>();
89                 String sep = "";
90                 boolean first = true;
91
92                 for (VfModuleCustomization o : vfModules) {
93                         if (first) buf.append("\n"); first = false;
94
95                         boolean vfNull = o.getVfModule() == null ? true : false;
96                         boolean hasVolumeGroup = false;
97                         String envt = o.getHeatEnvironmentArtifactUuid();
98                         if (envt != null && !envt.equals("")) {
99                                 hasVolumeGroup = true;
100                         }
101
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));
111
112             buf.append(sep+ this.setTemplate(template, valueMap));
113             sep = ",\n";
114                 }
115                 if (!first) buf.append("\n");
116                 if (isArray) buf.append("]");
117                 return buf.toString();
118         }
119 }