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.hibernate.Criteria;
28 import org.hibernate.Session;
29 import org.hibernate.SessionFactory;
30 import org.hibernate.Transaction;
31 import org.openecomp.policy.dao.RemoteCatalogValuesDao;
32 import org.openecomp.policy.rest.jpa.RemoteCatalogValues;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Service;
36 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
38 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
39 import org.openecomp.policy.common.logging.flexlogger.Logger;
41 @Service("RemoteCatalogValuesDao")
42 public class RemoteCatalogValuesDaoImpl implements RemoteCatalogValuesDao {
43 private static final Logger logger = FlexLogger.getLogger(RemoteCatalogValuesDaoImpl.class);
45 SessionFactory sessionfactory;
48 @SuppressWarnings("unchecked")
50 public List<RemoteCatalogValues> getRemoteCatalogValuesData() {
51 Session session = sessionfactory.openSession();
52 Transaction tx = session.beginTransaction();
53 List<RemoteCatalogValues> attributeData = null;
55 Criteria cr = session.createCriteria(RemoteCatalogValues.class);
56 attributeData = cr.list();
58 } catch (Exception e) {
59 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying RemoteCatalogValues Table"+e);
64 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
70 @SuppressWarnings("unchecked")
72 public List<String> getRemoteCatalogValuesDataByName() {
73 Session session = sessionfactory.openSession();
74 Transaction tx = session.beginTransaction();
75 List<String> data = new ArrayList<String>();
77 Criteria cr = session.createCriteria(RemoteCatalogValues.class);
78 List<RemoteCatalogValues> attributeData = cr.list();
79 for(int i = 0; i < attributeData.size(); i++){
80 data.add(attributeData.get(i).getName());
83 } catch (Exception e) {
84 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying RemoteCatalogValues Table"+e);
89 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
96 public void Save(RemoteCatalogValues attribute) {
97 Session session = sessionfactory.openSession();
98 Transaction tx = session.beginTransaction();
100 session.persist(attribute);
103 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving RemoteCatalogValues Table"+e);
107 }catch(Exception e1){
108 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
114 public void delete(RemoteCatalogValues attribute) {
115 Session session = sessionfactory.openSession();
116 Transaction tx = session.beginTransaction();
118 session.delete(attribute);
121 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Deleting RemoteCatalogValues Table"+e);
125 }catch(Exception e1){
126 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
132 public void update(RemoteCatalogValues attribute) {
133 Session session = sessionfactory.openSession();
134 Transaction tx = session.beginTransaction();
136 session.update(attribute);
139 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Updating RemoteCatalogValues Table"+e);
143 }catch(Exception e1){
144 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);