removing unused db file
[policy/engine.git] / ecomp-sdk-app / src / main / java / org / openecomp / policy / daoImp / UserInfoDaoImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.policy.daoImp;
22
23
24 import java.util.List;
25
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;
36
37 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
38
39 import org.openecomp.policy.common.logging.flexlogger.FlexLogger; 
40 import org.openecomp.policy.common.logging.flexlogger.Logger;
41
42
43 @Service("UserInfoDao")
44 public class UserInfoDaoImpl implements UserInfoDao{
45         private static final Logger logger = FlexLogger.getLogger(UserInfoDaoImpl.class);
46         @Autowired
47         SessionFactory sessionfactory;
48         
49         public SessionFactory getSessionfactory() {
50                 return sessionfactory;
51         }
52
53         public void setSessionfactory(SessionFactory sessionfactory) {
54                 this.sessionfactory = sessionfactory;
55         }
56
57         @Override
58         public void save(UserInfo userInfo) {
59                 Session session = sessionfactory.openSession();
60                 Transaction tx = session.beginTransaction();
61                 try {
62                         session.persist(userInfo);
63                         tx.commit();    
64                 }catch(Exception e){
65                         logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving UserInfo Table"+e);   
66                 }finally{
67                         try{
68                                 session.close();
69                         }catch(Exception e1){
70                                 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
71                         }
72                 }       
73         }
74
75         @SuppressWarnings("unchecked")
76         @Override
77         public List<UserInfo> getUserInfo() {
78                 Session session = sessionfactory.openSession();
79                 Transaction tx = session.beginTransaction();
80                 List<UserInfo> userData = null;
81         try {
82                 Criteria cr = session.createCriteria(UserInfo.class);
83             userData = cr.list();
84                         tx.commit();
85                 } catch (Exception e) {
86                         logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e); 
87                 }finally{
88                         try{
89                                 session.close();
90                         }catch(Exception e1){
91                                 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
92                         }
93                 }
94                 return userData;
95         }
96
97         @Override
98         public String getUserName(String loginid) {
99                 Session session = sessionfactory.openSession();
100                 Transaction tx = session.beginTransaction();
101                 UserInfo user = null;
102                 try {
103                         user = (UserInfo) session.get(UserInfo.class, loginid);
104                         tx.commit();
105                 } catch (Exception e) {
106                         logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying UserInfo Table"+e); 
107                 }finally{
108                         try{
109                                 session.close();
110                         }catch(Exception e1){
111                                 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
112                         }
113                 }
114                 return user.getUserName().toString();
115         }
116
117         @Override
118         public UserInfo getUserInfoByLoginId(String loginid) {
119                 // TODO Auto-generated method stub
120                 return null;
121         }
122         
123 }