9c81476f5d9e4a646728db0af894149d12661fac
[so.git] / adapters / mso-catalog-db-adapter / src / main / java / org / openecomp / mso / adapters / catalogdb / catalogrest / QueryAllottedResourceCustomization.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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 import org.jboss.resteasy.annotations.providers.NoJackson;
24
25 import javax.xml.bind.annotation.XmlRootElement;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30
31 @XmlRootElement(name = "serviceAllottedResources")
32 @NoJackson
33 public class QueryAllottedResourceCustomization extends CatalogQuery {
34         private List<AllottedResourceCustomization> allottedResourceCustomization;
35         private final String template =
36                 "\t{ \"allottedResource\"       : {\n"+
37                         "\t\t\"modelName\"              : <MODEL_NAME>,\n"+
38                         "\t\t\"modelUuid\"              : <MODEL_UUID>,\n"+
39                         "\t\t\"modelInvariantUuid\"     : <MODEL_INVARIANT_ID>,\n"+
40                         "\t\t\"modelVersion\"           : <MODEL_VERSION>,\n"+
41                         "\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>,\n"+
42                         "\t\t\"modelInstanceName\"      : <MODEL_INSTANCE_NAME>\n"+
43                 "\t}}";
44
45         public QueryAllottedResourceCustomization() { super(); allottedResourceCustomization = new ArrayList<AllottedResourceCustomization>(); }
46         public QueryAllottedResourceCustomization(List<AllottedResourceCustomization> vlist) { allottedResourceCustomization = vlist; }
47
48         public List<AllottedResourceCustomization> getServiceAllottedResources(){ return this.allottedResourceCustomization; }
49         public void setServiceAllottedResources(List<AllottedResourceCustomization> v) { this.allottedResourceCustomization = v; }
50
51         @Override
52         public String toString () {
53                 StringBuffer buf = new StringBuffer();
54
55                 boolean first = true;
56                 int i = 1;
57                 for (AllottedResourceCustomization o : allottedResourceCustomization) {
58                         buf.append(i+"\t");
59                         if (!first) buf.append("\n"); first = false;
60                         buf.append(o);
61                 }
62                 return buf.toString();
63     }
64
65         @Override
66         public String JSON2(boolean isArray, boolean isEmbed) {
67                 StringBuffer buf = new StringBuffer();
68                 if (!isEmbed && isArray) buf.append("{ ");
69                 if (isArray) buf.append("\"serviceAllottedResources\": [");
70                 Map<String, String> valueMap = new HashMap<String, String>();
71                 String sep = "";
72                 boolean first = true;
73
74                 for (AllottedResourceCustomization o : allottedResourceCustomization) {
75                         if (first) buf.append("\n"); first = false;
76
77                     put(valueMap, "MODEL_NAME",               o.getModelName());
78                     put(valueMap, "MODEL_UUID",               o.getModelUuid());
79                     put(valueMap, "MODEL_INVARIANT_ID",       o.getModelInvariantId());
80                     put(valueMap, "MODEL_VERSION",            o.getModelVersion());
81                     put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUuid());
82                     put(valueMap, "MODEL_INSTANCE_NAME",      o.getModelInstanceName());
83
84             buf.append(sep+ this.setTemplate(template, valueMap));
85             sep = ",\n";
86                 }
87                 if (!first) buf.append("\n");
88                 if (isArray) buf.append("]");
89                 if (!isEmbed && isArray) buf.append("}");
90                 return buf.toString();
91         }
92
93 }