2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.catalogdb.catalogrest;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
27 import javax.xml.bind.annotation.XmlRootElement;
28 import org.onap.so.db.catalog.beans.VnfcCustomization;
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}";
43 vnfcCustomizations = new ArrayList();
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());
53 this.vnfcCustomizations.add(vnfcCustomization);
58 public List<VnfcCustomization> getVnfcCustomizations() {
59 return vnfcCustomizations;
62 public void setVnfcCustomizations(List<VnfcCustomization> vnfcCustomizations) {
63 this.vnfcCustomizations = vnfcCustomizations;
67 public String toString() {
68 StringBuilder sb = new StringBuilder();
72 for (VnfcCustomization o : vnfcCustomizations) {
73 sb.append(i).append("\t");
84 public String JSON2(boolean isArray, boolean isEmbed) {
85 StringBuilder sb = new StringBuilder();
86 if (!isEmbed && isArray) {
91 sb.append("\"vnfcs\": [");
94 Map<String, String> valueMap = new HashMap<>();
98 for (VnfcCustomization o : vnfcCustomizations) {
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());
109 if (isJSONValid(o.getResourceInput())) {
110 put(valueMap, "RESOURCE_INPUT", o.getResourceInput());
112 sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
119 if (!isEmbed && isArray)
121 return sb.toString();