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;
23 import java.util.List;
25 import org.hibernate.Criteria;
26 import org.hibernate.Session;
27 import org.hibernate.SessionFactory;
28 import org.hibernate.Transaction;
29 import org.hibernate.criterion.Conjunction;
30 import org.hibernate.criterion.Disjunction;
31 import org.hibernate.criterion.Restrictions;
32 import org.openecomp.policy.dao.PolicyRolesDao;
33 import org.openecomp.policy.rest.jpa.PolicyRoles;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Service;
37 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
39 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
40 import org.openecomp.policy.common.logging.flexlogger.Logger;
42 @Service("PolicyRolesDao")
43 public class PolicyRolesDaoImpl implements PolicyRolesDao{
44 private static final Logger logger = FlexLogger.getLogger(PolicyRolesDaoImpl.class);
46 SessionFactory sessionfactory;
48 @SuppressWarnings("unchecked")
50 public List<PolicyRoles> getUserRoles() {
51 Session session = sessionfactory.openSession();
52 Transaction tx = session.beginTransaction();
53 List<PolicyRoles> rolesData = null;
55 Criteria cr = session.createCriteria(PolicyRoles.class);
56 Disjunction disjunction = Restrictions.disjunction();
57 Conjunction conjunction1 = Restrictions.conjunction();
58 conjunction1.add(Restrictions.eq("role", "admin"));
59 Conjunction conjunction2 = Restrictions.conjunction();
60 conjunction2.add(Restrictions.eq("role", "editor"));
61 Conjunction conjunction3 = Restrictions.conjunction();
62 conjunction3.add(Restrictions.eq("role", "guest"));
63 disjunction.add(conjunction1);
64 disjunction.add(conjunction2);
65 disjunction.add(conjunction3);
66 rolesData = cr.add(disjunction).list();
68 } catch (Exception e) {
69 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyRoles Table"+e);
74 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
81 public void save(PolicyRoles role) {
82 Session session = sessionfactory.openSession();
83 Transaction tx = session.beginTransaction();
85 session.persist(role);
88 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving PolicyRoles Table"+e);
93 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
100 public void delete(PolicyRoles role) {
101 Session session = sessionfactory.openSession();
102 Transaction tx = session.beginTransaction();
104 session.delete(role);
107 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting PolicyRoles Table"+e);
111 }catch(Exception e1){
112 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
119 public void update(PolicyRoles role) {
120 Session session = sessionfactory.openSession();
121 Transaction tx = session.beginTransaction();
123 session.update(role);
126 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating PolicyRoles Table"+e);
130 }catch(Exception e1){
131 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
137 @SuppressWarnings("unchecked")
139 public List<PolicyRoles> getRoles() {
140 Session session = sessionfactory.openSession();
141 Transaction tx = session.beginTransaction();
142 List<PolicyRoles> rolesData = null;
144 Criteria cr = session.createCriteria(PolicyRoles.class);
145 rolesData = cr.list();
147 } catch (Exception e) {
148 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying PolicyRoles Table"+e);
152 }catch(Exception e1){
153 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);