2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Huawei Intellectual Property. All rights reserved.
7 * Copyright (C) 2019 IBM.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.adapters.catalogdb.catalogrest;
25 import org.onap.so.db.catalog.beans.InstanceGroup;
26 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
27 import javax.xml.bind.annotation.XmlRootElement;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
33 @XmlRootElement(name = "groups")
34 public class QueryGroups extends CatalogQuery {
36 private List<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizations;
37 private static final String TEMPLATE = "\n" + "\t{ \"modelInfo\" : {\n"
38 + "\t\t\"modelName\" : <MODEL_NAME>,\n" + "\t\t\"modelUuid\" : <MODEL_UUID>,\n"
39 + "\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"
40 + "\t\t\"modelVersion\" : <MODEL_VERSION>\n" + "\t\t},\n" + "<_VNFCS_>\n" + "\t}";
42 public QueryGroups() {
44 vnfcInstanceGroupCustomizations = new ArrayList<>();
48 public QueryGroups(List<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizations) {
49 this.vnfcInstanceGroupCustomizations = new ArrayList<>();
50 if (vnfcInstanceGroupCustomizations != null) {
51 for (VnfcInstanceGroupCustomization g : vnfcInstanceGroupCustomizations) {
52 if (logger.isDebugEnabled()) {
53 logger.debug(g.toString());
55 this.vnfcInstanceGroupCustomizations.add(g);
61 public String JSON2(boolean isArray, boolean isEmbed) {
62 StringBuilder sb = new StringBuilder();
63 if (!isEmbed && isArray)
66 sb.append("\"groups\": [");
67 Map<String, String> valueMap = new HashMap<>();
71 for (VnfcInstanceGroupCustomization o : vnfcInstanceGroupCustomizations) {
76 boolean vnfcCustomizationNull = o.getVnfcCustomizations() == null;
77 InstanceGroup instanceGroup = o.getInstanceGroup();
79 if (instanceGroup != null) {
80 put(valueMap, "MODEL_NAME", instanceGroup.getModelName());
81 put(valueMap, "MODEL_UUID", instanceGroup.getModelUUID());
82 put(valueMap, "MODEL_INVARIANT_ID", instanceGroup.getModelInvariantUUID());
83 put(valueMap, "MODEL_VERSION", instanceGroup.getModelVersion());
86 String subItem = new QueryVnfcs(vnfcCustomizationNull ? null : o.getVnfcCustomizations()).JSON2(true, true);
87 valueMap.put("_VNFCS_", subItem.replaceAll("(?m)^", "\t\t"));
88 sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
95 if (!isEmbed && isArray)