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.ArrayList;
25 import java.util.List;
27 //import org.apache.commons.logging.Log;
28 //import org.apache.commons.logging.LogFactory;
29 import org.hibernate.Criteria;
30 import org.hibernate.Session;
31 import org.hibernate.SessionFactory;
32 import org.hibernate.Transaction;
33 import org.hibernate.criterion.Restrictions;
34 import org.openecomp.policy.rest.dao.DescriptiveScopeDao;
35 import org.openecomp.policy.rest.jpa.DescriptiveScope;
36 import org.openecomp.policy.rest.jpa.PolicyVersion;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Service;
40 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
42 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
43 import org.openecomp.policy.common.logging.flexlogger.Logger;
45 @Service("DescriptiveScopeDao")
46 public class DescriptiveScopeDaoImpl implements DescriptiveScopeDao{
47 private static final Logger logger = FlexLogger.getLogger(DescriptiveScopeDaoImpl.class);
49 SessionFactory sessionfactory;
51 @SuppressWarnings("unchecked")
53 public List<DescriptiveScope> getDescriptiveScope() {
54 Session session = sessionfactory.openSession();
55 Transaction tx = session.beginTransaction();
56 List<DescriptiveScope> descriptiveScopeData = null;
58 Criteria cr = session.createCriteria(DescriptiveScope.class);
59 descriptiveScopeData = cr.list();
61 } catch (Exception e) {
62 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e);
67 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
70 return descriptiveScopeData;
74 public void Save(DescriptiveScope descriptiveScope) {
75 Session session = sessionfactory.openSession();
76 Transaction tx = session.beginTransaction();
78 session.persist(descriptiveScope);
81 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving DescriptiveScope Table"+e);
86 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
93 public void delete(DescriptiveScope descriptiveScope) {
94 Session session = sessionfactory.openSession();
95 Transaction tx = session.beginTransaction();
97 session.delete(descriptiveScope);
100 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting DescriptiveScope Table"+e);
104 }catch(Exception e1){
105 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
112 public void update(DescriptiveScope descriptiveScope) {
113 Session session = sessionfactory.openSession();
114 Transaction tx = session.beginTransaction();
116 session.update(descriptiveScope);
119 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating DescriptiveScope Table"+e);
123 }catch(Exception e1){
124 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
130 @SuppressWarnings("unchecked")
132 public List<String> getDescriptiveScopeDataByName() {
133 Session session = sessionfactory.openSession();
134 Transaction tx = session.beginTransaction();
135 List<String> data = new ArrayList<String>();
137 Criteria cr = session.createCriteria(DescriptiveScope.class);
138 List<DescriptiveScope> descriptiveScopeData = cr.list();
139 for(int i = 0; i < descriptiveScopeData.size(); i++){
140 data.add(descriptiveScopeData.get(i).getScopeName());
143 } catch (Exception e) {
144 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e);
148 }catch(Exception e1){
149 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
156 public DescriptiveScope getDescriptiveScopeById(String name) {
157 Session session = sessionfactory.openSession();
158 Transaction tx = session.beginTransaction();
159 DescriptiveScope data = null;
161 Criteria cr = session.createCriteria(PolicyVersion.class);
162 cr.add(Restrictions.eq("scopename",name));
163 data = (DescriptiveScope) cr.list().get(0);
165 } catch (Exception e) {
166 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying DescriptiveScope Table"+e);
170 }catch(Exception e1){
171 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);