Add support to 7.1 VES data-stream in-parallel to 5.4
[holmes/engine-management.git] / engine-d / src / main / java / org / onap / holmes / engine / db / AlarmInfoDao.java
1 /**\r
2  * Copyright 2017 ZTE Corporation.\r
3  * <p>\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  * <p>\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  * <p>\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 package org.onap.holmes.engine.db;\r
17 \r
18 import org.onap.holmes.common.api.entity.AlarmInfo;\r
19 import org.onap.holmes.common.exception.AlarmInfoException;\r
20 import org.onap.holmes.common.utils.AlarmInfoMapper;\r
21 import org.skife.jdbi.v2.sqlobject.*;\r
22 import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;\r
23 \r
24 import java.util.List;\r
25 \r
26 @RegisterMapper(AlarmInfoMapper.class)\r
27 public abstract class AlarmInfoDao {\r
28 \r
29     @GetGeneratedKeys\r
30     @SqlUpdate("INSERT INTO ALARM_INFO  (EVENTID,EVENTNAME,STARTEPOCHMICROSEC,SOURCEID,SOURCENAME,SEQUENCE,ALARMISCLEARED,ROOTFLAG,LASTEPOCHMICROSEC) VALUES (:eventId,:eventName,:startEpochMicroSec,:sourceId,:sourceName,:sequence,:alarmIsCleared,:rootFlag,:lastEpochMicroSec)")\r
31     protected abstract String addAlarm(@BindBean AlarmInfo alarmInfo);\r
32 \r
33     @SqlQuery("SELECT * FROM ALARM_INFO")\r
34     protected abstract List<AlarmInfo> queryAlarm();\r
35 \r
36     @SqlUpdate("DELETE FROM ALARM_INFO WHERE EVENTNAME=:eventName AND SOURCEID=:sourceId AND SOURCENAME=:sourceName")\r
37     protected abstract int deleteAlarmByAlarmIsCleared(@Bind("eventName") String eventName,\r
38                                                        @Bind("sourceId") String sourceId,\r
39                                                        @Bind("sourceName") String sourceName);\r
40 \r
41     public AlarmInfo saveAlarm(AlarmInfo alarmInfo) throws AlarmInfoException {\r
42         try {\r
43             addAlarm(alarmInfo);\r
44             return alarmInfo;\r
45         } catch (Exception e) {\r
46             throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);\r
47         }\r
48     }\r
49 \r
50     public List<AlarmInfo> queryAllAlarm() throws AlarmInfoException {\r
51         try {\r
52             return queryAlarm();\r
53         } catch (Exception e) {\r
54             throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);\r
55         }\r
56     }\r
57 \r
58     public void deleteAlarm(AlarmInfo alarmInfo) {\r
59         if (alarmInfo.getAlarmIsCleared() != 1) {\r
60             return;\r
61         }\r
62 \r
63         String sourceId = alarmInfo.getSourceId();\r
64         String sourceName = alarmInfo.getSourceName();\r
65         String eventName = alarmInfo.getEventName();\r
66         eventName = eventName.substring(0, eventName.lastIndexOf("Cleared"));\r
67 \r
68         deleteAlarmByAlarmIsCleared(eventName, sourceId, sourceName);\r
69     }\r
70 }\r