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 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;
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}";
42 vnfcCustomizations = new ArrayList();
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());
52 this.vnfcCustomizations.add(vnfcCustomization);
57 public List<VnfcCustomization> getVnfcCustomizations() {
58 return vnfcCustomizations;
61 public void setVnfcCustomizations(List<VnfcCustomization> vnfcCustomizations) {
62 this.vnfcCustomizations = vnfcCustomizations;
66 public String toString() {
67 StringBuilder sb = new StringBuilder();
71 for (VnfcCustomization o : vnfcCustomizations) {
72 sb.append(i).append("\t");
83 public String JSON2(boolean isArray, boolean isEmbed) {
84 StringBuilder sb = new StringBuilder();
85 if (!isEmbed && isArray) {
90 sb.append("\"vnfcs\": [");
93 Map<String, String> valueMap = new HashMap<>();
97 for (VnfcCustomization o : vnfcCustomizations) {
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());
108 sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
115 if (!isEmbed && isArray)
117 return sb.toString();