@Test public void testGetEvents() throws Exception { final long oneHourMillis = 3600_000; final long nowMillis = new Date().getTime(); final String mpId = "mpId"; final String agentId = "agent1"; final String orgId = new DefaultOrganization().getId(); final Date intervalStart = new Date(nowMillis); final Date intervalEnd = new Date(nowMillis + 5 * oneHourMillis); final Date[] eventStartDates = { new Date(nowMillis - 4 * oneHourMillis), new Date(nowMillis - oneHourMillis), new Date(nowMillis + oneHourMillis), new Date(intervalEnd.getTime()), }; for (int i = 0; i < 4; i++) { final Date start = eventStartDates[i]; final Date end = new Date(start.getTime() + 2 * oneHourMillis); schedulerDatabase.storeEvent( mpId + i, orgId, Opt.some(agentId), Opt.some(start), Opt.some(end), Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none() ); } final int separationMillis = 60 * 1000; final List<String> eventIds = schedulerDatabase.getEvents(agentId, intervalStart, intervalEnd, separationMillis); Assert.assertEquals(3, eventIds.size()); Assert.assertFalse(eventIds.contains(mpId + 0)); Assert.assertTrue(eventIds.contains(mpId + 1)); Assert.assertTrue(eventIds.contains(mpId + 2)); Assert.assertTrue(eventIds.contains(mpId + 3)); }
@Override @SuppressWarnings("unchecked") public List<String> getEvents(String captureAgentId, Date start, Date end, int separationMillis) throws SchedulerServiceDatabaseException { final Date extendedStart = Date.from(start.toInstant().minusMillis(separationMillis)); final Date extendedEnd = Date.from(end.toInstant().plusMillis(separationMillis)); final EntityManager em = emf.createEntityManager(); final Query query = em.createNamedQuery("ExtendedEvent.findEvents") .setParameter("org", securityService.getOrganization().getId()) .setParameter("ca", captureAgentId) .setParameter("start", extendedStart) .setParameter("end", extendedEnd); try { return query.getResultList(); } catch (Exception e) { throw new SchedulerServiceDatabaseException(e); } finally { em.close(); } }
SchedulerServiceDatabaseImpl implements SchedulerServiceDatabase { @Override @SuppressWarnings("unchecked") public List<String> getEvents(String captureAgentId, Date start, Date end, int separationMillis) throws SchedulerServiceDatabaseException { final Date extendedStart = Date.from(start.toInstant().minusMillis(separationMillis)); final Date extendedEnd = Date.from(end.toInstant().plusMillis(separationMillis)); final EntityManager em = emf.createEntityManager(); final Query query = em.createNamedQuery("ExtendedEvent.findEvents") .setParameter("org", securityService.getOrganization().getId()) .setParameter("ca", captureAgentId) .setParameter("start", extendedStart) .setParameter("end", extendedEnd); try { return query.getResultList(); } catch (Exception e) { throw new SchedulerServiceDatabaseException(e); } finally { em.close(); } } }
SchedulerServiceDatabaseImpl implements SchedulerServiceDatabase { @Override @SuppressWarnings("unchecked") public List<String> getEvents(String captureAgentId, Date start, Date end, int separationMillis) throws SchedulerServiceDatabaseException { final Date extendedStart = Date.from(start.toInstant().minusMillis(separationMillis)); final Date extendedEnd = Date.from(end.toInstant().plusMillis(separationMillis)); final EntityManager em = emf.createEntityManager(); final Query query = em.createNamedQuery("ExtendedEvent.findEvents") .setParameter("org", securityService.getOrganization().getId()) .setParameter("ca", captureAgentId) .setParameter("start", extendedStart) .setParameter("end", extendedEnd); try { return query.getResultList(); } catch (Exception e) { throw new SchedulerServiceDatabaseException(e); } finally { em.close(); } }  }
SchedulerServiceDatabaseImpl implements SchedulerServiceDatabase { @Override @SuppressWarnings("unchecked") public List<String> getEvents(String captureAgentId, Date start, Date end, int separationMillis) throws SchedulerServiceDatabaseException { final Date extendedStart = Date.from(start.toInstant().minusMillis(separationMillis)); final Date extendedEnd = Date.from(end.toInstant().plusMillis(separationMillis)); final EntityManager em = emf.createEntityManager(); final Query query = em.createNamedQuery("ExtendedEvent.findEvents") .setParameter("org", securityService.getOrganization().getId()) .setParameter("ca", captureAgentId) .setParameter("start", extendedStart) .setParameter("end", extendedEnd); try { return query.getResultList(); } catch (Exception e) { throw new SchedulerServiceDatabaseException(e); } finally { em.close(); } }  void setEntityManagerFactory(EntityManagerFactory emf); void setSecurityService(SecurityService securityService); void activate(ComponentContext cc); @Override synchronized void touchLastEntry(String agentId); @Override Date getLastModified(String agentId); @Override @SuppressWarnings("unchecked") Map<String, Date> getLastModifiedDates(); @Override void storeEvent(String mediapackageId, String organizationId, Opt<String> captureAgentId, Opt<Date> start,
          Opt<Date> end, Opt<String> source, Opt<String> recordingState, Opt<Long> recordingLastHeard,
          Opt<String> presenters, Opt<Date> lastModifiedDate, Opt<String> checksum, Opt<Map<String,
          String>> workflowProperties, Opt<Map<String, String>> caProperties
  ); @Override @SuppressWarnings("unchecked") List<String> getEvents(String captureAgentId, Date start, Date end, int separationMillis); @Override @SuppressWarnings("unchecked") List<ExtendedEventDto> search(
      Opt<String> captureAgentId,
      Opt<Date> optStartsFrom,
      Opt<Date> optStartsTo,
      Opt<Date> optEndFrom,
      Opt<Date> optEndTo,
      Opt<Integer> limit); @Override List<ExtendedEventDto> getKnownRecordings(); @Override void deleteEvent(String mediapackageId); @Override List<ExtendedEventDto> getEvents(); @Override Opt<ExtendedEventDto> getEvent(String mediapackageId, String orgId); @Override Opt<ExtendedEventDto> getEvent(String mediapackageId); @Override void resetRecordingState(String mediapackageId); @Override int countEvents(); }
SchedulerServiceDatabaseImpl implements SchedulerServiceDatabase { @Override @SuppressWarnings("unchecked") public List<String> getEvents(String captureAgentId, Date start, Date end, int separationMillis) throws SchedulerServiceDatabaseException { final Date extendedStart = Date.from(start.toInstant().minusMillis(separationMillis)); final Date extendedEnd = Date.from(end.toInstant().plusMillis(separationMillis)); final EntityManager em = emf.createEntityManager(); final Query query = em.createNamedQuery("ExtendedEvent.findEvents") .setParameter("org", securityService.getOrganization().getId()) .setParameter("ca", captureAgentId) .setParameter("start", extendedStart) .setParameter("end", extendedEnd); try { return query.getResultList(); } catch (Exception e) { throw new SchedulerServiceDatabaseException(e); } finally { em.close(); } }  void setEntityManagerFactory(EntityManagerFactory emf); void setSecurityService(SecurityService securityService); void activate(ComponentContext cc); @Override synchronized void touchLastEntry(String agentId); @Override Date getLastModified(String agentId); @Override @SuppressWarnings("unchecked") Map<String, Date> getLastModifiedDates(); @Override void storeEvent(String mediapackageId, String organizationId, Opt<String> captureAgentId, Opt<Date> start,
          Opt<Date> end, Opt<String> source, Opt<String> recordingState, Opt<Long> recordingLastHeard,
          Opt<String> presenters, Opt<Date> lastModifiedDate, Opt<String> checksum, Opt<Map<String,
          String>> workflowProperties, Opt<Map<String, String>> caProperties
  ); @Override @SuppressWarnings("unchecked") List<String> getEvents(String captureAgentId, Date start, Date end, int separationMillis); @Override @SuppressWarnings("unchecked") List<ExtendedEventDto> search(
      Opt<String> captureAgentId,
      Opt<Date> optStartsFrom,
      Opt<Date> optStartsTo,
      Opt<Date> optEndFrom,
      Opt<Date> optEndTo,
      Opt<Integer> limit); @Override List<ExtendedEventDto> getKnownRecordings(); @Override void deleteEvent(String mediapackageId); @Override List<ExtendedEventDto> getEvents(); @Override Opt<ExtendedEventDto> getEvent(String mediapackageId, String orgId); @Override Opt<ExtendedEventDto> getEvent(String mediapackageId); @Override void resetRecordingState(String mediapackageId); @Override int countEvents(); static final String PERSISTENCE_UNIT; }