e7113e60c5ec436a1998723861fe680d414eb6c6
[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.jboss.resteasy.annotations.providers.NoJackson;
24
25 import javax.xml.bind.annotation.XmlRootElement;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30
31 @XmlRootElement(name = "vfModules")
32 @NoJackson
33 public class QueryVfModule extends CatalogQuery {
34         private List<VfModule> vfModules;
35         private final String template =
36                 "\t{ \"vfModule\"               : { \n"+
37                         "\t\t\"modelName\"              : <MODEL_NAME>,\n"+
38                         "\t\t\"modelUuid\"              : <MODEL_UUID>,\n"+
39                         "\t\t\"modelInvariantUuid\"     : <MODEL_INVARIANT_ID>,\n"+
40                         "\t\t\"modelVersion\"           : <MODEL_VERSION>,\n"+
41                         "\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+
42                         "\t\t\"vfModuleType\"           : <VF_MODULE_TYPE>,\n"+
43                         "\t\t\"isBase\"                 : <IS_BASE>,\n"+
44                         "\t\t\"vfModuleLabel\"          : <VF_MODULE_LABEL>,\n"+
45                         "\t\t\"initialCount\"           : <INITIAL_COUNT>\n"+
46                 "\t}}";
47
48         public QueryVfModule() { super(); vfModules = new ArrayList<VfModule>(); }
49         public QueryVfModule(List<VfModule> vlist) {
50                 LOGGER.debug ("QueryVfModule:");
51                 vfModules = new ArrayList<VfModule>();
52                 for (VfModule o : vlist) {
53                         LOGGER.debug ("-- o is a  vfModules ----");
54                         LOGGER.debug (o.toString());
55                         vfModules.add(o);
56                         LOGGER.debug ("-------------------");
57                 }
58         }
59
60         public List<VfModule> getVfModule(){ return this.vfModules; }
61         public void setVfModule(List<VfModule> v) { this.vfModules = v; }
62
63         @Override
64         public String toString () {
65                 StringBuffer buf = new StringBuffer();
66
67                 boolean first = true;
68                 int i = 1;
69                 for (VfModule o : vfModules) {
70                         buf.append(i+"\t");
71                         if (!first) buf.append("\n"); first = false;
72                         buf.append(o);
73                 }
74                 return buf.toString();
75     }
76
77         @Override
78         public String JSON2(boolean isArray, boolean x) {
79                 StringBuffer buf = new StringBuffer();
80                 if (isArray) buf.append("\"vfModules\": [");
81                 Map<String, String> valueMap = new HashMap<String, String>();
82                 String sep = "";
83                 boolean first = true;
84
85                 for (VfModule o : vfModules) {
86                         if (first) buf.append("\n"); first = false;
87
88                     put(valueMap, "MODEL_NAME",               o.getModelName());
89                     put(valueMap, "MODEL_UUID",               o.getModelUuid());
90                     put(valueMap, "MODEL_INVARIANT_ID",       o.getModelInvariantId());
91                     put(valueMap, "MODEL_VERSION",            o.getModelVersion());
92                     put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid());
93                     put(valueMap, "VF_MODULE_TYPE",           o.getVfModuleType());
94                     put(valueMap, "IS_BASE",                  new Boolean(o.isBase()? true: false));
95                     put(valueMap, "VF_MODULE_LABEL",          o.getVfModuleLabel());
96                     put(valueMap, "INITIAL_COUNT",            o.getInitialCount());
97
98             buf.append(sep+ this.setTemplate(template, valueMap));
99             sep = ",\n";
100                 }
101                 if (!first) buf.append("\n");
102                 if (isArray) buf.append("]");
103                 return buf.toString();
104         }
105 }