Upload the ESR server seed code.
[aai/esr-server.git] / esr-core / esr-mgr / src / main / java / org / onap / aai / esr / handle / EmsHandler.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.EmsData;
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
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30
31
32 public class EmsHandler extends BaseHandler<EmsData> {
33   private static final Logger logger = LoggerFactory.getLogger(EmsHandler.class);
34
35   @Override
36   public boolean validity(EmsData data) throws ExtsysException {
37     return true;
38   }
39
40   public List<EmsData> getAll() throws ExtsysException {
41     Map<String, String> query = new HashMap<String, String>();
42     return query(query, ExtSysResuorceType.EMS.name());
43   }
44
45   /**
46    * get ems list by id.
47    */
48   public List<EmsData> getEmsById(String id) throws ExtsysException {
49     Map<String, String> query = new HashMap<String, String>();
50     query.put(Parameters.id.name(), id);
51     return query(query, ExtSysResuorceType.EMS.name());
52   }
53   
54   /**
55    * update ems list by id.
56    */  
57   public EmsData update(EmsData emsData, String id) throws ExtsysException {
58     update(emsData, HqlFactory.getOidFilter(Parameters.id.name(), id),
59         ExtSysResuorceType.EMS.name());
60     List<EmsData> list = getEmsById(id);
61     if (list.size() <= 0) {
62       logger.error("update ems info error.");
63       throw new ExtsysException("0000", "update ems info error");
64     }
65     return list.get(0);
66   }
67
68   public EmsData add(EmsData emsData) throws ExtsysException {
69
70     return create(emsData, ExtSysResuorceType.EMS.name());
71   }
72   
73   /**
74    * delete ems list by id.
75    */  
76   public void delete(String id) throws ExtsysException {
77     EmsData ems = new EmsData();
78     ems.setId(id);
79     delete(ems, ExtSysResuorceType.EMS.name());
80   }
81 }