AuditRepositoryDAO { public List<AuditRepositoryRecord> queryByAuditOptions(final List<String> eventTypeList, final String userId, final List<String> remoteHcidList, final Date startDate, final Date endDate) { Session session = null; List<AuditRepositoryRecord> queryList = null; try { session = getSession(); LOG.info("Getting Record for Audit Query "); if (session != null) { final Criteria queryCriteria = session.createCriteria(AuditRepositoryRecord.class); if (NullChecker.isNotNullish(eventTypeList)) { queryCriteria.add(Restrictions.in("eventType", eventTypeList)); } if (NullChecker.isNotNullish(userId)) { queryCriteria.add(Restrictions.eq("userId", userId)); } if (NullChecker.isNotNullish(remoteHcidList)) { queryCriteria.add(Restrictions.in("remoteHcid", remoteHcidList)); } if (startDate != null && endDate != null) { queryCriteria.add(Expression.between("eventTimestamp", startDate, endDate)); } else if (startDate != null) { queryCriteria.add(Restrictions.ge("eventTimestamp", startDate)); } else if (endDate != null) { queryCriteria.add(Restrictions.le("eventTimestamp", endDate)); } queryList = queryCriteria.list(); } } catch (final HibernateException e) { LOG.error("Exception in AuditLog.get() occurred due to : {}", e.getLocalizedMessage(), e); } finally { closeSession(session); } return queryList; } AuditRepositoryDAO(); boolean insertAuditRepository(final List<AuditRepositoryRecord> auditList); List queryAuditRepositoryOnCriteria(final String eUserId, final String ePatientId, final Date startDate,
            final Date endDate); List<AuditRepositoryRecord> queryAuditRecords(final String messageId, final String relatesTo); List<AuditRepositoryRecord> queryByAuditOptions(final List<String> eventTypeList, final String userId,
            final List<String> remoteHcidList, final Date startDate, final Date endDate); Blob queryByAuditId(final long auditId);  }
@Test public void testQueryByEventTypeList() { eventType = new ArrayList<>(Arrays.asList("DocSubmissionDeferredReq", "DocSubmission", "QueryForDocuments")); responseList = auditLogDao.queryByAuditOptions(eventType, userId, remoteHcid, startDate, endDate); assertNotNull(responseList); }
@Test public void testQueryByDateSearch() { try { String dateStr = "12/13/2015 22:53:07"; SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); startDate = formatter.parse(dateStr); responseList = auditLogDao.queryByAuditOptions(eventType, userId, remoteHcid, startDate, endDate); assertNotNull(responseList); } catch (ParseException ex) { LOG.error("Exception occurred due to :" + ex.getLocalizedMessage(), ex); } }
@Test public void testQueryByStartEndDateSearch() { try { String dateStartStr = "12/10/2015 00:00:00"; String dateEndStr = "12/11/2015 00:00:00"; SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); startDate = formatter.parse(dateStartStr); endDate = formatter.parse(dateEndStr); responseList = auditLogDao.queryByAuditOptions(eventType, userId, remoteHcid, startDate, endDate); assertNotNull(responseList); } catch (ParseException ex) { LOG.error("Exception occurred due to :" + ex.getLocalizedMessage(), ex); } }