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=========================================================
20 package org.openecomp.mso.adapters.catalogdb.catalogrest;
21 /* should be called QueryVnfResource.java */
23 import org.openecomp.mso.db.catalog.beans.VnfResource;
24 import org.jboss.resteasy.annotations.providers.NoJackson;
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 = "serviceVnfs")
34 public class QueryServiceVnfs extends CatalogQuery {
35 private List<VnfResource> serviceVnfs;
36 private final String template =
38 "\t\t\"modelName\" : <MODEL_NAME>,\n"+
39 "\t\t\"modelUuid\" : <MODEL_UUID>,\n"+
40 "\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+
41 "\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+
42 "\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+
43 "\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>,\n"+
47 public QueryServiceVnfs() { super(); serviceVnfs = new ArrayList<VnfResource>(); }
48 public QueryServiceVnfs(List<VnfResource> vlist) {
49 LOGGER.debug ("QueryServiceVnfs:");
50 serviceVnfs = new ArrayList<VnfResource>();
51 for (VnfResource o : vlist) {
52 LOGGER.debug ("-- o is a serviceVnfs ----");
53 LOGGER.debug (o.toString());
55 LOGGER.debug ("-------------------");
59 public List<VnfResource> getServiceVnfs(){ return this.serviceVnfs; }
60 public void setServiceVnfs(List<VnfResource> v) { this.serviceVnfs = v; }
63 public String toString () {
64 StringBuffer buf = new StringBuffer();
68 for (VnfResource o : serviceVnfs) {
70 if (!first) buf.append("\n"); first = false;
73 return buf.toString();
77 public String JSON2(boolean isArray, boolean isEmbed) {
78 StringBuffer buf = new StringBuffer();
79 if (!isEmbed && isArray) buf.append("{ ");
80 if (isArray) buf.append("\"serviceVnfs\": [");
81 Map<String, String> valueMap = new HashMap<String, String>();
85 for (VnfResource o : serviceVnfs) {
86 if (first) buf.append("\n"); first = false;
88 put(valueMap, "MODEL_NAME", o.getModelName());
89 put(valueMap, "MODEL_UUID", o.getModelUuid());
90 put(valueMap, "MODEL_INVARIANT_ID", o.getModelInvariantId());
91 put(valueMap, "MODEL_VERSION", o.getModelVersion());
92 put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid());
93 put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName());
95 String subitem = new QueryVfModule(o.getVfModules()).JSON2(true, true);
96 valueMap.put("_VFMODULES_", subitem.replaceAll("(?m)^", "\t\t"));
98 buf.append(sep+ this.setTemplate(template, valueMap));
101 if (!first) buf.append("\n");
102 if (isArray) buf.append("]");
103 if (!isEmbed && isArray) buf.append("}");
104 return buf.toString();