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.EcompNameDao;
34 import org.openecomp.policy.rest.dao.RiskTypeDao;
35 import org.openecomp.policy.rest.jpa.EcompName;
36 import org.openecomp.policy.rest.jpa.RiskType;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Service;
40 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
42 @Service("RiskTypeDao")
43 public class RiskTypeDaoImpl implements RiskTypeDao {
44 private static final Log logger = LogFactory.getLog(RiskTypeDaoImpl.class);
46 SessionFactory sessionfactory;
48 public SessionFactory getSessionfactory() {
49 return sessionfactory;
52 public void setSessionfactory(SessionFactory sessionfactory) {
53 this.sessionfactory = sessionfactory;
56 @SuppressWarnings("unchecked")
58 public List<RiskType> getRiskName() {
59 System.out.println("RiskTypeDaoImpl: getRiskName() is called");
60 logger.debug("RiskTypeDaoImpl: getRiskName() is called");
61 Session session = HibernateSession.getSessionFactory();
62 Transaction tx = session.beginTransaction();
63 List<RiskType> riskTypeData = null;
65 Criteria cr = session.createCriteria(RiskType.class);
66 riskTypeData = cr.list();
67 logger.debug("Data returned from RiskType table: " + riskTypeData.toString());
69 } catch (Exception e) {
70 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying RiskType Table"+e);
75 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
82 public void Save(RiskType riskName) {
83 System.out.println("RiskTypeDaoImpl: Save() is called");
84 logger.debug("RiskTypeDaoImpl: Save() is called");
85 Session session = HibernateSession.getSessionFactory();
86 Transaction tx = session.beginTransaction();
88 session.persist(riskName);
91 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving RiskType Table"+e);
96 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
103 public void delete(RiskType riskName) {
104 Session session = HibernateSession.getSessionFactory();
105 Transaction tx = session.beginTransaction();
107 session.delete(riskName);
110 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting RiskType Table"+e);
114 }catch(Exception e1){
115 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
122 public void update(RiskType riskName) {
123 Session session = HibernateSession.getSessionFactory();
124 Transaction tx = session.beginTransaction();
126 session.update(riskName);
129 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating RiskType Table"+e);
133 }catch(Exception e1){
134 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
140 @SuppressWarnings("unchecked")
142 public List<String> getRiskTypeDataByName() {
143 logger.info("getRiskTypeDataByName is call from the DAO implementation class.");
144 Session session = HibernateSession.getSessionFactory();
145 Transaction tx = session.beginTransaction();
146 List<String> data = new ArrayList<String>();
148 Criteria cr = session.createCriteria(RiskType.class);
149 List<RiskType> riskTypeData = cr.list();
150 for(int i = 0; i < riskTypeData.size(); i++){
151 data.add(riskTypeData.get(i).getRiskName());
153 logger.info("data retrieved: " + data.toString());
155 } catch (Exception e) {
156 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying RiskType Table"+e);
160 }catch(Exception e1){
161 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);