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