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.AllottedResourceCustomization;
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 = "serviceAllottedResources")
33 public class QueryAllottedResourceCustomization extends CatalogQuery {
34 private List<AllottedResourceCustomization> allottedResourceCustomization;
35 private final String template =
37 // "\t{ \"allottedResource\" : {\n"+
38 "\t\t\"modelInfo\" : {\n"+
39 "\t\t\t\"modelName\" : <MODEL_NAME>,\n"+
40 "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n"+
41 "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n"+
42 "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n"+
43 "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+
44 "\t\t\t\"modelInstanceName\" : <MODEL_INSTANCE_NAME>\n"+
46 "\t\t\"toscaNodeType\" : <TOSCA_NODE_TYPE>,\n"+
47 "\t\t\"allottedResourceType\" : <ALLOTTED_RESOURCE_TYPE>,\n"+
48 "\t\t\"allottedResourceRole\" : <ALLOTTED_RESOURCE_ROLE>,\n"+
49 "\t\t\"providingServiceModelInvariantUuid\" : <PROVIDING_SERVICE_MODEL_INVARIANT_UUID>,\n"+
50 "\t\t\"nfFunction\" : <NF_FUNCTION>,\n"+
51 "\t\t\"nfType\" : <NF_TYPE>,\n"+
52 "\t\t\"nfRole\" : <NF_ROLE>,\n"+
53 "\t\t\"nfNamingCode\" : <NF_NAMING_CODE>\n"+
57 public QueryAllottedResourceCustomization() { super(); allottedResourceCustomization = new ArrayList<>(); }
58 public QueryAllottedResourceCustomization(List<AllottedResourceCustomization> vlist) { allottedResourceCustomization = vlist; }
60 public List<AllottedResourceCustomization> getServiceAllottedResources(){ return this.allottedResourceCustomization; }
61 public void setServiceAllottedResources(List<AllottedResourceCustomization> v) { this.allottedResourceCustomization = v; }
64 public String toString () {
65 StringBuilder sb = new StringBuilder();
69 for (AllottedResourceCustomization o : allottedResourceCustomization) {
70 sb.append(i).append("\t");
71 if (!first) sb.append("\n"); first = false;
78 public String JSON2(boolean isArray, boolean isEmbed) {
79 StringBuilder sb = new StringBuilder();
80 if (!isEmbed && isArray) sb.append("{ ");
81 if (isArray) sb.append("\"serviceAllottedResources\": [");
82 Map<String, String> valueMap = new HashMap<>();
86 if (this.allottedResourceCustomization != null) {
87 for (AllottedResourceCustomization o : allottedResourceCustomization) {
88 if (first) sb.append("\n"); first = false;
90 boolean arNull = o.getAllottedResource() == null ? true : false;
92 put(valueMap, "MODEL_NAME", arNull ? null : o.getAllottedResource().getModelName());
93 put(valueMap, "MODEL_UUID", arNull ? null : o.getAllottedResource().getModelUuid());
94 put(valueMap, "MODEL_INVARIANT_ID", arNull ? null : o.getAllottedResource().getModelInvariantUuid());
95 put(valueMap, "MODEL_VERSION", arNull ? null : o.getAllottedResource().getModelVersion());
96 put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid());
97 put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName());
98 put(valueMap, "TOSCA_NODE_TYPE", arNull ? null : o.getAllottedResource().getToscaNodeType());
99 put(valueMap, "ALLOTTED_RESOURCE_TYPE", o.getNfType());
100 put(valueMap, "ALLOTTED_RESOURCE_ROLE", o.getNfRole());
101 put(valueMap, "NF_TYPE", o.getNfType());
102 put(valueMap, "NF_ROLE", o.getNfRole());
103 put(valueMap, "NF_FUNCTION", o.getNfFunction());
104 put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode());
105 put(valueMap, "PROVIDING_SERVICE_MODEL_INVARIANT_UUID", o.getProvidingServiceModelInvariantUuid());
107 sb.append(sep).append(this.setTemplate(template, valueMap));
111 if (!first) sb.append("\n");
112 if (isArray) sb.append("]");
113 if (!isEmbed && isArray) sb.append("}");
114 return sb.toString();