2 * Copyright 2016 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.res.service.group.impl;
19 import java.util.List;
22 import org.onap.vfc.nfvo.res.service.dao.inf.VnfStatusDao;
23 import org.onap.vfc.nfvo.res.service.entity.VnfStatusEntity;
24 import org.onap.vfc.nfvo.res.service.group.inf.VnfStatusService;
25 import org.openo.baseservice.remoteservice.exception.ServiceException;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import net.sf.json.JSONObject;
37 * @version NFVO 0.5 Oct 29, 2016
39 public class VnfStatusServiceImpl implements VnfStatusService {
41 private static final Logger LOGGER = LoggerFactory.getLogger(VnfStatusServiceImpl.class);
43 private VnfStatusDao vnfStatusDao;
50 * @throws ServiceException
54 public JSONObject addVnfStatus(JSONObject object) throws ServiceException {
55 LOGGER.info("function=addVnfStatus; object: {}", object);
56 VnfStatusEntity vnfStatusEntity = VnfStatusEntity.toEntity(object);
58 if(!checkId(vnfStatusEntity.getVnfInstanceId())) {
59 result = vnfStatusDao.updateVnfStatus(vnfStatusEntity);
61 result = vnfStatusDao.addVnfStatus(vnfStatusEntity);
63 JSONObject resultObj = new JSONObject();
65 resultObj.put("vnfInstanceId", object.get("vnfInstanceId"));
67 LOGGER.error("function=addVnfStatus; msg=add vnfStatus into DB error.");
68 resultObj.put("message", "Add vnfStatus into DB error.");
76 * @param vnfInstanceId
80 private boolean checkId(String vnfInstanceId) {
81 VnfStatusEntity vnfStatus = vnfStatusDao.getVnfStatus(vnfInstanceId);
82 if(null == vnfStatus) {
93 * @throws ServiceException
97 public List<VnfStatusEntity> getList(Map<String, Object> map) throws ServiceException {
98 return vnfStatusDao.getVnfStatuss(map);
106 * @throws ServiceException
110 public int delete(String id) throws ServiceException {
111 return vnfStatusDao.deleteVnfStatusById(id);
114 public void setVnfStatusDao(VnfStatusDao vnfStatusDao) {
115 this.vnfStatusDao = vnfStatusDao;