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.InstanceGroup;
24 import org.onap.so.db.catalog.beans.VFCInstanceGroup;
25 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
26 import javax.xml.bind.annotation.XmlRootElement;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
32 @XmlRootElement(name = "groups")
33 public class QueryGroups extends CatalogQuery {
35 private List<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizations;
36 private static final String TEMPLATE = "\n" + "\t{ \"modelInfo\" : {\n"
37 + "\t\t\"modelName\" : <MODEL_NAME>,\n" + "\t\t\"modelUuid\" : <MODEL_UUID>,\n"
38 + "\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"
39 + "\t\t\"modelVersion\" : <MODEL_VERSION>\n" + "\t\t},\n" + "<_VNFCS_>\n" + "\t}";
41 public QueryGroups() {
43 vnfcInstanceGroupCustomizations = new ArrayList<>();
47 public QueryGroups(List<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizations) {
48 this.vnfcInstanceGroupCustomizations = new ArrayList<>();
49 if (vnfcInstanceGroupCustomizations != null) {
50 for (VnfcInstanceGroupCustomization g : vnfcInstanceGroupCustomizations) {
51 if (logger.isDebugEnabled()) {
52 logger.debug(g.toString());
54 this.vnfcInstanceGroupCustomizations.add(g);
60 public String JSON2(boolean isArray, boolean isEmbed) {
61 StringBuilder sb = new StringBuilder();
62 if (!isEmbed && isArray)
65 sb.append("\"groups\": [");
66 Map<String, String> valueMap = new HashMap<>();
70 for (VnfcInstanceGroupCustomization o : vnfcInstanceGroupCustomizations) {
75 boolean vnfcCustomizationNull = o.getVnfcCustomizations() == null;
76 InstanceGroup instanceGroup = o.getInstanceGroup();
78 if (instanceGroup != null) {
79 put(valueMap, "MODEL_NAME", instanceGroup.getModelName());
80 put(valueMap, "MODEL_UUID", instanceGroup.getModelUUID());
81 put(valueMap, "MODEL_INVARIANT_ID", instanceGroup.getModelInvariantUUID());
82 put(valueMap, "MODEL_VERSION", instanceGroup.getModelVersion());
85 String subItem = new QueryVnfcs(vnfcCustomizationNull ? null : o.getVnfcCustomizations()).JSON2(true, true);
86 valueMap.put("_VNFCS_", subItem.replaceAll("(?m)^", "\t\t"));
87 sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
94 if (!isEmbed && isArray)