dc73fe904d20ddcd64f95285d46caf10ae41cfa3
[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},\n"
39                     + "\t\t\"resourceInput\"            : <RESOURCE_INPUT>\n" + "\t}";
40
41     public QueryVnfcs() {
42         super();
43         vnfcCustomizations = new ArrayList();
44     }
45
46     public QueryVnfcs(List<VnfcCustomization> vnfcCustomizations) {
47         this.vnfcCustomizations = new ArrayList();
48         if (vnfcCustomizations != null) {
49             for (VnfcCustomization vnfcCustomization : vnfcCustomizations) {
50                 if (logger.isDebugEnabled()) {
51                     logger.debug(vnfcCustomization.toString());
52                 }
53                 this.vnfcCustomizations.add(vnfcCustomization);
54             }
55         }
56     }
57
58     public List<VnfcCustomization> getVnfcCustomizations() {
59         return vnfcCustomizations;
60     }
61
62     public void setVnfcCustomizations(List<VnfcCustomization> vnfcCustomizations) {
63         this.vnfcCustomizations = vnfcCustomizations;
64     }
65
66     @Override
67     public String toString() {
68         StringBuilder sb = new StringBuilder();
69
70         boolean first = true;
71         int i = 1;
72         for (VnfcCustomization o : vnfcCustomizations) {
73             sb.append(i).append("\t");
74             if (!first) {
75                 sb.append("\n");
76             }
77             first = false;
78             sb.append(o);
79         }
80         return sb.toString();
81     }
82
83     @Override
84     public String JSON2(boolean isArray, boolean isEmbed) {
85         StringBuilder sb = new StringBuilder();
86         if (!isEmbed && isArray) {
87             sb.append("{");
88         }
89
90         if (isArray) {
91             sb.append("\"vnfcs\": [");
92         }
93
94         Map<String, String> valueMap = new HashMap<>();
95         String sep = "";
96         boolean first = true;
97
98         for (VnfcCustomization o : vnfcCustomizations) {
99             if (first)
100                 sb.append("\n");
101             first = false;
102
103             put(valueMap, "MODEL_NAME", o.getModelName());
104             put(valueMap, "MODEL_UUID", o.getModelUUID());
105             put(valueMap, "MODEL_INVARIANT_ID", o.getModelInvariantUUID());
106             put(valueMap, "MODEL_VERSION", o.getModelVersion());
107             put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID());
108             put(valueMap, "RESOURCE_INPUT", o.getResourceInput());
109
110             sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
111             sep = ",\n";
112         }
113         if (!first)
114             sb.append("\n");
115         if (isArray)
116             sb.append("]");
117         if (!isEmbed && isArray)
118             sb.append("}");
119         return sb.toString();
120     }
121 }