Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / java / org / openecomp / policy / daoImp / GlobalRoleSettingsDaoImpl.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.hibernate.Criteria;
27 import org.hibernate.Session;
28 import org.hibernate.SessionFactory;
29 import org.hibernate.Transaction;
30 import org.openecomp.policy.dao.GlobalRoleSettingsDao;
31 import org.openecomp.policy.rest.jpa.GlobalRoleSettings;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.stereotype.Service;
34
35 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
36
37 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
38 import org.openecomp.policy.common.logging.flexlogger.Logger;
39
40
41 @Service("GlobalRoleSettingsDao")
42 public class GlobalRoleSettingsDaoImpl implements GlobalRoleSettingsDao{
43         private static final Logger logger = FlexLogger.getLogger(GlobalRoleSettingsDaoImpl.class);
44         @Autowired
45         SessionFactory sessionfactory;
46         
47         
48
49         @SuppressWarnings("unchecked")
50         @Override
51         public List<GlobalRoleSettings> getGlobalRoleSettings() {
52                 Session session = sessionfactory.openSession();
53                 Transaction tx = session.beginTransaction();
54         List<GlobalRoleSettings> lockdownData = null;
55         try {
56                 Criteria cr = session.createCriteria(GlobalRoleSettings.class);
57             lockdownData = cr.list();
58                         tx.commit();
59                 } catch (Exception e) {
60                         logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying GlobalRoleSettings Table"+e);       
61                 }finally{
62                         try{
63                                 session.close();
64                         }catch(Exception e1){
65                                 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
66                         }
67                 }
68                 return lockdownData;
69         }
70
71
72
73         @Override
74         public void update(GlobalRoleSettings globalRoleSettings) {
75                 Session session = sessionfactory.openSession();
76                 Transaction tx = session.beginTransaction();
77                 try {
78                         session.update(globalRoleSettings);
79                         tx.commit();    
80                 }catch(Exception e){
81                         logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating GlobalRoleSettings Table"+e);       
82                 }finally{
83                         try{
84                                 session.close();
85                         }catch(Exception e1){
86                                 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
87                         }
88                 }               
89         }
90
91 }