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.daoImp;
24 import java.util.ArrayList;
25 import java.util.List;
27 import org.hibernate.Criteria;
28 import org.hibernate.Query;
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.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.openecomp.policy.common.logging.flexlogger.FlexLogger;
41 import org.openecomp.policy.common.logging.flexlogger.Logger;
43 @Service("FirewallDictionaryListDao")
44 public class FirewallDictionaryListDaoImpl implements FirewallDictionaryListDao {
45 private static final Logger logger = FlexLogger.getLogger(FirewallDictionaryListDaoImpl.class);
47 SessionFactory sessionfactory;
49 @SuppressWarnings("unchecked")
51 public List<FirewallDictionaryList> getFWDictionaryListData() {
52 Session session = sessionfactory.openSession();
53 Transaction tx = session.beginTransaction();
54 List<FirewallDictionaryList> attributeData = null;
56 Criteria cr = session.createCriteria(FirewallDictionaryList.class);
57 attributeData = cr.list();
59 } catch (Exception e) {
60 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e);
65 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
72 @SuppressWarnings("unchecked")
74 public List<String> getFWDictionaryListDataByName() {
75 Session session = sessionfactory.openSession();
76 Transaction tx = session.beginTransaction();
77 List<String> data = new ArrayList<String>();
79 Criteria cr = session.createCriteria(FirewallDictionaryList.class);
80 List<FirewallDictionaryList> attributeData = cr.list();
81 for(int i = 0; i < attributeData.size(); i++){
82 data.add(attributeData.get(i).getParentItemName());
85 } catch (Exception e) {
86 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e);
91 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
98 public void Save(FirewallDictionaryList firewallDictionaryList) {
99 Session session = sessionfactory.openSession();
100 Transaction tx = session.beginTransaction();
102 session.persist(firewallDictionaryList);
105 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving FirewallDictionaryList Table"+e);
109 }catch(Exception e1){
110 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
117 public void delete(FirewallDictionaryList firewallDictionaryList) {
118 Session session = sessionfactory.openSession();
119 Transaction tx = session.beginTransaction();
121 session.delete(firewallDictionaryList);
124 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting FirewallDictionaryList Table"+e);
128 }catch(Exception e1){
129 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
136 public void update(FirewallDictionaryList firewallDictionaryList) {
137 Session session = sessionfactory.openSession();
138 Transaction tx = session.beginTransaction();
140 session.update(firewallDictionaryList);
143 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating FirewallDictionaryList Table"+e);
147 }catch(Exception e1){
148 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
155 public void updateQuery(String query) {
156 Session session = sessionfactory.openSession();
157 Transaction tx = session.beginTransaction();
159 Query hbquery = session.createQuery(query);
160 hbquery.executeUpdate();
162 } catch (Exception e) {
163 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating FirewallDictionaryList Table"+e);
167 }catch(Exception e1){
168 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
175 public FirewallDictionaryList getFWDictionaryDataById(String value) {
176 Session session = sessionfactory.openSession();
177 Transaction tx = session.beginTransaction();
178 FirewallDictionaryList data = null;
180 Criteria cr = session.createCriteria(FirewallDictionaryList.class);
181 cr = cr.add(Restrictions.eq("parentItemName",value));
182 data = (FirewallDictionaryList) cr.list().get(0);
184 } catch (Exception e) {
185 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FirewallDictionaryList Table"+e);
189 }catch(Exception e1){
190 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);