diff options
Diffstat (limited to 'rulemgt/src/main/java/org/onap/holmes/rulemgt/db')
-rw-r--r-- | rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java | 124 | ||||
-rw-r--r-- | rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryService.java (renamed from rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java) | 53 | ||||
-rw-r--r-- | rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java | 94 | ||||
-rw-r--r-- | rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java | 31 | ||||
-rw-r--r-- | rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java | 62 |
5 files changed, 212 insertions, 152 deletions
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java deleted file mode 100644 index a9be49f..0000000 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleDao.java +++ /dev/null @@ -1,124 +0,0 @@ -/**
- * Copyright 2017 ZTE Corporation.
- *
- * 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
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * 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.rulemgt.db;
-
-import java.util.List;
-
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.common.api.entity.CorrelationRule;
-import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.CorrelationRuleMapper;
-import org.skife.jdbi.v2.sqlobject.Bind;
-import org.skife.jdbi.v2.sqlobject.BindBean;
-import org.skife.jdbi.v2.sqlobject.GetGeneratedKeys;
-import org.skife.jdbi.v2.sqlobject.SqlQuery;
-import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapper;
-
-@Service
-@RegisterMapper(CorrelationRuleMapper.class)
-public abstract class CorrelationRuleDao {
-
- @GetGeneratedKeys
- @SqlUpdate("INSERT INTO APLUS_RULE (NAME,CTRLLOOP,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,PACKAGE,RID, ENGINEINSTANCE) VALUES (:name,:closedControlLoopName,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:content,:vendor,:createTime,:updateTime,:engineID,:packageName,:rid,:engineInstance)")
- protected abstract String addRule(@BindBean CorrelationRule correlationRule);
-
- @SqlUpdate("UPDATE APLUS_RULE SET CTRLLOOP=:closedControlLoopName,DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime, PACKAGE=:packageName, ENGINEINSTANCE=:engineInstance WHERE RID=:rid")
- protected abstract int updateRuleByRid(@BindBean CorrelationRule correlationRule);
-
- @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")
- protected abstract int deleteRuleByRid(@Bind("rid") String rid);
-
- @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")
- protected abstract int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);
-
- @SqlQuery("SELECT * FROM APLUS_RULE")
- protected abstract List<CorrelationRule> queryAllRules();
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")
- protected abstract CorrelationRule queryRuleById(@Bind("rid") String rid);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")
- protected abstract CorrelationRule queryRuleByName(@Bind("name") String name);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")
- public abstract List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);
-
- @SqlQuery("SELECT * FROM APLUS_RULE WHERE engineinstance=:engineinstance")
- public abstract List<CorrelationRule> queryRuleByEngineInstance(@Bind("engineinstance") String engineinstance);
-
- public List<CorrelationRule> queryRuleByRuleEngineInstance(String enginetype) {
- return queryRuleByEngineInstance(enginetype);
- }
-
- public List<CorrelationRule> queryRuleByRuleEnable(int enable) {
- return queryRuleByEnable(enable);
- }
-
-
- private void deleteRule2DbInner(CorrelationRule correlationRule) {
- String name = correlationRule.getName() != null ? correlationRule.getName().trim() : "";
- String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : "";
- if (!"".equals(name) && !"".equals(rid)) {
- deleteRuleByRidAndName(rid, name);
- } else if (!"".equals(rid)) {
- deleteRuleByRid(rid);
- }
- }
-
- public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- addRule(correlationRule);
- return correlationRule;
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public void updateRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- updateRuleByRid(correlationRule);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public void deleteRule(CorrelationRule correlationRule) throws CorrelationException {
- try {
- deleteRule2DbInner(correlationRule);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
-
- public CorrelationRule queryRuleByRid(String rid) throws CorrelationException {
- try {
- return queryRuleById(rid);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-
- public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException {
- try {
- return queryRuleByName(name);
- } catch (Exception e) {
- throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e);
- }
- }
-}
-
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryService.java index 104f74d..9658ded 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryDao.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleQueryService.java @@ -1,5 +1,5 @@ /**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2021 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,31 +15,28 @@ */
package org.onap.holmes.rulemgt.db;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
-import org.jvnet.hk2.annotations.Service;
-import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
-import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
+import org.jdbi.v3.core.Handle;
+import org.jdbi.v3.core.Jdbi;
+import org.jdbi.v3.core.statement.Query;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.exception.CorrelationException;
-import org.onap.holmes.common.utils.DbDaoUtil;
-import org.skife.jdbi.v2.Handle;
-import org.skife.jdbi.v2.Query;
+import org.onap.holmes.rulemgt.bean.request.RuleQueryCondition;
+import org.onap.holmes.rulemgt.constant.RuleMgtConstant;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.*;
@Service
@Slf4j
-public class CorrelationRuleQueryDao {
+public class CorrelationRuleQueryService {
- @Inject
- private DbDaoUtil dbDaoUtil;
+ @Autowired
+ private Jdbi jdbi;
public List<CorrelationRule> getCorrelationRulesByCondition(RuleQueryCondition ruleQueryCondition)
throws CorrelationException {
@@ -48,9 +45,9 @@ public class CorrelationRuleQueryDao { String whereStr = getWhereStrByRequestEntity(ruleQueryCondition);
try {
StringBuilder querySql = new StringBuilder("SELECT * FROM APLUS_RULE ").append(whereStr);
- handle = dbDaoUtil.getHandle();
+ handle = jdbi.open();
Query query = handle.createQuery(querySql.toString());
- for (Object value : query.list()) {
+ for (Object value : query.mapToMap().list()) {
CorrelationRule correlationRule = getCorrelationRule((Map) value);
correlationRules.add(correlationRule);
}
@@ -59,7 +56,7 @@ public class CorrelationRuleQueryDao { log.warn("Failed to query the rule: id =" + ruleQueryCondition.getRid() + ".");
throw new CorrelationException("Failed to query the rule.", e);
} finally {
- dbDaoUtil.close(handle);
+ handle.close();
}
}
@@ -69,19 +66,19 @@ public class CorrelationRuleQueryDao { correlationRule.setRid((String) value.get("rid"));
correlationRule.setDescription((String) value.get("description"));
correlationRule.setEnabled((Integer) value.get("enable"));
- correlationRule.setTemplateID((Long) value.get("templateID"));
- correlationRule.setEngineID((String) value.get("engineID"));
- correlationRule.setEngineType((String) value.get("engineType"));
+ correlationRule.setTemplateID((Long) value.get("templateid"));
+ correlationRule.setEngineID((String) value.get("engineid"));
+ correlationRule.setEngineType((String) value.get("enginetype"));
correlationRule.setCreator((String) value.get("creator"));
- correlationRule.setCreateTime((Date) value.get("createTime"));
+ correlationRule.setCreateTime((Date) value.get("createtime"));
correlationRule.setModifier((String) value.get("updator"));
- correlationRule.setUpdateTime((Date) value.get("updateTime"));
+ correlationRule.setUpdateTime((Date) value.get("updatetime"));
correlationRule.setParams((Properties) value.get("params"));
correlationRule.setContent((String) value.get("content"));
correlationRule.setVendor((String) value.get("vendor"));
correlationRule.setPackageName((String) value.get("package"));
correlationRule.setClosedControlLoopName((String) value.get("ctrlloop"));
- correlationRule.setEngineInstance((String) value.get("engineInstance"));
+ correlationRule.setEngineInstance((String) value.get("engineinstance"));
return correlationRule;
}
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java new file mode 100644 index 0000000..62eae0c --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/CorrelationRuleService.java @@ -0,0 +1,94 @@ +/** + * Copyright 2021-2022 ZTE Corporation. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.rulemgt.db; + +import org.apache.commons.lang3.StringUtils; +import org.onap.holmes.common.api.entity.CorrelationRule; +import org.onap.holmes.common.exception.CorrelationException; +import org.onap.holmes.rulemgt.db.jdbi.CorrelationRuleDao; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class CorrelationRuleService { + + @Autowired + private CorrelationRuleDao correlationRuleDao; + + public List<CorrelationRule> queryRuleByRuleEngineInstance(String enginetype) { + return correlationRuleDao.queryRuleByEngineInstance(enginetype); + } + + public List<CorrelationRule> queryRuleByRuleEnable(int enable) { + return correlationRuleDao.queryRuleByEnable(enable); + } + + + private void deleteRule2DbInner(CorrelationRule correlationRule) { + String name = correlationRule.getName() != null ? correlationRule.getName().trim() : ""; + String rid = correlationRule.getRid() != null ? correlationRule.getRid().trim() : ""; + if (!StringUtils.EMPTY.equals(name) && !StringUtils.EMPTY.equals(rid)) { + correlationRuleDao.deleteRuleByRidAndName(rid, name); + } else if (!"".equals(rid)) { + correlationRuleDao.deleteRuleByRid(rid); + } + } + + public CorrelationRule saveRule(CorrelationRule correlationRule) throws CorrelationException { + try { + correlationRuleDao.addRule(correlationRule); + return correlationRule; + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } + + public void updateRule(CorrelationRule correlationRule) throws CorrelationException { + try { + correlationRuleDao.updateRuleByRid(correlationRule); + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } + + public void deleteRule(CorrelationRule correlationRule) throws CorrelationException { + try { + deleteRule2DbInner(correlationRule); + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } + + + public CorrelationRule queryRuleByRid(String rid) throws CorrelationException { + try { + return correlationRuleDao.queryRuleById(rid); + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } + + public CorrelationRule queryRuleByRuleName(String name) throws CorrelationException { + try { + return correlationRuleDao.queryRuleByName(name); + } catch (Exception e) { + throw new CorrelationException("Can not access the database. Please contact the administrator for help.", e); + } + } +} diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java new file mode 100644 index 0000000..6addf0f --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/DaoProvider.java @@ -0,0 +1,31 @@ +/** + * Copyright 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.rulemgt.db; + +import org.jdbi.v3.core.Jdbi; +import org.onap.holmes.rulemgt.db.jdbi.CorrelationRuleDao; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class DaoProvider { + + @Bean + public CorrelationRuleDao correlationRuleDao(Jdbi jdbi) { + return jdbi.onDemand(CorrelationRuleDao.class); + } +} diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java new file mode 100644 index 0000000..2ad1d17 --- /dev/null +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/db/jdbi/CorrelationRuleDao.java @@ -0,0 +1,62 @@ +/**
+ * Copyright 2017-2021 ZTE Corporation.
+ *
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.rulemgt.db.jdbi;
+
+import org.jdbi.v3.sqlobject.config.RegisterRowMapper;
+import org.jdbi.v3.sqlobject.customizer.Bind;
+import org.jdbi.v3.sqlobject.customizer.BindBean;
+import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys;
+import org.jdbi.v3.sqlobject.statement.SqlQuery;
+import org.jdbi.v3.sqlobject.statement.SqlUpdate;
+import org.onap.holmes.common.api.entity.CorrelationRule;
+import org.onap.holmes.common.utils.CorrelationRuleMapper;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+@RegisterRowMapper(CorrelationRuleMapper.class)
+public interface CorrelationRuleDao {
+
+ @GetGeneratedKeys
+ @SqlUpdate("INSERT INTO APLUS_RULE (NAME,CTRLLOOP,DESCRIPTION,ENABLE,TEMPLATEID,ENGINETYPE,CREATOR,UPDATOR,PARAMS,CONTENT ,VENDOR,CREATETIME,UPDATETIME,ENGINEID,PACKAGE,RID, ENGINEINSTANCE) VALUES (:name,:closedControlLoopName,:description,:enabled,:templateID,:engineType,:creator,:modifier,:params,:content,:vendor,:createTime,:updateTime,:engineID,:packageName,:rid,:engineInstance)")
+ String addRule(@BindBean CorrelationRule correlationRule);
+
+ @SqlUpdate("UPDATE APLUS_RULE SET CTRLLOOP=:closedControlLoopName,DESCRIPTION=:description,ENABLE=:enabled,CONTENT=:content,UPDATOR=:modifier,UPDATETIME=:updateTime, PACKAGE=:packageName, ENGINEINSTANCE=:engineInstance WHERE RID=:rid")
+ int updateRuleByRid(@BindBean CorrelationRule correlationRule);
+
+ @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid")
+ int deleteRuleByRid(@Bind("rid") String rid);
+
+ @SqlUpdate("DELETE FROM APLUS_RULE WHERE RID=:rid AND NAME=:name")
+ int deleteRuleByRidAndName(@Bind("rid") String rid, @Bind("name") String name);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE")
+ List<CorrelationRule> queryAllRules();
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE RID=:rid")
+ CorrelationRule queryRuleById(@Bind("rid") String rid);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE NAME=:name")
+ CorrelationRule queryRuleByName(@Bind("name") String name);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE enable=:enable")
+ List<CorrelationRule> queryRuleByEnable(@Bind("enable") int enable);
+
+ @SqlQuery("SELECT * FROM APLUS_RULE WHERE engineinstance=:engineinstance")
+ List<CorrelationRule> queryRuleByEngineInstance(@Bind("engineinstance") String engineinstance);
+}
+
|