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.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.rest.dao.UserInfoDao;
33 import org.openecomp.policy.rest.jpa.UserInfo;
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 @Service("UserInfoDao")
44 public class UserInfoDaoImpl implements UserInfoDao{
45 private static final Logger logger = FlexLogger.getLogger(UserInfoDaoImpl.class);
47 SessionFactory sessionfactory;
49 public SessionFactory getSessionfactory() {
50 return sessionfactory;
53 public void setSessionfactory(SessionFactory sessionfactory) {
54 this.sessionfactory = sessionfactory;
58 public void save(UserInfo userInfo) {
59 Session session = sessionfactory.openSession();
60 Transaction tx = session.beginTransaction();
62 session.persist(userInfo);
65 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving UserInfo Table"+e);
70 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
75 @SuppressWarnings("unchecked")
77 public List<UserInfo> getUserInfo() {
78 Session session = sessionfactory.openSession();
79 Transaction tx = session.beginTransaction();
80 List<UserInfo> userData = null;
82 Criteria cr = session.createCriteria(UserInfo.class);
85 } catch (Exception e) {
86 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e);
91 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
98 public String getUserName(String loginid) {
99 Session session = sessionfactory.openSession();
100 Transaction tx = session.beginTransaction();
101 UserInfo user = null;
103 user = (UserInfo) session.get(UserInfo.class, loginid);
105 } catch (Exception e) {
106 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e);
110 }catch(Exception e1){
111 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
114 return user.getUserName().toString();
118 public UserInfo getUserInfoByLoginId(String loginid) {
119 // TODO Auto-generated method stub