c1acc319f7706e3ca184898d061efd88e6d0151a
[so.git] /
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 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;
31
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 =
37             "\t{\n" + "\t\t\"modelInfo\"       : {\n" + "\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" + "\t\t},\n"
43                     + "\t\t\"toscaNodeType\"                      : <TOSCA_NODE_TYPE>,\n"
44                     + "\t\t\"allottedResourceType\"               : <ALLOTTED_RESOURCE_TYPE>,\n"
45                     + "\t\t\"allottedResourceRole\"               : <ALLOTTED_RESOURCE_ROLE>,\n"
46                     + "\t\t\"providingServiceModelName\"          : <PROVIDING_SERVICE_MODEL_NAME>,\n"
47                     + "\t\t\"providingServiceModelInvariantUuid\" : <PROVIDING_SERVICE_MODEL_INVARIANT_UUID>,\n"
48                     + "\t\t\"providingServiceModelUuid\"          : <PROVIDING_SERVICE_MODEL_UUID>,\n"
49                     + "\t\t\"nfFunction\"                         : <NF_FUNCTION>,\n"
50                     + "\t\t\"nfType\"                             : <NF_TYPE>,\n"
51                     + "\t\t\"nfRole\"                             : <NF_ROLE>,\n"
52                     + "\t\t\"nfNamingCode\"                       : <NF_NAMING_CODE>,\n"
53                     + "\t\t\"resourceInput\"                      : <RESOURCE_INPUT>\n" + "\t}";
54
55     public QueryAllottedResourceCustomization() {
56         super();
57         allottedResourceCustomization = new ArrayList<>();
58     }
59
60     public QueryAllottedResourceCustomization(List<AllottedResourceCustomization> vlist) {
61         allottedResourceCustomization = vlist;
62     }
63
64     public List<AllottedResourceCustomization> getServiceAllottedResources() {
65         return this.allottedResourceCustomization;
66     }
67
68     public void setServiceAllottedResources(List<AllottedResourceCustomization> v) {
69         this.allottedResourceCustomization = v;
70     }
71
72     @Override
73     public String toString() {
74         StringBuilder sb = new StringBuilder();
75
76         boolean first = true;
77         int i = 1;
78         for (AllottedResourceCustomization o : allottedResourceCustomization) {
79             sb.append(i).append("\t");
80             if (!first)
81                 sb.append("\n");
82
83             first = false;
84             sb.append(o);
85         }
86         return sb.toString();
87     }
88
89     @Override
90     public String JSON2(boolean isArray, boolean isEmbed) {
91         StringBuilder sb = new StringBuilder();
92         if (!isEmbed && isArray)
93             sb.append("{ ");
94         if (isArray)
95             sb.append("\"serviceAllottedResources\": [");
96         Map<String, String> valueMap = new HashMap<>();
97         String sep = "";
98         boolean first = true;
99
100         if (this.allottedResourceCustomization != null) {
101             for (AllottedResourceCustomization o : allottedResourceCustomization) {
102                 if (first)
103                     sb.append("\n");
104
105                 first = false;
106
107                 boolean arNull = o.getAllottedResource() == null;
108
109                 put(valueMap, "MODEL_NAME", arNull ? null : o.getAllottedResource().getModelName());
110                 put(valueMap, "MODEL_UUID", arNull ? null : o.getAllottedResource().getModelUUID());
111                 put(valueMap, "MODEL_INVARIANT_ID", arNull ? null : o.getAllottedResource().getModelInvariantUUID());
112                 put(valueMap, "MODEL_VERSION", arNull ? null : o.getAllottedResource().getModelVersion());
113                 put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID());
114                 put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName());
115                 put(valueMap, "TOSCA_NODE_TYPE", arNull ? null : o.getAllottedResource().getToscaNodeType());
116                 put(valueMap, "ALLOTTED_RESOURCE_TYPE", arNull ? null : o.getAllottedResource().getSubcategory());
117                 put(valueMap, "ALLOTTED_RESOURCE_ROLE",
118                         o.getTargetNetworkRole() != null ? o.getTargetNetworkRole() : o.getNfRole());
119                 put(valueMap, "NF_TYPE", o.getNfType());
120                 put(valueMap, "NF_ROLE", o.getNfRole());
121                 put(valueMap, "NF_FUNCTION", o.getNfFunction());
122                 put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode());
123                 put(valueMap, "PROVIDING_SERVICE_MODEL_INVARIANT_UUID", o.getProvidingServiceModelInvariantUUID());
124                 put(valueMap, "PROVIDING_SERVICE_MODEL_UUID", o.getProvidingServiceModelUUID());
125                 put(valueMap, "PROVIDING_SERVICE_MODEL_NAME", o.getProvidingServiceModelName());
126                 put(valueMap, "RESOURCE_INPUT", o.getResourceInput());
127
128                 sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
129                 sep = ",\n";
130             }
131         }
132         if (!first)
133             sb.append("\n");
134
135         if (isArray)
136             sb.append("]");
137
138         if (!isEmbed && isArray)
139             sb.append("}");
140
141         return sb.toString();
142     }
143
144 }