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.FunctionDefinitionDao;
32 import org.openecomp.policy.rest.jpa.FunctionDefinition;
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("FunctionDefinitionDao")
42 public class FunctionDefinitionDaoImpl implements FunctionDefinitionDao{
43 private static final Logger logger = FlexLogger.getLogger(FunctionDefinitionDaoImpl.class);
45 SessionFactory sessionfactory;
47 @SuppressWarnings("unchecked")
49 public List<String> getFunctionDefinitionByName() {
50 Session session = sessionfactory.openSession();
51 Transaction tx = session.beginTransaction();
52 List<String> data = new ArrayList<String>();
54 Criteria cr = session.createCriteria(FunctionDefinition.class);
55 List<FunctionDefinition> functionDefinitionData = cr.list();
56 for(int i = 0; i < functionDefinitionData.size(); i++){
57 data.add(functionDefinitionData.get(i).getShortname());
60 } catch (Exception e) {
61 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FunctionDefinition Table"+e);
66 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
72 @SuppressWarnings("unchecked")
74 public List<FunctionDefinition> getFunctionDefinition() {
75 Session session = sessionfactory.openSession();
76 Transaction tx = session.beginTransaction();
77 List<FunctionDefinition> functionDefinitionData = null;
79 Criteria cr = session.createCriteria(FunctionDefinition.class);
80 functionDefinitionData = cr.list();
82 } catch (Exception e) {
83 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying FunctionDefinition Table"+e);
88 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
91 return functionDefinitionData;