AT&T 1712 and 1802 release code
[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.openecomp.mso.db.catalog.beans.VfModule;
29 import org.openecomp.mso.logger.MsoLogger;
30
31 import com.fasterxml.jackson.databind.ObjectMapper;
32
33 @XmlRootElement(name = "vfModules")
34 public class QueryVfModules {
35         private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
36         private List<VfModule> vfModules;
37
38         public QueryVfModules() {
39                 super();
40                 vfModules = new ArrayList<>();
41         }
42         public QueryVfModules(List<VfModule> vlist) { 
43                 LOGGER.debug ("QueryVfModules:");
44                 vfModules = new ArrayList<>();
45                 for (VfModule o : vlist) {
46                         LOGGER.debug ("-- o is a vfModules ----");
47                         LOGGER.debug (o.toString());
48                         vfModules.add(o);
49                         LOGGER.debug ("-------------------");
50                 }
51         }
52
53         public List<VfModule> getVfModules(){ return this.vfModules; }
54
55         public void setVfModules(List<VfModule> v) { this.vfModules = v; }
56         
57         @Override
58         public String toString () {
59                 StringBuilder sb = new StringBuilder();
60
61                 boolean first = true;
62                 int i = 1;
63                 for (VfModule o : vfModules) {
64                         sb.append(i).append("\t");
65                         if (!first) sb.append("\n");
66                         first = false;
67                         sb.append(o);
68                 }
69                 return sb.toString();
70     }
71         
72         public String toJsonString() {
73                 String jsonString = null;
74                 try {
75                         ObjectMapper mapper = new ObjectMapper();
76                         jsonString = mapper.writeValueAsString(this);
77                         LOGGER.debug ("QueryVfModules jsonString: "+jsonString);
78                 }
79                 catch (Exception e) {
80                     LOGGER.debug ("Exception:", e);
81                         LOGGER.debug ("QueryVfModules jsonString exception:"+e.getMessage()); 
82                 }
83                 return jsonString;
84         }
85 }