SchedulerServiceDatabaseImpl implements SchedulerServiceDatabase { @Override public void resetRecordingState(String mediapackageId) throws NotFoundException, SchedulerServiceDatabaseException { EntityManager em = null; EntityTransaction tx = null; try { em = emf.createEntityManager(); tx = em.getTransaction(); tx.begin(); final String orgId = securityService.getOrganization().getId(); Opt<ExtendedEventDto> entity = getExtendedEventDto(mediapackageId, orgId, em); if (entity.isNone()) { throw new NotFoundException("Event with ID " + mediapackageId + " does not exist"); } entity.get().setRecordingState(null); entity.get().setRecordingLastHeard(null); em.merge(entity.get()); tx.commit(); } catch (NotFoundException e) { throw e; } catch (Exception e) { if (tx.isActive()) tx.rollback(); throw new SchedulerServiceDatabaseException(e); } finally { if (em != null) 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; }
@Test public void testResetRecordingState() throws Exception { final String mpId = "mpid"; final String orgId = new DefaultOrganization().getId(); final String agentId = "agent1"; final Date start = new Date(1546844400000L); final Date end = new Date(1570953300000L); final String source = "source"; final String recordingState = "recordingState"; final Long lastHeard = new Date().getTime(); final String presenters = "Werner"; final Date lastModifiedDate = new Date(); final String checksum = "checksum"; final Map<String, String> wfProperties = Collections.singletonMap("wffoo", "wfbar"); final Map<String, String> caProperties = Collections.singletonMap("cafoo", "cabar"); schedulerDatabase.storeEvent( mpId, orgId, Opt.some(agentId), Opt.some(start), Opt.some(end), Opt.some(source), Opt.some(recordingState), Opt.some(lastHeard), Opt.some(presenters), Opt.some(lastModifiedDate), Opt.some(checksum), Opt.some(wfProperties), Opt.some(caProperties) ); schedulerDatabase.resetRecordingState(mpId); final Opt<ExtendedEventDto> updatedEvent = schedulerDatabase.getEvent(mpId); Assert.assertTrue(updatedEvent.isSome()); Assert.assertEquals(mpId, updatedEvent.get().getMediaPackageId()); Assert.assertEquals(orgId, updatedEvent.get().getOrganization()); Assert.assertEquals(agentId, updatedEvent.get().getCaptureAgentId()); Assert.assertEquals(start, updatedEvent.get().getStartDate()); Assert.assertEquals(end, updatedEvent.get().getEndDate()); Assert.assertEquals(source, updatedEvent.get().getSource()); Assert.assertNull(updatedEvent.get().getRecordingState()); Assert.assertNull(updatedEvent.get().getRecordingLastHeard()); Assert.assertEquals(presenters, updatedEvent.get().getPresenters()); Assert.assertEquals(lastModifiedDate, updatedEvent.get().getLastModifiedDate()); Assert.assertEquals(checksum, updatedEvent.get().getChecksum()); Assert.assertEquals(new Gson().toJson(wfProperties), updatedEvent.get().getWorkflowProperties()); Assert.assertEquals(new Gson().toJson(caProperties), updatedEvent.get().getCaptureAgentProperties()); }