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;
22 import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
23 import org.jboss.resteasy.annotations.providers.NoJackson;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
31 @XmlRootElement(name = "serviceNetworks")
33 public class QueryServiceNetworks extends CatalogQuery {
34 private List<NetworkResourceCustomization> serviceNetworks;
35 private final String template =
36 "\t{ \"network\" : {\n"+
37 "\t\t\"modelName\" : <MODEL_NAME>,\n"+
38 "\t\t\"modelUuid\" : <MODEL_UUID>,\n"+
39 "\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+
40 "\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+
41 "\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+
42 "\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>,\n"+
43 "\t\t\"networkType\" : <NETWORK_TYPE>\n"+
46 public QueryServiceNetworks() { super(); serviceNetworks = new ArrayList<NetworkResourceCustomization>(); }
47 public QueryServiceNetworks(List<NetworkResourceCustomization> vlist) {
48 LOGGER.debug ("QueryServiceNetworks:");
49 serviceNetworks = new ArrayList<NetworkResourceCustomization>();
50 for (NetworkResourceCustomization o : vlist) {
51 LOGGER.debug (o.toString());
52 serviceNetworks.add(o);
53 LOGGER.debug ("-------------------");
57 public List<NetworkResourceCustomization> getServiceNetworks(){ return this.serviceNetworks; }
58 public void setServiceNetworks(List<NetworkResourceCustomization> v) { this.serviceNetworks = v; }
61 public String toString () {
62 StringBuffer buf = new StringBuffer();
66 for (NetworkResourceCustomization o : serviceNetworks) {
68 if (!first) buf.append("\n"); first = false;
71 return buf.toString();
75 public String JSON2(boolean isArray, boolean isEmbed) {
76 StringBuffer buf = new StringBuffer();
77 if (!isEmbed && isArray) buf.append("{ ");
78 if (isArray) buf.append("\"serviceNetworks\": [");
79 Map<String, String> valueMap = new HashMap<String, String>();
83 for (NetworkResourceCustomization o : serviceNetworks) {
84 if (first) buf.append("\n"); first = false;
86 put(valueMap, "MODEL_NAME", o.getModelName());
87 put(valueMap, "MODEL_UUID", o.getModelUuid());
88 put(valueMap, "MODEL_INVARIANT_ID", o.getModelInvariantId());
89 put(valueMap, "MODEL_VERSION", o.getModelVersion());
90 put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid());
91 put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName());
92 put(valueMap, "NETWORK_TYPE", o.getNetworkType());
94 buf.append(sep+ this.setTemplate(template, valueMap));
97 if (!first) buf.append("\n");
98 if (isArray) buf.append("]");
99 if (!isEmbed && isArray) buf.append("}");
100 return buf.toString();