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;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
27 import javax.xml.bind.annotation.XmlRootElement;
28 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 @XmlRootElement(name = "serviceAllottedResources")
33 public class QueryAllottedResourceCustomization extends CatalogQuery {
34 protected static Logger logger = LoggerFactory.getLogger(QueryAllottedResourceCustomization.class);
35 private List<AllottedResourceCustomization> allottedResourceCustomization;
36 private static final String TEMPLATE =
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\"providingServiceModelName\" : <PROVIDING_SERVICE_MODEL_NAME>,\n"+
50 "\t\t\"providingServiceModelInvariantUuid\" : <PROVIDING_SERVICE_MODEL_INVARIANT_UUID>,\n"+
51 "\t\t\"providingServiceModelUuid\" : <PROVIDING_SERVICE_MODEL_UUID>,\n"+
52 "\t\t\"nfFunction\" : <NF_FUNCTION>,\n"+
53 "\t\t\"nfType\" : <NF_TYPE>,\n"+
54 "\t\t\"nfRole\" : <NF_ROLE>,\n"+
55 "\t\t\"nfNamingCode\" : <NF_NAMING_CODE>,\n"+
56 "\t\t\"resourceInput\" : <RESOURCE_INPUT>\n"+
59 public QueryAllottedResourceCustomization() {
61 allottedResourceCustomization = new ArrayList<>();
64 public QueryAllottedResourceCustomization(List<AllottedResourceCustomization> vlist) {
65 allottedResourceCustomization = vlist;
68 public List<AllottedResourceCustomization> getServiceAllottedResources(){
69 return this.allottedResourceCustomization;
72 public void setServiceAllottedResources(List<AllottedResourceCustomization> v) {
73 this.allottedResourceCustomization = v;
77 public String toString () {
78 StringBuilder sb = new StringBuilder();
82 for (AllottedResourceCustomization o : allottedResourceCustomization) {
83 sb.append(i).append("\t");
94 public String JSON2(boolean isArray, boolean isEmbed) {
95 StringBuilder sb = new StringBuilder();
96 if (!isEmbed && isArray)
99 sb.append("\"serviceAllottedResources\": [");
100 Map<String, String> valueMap = new HashMap<>();
102 boolean first = true;
104 if (this.allottedResourceCustomization != null) {
105 for (AllottedResourceCustomization o : allottedResourceCustomization) {
111 boolean arNull = o.getAllottedResource() == null ? true : false;
113 put(valueMap, "MODEL_NAME", arNull ? null : o.getAllottedResource().getModelName());
114 put(valueMap, "MODEL_UUID", arNull ? null : o.getAllottedResource().getModelUUID());
115 put(valueMap, "MODEL_INVARIANT_ID", arNull ? null : o.getAllottedResource().getModelInvariantUUID());
116 put(valueMap, "MODEL_VERSION", arNull ? null : o.getAllottedResource().getModelVersion());
117 put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID());
118 put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName());
119 put(valueMap, "TOSCA_NODE_TYPE", arNull ? null : o.getAllottedResource().getToscaNodeType());
120 put(valueMap, "ALLOTTED_RESOURCE_TYPE", arNull ? null : o.getAllottedResource().getSubcategory());
121 put(valueMap, "ALLOTTED_RESOURCE_ROLE", o.getTargetNetworkRole() != null ? o.getTargetNetworkRole() : o.getNfRole());
122 put(valueMap, "NF_TYPE", o.getNfType());
123 put(valueMap, "NF_ROLE", o.getNfRole());
124 put(valueMap, "NF_FUNCTION", o.getNfFunction());
125 put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode());
126 put(valueMap, "PROVIDING_SERVICE_MODEL_INVARIANT_UUID", o.getProvidingServiceModelInvariantUUID());
127 put(valueMap, "PROVIDING_SERVICE_MODEL_UUID", o.getProvidingServiceModelUUID());
128 put(valueMap, "PROVIDING_SERVICE_MODEL_NAME", o.getProvidingServiceModelName());
129 put(valueMap, "RESOURCE_INPUT", o.getResourceInput());
131 sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
141 if (!isEmbed && isArray)
144 return sb.toString();