2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.pap.xacml.rest.daoimpl;
23 import java.util.ArrayList;
24 import java.util.List;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.hibernate.Criteria;
29 import org.hibernate.Session;
30 import org.hibernate.SessionFactory;
31 import org.hibernate.Transaction;
32 import org.hibernate.criterion.Restrictions;
33 import org.openecomp.policy.pap.xacml.rest.HibernateSession;
34 import org.openecomp.policy.rest.dao.PolicyScopeServiceDao;
35 import org.openecomp.policy.rest.jpa.PolicyScopeService;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Service;
39 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
41 @Service("PolicyScopeServiceDao")
42 public class PolicyScopeServiceDaoImpl implements PolicyScopeServiceDao{
43 private static final Log logger = LogFactory.getLog(PolicyScopeServiceDaoImpl.class);
45 SessionFactory sessionfactory;
47 public SessionFactory getSessionfactory() {
48 return sessionfactory;
51 public void setSessionfactory(SessionFactory sessionfactory) {
52 this.sessionfactory = sessionfactory;
55 @SuppressWarnings("unchecked")
57 public List<PolicyScopeService> getPolicyScopeServiceData() {
58 Session session = HibernateSession.getSessionFactory();
59 Transaction tx = session.beginTransaction();
60 List<PolicyScopeService> attributeData = null;
62 Criteria cr = session.createCriteria(PolicyScopeService.class);
63 attributeData = cr.list();
65 } catch (Exception e) {
66 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeService Table"+e);
71 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
77 @SuppressWarnings("unchecked")
79 public List<String> getPolicyScopeServiceDataByName() {
80 Session session = HibernateSession.getSessionFactory();
81 Transaction tx = session.beginTransaction();
82 List<String> data = new ArrayList<String>();
84 Criteria cr = session.createCriteria(PolicyScopeService.class);
85 List<PolicyScopeService> attributeData = cr.list();
86 for(int i = 0; i < attributeData.size(); i++){
87 data.add(attributeData.get(i).getName());
90 } catch (Exception e) {
91 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeService Table"+e);
96 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
103 public void Save(PolicyScopeService attribute) {
104 Session session = HibernateSession.getSessionFactory();
105 Transaction tx = session.beginTransaction();
107 session.persist(attribute);
110 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyScopeService Table"+e);
114 }catch(Exception e1){
115 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
122 public void delete(PolicyScopeService attribute) {
123 Session session = HibernateSession.getSessionFactory();
124 Transaction tx = session.beginTransaction();
126 session.delete(attribute);
129 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyScopeService Table"+e);
133 }catch(Exception e1){
134 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
141 public void update(PolicyScopeService attribute) {
142 Session session = HibernateSession.getSessionFactory();
143 Transaction tx = session.beginTransaction();
145 session.update(attribute);
148 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyScopeService Table"+e);
152 }catch(Exception e1){
153 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
159 @SuppressWarnings("unchecked")
161 public List<PolicyScopeService> CheckDuplicateEntry(String value) {
162 Session session = HibernateSession.getSessionFactory();
163 Transaction tx = session.beginTransaction();
164 List<PolicyScopeService> data = null;
166 Criteria cr = session.createCriteria(PolicyScopeService.class);
167 cr.add(Restrictions.eq("name",value));
170 } catch (Exception e) {
171 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyScopeService Table"+e);
175 }catch(Exception e1){
176 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);