2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T 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;
22 /* should be called QueryVnfResource.java */
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
29 import javax.xml.bind.annotation.XmlRootElement;
31 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
33 @XmlRootElement(name = "serviceVnfs")
34 public class QueryServiceVnfs extends CatalogQuery {
35 private List<VnfResourceCustomization> serviceVnfs;
36 private final String template =
38 "\t{ \"modelInfo\" : {\n"+
39 "\t\t\"modelName\" : <MODEL_NAME>,\n"+
40 "\t\t\"modelUuid\" : <MODEL_UUID>,\n"+
41 "\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+
42 "\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+
43 "\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+
44 "\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n"+
46 "\t\"toscaNodeType\" : <TOSCA_NODE_TYPE>,\n"+
47 "\t\"nfFunction\" : <NF_FUNCTION>,\n"+
48 "\t\"nfType\" : <NF_TYPE>,\n"+
49 "\t\"nfRole\" : <NF_ROLE>,\n"+
50 "\t\"nfNamingCode\" : <NF_NAMING_CODE>,\n"+
51 "\t\"multiStageDesign\" : <MULTI_STEP_DESIGN>,\n"+
55 public QueryServiceVnfs() { super(); serviceVnfs = new ArrayList<>(); }
56 public QueryServiceVnfs(List<VnfResourceCustomization> vlist) {
57 LOGGER.debug ("QueryServiceVnfs:");
58 serviceVnfs = new ArrayList<>();
59 for (VnfResourceCustomization o : vlist) {
60 LOGGER.debug ("-- o is a serviceVnfs ----");
61 LOGGER.debug (o.toString());
63 LOGGER.debug ("-------------------");
67 public List<VnfResourceCustomization> getServiceVnfs(){ return this.serviceVnfs; }
68 public void setServiceVnfs(List<VnfResourceCustomization> v) { this.serviceVnfs = v; }
71 public String toString () {
72 StringBuilder sb = new StringBuilder();
76 for (VnfResourceCustomization o : serviceVnfs) {
77 sb.append(i).append("\t");
78 if (!first) sb.append("\n"); first = false;
85 public String JSON2(boolean isArray, boolean isEmbed) {
86 StringBuilder sb = new StringBuilder();
87 if (!isEmbed && isArray) sb.append("{ ");
88 if (isArray) sb.append("\"serviceVnfs\": [");
89 Map<String, String> valueMap = new HashMap<>();
93 for (VnfResourceCustomization o : serviceVnfs) {
94 if (first) sb.append("\n"); first = false;
96 boolean vrNull = o.getVnfResources() == null ? true : false;
98 put(valueMap, "MODEL_NAME", vrNull ? null : o.getVnfResources().getModelName());
99 put(valueMap, "MODEL_UUID", vrNull ? null : o.getVnfResources().getModelUUID());
100 put(valueMap, "MODEL_INVARIANT_ID", vrNull ? null : o.getVnfResources().getModelInvariantId());
101 put(valueMap, "MODEL_VERSION", vrNull ? null : o.getVnfResources().getModelVersion());
102 put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID());
103 put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName());
104 put(valueMap, "TOSCA_NODE_TYPE", vrNull ? null : o.getVnfResources().getToscaNodeType());
105 put(valueMap, "NF_FUNCTION", o.getNfFunction());
106 put(valueMap, "NF_TYPE", o.getNfType());
107 put(valueMap, "NF_ROLE", o.getNfRole());
108 put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode());
109 put(valueMap, "MULTI_STEP_DESIGN", o.getMultiStageDesign());
111 String subitem = new QueryVfModule(vrNull ? null : o.getVfModuleCustomizations()).JSON2(true, true);
112 valueMap.put("_VFMODULES_", subitem.replaceAll("(?m)^", "\t\t"));
114 sb.append(sep).append(this.setTemplate(template, valueMap));
117 if (!first) sb.append("\n");
118 if (isArray) sb.append("]");
119 if (!isEmbed && isArray) sb.append("}");
120 return sb.toString();