-/**\r
- * Copyright 2017 ZTE Corporation.\r
- * <p>\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * <p>\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * <p>\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package org.onap.holmes.engine.db;\r
-\r
-import org.onap.holmes.common.api.entity.AlarmInfo;\r
-import org.onap.holmes.common.exception.AlarmInfoException;\r
-import org.onap.holmes.common.utils.AlarmInfoMapper;\r
-import org.skife.jdbi.v2.sqlobject.*;\r
-import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;\r
-\r
-import java.util.List;\r
-\r
-@RegisterMapper(AlarmInfoMapper.class)\r
-public abstract class AlarmInfoDao {\r
-\r
- @GetGeneratedKeys\r
- @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
- protected abstract String addAlarm(@BindBean AlarmInfo alarmInfo);\r
-\r
- @SqlQuery("SELECT * FROM ALARM_INFO")\r
- protected abstract List<AlarmInfo> queryAlarm();\r
-\r
- @SqlUpdate("DELETE FROM ALARM_INFO WHERE EVENTNAME=:eventName AND SOURCEID=:sourceId AND SOURCENAME=:sourceName")\r
- protected abstract int deleteAlarmByAlarmIsCleared(@Bind("eventName") String eventName,\r
- @Bind("sourceId") String sourceId,\r
- @Bind("sourceName") String sourceName);\r
-\r
- public AlarmInfo saveAlarm(AlarmInfo alarmInfo) throws AlarmInfoException {\r
- try {\r
- addAlarm(alarmInfo);\r
- return alarmInfo;\r
- } catch (Exception e) {\r
- throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);\r
- }\r
- }\r
-\r
- public List<AlarmInfo> queryAllAlarm() throws AlarmInfoException {\r
- try {\r
- return queryAlarm();\r
- } catch (Exception e) {\r
- throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);\r
- }\r
- }\r
-\r
- public void deleteAlarm(AlarmInfo alarmInfo) {\r
- if (alarmInfo.getAlarmIsCleared() != 1) {\r
- return;\r
- }\r
-\r
- String sourceId = alarmInfo.getSourceId();\r
- String sourceName = alarmInfo.getSourceName();\r
- String eventName = alarmInfo.getEventName();\r
- eventName = eventName.substring(0, eventName.lastIndexOf("Cleared"));\r
-\r
- deleteAlarmByAlarmIsCleared(eventName, sourceId, sourceName);\r
- }\r
-}\r
+/**
+ * Copyright 2021-2022 ZTE Corporation.
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.holmes.engine.db;
+
+import org.onap.holmes.common.api.entity.AlarmInfo;
+import org.onap.holmes.common.exception.AlarmInfoException;
+import org.onap.holmes.engine.db.jdbi.AlarmInfoDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+
+public class AlarmInfoDaoService {
+
+ @Autowired
+ private AlarmInfoDao alarmInfoDao;
+
+ public AlarmInfo saveAlarm(AlarmInfo alarmInfo) throws AlarmInfoException {
+ try {
+ alarmInfoDao.addAlarm(alarmInfo);
+ return alarmInfo;
+ } catch (Exception e) {
+ throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+ public List<AlarmInfo> queryAllAlarm() throws AlarmInfoException {
+ try {
+ return alarmInfoDao.queryAlarm();
+ } catch (Exception e) {
+ throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
+ }
+ }
+
+ public void deleteAlarm(AlarmInfo alarmInfo) {
+ if (alarmInfo.getAlarmIsCleared() != 1) {
+ return;
+ }
+
+ String sourceId = alarmInfo.getSourceId();
+ String sourceName = alarmInfo.getSourceName();
+ String eventName = alarmInfo.getEventName();
+ eventName = eventName.substring(0, eventName.lastIndexOf("Cleared"));
+
+ alarmInfoDao.deleteAlarmByAlarmIsCleared(eventName, sourceId, sourceName);
+ }
+}