Containerization feature of SO
[so.git] / adapters / mso-catalog-db-adapter / src / main / java / org / onap / so / adapters / catalogdb / catalogrest / QueryAllottedResourceCustomization.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.adapters.catalogdb.catalogrest;
22
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
28 import javax.xml.bind.annotation.XmlRootElement;
29
30 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
31 import org.onap.so.logger.MsoLogger;
32
33 @XmlRootElement(name = "serviceAllottedResources")
34 public class QueryAllottedResourceCustomization extends CatalogQuery {
35         protected static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA,QueryAllottedResourceCustomization.class);
36         private List<AllottedResourceCustomization> allottedResourceCustomization;
37         private final String template =
38                 "\t{\n"+
39 //              "\t{ \"allottedResource\"       : {\n"+
40                 "\t\t\"modelInfo\"       : {\n"+
41                         "\t\t\t\"modelName\"              : <MODEL_NAME>,\n"+
42                         "\t\t\t\"modelUuid\"              : <MODEL_UUID>,\n"+
43                         "\t\t\t\"modelInvariantUuid\"     : <MODEL_INVARIANT_ID>,\n"+
44                         "\t\t\t\"modelVersion\"           : <MODEL_VERSION>,\n"+
45                         "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+
46                         "\t\t\t\"modelInstanceName\"      : <MODEL_INSTANCE_NAME>\n"+
47                 "\t\t},\n"+
48                 "\t\t\"toscaNodeType\"                      : <TOSCA_NODE_TYPE>,\n"+ 
49                 "\t\t\"allottedResourceType\"               : <ALLOTTED_RESOURCE_TYPE>,\n"+ 
50                 "\t\t\"allottedResourceRole\"               : <ALLOTTED_RESOURCE_ROLE>,\n"+ 
51                 "\t\t\"providingServiceModelName\"          : <PROVIDING_SERVICE_MODEL_NAME>,\n"+ 
52                 "\t\t\"providingServiceModelInvariantUuid\" : <PROVIDING_SERVICE_MODEL_INVARIANT_UUID>,\n"+ 
53                 "\t\t\"providingServiceModelUuid\"          : <PROVIDING_SERVICE_MODEL_UUID>,\n"+ 
54                 "\t\t\"nfFunction\"                         : <NF_FUNCTION>,\n"+ 
55                 "\t\t\"nfType\"                             : <NF_TYPE>,\n"+ 
56                 "\t\t\"nfRole\"                             : <NF_ROLE>,\n"+ 
57                 "\t\t\"nfNamingCode\"                       : <NF_NAMING_CODE>\n"+ 
58             "\t}";                      
59 //              "\t}}";
60
61         public QueryAllottedResourceCustomization() { super(); allottedResourceCustomization = new ArrayList<>(); }
62         public QueryAllottedResourceCustomization(List<AllottedResourceCustomization> vlist) { allottedResourceCustomization = vlist; }
63
64         public List<AllottedResourceCustomization> getServiceAllottedResources(){ return this.allottedResourceCustomization; }
65         public void setServiceAllottedResources(List<AllottedResourceCustomization> v) { this.allottedResourceCustomization = v; }
66
67         @Override
68         public String toString () {
69                 StringBuilder sb = new StringBuilder();
70
71                 boolean first = true;
72                 int i = 1;
73                 for (AllottedResourceCustomization o : allottedResourceCustomization) {
74                         sb.append(i).append("\t");
75                         if (!first) sb.append("\n"); first = false;
76                         sb.append(o);
77                 }
78                 return sb.toString();
79     }
80
81         @Override
82         public String JSON2(boolean isArray, boolean isEmbed) {
83                 StringBuilder sb = new StringBuilder();
84                 if (!isEmbed && isArray) sb.append("{ ");
85                 if (isArray) sb.append("\"serviceAllottedResources\": [");
86                 Map<String, String> valueMap = new HashMap<>();
87                 String sep = "";
88                 boolean first = true;
89
90                 if (this.allottedResourceCustomization != null) {
91                 for (AllottedResourceCustomization o : allottedResourceCustomization) {
92                         if (first) sb.append("\n"); first = false;
93
94                                 boolean arNull = o.getAllottedResource() == null ? true : false;
95         
96                             put(valueMap, "MODEL_NAME",               arNull ? null : o.getAllottedResource().getModelName());
97                             put(valueMap, "MODEL_UUID",               arNull ? null : o.getAllottedResource().getModelUUID());
98                             put(valueMap, "MODEL_INVARIANT_ID",       arNull ? null : o.getAllottedResource().getModelInvariantUUID());
99                             put(valueMap, "MODEL_VERSION",            arNull ? null : o.getAllottedResource().getModelVersion());
100                     put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID());
101                     put(valueMap, "MODEL_INSTANCE_NAME",      o.getModelInstanceName());
102                             put(valueMap, "TOSCA_NODE_TYPE",      arNull ? null : o.getAllottedResource().getToscaNodeType());
103                             put(valueMap, "ALLOTTED_RESOURCE_TYPE",     arNull ? null : o.getAllottedResource().getSubcategory());
104                             put(valueMap, "ALLOTTED_RESOURCE_ROLE",     o.getTargetNetworkRole());
105                             put(valueMap, "NF_TYPE",     o.getNfType());
106                             put(valueMap, "NF_ROLE",     o.getNfRole());
107                             put(valueMap, "NF_FUNCTION",     o.getNfFunction());
108                             put(valueMap, "NF_NAMING_CODE",     o.getNfNamingCode());
109                             put(valueMap, "PROVIDING_SERVICE_MODEL_INVARIANT_UUID",     o.getProvidingServiceModelInvariantUUID());
110                             put(valueMap, "PROVIDING_SERVICE_MODEL_UUID",     o.getProvidingServiceModelUUID());
111                             put(valueMap, "PROVIDING_SERVICE_MODEL_NAME",     o.getProvidingServiceModelName());
112
113             sb.append(sep).append(this.setTemplate(template, valueMap));
114             sep = ",\n";
115                 }
116                 }
117                 if (!first) sb.append("\n");
118                 if (isArray) sb.append("]");
119                 if (!isEmbed && isArray) sb.append("}");
120                 return sb.toString();
121         }
122
123 }