0ea054309b3a76254ae25c50bcae65a7d957a388
[so.git] /
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.catalogrest;
21 /* should be called QueryVnfResource.java */
22
23 import org.openecomp.mso.db.catalog.beans.VnfResource;
24 import org.openecomp.mso.logger.MsoLogger;
25 import org.codehaus.jackson.map.ObjectMapper;
26 import org.jboss.resteasy.annotations.providers.NoJackson;
27
28 import javax.xml.bind.annotation.XmlRootElement;
29 import java.util.ArrayList;
30 import java.util.List;
31
32 @XmlRootElement(name = "serviceVnfs")
33 @NoJackson
34 public class QueryServiceVnfs {
35         private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
36         private List<VnfResource> serviceVnfs;
37
38         public QueryServiceVnfs() { super(); serviceVnfs = new ArrayList<VnfResource>(); }
39         public QueryServiceVnfs(List<VnfResource> vlist) {
40                 LOGGER.debug ("QueryServiceVnfs:");
41                 serviceVnfs = new ArrayList<VnfResource>();
42                 for (VnfResource o : vlist) {
43                         LOGGER.debug ("-- o is a  serviceVnfs ----");
44                         LOGGER.debug (o.toString());
45                         serviceVnfs.add(o);
46                         LOGGER.debug ("-------------------");
47                 }
48         }
49
50         public List<VnfResource> getServiceVnfs(){ return this.serviceVnfs; }
51         public void setServiceVnfs(List<VnfResource> v) { this.serviceVnfs = v; }
52
53         @Override
54         public String toString () {
55                 StringBuffer buf = new StringBuffer();
56
57                 boolean first = true;
58                 int i = 1;
59                 for (VnfResource o : serviceVnfs) {
60                         buf.append(i+"\t");
61                         if (!first) buf.append("\n"); first = false;
62                         buf.append(o);
63                 }
64                 return buf.toString();
65     }
66
67         public String toJsonString() {
68                 String jsonString = null;
69                 try {
70                         ObjectMapper mapper = new ObjectMapper();
71                         jsonString = mapper.writeValueAsString(this);
72                         LOGGER.debug ("QuerySrviceVnfs jsonString: "+jsonString);
73                 }
74                 catch (Exception e) {
75                         LOGGER.debug ("QuerySrviceVnfs jsonString exception:"+e.getMessage());
76                 }
77                 return jsonString;
78         }
79 }