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.hibernate.Criteria;
27 import org.hibernate.Query;
28 import org.hibernate.Session;
29 import org.hibernate.SessionFactory;
30 import org.hibernate.Transaction;
31 import org.hibernate.criterion.Restrictions;
32 import org.openecomp.policy.pap.xacml.rest.HibernateSession;
33 import org.openecomp.policy.rest.dao.FirewallDictionaryListDao;
34 import org.openecomp.policy.rest.jpa.FirewallDictionaryList;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Service;
38 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.logging.LogFactory;
43 @Service("FirewallDictionaryListDao")
44 public class FirewallDictionaryListDaoImpl implements FirewallDictionaryListDao {
45 private static final Log logger = LogFactory.getLog(FirewallDictionaryListDaoImpl.class);
47 SessionFactory sessionfactory;
49 public SessionFactory getSessionfactory() {
50 return sessionfactory;
53 public void setSessionfactory(SessionFactory sessionfactory) {
54 this.sessionfactory = sessionfactory;
58 public List<FirewallDictionaryList> getFWDictionaryListData() {
59 Session session = HibernateSession.getSessionFactory();
60 Transaction tx = session.beginTransaction();
61 List<FirewallDictionaryList> attributeData = null;
63 Criteria cr = session.createCriteria(FirewallDictionaryList.class);
64 attributeData = cr.list();
66 } catch (Exception e) {
67 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e);
72 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
80 public List<String> getFWDictionaryListDataByName() {
81 Session session = HibernateSession.getSessionFactory();
82 Transaction tx = session.beginTransaction();
83 List<String> data = new ArrayList<String>();
85 Criteria cr = session.createCriteria(FirewallDictionaryList.class);
86 List<FirewallDictionaryList> attributeData = cr.list();
87 for(int i = 0; i < attributeData.size(); i++){
88 data.add(attributeData.get(i).getParentItemName());
91 } catch (Exception e) {
92 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e);
97 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
104 public void Save(FirewallDictionaryList firewallDictionaryList) {
105 Session session = HibernateSession.getSessionFactory();
106 Transaction tx = session.beginTransaction();
108 session.persist(firewallDictionaryList);
111 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving FirewallDictionaryList Table"+e);
115 }catch(Exception e1){
116 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
123 public void delete(FirewallDictionaryList firewallDictionaryList) {
124 Session session = HibernateSession.getSessionFactory();
125 Transaction tx = session.beginTransaction();
127 session.delete(firewallDictionaryList);
130 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting FirewallDictionaryList Table"+e);
134 }catch(Exception e1){
135 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
142 public void update(FirewallDictionaryList firewallDictionaryList) {
143 Session session = HibernateSession.getSessionFactory();
144 Transaction tx = session.beginTransaction();
146 session.update(firewallDictionaryList);
149 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating FirewallDictionaryList Table"+e);
153 }catch(Exception e1){
154 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
161 public void updateQuery(String query) {
162 Session session = HibernateSession.getSessionFactory();
163 Transaction tx = session.beginTransaction();
165 Query hbquery = session.createQuery(query);
166 hbquery.executeUpdate();
168 } catch (Exception e) {
169 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating FirewallDictionaryList Table"+e);
173 }catch(Exception e1){
174 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
181 public FirewallDictionaryList getFWDictionaryDataById(String value) {
182 Session session = HibernateSession.getSessionFactory();
183 Transaction tx = session.beginTransaction();
184 FirewallDictionaryList data = null;
186 Criteria cr = session.createCriteria(FirewallDictionaryList.class);
187 cr = cr.add(Restrictions.eq("parentItemName",value));
188 data = (FirewallDictionaryList) cr.list().get(0);
190 } catch (Exception e) {
191 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e);
195 }catch(Exception e1){
196 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);