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.onap.policy.daoImp;
24 import java.util.List;
26 import org.hibernate.Criteria;
27 import org.hibernate.Session;
28 import org.springframework.stereotype.Service;
30 import org.onap.policy.xacml.api.XACMLErrorConstants;
32 import org.hibernate.Transaction;
33 import org.hibernate.criterion.Restrictions;
34 import org.onap.policy.conf.HibernateSession;
35 import org.onap.policy.controller.PolicyController;
36 import org.onap.policy.dao.SystemLogDbDao;
37 import org.onap.policy.rest.jpa.SystemLogDB;
38 import org.onap.policy.common.logging.flexlogger.FlexLogger;
39 import org.onap.policy.common.logging.flexlogger.Logger;
42 @Service("SystemLogDbDao")
43 public class SystemLogDbDaoImpl implements SystemLogDbDao {
44 private static final Logger logger = FlexLogger.getLogger(SystemLogDbDaoImpl.class);
46 private static boolean jUnit = false;
48 public static boolean isjUnit() {
52 public static void setjUnit(boolean jUnit) {
53 SystemLogDbDaoImpl.jUnit = jUnit;
56 @SuppressWarnings("unchecked")
58 public List<SystemLogDB> getLoggingData() {
59 Session session = HibernateSession.getSession();
60 Transaction tx = session.beginTransaction();
61 List<SystemLogDB> system = null;
63 String sqlWhere = null;
67 sqlWhere = "date > DATE_SUB(curdate(), INTERVAL 5 DAY) ORDER BY date DESC limit "+PolicyController.getLogTableLimit()+"";
69 Criteria cr = session.createCriteria(SystemLogDB.class);
70 cr.add(Restrictions.sqlRestriction(sqlWhere));
73 } catch (Exception e) {
74 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SystemLogDB Table"+e);
79 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
85 @SuppressWarnings("unchecked")
87 public List<SystemLogDB> getSystemAlertData() {
88 Session session = HibernateSession.getSession();;
89 Transaction tx = session.beginTransaction();
90 List<SystemLogDB> system = null;
92 String sqlWhere = null;
96 sqlWhere = "date > DATE_SUB(curdate(), INTERVAL 5 DAY) and logtype = 'error' ORDER BY date DESC limit "+PolicyController.getSystemAlertTableLimit()+"";
98 Criteria cr = session.createCriteria(SystemLogDB.class);
99 cr.add(Restrictions.sqlRestriction(sqlWhere));
102 } catch (Exception e) {
103 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying SystemLogDB Table"+e);
107 }catch(Exception e1){
108 logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);