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.openecomp.policy.pap.xacml.rest.HibernateSession;
33 import org.openecomp.policy.rest.dao.PEPOptionsDao;
34 import org.openecomp.policy.rest.jpa.PEPOptions;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Service;
38 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
40 @Service("PEPOptionsDao")
41 public class PEPOptionsDaoImpl implements PEPOptionsDao{
42 private static final Log logger = LogFactory.getLog(PEPOptionsDaoImpl.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<PEPOptions> getPEPOptionsData() {
58 Session session = HibernateSession.getSessionFactory();
59 Transaction tx = session.beginTransaction();
60 List<PEPOptions> pepOptionsData = null;
62 Criteria cr = session.createCriteria(PEPOptions.class);
63 pepOptionsData = cr.list();
65 } catch (Exception e) {
66 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PEPOptions Table"+e);
71 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
74 return pepOptionsData;
79 public void Save(PEPOptions pepOptions) {
80 Session session = HibernateSession.getSessionFactory();
81 Transaction tx = session.beginTransaction();
83 session.persist(pepOptions);
86 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PEPOptions Table"+e);
91 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
98 public void delete(PEPOptions pepOptions) {
99 Session session = HibernateSession.getSessionFactory();
100 Transaction tx = session.beginTransaction();
102 session.delete(pepOptions);
105 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PEPOptions Table"+e);
109 }catch(Exception e1){
110 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
116 public void update(PEPOptions pepOptions) {
117 Session session = HibernateSession.getSessionFactory();
118 Transaction tx = session.beginTransaction();
120 session.update(pepOptions);
123 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PEPOptions Table"+e);
127 }catch(Exception e1){
128 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
134 @SuppressWarnings("unchecked")
136 public List<String> getPEPOptionsDataByName() {
137 Session session = HibernateSession.getSessionFactory();
138 Transaction tx = session.beginTransaction();
139 List<String> data = new ArrayList<String>();
141 Criteria cr = session.createCriteria(PEPOptions.class);
142 List<PEPOptions> pepOptionsData = cr.list();
143 for(int i = 0; i < pepOptionsData.size(); i++){
144 data.add(pepOptionsData.get(i).getPepName());
147 } catch (Exception e) {
148 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PEPOptions Table"+e);
152 }catch(Exception e1){
153 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);