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.
17 package org.onap.holmes.rulemgt.db;
19 import org.apache.commons.lang3.StringUtils;
20 import org.onap.holmes.common.api.entity.CorrelationRule;
21 import org.onap.holmes.common.exception.CorrelationException;
22 import org.onap.holmes.rulemgt.db.jdbi.CorrelationRuleDao;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.stereotype.Service;
26 import java.util.List;
29 public class CorrelationRuleService {
32 private CorrelationRuleDao correlationRuleDao;
34 public List<CorrelationRule> queryRuleByRuleEngineInstance(String enginetype) {
35 return correlationRuleDao.queryRuleByEngineInstance(enginetype);
38 public List<CorrelationRule> queryRuleByRuleEnable(int enable) {
39 return correlationRuleDao.queryRuleByEnable(enable);
43 private void deleteRule2DbInner(CorrelationRule correlationRule) {
44 String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";
45 String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";
46 if (!StringUtils.EMPTY.equals(name) && !StringUtils.EMPTY.equals(rid)) {
47 correlationRuleDao.deleteRuleByRidAndName(rid, name);
48 } else if (!"".equals(rid)) {
49 correlationRuleDao.deleteRuleByRid(rid);
53 public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException {
55 correlationRuleDao.addRule(correlationRule);
56 return correlationRule;
57 } catch (Exception e) {
58 throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
62 public void updateRule(CorrelationRule correlationRule) throws CorrelationException {
64 correlationRuleDao.updateRuleByRid(correlationRule);
65 } catch (Exception e) {
66 throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
70 public void deleteRule(CorrelationRule correlationRule) throws CorrelationException {
72 deleteRule2DbInner(correlationRule);
73 } catch (Exception e) {
74 throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
79 public CorrelationRule queryRuleByRid(String rid) throws CorrelationException {
81 return correlationRuleDao.queryRuleById(rid);
82 } catch (Exception e) {
83 throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
87 public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException {
89 return correlationRuleDao.queryRuleByName(name);
90 } catch (Exception e) {
91 throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);