AT&T 1712 and 1802 release code
[so.git] / adapters / mso-catalog-db-adapter / src / main / java / org / openecomp / mso / 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 package org.openecomp.mso.adapters.catalogdb.catalogrest;
21
22 import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
23
24 import javax.xml.bind.annotation.XmlRootElement;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
30 @XmlRootElement(name = "serviceAllottedResources")
31 public class QueryAllottedResourceCustomization extends CatalogQuery {
32         private List<AllottedResourceCustomization> allottedResourceCustomization;
33         private final String template =
34                 "\t{\n"+
35 //              "\t{ \"allottedResource\"       : {\n"+
36                 "\t\t\"modelInfo\"       : {\n"+
37                         "\t\t\t\"modelName\"              : <MODEL_NAME>,\n"+
38                         "\t\t\t\"modelUuid\"              : <MODEL_UUID>,\n"+
39                         "\t\t\t\"modelInvariantUuid\"     : <MODEL_INVARIANT_ID>,\n"+
40                         "\t\t\t\"modelVersion\"           : <MODEL_VERSION>,\n"+
41                         "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+
42                         "\t\t\t\"modelInstanceName\"      : <MODEL_INSTANCE_NAME>\n"+
43                 "\t\t},\n"+
44                 "\t\t\"toscaNodeType\"                      : <TOSCA_NODE_TYPE>,\n"+ 
45                 "\t\t\"allottedResourceType\"               : <ALLOTTED_RESOURCE_TYPE>,\n"+ 
46                 "\t\t\"allottedResourceRole\"               : <ALLOTTED_RESOURCE_ROLE>,\n"+ 
47                 "\t\t\"providingServiceModelName\"          : <PROVIDING_SERVICE_MODEL_NAME>,\n"+ 
48                 "\t\t\"providingServiceModelInvariantUuid\" : <PROVIDING_SERVICE_MODEL_INVARIANT_UUID>,\n"+ 
49                 "\t\t\"providingServiceModelUuid\"          : <PROVIDING_SERVICE_MODEL_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"+ 
54             "\t}";                      
55 //              "\t}}";
56
57         public QueryAllottedResourceCustomization() { super(); allottedResourceCustomization = new ArrayList<>(); }
58         public QueryAllottedResourceCustomization(List<AllottedResourceCustomization> vlist) { allottedResourceCustomization = vlist; }
59
60         public List<AllottedResourceCustomization> getServiceAllottedResources(){ return this.allottedResourceCustomization; }
61         public void setServiceAllottedResources(List<AllottedResourceCustomization> v) { this.allottedResourceCustomization = v; }
62
63         @Override
64         public String toString () {
65                 StringBuilder sb = new StringBuilder();
66
67                 boolean first = true;
68                 int i = 1;
69                 for (AllottedResourceCustomization o : allottedResourceCustomization) {
70                         sb.append(i).append("\t");
71                         if (!first) sb.append("\n"); first = false;
72                         sb.append(o);
73                 }
74                 return sb.toString();
75     }
76
77         @Override
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<>();
83                 String sep = "";
84                 boolean first = true;
85
86                 if (this.allottedResourceCustomization != null) {
87                 for (AllottedResourceCustomization o : allottedResourceCustomization) {
88                         if (first) sb.append("\n"); first = false;
89
90                                 boolean arNull = o.getAllottedResource() == null ? true : false;
91         
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",     arNull ? null : o.getAllottedResource().getSubcategory());
100                             put(valueMap, "ALLOTTED_RESOURCE_ROLE",     o.getTargetNetworkRole());
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());
106                             put(valueMap, "PROVIDING_SERVICE_MODEL_UUID",     o.getProvidingServiceModelUuid());
107                             put(valueMap, "PROVIDING_SERVICE_MODEL_NAME",     o.getProvidingServiceModelName());
108
109             sb.append(sep).append(this.setTemplate(template, valueMap));
110             sep = ",\n";
111                 }
112                 }
113                 if (!first) sb.append("\n");
114                 if (isArray) sb.append("]");
115                 if (!isEmbed && isArray) sb.append("}");
116                 return sb.toString();
117         }
118
119 }