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.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.dao.RolesDao;
33 import org.openecomp.policy.model.Roles;
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;
43 public class RolesDaoImpl implements RolesDao{
44 private static final Logger logger = FlexLogger.getLogger(RolesDaoImpl.class);
46 SessionFactory sessionfactory;
49 public void save(Roles role) {
50 Session session = sessionfactory.openSession();
51 Transaction tx = session.beginTransaction();
53 session.persist(role);
56 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving Roles Table"+e);
61 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
67 public void delete(Roles role) {
68 Session session = sessionfactory.openSession();
69 Transaction tx = session.beginTransaction();
71 System.out.println("delete from Roles where loginid = '"+role.getLoginId()+"'");
72 Query q = session.createQuery(" delete from Roles where loginid = '"+role.getLoginId()+"'");
76 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting Roles Table"+e);
81 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
86 @SuppressWarnings("unchecked")
88 public List<Roles> getUserRoles(String userId) {
89 System.out.println("User Id:"+userId);
90 Session session = sessionfactory.openSession();
91 Transaction tx = session.beginTransaction();
92 List<Roles> rolesData = null;
94 Criteria cr = session.createCriteria(Roles.class);
95 cr = cr.add(Restrictions.eq("loginId",userId));
96 rolesData = cr.list();
98 } catch (Exception e) {
99 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Roles Table"+e);
103 }catch(Exception e1){
104 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);