3a30015a70c5d77b8523c1d2003c12ef013585d9
[vfc/nfvo/resmanagement.git] /
1 /*
2  * Copyright 2017 Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.vfc.nfvo.resmanagement.service.entity;
18
19 import java.io.Serializable;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil;
23
24 import net.sf.json.JSONObject;
25
26 /**
27  * <br>
28  * <p>
29  * </p>
30  *
31  * @author
32  * @version VFC 1.0 Sep 1, 2017
33  */
34 public class NsEntity implements Serializable {
35
36     private String id;
37
38     private String name;
39
40     private String nsdId;
41
42     private String description;
43
44     private String status;
45
46     private String createTime;
47
48     private String lastUpdate;
49
50     private String resourceVersion;
51
52     public String getResourceVersion() {
53         return resourceVersion;
54     }
55
56     public void setResourceVersion(String resourceVersion) {
57         this.resourceVersion = resourceVersion;
58     }
59
60     private static final long serialVersionUID = 1L;
61
62     public String getId() {
63         return id;
64     }
65
66     public void setId(String id) {
67         this.id = id;
68     }
69
70     public String getName() {
71         return name;
72     }
73
74     public void setName(String name) {
75         this.name = name;
76     }
77
78     public String getNsdId() {
79         return nsdId;
80     }
81
82     public void setNsdId(String nsdId) {
83         this.nsdId = nsdId;
84     }
85
86     public String getDescription() {
87         return description;
88     }
89
90     public void setDescription(String description) {
91         this.description = description;
92     }
93
94     public String getStatus() {
95         return status;
96     }
97
98     public void setStatus(String status) {
99         this.status = status;
100     }
101
102     public String getCreateTime() {
103         return createTime;
104     }
105
106     public void setCreateTime(String createTime) {
107         this.createTime = createTime;
108     }
109
110     public String getLastUpdate() {
111         return lastUpdate;
112     }
113
114     public void setLastUpdate(String lastUpdate) {
115         this.lastUpdate = lastUpdate;
116     }
117
118     public static NsEntity toEntity(JSONObject jsonObject) {
119         NsEntity nsEntity = new NsEntity();
120         nsEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id"));
121         nsEntity.setNsdId(JsonUtil.getJsonFieldStr(jsonObject, "nsdId"));
122         nsEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name"));
123         nsEntity.setDescription(JsonUtil.getJsonFieldStr(jsonObject, "description"));
124         nsEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "status"));
125         nsEntity.setCreateTime(JsonUtil.getJsonFieldStr(jsonObject, "createTime"));
126         nsEntity.setLastUpdate(JsonUtil.getJsonFieldStr(jsonObject, "lastUpdate"));
127         return nsEntity;
128     }
129
130     @Override
131     public String toString() {
132         JSONObject nsResJson = new JSONObject();
133         nsResJson.put("id", StringUtils.trimToEmpty(this.getId()));
134         nsResJson.put("nsdId", StringUtils.trimToEmpty(this.getNsdId()));
135         nsResJson.put("name", StringUtils.trimToEmpty(this.getName()));
136         nsResJson.put("description", StringUtils.trimToEmpty(this.getDescription()));
137         nsResJson.put("status", StringUtils.trimToEmpty(this.getStatus()));
138         nsResJson.put("createTime", StringUtils.trimToEmpty(this.getCreateTime()));
139         nsResJson.put("lastUpdate", StringUtils.trimToEmpty(this.getLastUpdate()));
140         return nsResJson.toString();
141     }
142
143     public String toStringForAai() {
144         JSONObject nsResJson = new JSONObject();
145         nsResJson.put("service-instnace-id", StringUtils.trimToEmpty(this.getId()));
146         nsResJson.put("service-instance-name", StringUtils.trimToEmpty(this.getName()));
147         nsResJson.put("description", StringUtils.trimToEmpty(this.getDescription()));
148         nsResJson.put("orchestration-status", StringUtils.trimToEmpty(this.getStatus()));
149         nsResJson.put("created-at", StringUtils.trimToEmpty(this.getCreateTime()));
150         nsResJson.put("updated-at", StringUtils.trimToEmpty(this.getLastUpdate()));
151         nsResJson.put("resource-version", StringUtils.trimToEmpty(this.getResourceVersion()));
152         return nsResJson.toString();
153     }
154
155     public static NsEntity toEntityFromAai(JSONObject jsonObject) {
156         NsEntity nsEntity = new NsEntity();
157         nsEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "service-instance-id"));
158         nsEntity.setNsdId(JsonUtil.getJsonFieldStr(jsonObject, "service-instance-id"));
159         nsEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "service-instance-name"));
160         nsEntity.setDescription(JsonUtil.getJsonFieldStr(jsonObject, "description"));
161         nsEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "orchestration-status"));
162         nsEntity.setCreateTime(JsonUtil.getJsonFieldStr(jsonObject, "created-at"));
163         nsEntity.setLastUpdate(JsonUtil.getJsonFieldStr(jsonObject, "updated-at"));
164         nsEntity.setResourceVersion(JsonUtil.getJsonFieldStr(jsonObject, "resource-version"));
165         return nsEntity;
166     }
167
168 }