2 * Copyright 2021-2022 ZTE Corporation.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.holmes.engine.db;
18 import org.onap.holmes.common.api.entity.AlarmInfo;
19 import org.onap.holmes.common.exception.AlarmInfoException;
20 import org.onap.holmes.engine.db.jdbi.AlarmInfoDao;
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.stereotype.Service;
24 import java.util.List;
28 public class AlarmInfoDaoService {
31 private AlarmInfoDao alarmInfoDao;
33 public AlarmInfo saveAlarm(AlarmInfo alarmInfo) throws AlarmInfoException {
35 alarmInfoDao.addAlarm(alarmInfo);
37 } catch (Exception e) {
38 throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
42 public List<AlarmInfo> queryAllAlarm() throws AlarmInfoException {
44 return alarmInfoDao.queryAlarm();
45 } catch (Exception e) {
46 throw new AlarmInfoException("Can not access the database. Please contact the administrator for help.", e);
50 public void deleteAlarm(AlarmInfo alarmInfo) {
51 if (alarmInfo.getAlarmIsCleared() != 1) {
55 String sourceId = alarmInfo.getSourceId();
56 String sourceName = alarmInfo.getSourceName();
57 String eventName = alarmInfo.getEventName();
58 eventName = eventName.substring(0, eventName.lastIndexOf("Cleared"));
60 alarmInfoDao.deleteAlarmByAlarmIsCleared(eventName, sourceId, sourceName);