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.List;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.hibernate.Criteria;
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.pap.xacml.rest.HibernateSession;
33 import org.openecomp.policy.rest.dao.UserInfoDao;
34 import org.openecomp.policy.rest.jpa.UserInfo;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Service;
38 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
41 @Service("UserInfoDao")
42 public class UserInfoDaoImpl implements UserInfoDao{
43 private static final Log logger = LogFactory.getLog(UserInfoDaoImpl.class);
45 SessionFactory sessionfactory;
47 public SessionFactory getSessionfactory() {
48 return sessionfactory;
51 public void setSessionfactory(SessionFactory sessionfactory) {
52 this.sessionfactory = sessionfactory;
56 public void save(UserInfo userInfo) {
57 Session session = HibernateSession.getSessionFactory();
58 Transaction tx = session.beginTransaction();
60 session.persist(userInfo);
63 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving UserInfo Table"+e);
68 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
73 @SuppressWarnings("unchecked")
75 public List<UserInfo> getUserInfo() {
76 System.out.println("UserInfoDaoImpl: getUserInfo().. getting user info before save()");
77 Session session = HibernateSession.getSessionFactory();
78 Transaction tx = session.beginTransaction();
79 List<UserInfo> userData = null;
81 Criteria cr = session.createCriteria(UserInfo.class);
84 } catch (Exception e) {
85 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e);
90 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
97 public String getUserName(String loginid) {
98 Session session = HibernateSession.getSessionFactory();
99 Transaction tx = session.beginTransaction();
100 UserInfo user = null;
102 user = (UserInfo) session.get(UserInfo.class, loginid);
104 } catch (Exception e) {
105 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e);
109 }catch(Exception e1){
110 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
113 return user.getUserName().toString();
117 public UserInfo getUserInfoByLoginId(String loginid) {
118 Session session = HibernateSession.getSessionFactory();
119 Transaction tx = session.beginTransaction();
120 UserInfo userData = null;
122 Criteria cr = session.createCriteria(UserInfo.class);
123 cr.add(Restrictions.eq("userLoginId", loginid));
124 userData = (UserInfo) cr.list().get(0);
126 } catch (Exception e) {
127 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e);
131 }catch(Exception e1){
132 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);