5c6dda394027798244bb252dc2faad2c8cbf1cd3
[vfc/nfvo/resmanagement.git] /
1 /*
2  * Copyright 2016 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.business.impl;
18
19 import java.util.List;
20
21 import org.apache.commons.lang3.StringUtils;
22 import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil;
23 import org.onap.vfc.nfvo.resmanagement.common.util.StringUtil;
24 import org.onap.vfc.nfvo.resmanagement.service.business.inf.VimBusiness;
25 import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VimDao;
26 import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity;
27 import org.openo.baseservice.remoteservice.exception.ServiceException;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * Vim info interface.<br/>
33  * <p>
34  * </p>
35  *
36  * @author
37  * @version NFVO 0.5 Aug 24, 2016
38  */
39 public class VimBusinessImpl implements VimBusiness {
40
41     private static final Logger LOGGER = LoggerFactory.getLogger(VimBusinessImpl.class);
42
43     private VimDao vimDao;
44
45     @Override
46     public VimEntity getVim(String id) {
47         if(StringUtils.isEmpty(id)) {
48             LOGGER.error("function=getVim; msg=get error, because id is empty.");
49             return null;
50         }
51         return vimDao.getVim(id);
52     }
53
54     @Override
55     public List<VimEntity> getVims() {
56         return vimDao.getVims();
57     }
58
59     @Override
60     public int deleteVim(String id) throws ServiceException {
61         if(StringUtils.isEmpty(id)) {
62             LOGGER.error("function=deleteVim; msg=deleteVim error, because id is empty.");
63             throw new ServiceException(
64                     ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.vim.del.id.check"));
65         }
66         return vimDao.deleteVim(id);
67     }
68
69     @Override
70     public int addVim(String id) throws ServiceException {
71         if(!StringUtil.isValidString(id)) {
72             LOGGER.error("function=addVim; msg=add error, because id is null.");
73             throw new ServiceException(
74                     ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.vim.add.id.null"));
75         }
76         if(!checkId(id)) {
77             LOGGER.error("function=addVim; msg=add error, because id is already exist.");
78             throw new ServiceException(
79                     ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.vim.add.id.check"));
80         }
81
82         VimEntity vimEntity = new VimEntity();
83         vimEntity.setId(id);
84         return vimDao.addVim(vimEntity);
85     }
86
87     private boolean checkId(String id) {
88         VimEntity vim = vimDao.getVim(id);
89         if(null == vim) {
90             return true;
91         }
92         return false;
93     }
94
95     public void setVimDao(VimDao vimDao) {
96         this.vimDao = vimDao;
97     }
98
99 }