2 * Copyright 2017 Huawei Technologies Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.vfc.nfvo.resmanagement.service.entity;
19 import java.io.Serializable;
21 import org.apache.commons.lang.StringUtils;
22 import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil;
24 import net.sf.json.JSONObject;
32 * @version VFC 1.0 Sep 1, 2017
34 public class NsEntity implements Serializable {
42 private String description;
44 private String status;
46 private String createTime;
48 private String lastUpdate;
50 private String resourceVersion;
52 public String getResourceVersion() {
53 return resourceVersion;
56 public void setResourceVersion(String resourceVersion) {
57 this.resourceVersion = resourceVersion;
60 private static final long serialVersionUID = 1L;
62 public String getId() {
66 public void setId(String id) {
70 public String getName() {
74 public void setName(String name) {
78 public String getNsdId() {
82 public void setNsdId(String nsdId) {
86 public String getDescription() {
90 public void setDescription(String description) {
91 this.description = description;
94 public String getStatus() {
98 public void setStatus(String status) {
102 public String getCreateTime() {
106 public void setCreateTime(String createTime) {
107 this.createTime = createTime;
110 public String getLastUpdate() {
114 public void setLastUpdate(String lastUpdate) {
115 this.lastUpdate = lastUpdate;
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"));
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();
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();
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"));