Upload the ESR server seed code.
[aai/esr-server.git] / esr-core / esr-mgr / src / main / java / org / onap / aai / esr / handle / VimHandler.java
1 /**
2  * Copyright 2016 ZTE Corporation.
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 package org.onap.aai.esr.handle;
17
18 import org.onap.aai.esr.common.ExtSysResuorceType;
19 import org.onap.aai.esr.common.Parameters;
20 import org.onap.aai.esr.entity.db.VimData;
21 import org.onap.aai.esr.exception.ExtsysException;
22 import org.onap.aai.esr.util.HqlFactory;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
30
31 public class VimHandler extends BaseHandler<VimData> {
32   private static final Logger logger = LoggerFactory.getLogger(VimHandler.class);
33
34   @Override
35   public boolean validity(VimData data) throws ExtsysException {
36     return true;
37   }
38
39   public List<VimData> getAll() throws ExtsysException {
40     Map<String, String> query = new HashMap<String, String>();
41     return query(query, ExtSysResuorceType.VIM.name());
42   }
43
44   /**
45    * query vim list by id.
46    */
47   public List<VimData> getVimById(String id) throws ExtsysException {
48     Map<String, String> query = new HashMap<String, String>();
49     query.put(Parameters.id.name(), id);
50     return query(query, ExtSysResuorceType.VIM.name());
51   }
52   
53   /**
54    * update vim list by id.
55    */
56   public VimData update(VimData vimData, String id) throws ExtsysException {
57     update(vimData, HqlFactory.getOidFilter(Parameters.id.name(), id),
58         ExtSysResuorceType.VIM.name());
59     List<VimData> list = getVimById(id);
60     if (list.size() <= 0) {
61       logger.error("update vim info error.");
62       throw new ExtsysException("0000", "update vim info error");
63     }
64     return list.get(0);
65   }
66
67   public VimData add(VimData vimData) throws ExtsysException {
68     return create(vimData, ExtSysResuorceType.VIM.name());
69   }
70   
71   /**
72    * delete vim list by id.
73    */
74   public void delete(String id) throws ExtsysException {
75     VimData vim = new VimData();
76     vim.setId(id);
77     delete(vim, ExtSysResuorceType.VIM.name());
78   }
79 }