Initial OpenECOMP policy/engine commit
[policy/engine.git] / ECOMP-PAP-REST / src / main / java / org / openecomp / policy / pap / xacml / rest / controller / CheckDictionaryDuplicateEntries.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-PAP-REST
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.pap.xacml.rest.controller;
22
23 /*
24  * 
25  * 
26  * 
27  * */
28 import java.util.List;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.hibernate.Criteria;
33 import org.hibernate.Session;
34 import org.hibernate.Transaction;
35 import org.hibernate.criterion.Restrictions;
36 import org.openecomp.policy.pap.xacml.rest.HibernateSession;
37
38 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
39
40 public class CheckDictionaryDuplicateEntries {
41
42         private static final Log logger = LogFactory.getLog(CheckDictionaryDuplicateEntries.class);
43         
44         @SuppressWarnings({ "unchecked", "rawtypes" })
45         public List<Object> CheckDuplicateEntry(String value, String columnName, Class class1) {
46                 Session session = HibernateSession.getSessionFactory();
47                 Transaction tx = session.beginTransaction();
48                 List<Object> data = null;
49                 try {
50                         Criteria cr = session.createCriteria(class1);
51                         cr.add(Restrictions.eq(columnName,value));
52                         data = cr.list();
53                         tx.commit();
54                 } catch (Exception e) {
55                         logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying for Duplicate Entries for Table"+e + class1);       
56                 }finally{
57                         try{
58                                 session.close();
59                         }catch(Exception e1){
60                                 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
61                         }
62                 }
63                 return data;
64         }
65 }