00a5cafb293b8d129102672a345eb54eb4991d5c
[so.git] / adapters / mso-catalog-db-adapter / src / main / java / org / openecomp / mso / adapters / catalogdb / catalogrest / QueryVfModules.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.openecomp.mso.adapters.catalogdb.catalogrest;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import javax.xml.bind.annotation.XmlRootElement;
27
28 import org.codehaus.jackson.map.ObjectMapper;
29 import org.jboss.resteasy.annotations.providers.NoJackson;
30
31 import org.openecomp.mso.db.catalog.beans.VfModule;
32 import org.openecomp.mso.logger.MsoLogger;
33
34 @XmlRootElement(name = "vfModules")
35 @NoJackson
36 public class QueryVfModules {
37         private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
38         private List<VfModule> vfModules;
39
40         public QueryVfModules() {
41                 super();
42                 vfModules = new ArrayList<>();
43         }
44         public QueryVfModules(List<VfModule> vlist) { 
45                 LOGGER.debug ("QueryVfModules:");
46                 vfModules = new ArrayList<>();
47                 for (VfModule o : vlist) {
48                         LOGGER.debug ("-- o is a vfModules ----");
49                         LOGGER.debug (o.toString());
50                         vfModules.add(o);
51                         LOGGER.debug ("-------------------");
52                 }
53         }
54
55         public List<VfModule> getVfModules(){ return this.vfModules; }
56
57         public void setVfModules(List<VfModule> v) { this.vfModules = v; }
58         
59         @Override
60         public String toString () {
61                 StringBuilder sb = new StringBuilder();
62
63                 boolean first = true;
64                 int i = 1;
65                 for (VfModule o : vfModules) {
66                         sb.append(i).append("\t");
67                         if (!first) sb.append("\n");
68                         first = false;
69                         sb.append(o);
70                 }
71                 return sb.toString();
72     }
73         
74         public String toJsonString() {
75                 String jsonString = null;
76                 try {
77                         ObjectMapper mapper = new ObjectMapper();
78                         jsonString = mapper.writeValueAsString(this);
79                         LOGGER.debug ("QueryVfModules jsonString: "+jsonString);
80                 }
81                 catch (Exception e) {
82                     LOGGER.debug ("Exception:", e);
83                         LOGGER.debug ("QueryVfModules jsonString exception:"+e.getMessage()); 
84                 }
85                 return jsonString;
86         }
87 }