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.SecurityZoneDao;
34 import org.openecomp.policy.rest.jpa.SecurityZone;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Service;
38 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
40 @Service("SecurityZoneDao")
41 public class SecurityZoneDaoImpl implements SecurityZoneDao{
42 private static final Log logger = LogFactory.getLog(SecurityZoneDaoImpl.class);
44 SessionFactory sessionfactory;
46 public SessionFactory getSessionfactory() {
47 return sessionfactory;
50 public void setSessionfactory(SessionFactory sessionfactory) {
51 this.sessionfactory = sessionfactory;
54 @SuppressWarnings("unchecked")
56 public List<SecurityZone> getSecurityZoneData() {
57 Session session = HibernateSession.getSessionFactory();
58 Transaction tx = session.beginTransaction();
59 List<SecurityZone> attributeData = null;
61 Criteria cr = session.createCriteria(SecurityZone.class);
62 attributeData = cr.list();
64 } catch (Exception e) {
65 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SecurityZone Table"+e);
70 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
78 public void Save(SecurityZone attribute) {
79 Session session = HibernateSession.getSessionFactory();
80 Transaction tx = session.beginTransaction();
82 session.persist(attribute);
85 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving SecurityZone Table"+e);
90 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
96 public void delete(SecurityZone attribute) {
97 Session session = HibernateSession.getSessionFactory();
98 Transaction tx = session.beginTransaction();
100 session.delete(attribute);
103 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting SecurityZone Table"+e);
107 }catch(Exception e1){
108 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
114 public void update(SecurityZone attribute) {
115 Session session = HibernateSession.getSessionFactory();
116 Transaction tx = session.beginTransaction();
118 session.update(attribute);
121 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating SecurityZone Table"+e);
125 }catch(Exception e1){
126 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
132 @SuppressWarnings("unchecked")
134 public List<String> getSecurityZoneDataByName() {
135 Session session = HibernateSession.getSessionFactory();
136 Transaction tx = session.beginTransaction();
137 List<String> data = new ArrayList<String>();
139 Criteria cr = session.createCriteria(SecurityZone.class);
140 List<SecurityZone> attributeData = cr.list();
141 for(int i = 0; i < attributeData.size(); i++){
142 data.add(attributeData.get(i).getZoneName());
145 } catch (Exception e) {
146 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SecurityZone Table"+e);
150 }catch(Exception e1){
151 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);