0bf82fd8b764750d4e1e486c6e9c31c54e9b8f4d
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 Huawei 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 org.onap.so.db.catalog.beans.VnfcCustomization;
24 import javax.xml.bind.annotation.XmlRootElement;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
30 @XmlRootElement(name = "vnfcs")
31 public class QueryVnfcs extends CatalogQuery {
32     private List<VnfcCustomization> vnfcCustomizations;
33     private static final String TEMPLATE =
34             "\t{\n" + "\t\t\"modelInfo\"               : { \n" + "\t\t\t\"modelName\"              : <MODEL_NAME>,\n"
35                     + "\t\t\t\"modelUuid\"              : <MODEL_UUID>,\n"
36                     + "\t\t\t\"modelInvariantUuid\"     : <MODEL_INVARIANT_ID>,\n"
37                     + "\t\t\t\"modelVersion\"           : <MODEL_VERSION>,\n"
38                     + "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>\n" + "\t\t}" + "\t}";
39
40     public QueryVnfcs() {
41         super();
42         vnfcCustomizations = new ArrayList();
43     }
44
45     public QueryVnfcs(List<VnfcCustomization> vnfcCustomizations) {
46         this.vnfcCustomizations = new ArrayList();
47         if (vnfcCustomizations != null) {
48             for (VnfcCustomization vnfcCustomization : vnfcCustomizations) {
49                 if (logger.isDebugEnabled()) {
50                     logger.debug(vnfcCustomization.toString());
51                 }
52                 this.vnfcCustomizations.add(vnfcCustomization);
53             }
54         }
55     }
56
57     public List<VnfcCustomization> getVnfcCustomizations() {
58         return vnfcCustomizations;
59     }
60
61     public void setVnfcCustomizations(List<VnfcCustomization> vnfcCustomizations) {
62         this.vnfcCustomizations = vnfcCustomizations;
63     }
64
65     @Override
66     public String toString() {
67         StringBuilder sb = new StringBuilder();
68
69         boolean first = true;
70         int i = 1;
71         for (VnfcCustomization o : vnfcCustomizations) {
72             sb.append(i).append("\t");
73             if (!first) {
74                 sb.append("\n");
75             }
76             first = false;
77             sb.append(o);
78         }
79         return sb.toString();
80     }
81
82     @Override
83     public String JSON2(boolean isArray, boolean isEmbed) {
84         StringBuilder sb = new StringBuilder();
85         if (!isEmbed && isArray) {
86             sb.append("{");
87         }
88
89         if (isArray) {
90             sb.append("\"vnfcs\": [");
91         }
92
93         Map<String, String> valueMap = new HashMap<>();
94         String sep = "";
95         boolean first = true;
96
97         for (VnfcCustomization o : vnfcCustomizations) {
98             if (first)
99                 sb.append("\n");
100             first = false;
101
102             put(valueMap, "MODEL_NAME", o.getModelName());
103             put(valueMap, "MODEL_UUID", o.getModelUUID());
104             put(valueMap, "MODEL_INVARIANT_ID", o.getModelInvariantUUID());
105             put(valueMap, "MODEL_VERSION", o.getModelVersion());
106             put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID());
107
108             sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
109             sep = ",\n";
110         }
111         if (!first)
112             sb.append("\n");
113         if (isArray)
114             sb.append("]");
115         if (!isEmbed && isArray)
116             sb.append("}");
117         return sb.toString();
118     }
119 }