From 91d04c64771832a0b8815ffbe1f0f9920320d94d Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Tue, 14 Feb 2017 19:41:00 -0500 Subject: Initial OpenECOMP policy/engine commit Change-Id: I7dbff37733b661643dd4d1caefa3d7dccc361b6e Signed-off-by: Pamela Dragosh --- .../pap/xacml/rest/daoimpl/ActionListDaoImpl.java | 158 ++++++++++++++++ .../rest/daoimpl/ActionPolicyDictDaoImpl.java | 185 +++++++++++++++++++ .../xacml/rest/daoimpl/AddressGroupDaoImpl.java | 157 ++++++++++++++++ .../pap/xacml/rest/daoimpl/AttributeDaoImpl.java | 157 ++++++++++++++++ .../rest/daoimpl/BRMSParamTemplateDaoImpl.java | 157 ++++++++++++++++ .../pap/xacml/rest/daoimpl/CategoryDaoImpl.java | 76 ++++++++ .../pap/xacml/rest/daoimpl/DCAEUUIDDaoImpl.java | 157 ++++++++++++++++ .../xacml/rest/daoimpl/DecisionPolicyDaoImpl.java | 158 ++++++++++++++++ .../rest/daoimpl/DescriptiveScopeDaoImpl.java | 182 +++++++++++++++++++ .../pap/xacml/rest/daoimpl/EcompNameDaoImpl.java | 167 +++++++++++++++++ .../xacml/rest/daoimpl/EnforcerPolicyDaoImpl.java | 132 ++++++++++++++ .../daoimpl/FirewallDictionaryListDaoImpl.java | 202 +++++++++++++++++++++ .../rest/daoimpl/GroupPolicyScopeListDaoImpl.java | 182 +++++++++++++++++++ .../daoimpl/MicroServiceConfigNameDaoImpl.java | 158 ++++++++++++++++ .../rest/daoimpl/MicroServiceLocationDaoImpl.java | 158 ++++++++++++++++ .../rest/daoimpl/MicroServiceModelsDaoImpl.java | 161 ++++++++++++++++ .../pap/xacml/rest/daoimpl/PEPOptionsDaoImpl.java | 159 ++++++++++++++++ .../rest/daoimpl/PolicyScopeClosedLoopDaoImpl.java | 181 ++++++++++++++++++ .../rest/daoimpl/PolicyScopeResourceDaoImpl.java | 181 ++++++++++++++++++ .../rest/daoimpl/PolicyScopeServiceDaoImpl.java | 182 +++++++++++++++++++ .../xacml/rest/daoimpl/PolicyScopeTypeDaoImpl.java | 182 +++++++++++++++++++ .../pap/xacml/rest/daoimpl/PortListDaoImpl.java | 158 ++++++++++++++++ .../pap/xacml/rest/daoimpl/PrefixListDaoImpl.java | 158 ++++++++++++++++ .../xacml/rest/daoimpl/ProtocolListDaoImpl.java | 158 ++++++++++++++++ .../pap/xacml/rest/daoimpl/RiskTypeDaoImpl.java | 167 +++++++++++++++++ .../rest/daoimpl/SafePolicyWarningDaoImpl.java | 181 ++++++++++++++++++ .../xacml/rest/daoimpl/SecurityZoneDaoImpl.java | 157 ++++++++++++++++ .../rest/daoimpl/ServiceDictionaryDaoImpl.java | 157 ++++++++++++++++ .../xacml/rest/daoimpl/ServiceGroupDaoImpl.java | 158 ++++++++++++++++ .../pap/xacml/rest/daoimpl/ServiceListDaoImpl.java | 159 ++++++++++++++++ .../xacml/rest/daoimpl/SiteDictionaryDaoImpl.java | 159 ++++++++++++++++ .../pap/xacml/rest/daoimpl/TermListDaoImpl.java | 181 ++++++++++++++++++ .../pap/xacml/rest/daoimpl/UserInfoDaoImpl.java | 138 ++++++++++++++ .../pap/xacml/rest/daoimpl/VNFTypeDaoImpl.java | 158 ++++++++++++++++ .../pap/xacml/rest/daoimpl/VSCLActionDaoImpl.java | 158 ++++++++++++++++ .../rest/daoimpl/VarbindDictionaryDaoImpl.java | 181 ++++++++++++++++++ .../policy/pap/xacml/rest/daoimpl/ZoneDaoImpl.java | 159 ++++++++++++++++ 37 files changed, 6019 insertions(+) create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionPolicyDictDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AddressGroupDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AttributeDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/BRMSParamTemplateDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/CategoryDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DCAEUUIDDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DecisionPolicyDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DescriptiveScopeDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EcompNameDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EnforcerPolicyDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/FirewallDictionaryListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/GroupPolicyScopeListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceConfigNameDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceLocationDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceModelsDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PEPOptionsDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeClosedLoopDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeResourceDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeServiceDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeTypeDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PortListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PrefixListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ProtocolListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/RiskTypeDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SafePolicyWarningDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SecurityZoneDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceDictionaryDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceGroupDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SiteDictionaryDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/TermListDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/UserInfoDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VNFTypeDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VSCLActionDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VarbindDictionaryDaoImpl.java create mode 100644 ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ZoneDaoImpl.java (limited to 'ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl') diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionListDaoImpl.java new file mode 100644 index 000000000..ba6c2c41e --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionListDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ActionListDao; +import org.openecomp.policy.rest.jpa.ActionList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("ActionListDao") +public class ActionListDaoImpl implements ActionListDao{ + + private static final Log logger = LogFactory.getLog(ActionListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getActionListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List actionListData = null; + try { + Criteria cr = session.createCriteria(ActionList.class); + actionListData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return actionListData; + + } + + @Override + public void Save(ActionList actionList) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(actionList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ActionList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(ActionList actionList) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(actionList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ActionList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ActionList actionList) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(actionList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ActionList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getActionListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ActionList.class); + List actionListData = cr.list(); + for(int i = 0; i < actionListData.size(); i++){ + data.add(actionListData.get(i).getActionName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionPolicyDictDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionPolicyDictDaoImpl.java new file mode 100644 index 000000000..50d41fd02 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ActionPolicyDictDaoImpl.java @@ -0,0 +1,185 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ActionPolicyDictDao; +import org.openecomp.policy.rest.jpa.ActionPolicyDict; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + + +@Service("ActionPolicyDictDao") +public class ActionPolicyDictDaoImpl implements ActionPolicyDictDao { + private static final Log logger = LogFactory.getLog(ActionPolicyDictDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + + @SuppressWarnings("unchecked") + @Override + public List getActionDictData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + + List actionDictData = null; + try { + Criteria cr = session.createCriteria(ActionPolicyDict.class); + actionDictData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return actionDictData; + } + + @Override + public void Save(ActionPolicyDict action) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(action); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void delete(ActionPolicyDict action) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(action); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ActionPolicyDict action) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(action); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getActionDictDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ActionPolicyDict.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getAttributeName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @SuppressWarnings("unchecked") + @Override + public ActionPolicyDict getActionEntityDatabyId(String action) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + ActionPolicyDict data = null; + try { + Criteria cr = session.createCriteria(ActionPolicyDict.class); + List attributeData = cr.add(Restrictions.eq("attributeName", action)).list(); + for(Object entity : attributeData){ + data = (ActionPolicyDict) entity; + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ActionDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AddressGroupDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AddressGroupDaoImpl.java new file mode 100644 index 000000000..951a38a28 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AddressGroupDaoImpl.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.AddressGroupDao; +import org.openecomp.policy.rest.jpa.AddressGroup; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("AddressGroupDao") +public class AddressGroupDaoImpl implements AddressGroupDao{ + private static final Log logger = LogFactory.getLog(AddressGroupDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getAddressGroupData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(AddressGroup.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(AddressGroup attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(AddressGroup attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(AddressGroup attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getAddressGroupDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(AddressGroup.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getGroupName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying AddressGroup Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AttributeDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AttributeDaoImpl.java new file mode 100644 index 000000000..7eb51d3f4 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/AttributeDaoImpl.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.AttributeDao; +import org.openecomp.policy.rest.jpa.Attribute; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("AttributeDao") +public class AttributeDaoImpl implements AttributeDao { + private static final Log logger = LogFactory.getLog(AttributeDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(Attribute.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(Attribute attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(Attribute attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(Attribute attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public List getAttributeData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(Attribute.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getXacmlId()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/BRMSParamTemplateDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/BRMSParamTemplateDaoImpl.java new file mode 100644 index 000000000..4f8478da6 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/BRMSParamTemplateDaoImpl.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.BRMSParamTemplateDao; +import org.openecomp.policy.rest.jpa.BRMSParamTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("BRMSParamTemplateDao") +public class BRMSParamTemplateDaoImpl implements BRMSParamTemplateDao{ + private static final Log logger = LogFactory.getLog(BRMSParamTemplateDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getBRMSParamTemplateData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData =null; + try { + Criteria cr = session.createCriteria(BRMSParamTemplate.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(BRMSParamTemplate attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(BRMSParamTemplate attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(BRMSParamTemplate attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getBRMSParamDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(BRMSParamTemplate.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getRuleName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying BRMSParamTemplate Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/CategoryDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/CategoryDaoImpl.java new file mode 100644 index 000000000..f3fcbf152 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/CategoryDaoImpl.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.CategoryDao; +import org.openecomp.policy.rest.jpa.Category; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("CategoryDao") +public class CategoryDaoImpl implements CategoryDao { + private static final Log logger = LogFactory.getLog(CategoryDaoImpl.class); + + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getCategoryListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List categoryListData = null; + try { + Criteria cr = session.createCriteria(Category.class); + categoryListData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Category Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return categoryListData; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DCAEUUIDDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DCAEUUIDDaoImpl.java new file mode 100644 index 000000000..ddd4606f9 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DCAEUUIDDaoImpl.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.DCAEUUIDDao; +import org.openecomp.policy.rest.jpa.DCAEuuid; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("DCAEUUIDDao") +public class DCAEUUIDDaoImpl implements DCAEUUIDDao{ + private static final Log logger = LogFactory.getLog(DCAEUUIDDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getDCAEuuidData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(DCAEuuid.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DCAEUUID Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(DCAEuuid attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving DCAEUUID Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(DCAEuuid attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting DCAEUUID Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(DCAEuuid attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating DCAEUUID Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getDCAEuuidDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(DCAEuuid.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DCAEUUID Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DecisionPolicyDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DecisionPolicyDaoImpl.java new file mode 100644 index 000000000..9762e1d34 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DecisionPolicyDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.DecisionPolicyDao; +import org.openecomp.policy.rest.jpa.DecisionSettings; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("DecisionSettingsDao") +public class DecisionPolicyDaoImpl implements DecisionPolicyDao{ + private static final Log logger = LogFactory.getLog(DecisionPolicyDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getDecisionSettingsData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List decisionSettingsData = null; + try { + Criteria cr = session.createCriteria(DecisionSettings.class); + decisionSettingsData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DecisionSettings Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return decisionSettingsData; + + } + + @Override + public void Save(DecisionSettings decisionSettings) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(decisionSettings); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving DecisionSettings Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(DecisionSettings decisionSettings) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(decisionSettings); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting DecisionSettings Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(DecisionSettings decisionSettings) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(decisionSettings); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating DecisionSettings Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public List getDecisionDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(DecisionSettings.class); + List decisionSettingsData = cr.list(); + for(int i = 0; i < decisionSettingsData.size(); i++){ + data.add(decisionSettingsData.get(i).getXacmlId()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DecisionSettings Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DescriptiveScopeDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DescriptiveScopeDaoImpl.java new file mode 100644 index 000000000..8d286859c --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/DescriptiveScopeDaoImpl.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.DescriptiveScopeDao; +import org.openecomp.policy.rest.jpa.DescriptiveScope; +import org.openecomp.policy.rest.jpa.PolicyVersion; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("DescriptiveScopeDao") +public class DescriptiveScopeDaoImpl implements DescriptiveScopeDao{ + private static final Log logger = LogFactory.getLog(DescriptiveScopeDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getDescriptiveScope() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List descriptiveScopeData = null; + try { + Criteria cr = session.createCriteria(DescriptiveScope.class); + descriptiveScopeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return descriptiveScopeData; + } + + @Override + public void Save(DescriptiveScope descriptiveScope) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(descriptiveScope); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(DescriptiveScope descriptiveScope) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(descriptiveScope); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(DescriptiveScope descriptiveScope) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(descriptiveScope); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getDescriptiveScopeDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(DescriptiveScope.class); + List descriptiveScopeData = cr.list(); + for(int i = 0; i < descriptiveScopeData.size(); i++){ + data.add(descriptiveScopeData.get(i).getScopeName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public DescriptiveScope getDescriptiveScopeById(String name) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + DescriptiveScope data = null; + try { + Criteria cr = session.createCriteria(DescriptiveScope.class); + cr.add(Restrictions.eq("scopename",name)); + data = (DescriptiveScope) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EcompNameDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EcompNameDaoImpl.java new file mode 100644 index 000000000..9bafc3a5c --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EcompNameDaoImpl.java @@ -0,0 +1,167 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.EcompNameDao; +import org.openecomp.policy.rest.jpa.EcompName; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("EcompNameDao") +public class EcompNameDaoImpl implements EcompNameDao { + private static final Log logger = LogFactory.getLog(EcompNameDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getEcompName() { + System.out.println("EcompNameDaoImpl: getEcompName() is called"); + logger.debug("EcompNameDaoImpl: getEcompName() is called"); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List ecompNameData = null; + try { + Criteria cr = session.createCriteria(EcompName.class); + ecompNameData = cr.list(); + System.out.println("Data returned from ecompname table"+ecompNameData.toString()); + logger.debug("Data returned from ecompname table: " + ecompNameData.toString()); + tx.commit(); + } catch (Exception e) { + System.out.println("Exception Occured while Querying ecompname"+e); + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying EcompName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return ecompNameData; + } + + @Override + public void Save(EcompName ecompName) { + System.out.println("EcompNameDaoImpl: Save() is called"); + logger.debug("EcompNameDaoImpl: Save() is called"); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(ecompName); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving EcompName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(EcompName ecompName) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(ecompName); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting EcompName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(EcompName ecompName) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(ecompName); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating EcompName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getEcompNameDataByName() { + logger.info("getEcompNameDataByName is call from the DAO implementation class."); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(EcompName.class); + List ecompNameData = cr.list(); + for(int i = 0; i < ecompNameData.size(); i++){ + data.add(ecompNameData.get(i).getEcompName()); + } + logger.info("data retrieved: " + data.toString()); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying EcompName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EnforcerPolicyDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EnforcerPolicyDaoImpl.java new file mode 100644 index 000000000..ba621ab17 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/EnforcerPolicyDaoImpl.java @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.EnforcerPolicyDao; +import org.openecomp.policy.rest.jpa.EnforcingType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("EnforcerPolicyDao") +public class EnforcerPolicyDaoImpl implements EnforcerPolicyDao { + private static final Log logger = LogFactory.getLog(EnforcerPolicyDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getEnforcingTypeData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List enforcingTypeData = null; + try { + Criteria cr = session.createCriteria(EnforcingType.class); + enforcingTypeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying EnforcingType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return enforcingTypeData; + + } + + @Override + public void Save(EnforcingType enforcingType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(enforcingType); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving EnforcingType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(EnforcingType enforcingType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(enforcingType); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting EnforcingType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(EnforcingType enforcingType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(enforcingType); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating EnforcingType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/FirewallDictionaryListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/FirewallDictionaryListDaoImpl.java new file mode 100644 index 000000000..b19a58b93 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/FirewallDictionaryListDaoImpl.java @@ -0,0 +1,202 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.Query; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.FirewallDictionaryListDao; +import org.openecomp.policy.rest.jpa.FirewallDictionaryList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +@Service("FirewallDictionaryListDao") +public class FirewallDictionaryListDaoImpl implements FirewallDictionaryListDao { + private static final Log logger = LogFactory.getLog(FirewallDictionaryListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @Override + public List getFWDictionaryListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(FirewallDictionaryList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public List getFWDictionaryListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(FirewallDictionaryList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getParentItemName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(FirewallDictionaryList firewallDictionaryList) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(firewallDictionaryList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(FirewallDictionaryList firewallDictionaryList) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(firewallDictionaryList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(FirewallDictionaryList firewallDictionaryList) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(firewallDictionaryList); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void updateQuery(String query) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + Query hbquery = session.createQuery(query); + hbquery.executeUpdate(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public FirewallDictionaryList getFWDictionaryDataById(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + FirewallDictionaryList data = null; + try { + Criteria cr = session.createCriteria(FirewallDictionaryList.class); + cr = cr.add(Restrictions.eq("parentItemName",value)); + data = (FirewallDictionaryList) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/GroupPolicyScopeListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/GroupPolicyScopeListDaoImpl.java new file mode 100644 index 000000000..edc147fc2 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/GroupPolicyScopeListDaoImpl.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.GroupPolicyScopeListDao; +import org.openecomp.policy.rest.jpa.GroupPolicyScopeList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("GroupPolicyScopeListDao") +public class GroupPolicyScopeListDaoImpl implements GroupPolicyScopeListDao { + private static final Log logger = LogFactory.getLog(GroupPolicyScopeListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getGroupPolicyScopeListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(GroupPolicyScopeList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupPolicyScopeList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getGroupPolicyScopeListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(GroupPolicyScopeList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getGroupName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupPolicyScopeList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(GroupPolicyScopeList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving GroupPolicyScopeList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(GroupPolicyScopeList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(GroupPolicyScopeList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List CheckDuplicateEntry(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(GroupPolicyScopeList.class); + cr.add(Restrictions.eq("name",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupPolicyScopeList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceConfigNameDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceConfigNameDaoImpl.java new file mode 100644 index 000000000..fdee32cc9 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceConfigNameDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.MicroServiceConfigNameDao; +import org.openecomp.policy.rest.jpa.MicroServiceConfigName; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("MicroServiceConfigNameDao") +public class MicroServiceConfigNameDaoImpl implements MicroServiceConfigNameDao{ + private static final Log logger = LogFactory.getLog(MicroServiceConfigNameDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getMicroServiceConfigNameData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(MicroServiceConfigName.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceConfigName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(MicroServiceConfigName attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving MicroServiceConfigName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(MicroServiceConfigName attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting MicroServiceConfigName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(MicroServiceConfigName attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating MicroServiceConfigName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getMSConfigDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(MicroServiceConfigName.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceConfigName Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceLocationDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceLocationDaoImpl.java new file mode 100644 index 000000000..91a2f42cf --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceLocationDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.MicroServiceLocationDao; +import org.openecomp.policy.rest.jpa.MicroServiceLocation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("MicroServiceLocationDao") +public class MicroServiceLocationDaoImpl implements MicroServiceLocationDao{ + private static final Log logger = LogFactory.getLog(MicroServiceLocationDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getMicroServiceLocationData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(MicroServiceLocation.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceLocation Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(MicroServiceLocation attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving MicroServiceLocation Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(MicroServiceLocation attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting MicroServiceLocation Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(MicroServiceLocation attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating MicroServiceLocation Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getMSLocationDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(MicroServiceLocation.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceLocation Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceModelsDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceModelsDaoImpl.java new file mode 100644 index 000000000..c4e66b5a3 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/MicroServiceModelsDaoImpl.java @@ -0,0 +1,161 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.MicroServiceModelsDao; +import org.openecomp.policy.rest.jpa.MicroServiceModels; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("MicroServiceModelsDao") +public class MicroServiceModelsDaoImpl implements MicroServiceModelsDao{ + private static final Log logger = LogFactory.getLog(MicroServiceModelsDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getMicroServiceModelsData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(MicroServiceModels.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(MicroServiceModels attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(MicroServiceModels attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(MicroServiceModels attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getMSModelsDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(MicroServiceModels.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + if(attributeData.get(i).getVersion() == null || attributeData.get(i).getVersion().equals("")){ + data.add(attributeData.get(i).getModelName()); + }else{ + data.add(attributeData.get(i).getModelName() + "-v" + attributeData.get(i).getVersion()); + } + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying MicroServiceModels Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PEPOptionsDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PEPOptionsDaoImpl.java new file mode 100644 index 000000000..92b89e9e3 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PEPOptionsDaoImpl.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PEPOptionsDao; +import org.openecomp.policy.rest.jpa.PEPOptions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PEPOptionsDao") +public class PEPOptionsDaoImpl implements PEPOptionsDao{ + private static final Log logger = LogFactory.getLog(PEPOptionsDaoImpl.class); + + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPEPOptionsData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List pepOptionsData = null; + try { + Criteria cr = session.createCriteria(PEPOptions.class); + pepOptionsData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PEPOptions Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return pepOptionsData; + + } + + @Override + public void Save(PEPOptions pepOptions) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(pepOptions); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PEPOptions Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PEPOptions pepOptions) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(pepOptions); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PEPOptions Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(PEPOptions pepOptions) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(pepOptions); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PEPOptions Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getPEPOptionsDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PEPOptions.class); + List pepOptionsData = cr.list(); + for(int i = 0; i < pepOptionsData.size(); i++){ + data.add(pepOptionsData.get(i).getPepName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PEPOptions Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeClosedLoopDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeClosedLoopDaoImpl.java new file mode 100644 index 000000000..6ac3e5bc9 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeClosedLoopDaoImpl.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PolicyScopeClosedLoopDao; +import org.openecomp.policy.rest.jpa.PolicyScopeClosedLoop; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PolicyScopeClosedLoopDao") +public class PolicyScopeClosedLoopDaoImpl implements PolicyScopeClosedLoopDao{ + private static final Log logger = LogFactory.getLog(PolicyScopeClosedLoopDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeClosedLoopData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PolicyScopeClosedLoop.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeClosedLoop Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeClosedLoopDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PolicyScopeClosedLoop.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeClosedLoop Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(PolicyScopeClosedLoop attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyScopeClosedLoop Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PolicyScopeClosedLoop attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyScopeClosedLoop Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(PolicyScopeClosedLoop attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyScopeClosedLoop Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List CheckDuplicateEntry(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(PolicyScopeClosedLoop.class); + cr.add(Restrictions.eq("name",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeClosedLoop Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeResourceDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeResourceDaoImpl.java new file mode 100644 index 000000000..6fe91b112 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeResourceDaoImpl.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PolicyScopeResourceDao; +import org.openecomp.policy.rest.jpa.PolicyScopeResource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PolicyScopeResourceDao") +public class PolicyScopeResourceDaoImpl implements PolicyScopeResourceDao{ + private static final Log logger = LogFactory.getLog(PolicyScopeResourceDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeResourceData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PolicyScopeResource.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeResource Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeResourceDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PolicyScopeResource.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeResource Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(PolicyScopeResource attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyScopeResource Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void delete(PolicyScopeResource attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyScopeResource Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(PolicyScopeResource attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyScopeResource Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List CheckDuplicateEntry(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(PolicyScopeResource.class); + cr.add(Restrictions.eq("name",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeResource Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeServiceDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeServiceDaoImpl.java new file mode 100644 index 000000000..d90d5a014 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeServiceDaoImpl.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PolicyScopeServiceDao; +import org.openecomp.policy.rest.jpa.PolicyScopeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PolicyScopeServiceDao") +public class PolicyScopeServiceDaoImpl implements PolicyScopeServiceDao{ + private static final Log logger = LogFactory.getLog(PolicyScopeServiceDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeServiceData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PolicyScopeService.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeService Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeServiceDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PolicyScopeService.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeService Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(PolicyScopeService attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyScopeService Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PolicyScopeService attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyScopeService Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(PolicyScopeService attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyScopeService Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List CheckDuplicateEntry(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(PolicyScopeService.class); + cr.add(Restrictions.eq("name",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeService Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeTypeDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeTypeDaoImpl.java new file mode 100644 index 000000000..66317a4d0 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PolicyScopeTypeDaoImpl.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PolicyScopeTypeDao; +import org.openecomp.policy.rest.jpa.PolicyScopeType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PolicyScopeTypeDao") +public class PolicyScopeTypeDaoImpl implements PolicyScopeTypeDao{ + private static final Log logger = LogFactory.getLog(PolicyScopeTypeDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeTypeData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PolicyScopeType.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getPolicyScopeTypeDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PolicyScopeType.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(PolicyScopeType attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyScopeType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PolicyScopeType attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyScopeType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(PolicyScopeType attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyScopeType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List CheckDuplicateEntry(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(PolicyScopeType.class); + cr.add(Restrictions.eq("name",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PortListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PortListDaoImpl.java new file mode 100644 index 000000000..a3139b2c6 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PortListDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PortListDao; +import org.openecomp.policy.rest.jpa.PortList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PortListDao") +public class PortListDaoImpl implements PortListDao { + private static final Log logger = LogFactory.getLog(PortListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPortListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PortList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PortList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(PortList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PortList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PortList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PortList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(PortList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PortList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getPortListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PortList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getPortName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PortList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PrefixListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PrefixListDaoImpl.java new file mode 100644 index 000000000..2fecc7d88 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/PrefixListDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.PrefixListDao; +import org.openecomp.policy.rest.jpa.PREFIXLIST; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("PrefixListDao") +public class PrefixListDaoImpl implements PrefixListDao{ + private static final Log logger = LogFactory.getLog(PrefixListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getPREFIXLISTData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(PREFIXLIST.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(PREFIXLIST attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(PREFIXLIST attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(PREFIXLIST attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getPrefixListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(PREFIXLIST.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getPrefixListName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PREFIXLIST Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ProtocolListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ProtocolListDaoImpl.java new file mode 100644 index 000000000..7d78d387a --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ProtocolListDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ProtocolListDao; +import org.openecomp.policy.rest.jpa.ProtocolList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("ProtocolListDao") +public class ProtocolListDaoImpl implements ProtocolListDao { + private static final Log logger = LogFactory.getLog(ProtocolListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getProtocolListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(ProtocolList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ProtocolList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(ProtocolList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ProtocolList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(ProtocolList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ProtocolList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ProtocolList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ProtocolList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getProtocolListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ProtocolList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getProtocolName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ProtocolList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/RiskTypeDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/RiskTypeDaoImpl.java new file mode 100644 index 000000000..1318f82fa --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/RiskTypeDaoImpl.java @@ -0,0 +1,167 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.EcompNameDao; +import org.openecomp.policy.rest.dao.RiskTypeDao; +import org.openecomp.policy.rest.jpa.EcompName; +import org.openecomp.policy.rest.jpa.RiskType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("RiskTypeDao") +public class RiskTypeDaoImpl implements RiskTypeDao { + private static final Log logger = LogFactory.getLog(RiskTypeDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getRiskName() { + System.out.println("RiskTypeDaoImpl: getRiskName() is called"); + logger.debug("RiskTypeDaoImpl: getRiskName() is called"); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List riskTypeData = null; + try { + Criteria cr = session.createCriteria(RiskType.class); + riskTypeData = cr.list(); + logger.debug("Data returned from RiskType table: " + riskTypeData.toString()); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying RiskType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return riskTypeData; + } + + @Override + public void Save(RiskType riskName) { + System.out.println("RiskTypeDaoImpl: Save() is called"); + logger.debug("RiskTypeDaoImpl: Save() is called"); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(riskName); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving RiskType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(RiskType riskName) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(riskName); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting RiskType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(RiskType riskName) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(riskName); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating RiskType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getRiskTypeDataByName() { + logger.info("getRiskTypeDataByName is call from the DAO implementation class."); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(RiskType.class); + List riskTypeData = cr.list(); + for(int i = 0; i < riskTypeData.size(); i++){ + data.add(riskTypeData.get(i).getRiskName()); + } + logger.info("data retrieved: " + data.toString()); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying RiskType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SafePolicyWarningDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SafePolicyWarningDaoImpl.java new file mode 100644 index 000000000..37a77f9b5 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SafePolicyWarningDaoImpl.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.SafePolicyWarningDao; +import org.openecomp.policy.rest.jpa.SafePolicyWarning; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("SafePolicyWarningDao") +public class SafePolicyWarningDaoImpl implements SafePolicyWarningDao { + private static final Log logger = LogFactory.getLog(SafePolicyWarningDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getSafePolicyWarningData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(SafePolicyWarning.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SafePolicyWarning Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + } + + @SuppressWarnings("unchecked") + @Override + public List getSafePolicyWarningDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(SafePolicyWarning.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SafePolicyWarning Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public void Save(SafePolicyWarning attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving SafePolicyWarning Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(SafePolicyWarning attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void update(SafePolicyWarning attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Attribute Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public SafePolicyWarning getSafePolicyWarningDataById(String riskType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + SafePolicyWarning data = null; + try { + Criteria cr = session.createCriteria(SafePolicyWarning.class); + cr.add(Restrictions.eq("name",riskType)); + data = (SafePolicyWarning) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SafePolicyWarning Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SecurityZoneDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SecurityZoneDaoImpl.java new file mode 100644 index 000000000..9c79773dd --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SecurityZoneDaoImpl.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.SecurityZoneDao; +import org.openecomp.policy.rest.jpa.SecurityZone; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("SecurityZoneDao") +public class SecurityZoneDaoImpl implements SecurityZoneDao{ + private static final Log logger = LogFactory.getLog(SecurityZoneDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getSecurityZoneData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(SecurityZone.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(SecurityZone attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void delete(SecurityZone attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(SecurityZone attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getSecurityZoneDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(SecurityZone.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getZoneName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SecurityZone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceDictionaryDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceDictionaryDaoImpl.java new file mode 100644 index 000000000..226c50060 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceDictionaryDaoImpl.java @@ -0,0 +1,157 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ServiceDictionaryDao; +import org.openecomp.policy.rest.jpa.ClosedLoopD2Services; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("ServiceDictionaryDao") +public class ServiceDictionaryDaoImpl implements ServiceDictionaryDao { + private static final Log logger = LogFactory.getLog(ServiceDictionaryDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getClosedLoopD2ServicesData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List closedLoopD2ServicesData = null; + try { + Criteria cr = session.createCriteria(ClosedLoopD2Services.class); + closedLoopD2ServicesData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ClosedLoopD2Services Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return closedLoopD2ServicesData; + + } + + @Override + public void Save(ClosedLoopD2Services closedLoopD2Services) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(closedLoopD2Services); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ClosedLoopD2Services Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(ClosedLoopD2Services closedLoopD2Services) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(closedLoopD2Services); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ClosedLoopD2Services Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ClosedLoopD2Services closedLoopD2Services) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(closedLoopD2Services); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ClosedLoopD2Services Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public List getCLServiceDictDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ClosedLoopD2Services.class); + List closedLoopD2ServicesData = cr.list(); + for(int i = 0; i < closedLoopD2ServicesData.size(); i++){ + data.add(closedLoopD2ServicesData.get(i).getServiceName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ClosedLoopD2Services Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceGroupDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceGroupDaoImpl.java new file mode 100644 index 000000000..725631306 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceGroupDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ServiceGroupDao; +import org.openecomp.policy.rest.jpa.GroupServiceList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("ServiceGroupDao") +public class ServiceGroupDaoImpl implements ServiceGroupDao{ + private static final Log logger = LogFactory.getLog(ServiceGroupDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getGroupServiceListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(GroupServiceList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(GroupServiceList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(GroupServiceList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(GroupServiceList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getGroupServiceDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(GroupServiceList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getGroupName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GroupServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceListDaoImpl.java new file mode 100644 index 000000000..01ff3e4fc --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ServiceListDaoImpl.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ServiceListDao; +import org.openecomp.policy.rest.jpa.ServiceList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("ServiceListDao") +public class ServiceListDaoImpl implements ServiceListDao { + private static final Log logger = LogFactory.getLog(ServiceListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getServiceListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(ServiceList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(ServiceList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(ServiceList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ServiceList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getServiceListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ServiceList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getServiceName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ServiceList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SiteDictionaryDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SiteDictionaryDaoImpl.java new file mode 100644 index 000000000..3b2a75176 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/SiteDictionaryDaoImpl.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.SiteDictionaryDao; +import org.openecomp.policy.rest.jpa.ClosedLoopSite; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + + +@Service("SiteDictionaryDao") +public class SiteDictionaryDaoImpl implements SiteDictionaryDao { + private static final Log logger = LogFactory.getLog(SiteDictionaryDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getClosedLoopSiteData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List closedLoopSiteData = null; + try { + Criteria cr = session.createCriteria(ClosedLoopSite.class); + closedLoopSiteData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ClosedLoopSite Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return closedLoopSiteData; + + } + + @Override + public void Save(ClosedLoopSite closedLoopSite) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(closedLoopSite); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving ClosedLoopSite Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(ClosedLoopSite closedLoopSite) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(closedLoopSite); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting ClosedLoopSite Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(ClosedLoopSite closedLoopSite) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(closedLoopSite); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating ClosedLoopSite Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getCLSiteDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(ClosedLoopSite.class); + List closedLoopSiteData = cr.list(); + for(int i = 0; i < closedLoopSiteData.size(); i++){ + data.add(closedLoopSiteData.get(i).getSiteName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying ClosedLoopSite Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/TermListDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/TermListDaoImpl.java new file mode 100644 index 000000000..7568d60b0 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/TermListDaoImpl.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.TermListDao; +import org.openecomp.policy.rest.jpa.TermList; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("TermListDao") +public class TermListDaoImpl implements TermListDao{ + private static final Log logger = LogFactory.getLog(TermListDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getTermListData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(TermList.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(TermList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(TermList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(TermList attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getTermListDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(TermList.class); + List attributeData = cr.list(); + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getTermName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public TermList getTermListValueByName(String name) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + TermList data = null; + try { + Criteria cr = session.createCriteria(TermList.class); + cr.add(Restrictions.eq("termName",name)); + data = (TermList) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying TermList Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/UserInfoDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/UserInfoDaoImpl.java new file mode 100644 index 000000000..04ad69c1a --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/UserInfoDaoImpl.java @@ -0,0 +1,138 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.UserInfoDao; +import org.openecomp.policy.rest.jpa.UserInfo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + + +@Service("UserInfoDao") +public class UserInfoDaoImpl implements UserInfoDao{ + private static final Log logger = LogFactory.getLog(UserInfoDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @Override + public void save(UserInfo userInfo) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(userInfo); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving UserInfo Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @SuppressWarnings("unchecked") + @Override + public List getUserInfo() { + System.out.println("UserInfoDaoImpl: getUserInfo().. getting user info before save()"); + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List userData = null; + try { + Criteria cr = session.createCriteria(UserInfo.class); + userData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return userData; + } + + @Override + public String getUserName(String loginid) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + UserInfo user = null; + try { + user = (UserInfo) session.get(UserInfo.class, loginid); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return user.getUserName().toString(); + } + + @Override + public UserInfo getUserInfoByLoginId(String loginid) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + UserInfo userData = null; + try { + Criteria cr = session.createCriteria(UserInfo.class); + cr.add(Restrictions.eq("userLoginId", loginid)); + userData = (UserInfo) cr.list().get(0); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return userData; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VNFTypeDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VNFTypeDaoImpl.java new file mode 100644 index 000000000..4d424fa9f --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VNFTypeDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.VNFTypeDao; +import org.openecomp.policy.rest.jpa.VNFType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("VNFTypeDao") +public class VNFTypeDaoImpl implements VNFTypeDao { + private static final Log logger = LogFactory.getLog(VNFTypeDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getVNFTypeData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List vnfTypeData = null; + try { + Criteria cr = session.createCriteria(VNFType.class); + vnfTypeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VNFType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return vnfTypeData; + + } + + @Override + public void Save(VNFType vnfType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(vnfType); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving VNFType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(VNFType vnfType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(vnfType); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting VNFType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(VNFType vnfType) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(vnfType); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating VNFType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getVNFTypeDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(VNFType.class); + List vnfTypeData = cr.list(); + for(int i = 0; i < vnfTypeData.size(); i++){ + data.add(vnfTypeData.get(i).getVnftype()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VNFType Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + + } +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VSCLActionDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VSCLActionDaoImpl.java new file mode 100644 index 000000000..8ab6bfd19 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VSCLActionDaoImpl.java @@ -0,0 +1,158 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.VSCLActionDao; +import org.openecomp.policy.rest.jpa.VSCLAction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("VSCLActionDao") +public class VSCLActionDaoImpl implements VSCLActionDao{ + private static final Log logger = LogFactory.getLog(VSCLActionDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getVSCLActionData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List vSCLActionData = null; + try { + Criteria cr = session.createCriteria(VSCLAction.class); + vSCLActionData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VSCLAction Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return vSCLActionData; + + } + + @Override + public void Save(VSCLAction vSCLAction) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(vSCLAction); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving VSCLAction Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(VSCLAction vSCLAction) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(vSCLAction); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting VSCLAction Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(VSCLAction vSCLAction) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(vSCLAction); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating VSCLAction Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getVsclActionDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(VSCLAction.class); + List vSCLActionData = cr.list(); + for(int i = 0; i < vSCLActionData.size(); i++){ + data.add(vSCLActionData.get(i).getVsclaction()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VSCLAction Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VarbindDictionaryDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VarbindDictionaryDaoImpl.java new file mode 100644 index 000000000..dba3a0d57 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/VarbindDictionaryDaoImpl.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.criterion.Restrictions; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.VarbindDictionaryDao; +import org.openecomp.policy.rest.jpa.VarbindDictionary; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("VarbindDictionaryDao") +public class VarbindDictionaryDaoImpl implements VarbindDictionaryDao { + private static final Log logger = LogFactory.getLog(VarbindDictionaryDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getVarbindDictionaryData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List varbindDictionaryData = null; + try { + Criteria cr = session.createCriteria(VarbindDictionary.class); + varbindDictionaryData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return varbindDictionaryData; + + } + + @Override + public void Save(VarbindDictionary varbindDictionary) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(varbindDictionary); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(VarbindDictionary varbindDictionary) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(varbindDictionary); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(VarbindDictionary varbindDictionary) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(varbindDictionary); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getVarbindDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(VarbindDictionary.class); + List varbindDictionaryData = cr.list(); + for(int i = 0; i < varbindDictionaryData.size(); i++){ + data.add(varbindDictionaryData.get(i).getVarbindName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + + @Override + public List getVarbindEntityByName(String value) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = null; + try { + Criteria cr = session.createCriteria(VarbindDictionary.class); + cr.add(Restrictions.eq("varbindName",value)); + data = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying VarbindDictionary Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ZoneDaoImpl.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ZoneDaoImpl.java new file mode 100644 index 000000000..865a08516 --- /dev/null +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/daoimpl/ZoneDaoImpl.java @@ -0,0 +1,159 @@ +/*- + * ============LICENSE_START======================================================= + * ECOMP-PAP-REST + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.policy.pap.xacml.rest.daoimpl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.openecomp.policy.pap.xacml.rest.HibernateSession; +import org.openecomp.policy.rest.dao.ZoneDao; +import org.openecomp.policy.rest.jpa.Zone; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import org.openecomp.policy.xacml.api.XACMLErrorConstants; + +@Service("ZoneDao") +public class ZoneDaoImpl implements ZoneDao{ + private static final Log logger = LogFactory.getLog(ZoneDaoImpl.class); + @Autowired + SessionFactory sessionfactory; + + public SessionFactory getSessionfactory() { + return sessionfactory; + } + + public void setSessionfactory(SessionFactory sessionfactory) { + this.sessionfactory = sessionfactory; + } + + @SuppressWarnings("unchecked") + @Override + public List getZoneData() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List attributeData = null; + try { + Criteria cr = session.createCriteria(Zone.class); + attributeData = cr.list(); + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Zone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return attributeData; + + } + + @Override + public void Save(Zone attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.persist(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving Zone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @Override + public void delete(Zone attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.delete(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting Zone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + } + + @Override + public void update(Zone attribute) { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + try { + session.update(attribute); + tx.commit(); + }catch(Exception e){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating Zone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + + } + + @SuppressWarnings("unchecked") + @Override + public List getZoneDataByName() { + Session session = HibernateSession.getSessionFactory(); + Transaction tx = session.beginTransaction(); + List data = new ArrayList(); + try { + Criteria cr = session.createCriteria(Zone.class); + List attributeData = cr.list(); + + for(int i = 0; i < attributeData.size(); i++){ + data.add(attributeData.get(i).getZoneName()); + } + tx.commit(); + } catch (Exception e) { + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Zone Table"+e); + }finally{ + try{ + session.close(); + }catch(Exception e1){ + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1); + } + } + return data; + } + +} -- cgit 1.2.3-korg