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.hibernate.criterion.Restrictions;
33 import org.openecomp.policy.pap.xacml.rest.HibernateSession;
34 import org.openecomp.policy.rest.dao.DescriptiveScopeDao;
35 import org.openecomp.policy.rest.jpa.DescriptiveScope;
36 import org.openecomp.policy.rest.jpa.PolicyVersion;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Service;
40 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
42 @Service("DescriptiveScopeDao")
43 public class DescriptiveScopeDaoImpl implements DescriptiveScopeDao{
44 private static final Log logger = LogFactory.getLog(DescriptiveScopeDaoImpl.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<DescriptiveScope> getDescriptiveScope() {
59 Session session = HibernateSession.getSessionFactory();
60 Transaction tx = session.beginTransaction();
61 List<DescriptiveScope> descriptiveScopeData = null;
63 Criteria cr = session.createCriteria(DescriptiveScope.class);
64 descriptiveScopeData = cr.list();
66 } catch (Exception e) {
67 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e);
72 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
75 return descriptiveScopeData;
79 public void Save(DescriptiveScope descriptiveScope) {
80 Session session = HibernateSession.getSessionFactory();
81 Transaction tx = session.beginTransaction();
83 session.persist(descriptiveScope);
86 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving DescriptiveScope Table"+e);
91 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
98 public void delete(DescriptiveScope descriptiveScope) {
99 Session session = HibernateSession.getSessionFactory();
100 Transaction tx = session.beginTransaction();
102 session.delete(descriptiveScope);
105 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting DescriptiveScope Table"+e);
109 }catch(Exception e1){
110 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
117 public void update(DescriptiveScope descriptiveScope) {
118 Session session = HibernateSession.getSessionFactory();
119 Transaction tx = session.beginTransaction();
121 session.update(descriptiveScope);
124 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating DescriptiveScope Table"+e);
128 }catch(Exception e1){
129 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
135 @SuppressWarnings("unchecked")
137 public List<String> getDescriptiveScopeDataByName() {
138 Session session = HibernateSession.getSessionFactory();
139 Transaction tx = session.beginTransaction();
140 List<String> data = new ArrayList<String>();
142 Criteria cr = session.createCriteria(DescriptiveScope.class);
143 List<DescriptiveScope> descriptiveScopeData = cr.list();
144 for(int i = 0; i < descriptiveScopeData.size(); i++){
145 data.add(descriptiveScopeData.get(i).getScopeName());
148 } catch (Exception e) {
149 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e);
153 }catch(Exception e1){
154 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
161 public DescriptiveScope getDescriptiveScopeById(String name) {
162 Session session = HibernateSession.getSessionFactory();
163 Transaction tx = session.beginTransaction();
164 DescriptiveScope data = null;
166 Criteria cr = session.createCriteria(DescriptiveScope.class);
167 cr.add(Restrictions.eq("scopename",name));
168 data = (DescriptiveScope) cr.list().get(0);
170 } catch (Exception e) {
171 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e);
175 }catch(Exception e1){
176 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);