SchedulerServiceImpl extends AbstractIndexProducer implements SchedulerService, ManagedService { @Override public Opt<MediaPackage> getUpcomingRecording(String captureAgentId) throws SchedulerException { try { final Date now = new Date(); List<ExtendedEventDto> result = persistence.search(Opt.some(captureAgentId), Opt.some(now), Opt.none(), Opt.none(), Opt.none(), Opt.some(1)); if (result.isEmpty()) { return Opt.none(); } return Opt.some(getEventMediaPackage(result.get(0).getMediaPackageId())); } catch (Exception e) { throw new SchedulerException(e); } }  void setMessageSender(MessageSender messageSender); void setMessageReceiver(MessageReceiver messageReceiver); void setPersistence(SchedulerServiceDatabase persistence); void setSeriesService(SeriesService seriesService); void setSecurityService(SecurityService securityService); void setAssetManager(AssetManager assetManager); void setWorkspace(Workspace workspace); void setAuthorizationService(AuthorizationService authorizationService); void setOrgDirectoryService(OrganizationDirectoryService orgDirectoryService); void addCatalogUIAdapter(EventCatalogUIAdapter catalogUIAdapter); void removeCatalogUIAdapter(EventCatalogUIAdapter catalogUIAdapter); void activate(ComponentContext cc); @Override void deactivate(); @Override void updated(Dictionary<String, ?> properties); @Override void addEvent(Date startDateTime, Date endDateTime, String captureAgentId, Set<String> userIds,
          MediaPackage mediaPackage, Map<String, String> wfProperties, Map<String, String> caMetadata,
          Opt<String> schedulingSource); @Override Map<String, Period> addMultipleEvents(RRule rRule, Date start, Date end, Long duration, TimeZone tz,
          String captureAgentId, Set<String> userIds, MediaPackage templateMp, Map<String, String> wfProperties,
          Map<String, String> caMetadata, Opt<String> schedulingSource); @Override void updateEvent(final String mpId, Opt<Date> startDateTime, Opt<Date> endDateTime, Opt<String> captureAgentId,
          Opt<Set<String>> userIds, Opt<MediaPackage> mediaPackage, Opt<Map<String, String>> wfProperties,
          Opt<Map<String, String>> caMetadata); @Override void updateEvent(final String mpId, Opt<Date> startDateTime, Opt<Date> endDateTime, Opt<String> captureAgentId,
          Opt<Set<String>> userIds, Opt<MediaPackage> mediaPackage, Opt<Map<String, String>> wfProperties,
          Opt<Map<String, String>> caMetadata, boolean allowConflict); @Override synchronized void removeEvent(String mediaPackageId); @Override MediaPackage getMediaPackage(String mediaPackageId); @Override DublinCoreCatalog getDublinCore(String mediaPackageId); @Override TechnicalMetadata getTechnicalMetadata(String mediaPackageId); @Override Map<String, String> getWorkflowConfig(String mediaPackageId); @Override Map<String, String> getCaptureAgentConfiguration(String mediaPackageId); @Override int getEventCount(); @Override List<MediaPackage> search(Opt<String> captureAgentId, Opt<Date> startsFrom, Opt<Date> startsTo,
          Opt<Date> endFrom, Opt<Date> endTo); @Override Opt<MediaPackage> getCurrentRecording(String captureAgentId); @Override Opt<MediaPackage> getUpcomingRecording(String captureAgentId); @Override List<MediaPackage> findConflictingEvents(String captureDeviceID, Date startDate, Date endDate); @Override List<MediaPackage> findConflictingEvents(String captureAgentId, RRule rrule, Date start, Date end,
          long duration, TimeZone tz); @Override String getCalendar(Opt<String> captureAgentId, Opt<String> seriesId, Opt<Date> cutoff); @Override String getScheduleLastModified(String captureAgentId); @Override void removeScheduledRecordingsBeforeBuffer(long buffer); @Override boolean updateRecordingState(String id, String state); @Override Recording getRecordingState(String id); @Override void removeRecording(String id); @Override Map<String, Recording> getKnownRecordings(); @Override void repopulate(final String indexName); @Override MessageReceiver getMessageReceiver(); @Override Service getService(); @Override String getClassName(); @Override MessageSender getMessageSender(); @Override SecurityService getSecurityService(); @Override String getSystemUserName(); static final String WORKFLOW_CONFIG_PREFIX; }
@Test public void testGetUpcomingRecording() throws Exception { final long nowMillis = System.currentTimeMillis(); final long oneHourMillis = 3600_000; final String captureAgentId = "Device A"; final Set<String> userIds = Collections.emptySet(); final Map<String, String> wfProperties = this.wfProperties; final Map<String, String> caProperties = Collections.singletonMap("foo", "bar"); final Opt<String> schedulingSource = Opt.none(); final String id = "Recording"; for (int i = 0; i < 3; i++) { final long offset = i * 3 * oneHourMillis; final Date start = new Date(nowMillis - 4 * oneHourMillis + offset); final Date end = new Date(nowMillis - 2 * oneHourMillis + offset); final MediaPackage mp = generateEvent(Opt.some(id + i)); final DublinCoreCatalog dublinCoreCatalog = generateEvent(captureAgentId, Opt.some(mp.getIdentifier().toString()), Opt.some("Test Title" + i), start, end); addDublinCore(Opt.some(mp.getIdentifier().toString()), mp, dublinCoreCatalog); schedSvc.addEvent( start, end, captureAgentId, userIds, mp, wfProperties, caProperties, schedulingSource ); } final Opt<MediaPackage> currentRecording = schedSvc.getUpcomingRecording(captureAgentId); assertTrue(currentRecording.isSome()); final TechnicalMetadata technicalMetadata = schedSvc.getTechnicalMetadata(currentRecording.get().getIdentifier().toString()); assertEquals(id + 2, currentRecording.get().getIdentifier().toString()); assertEquals(nowMillis + 2 * oneHourMillis, technicalMetadata.getStartDate().getTime()); assertEquals(nowMillis + 4 * oneHourMillis, technicalMetadata.getEndDate().getTime()); }