From 1e61676b77dd09659027b8984f050df7e8538526 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Tue, 22 Oct 2019 07:53:44 -0400 Subject: Consolidate PolicyRestAdapter setup Put common code into PolicyEngineUtils that the controllers use to populate the PolicyRestController. Also some more sonar cleanup and formatting of XML files. Shortened 120 line characters. Removed some trailing spaces from comments. Fixed up one JUnit. Licenses. Issue-ID: POLICY-2133 Change-Id: Id7d8ac3ab60331535f048ec0f26aeb17a099414e Signed-off-by: Pamela Dragosh --- .../pap/xacml/rest/daoimpl/CommonClassDaoImpl.java | 96 +++++++--------------- 1 file changed, 31 insertions(+), 65 deletions(-) (limited to 'ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java') diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java index 2688d7d3c..ee5c22f1c 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java @@ -22,7 +22,9 @@ package org.onap.policy.pap.xacml.rest.daoimpl; import java.util.List; import java.util.Map; + import javax.script.SimpleBindings; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.Criteria; @@ -51,10 +53,8 @@ public class CommonClassDaoImpl implements CommonClassDao { private static final Log LOGGER = LogFactory.getLog(CommonClassDaoImpl.class); - private static SessionFactory sessionFactory; - @Autowired private CommonClassDaoImpl(SessionFactory sessionFactory) { CommonClassDaoImpl.sessionFactory = sessionFactory; @@ -78,14 +78,12 @@ public class CommonClassDaoImpl implements CommonClassDao { try { session.close(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Closing Connection/Statement" + e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement" + e); } } return data; } - @SuppressWarnings({"rawtypes", "unchecked"}) @Override public List getDataById(Class className, String columnName, String key) { @@ -109,8 +107,7 @@ public class CommonClassDaoImpl implements CommonClassDao { try { session.close(); } catch (Exception e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Closing Connection/Statement" + e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement" + e1); } } return data; @@ -131,8 +128,7 @@ public class CommonClassDaoImpl implements CommonClassDao { try { session.close(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Closing Connection/Statement" + e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement" + e); } } return data; @@ -146,14 +142,12 @@ public class CommonClassDaoImpl implements CommonClassDao { session.persist(entity); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Saving data to Table" + e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving data to Table" + e); } finally { try { session.close(); } catch (Exception e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Closing Connection/Statement" + e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement" + e1); } } @@ -167,20 +161,17 @@ public class CommonClassDaoImpl implements CommonClassDao { session.delete(entity); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Deleting data from Table" + e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting data from Table" + e); } finally { try { session.close(); } catch (Exception e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Closing Connection/Statement" + e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement" + e1); } } } - @Override public void update(Object entity) { Session session = sessionFactory.openSession(); @@ -189,20 +180,17 @@ public class CommonClassDaoImpl implements CommonClassDao { session.update(entity); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Updating data to Table" + e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating data to Table" + e); } finally { try { session.close(); } catch (Exception e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Closing Connection/Statement" + e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement" + e1); } } } - @SuppressWarnings({"unchecked", "rawtypes"}) @Override public List checkDuplicateEntry(String value, String columnName, Class className) { @@ -231,20 +219,18 @@ public class CommonClassDaoImpl implements CommonClassDao { data = cr.list(); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Querying for Duplicate Entries for Table" + e + className); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying for Duplicate Entries for Table" + + e + className); } finally { try { session.close(); } catch (Exception e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Closing Connection/Statement" + e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement" + e1); } } return data; } - @SuppressWarnings("unchecked") @Override public List getDataByQuery(String query, SimpleBindings params) { @@ -263,21 +249,18 @@ public class CommonClassDaoImpl implements CommonClassDao { data = hbquery.list(); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Querying Database Table" + e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Database Table" + e); throw e; } finally { try { session.close(); } catch (HibernateException e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Closing Connection/Statement", e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement", e1); } } return data; } - @Override public void updateQuery(String query) { Session session = sessionFactory.openSession(); @@ -287,19 +270,16 @@ public class CommonClassDaoImpl implements CommonClassDao { hbquery.executeUpdate(); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Updating Database Table" + e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Database Table" + e); } finally { try { session.close(); } catch (Exception e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Closing Connection/Statement" + e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement" + e1); } } } - @SuppressWarnings("rawtypes") @Override public Object getEntityItem(Class className, String columnName, String key) { @@ -320,20 +300,17 @@ public class CommonClassDaoImpl implements CommonClassDao { data = cr.list().get(0); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Querying Database Table" + e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Database Table" + e); } finally { try { session.close(); } catch (Exception e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Closing Connection/Statement" + e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement" + e1); } } return data; } - @SuppressWarnings("unchecked") @Override public List getUserRoles() { @@ -355,20 +332,17 @@ public class CommonClassDaoImpl implements CommonClassDao { rolesData = cr.add(disjunction).list(); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Querying PolicyRoles Table" + e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyRoles Table" + e); } finally { try { session.close(); } catch (Exception e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Closing Connection/Statement" + e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement" + e1); } } return rolesData; } - @SuppressWarnings("unchecked") @Override public void updateClAlarms(String clName, String alarms) { @@ -384,14 +358,12 @@ public class CommonClassDaoImpl implements CommonClassDao { session.update(closedloop); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Updating ClosedLoops Table" + e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ClosedLoops Table" + e); } finally { session.close(); } } - @SuppressWarnings("unchecked") @Override public void updateClYaml(String clName, String yaml) { @@ -407,14 +379,12 @@ public class CommonClassDaoImpl implements CommonClassDao { session.update(closedloop); tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Updating ClosedLoops Table" + e); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ClosedLoops Table" + e); } finally { session.close(); } } - @SuppressWarnings("unchecked") @Override public void deleteAll() { @@ -438,8 +408,8 @@ public class CommonClassDaoImpl implements CommonClassDao { tx.commit(); } catch (Exception e) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error while deleting ClosedLoops from the table" + e); + LOGGER.error( + XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while deleting ClosedLoops from the table" + e); } finally { session.close(); } @@ -447,8 +417,7 @@ public class CommonClassDaoImpl implements CommonClassDao { @SuppressWarnings({"unchecked"}) @Override - public List checkExistingGroupListforUpdate(String groupListValue, - String groupNameValue) { + public List checkExistingGroupListforUpdate(String groupListValue, String groupNameValue) { Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); List data = null; @@ -461,23 +430,20 @@ public class CommonClassDaoImpl implements CommonClassDao { tx.commit(); } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Querying for Duplicate Entries for GroupPolicyScopeList Table" - + e); + + "Error While Querying for Duplicate Entries for GroupPolicyScopeList Table" + e); } finally { try { session.close(); } catch (Exception e1) { - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW - + "Error While Closing Connection/Statement" + e1); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement" + e1); } } return data; } - @Override - public List getMultipleDataOnAddingConjunction( - @SuppressWarnings("rawtypes") Class className, String columnName, List data) { + public List getMultipleDataOnAddingConjunction(@SuppressWarnings("rawtypes") Class className, + String columnName, List data) { return null; } -- cgit 1.2.3-korg