use of org.opencastproject.assetmanager.api.query.ARecord in project opencast by opencast.
the class SchedulerServiceImplTest method testTransactionCommitConflict.
@Test
public void testTransactionCommitConflict() throws Exception {
Date start = new Date();
Date end = new Date(System.currentTimeMillis() + 60000);
String captureDeviceID = "demo";
String seriesId = "series1";
Set<String> userIds = new HashSet<>();
userIds.add("user1");
userIds.add("user2");
MediaPackage mp = generateEvent(Opt.<String>none());
mp.setSeries(seriesId);
DublinCoreCatalog extendedEvent = generateExtendedEvent(Opt.<String>none(), "extended");
addDublinCore(Opt.<String>none(), mp, extendedEvent);
DublinCoreCatalog event = generateEvent(captureDeviceID, start, end);
addDublinCore(Opt.<String>none(), mp, event);
addAcl(Opt.<String>none(), mp, acl);
Map<String, String> caProperties = generateCaptureAgentMetadata("demo");
SchedulerTransaction trx = schedSvc.createTransaction("new");
trx.addEvent(start, end, captureDeviceID, userIds, mp, wfProperties, caProperties, Opt.<Boolean>none());
try {
trx.commit();
} catch (SchedulerConflictException e) {
fail("Pre-conflict detection not working!");
}
AQueryBuilder query = assetManager.createQuery();
AResult result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
assertEquals(1, result.getSize());
Opt<ARecord> record = result.getRecords().head();
assertTrue(record.isSome());
assertEquals(new VersionImpl(0), record.get().getSnapshot().get().getVersion());
schedSvc.updateEvent(mp.getIdentifier().compact(), Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.<MediaPackage>none(), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.some(Opt.some(true)), SchedulerService.ORIGIN);
// Update with same checksum
trx = schedSvc.createTransaction("new");
trx.addEvent(start, end, captureDeviceID, userIds, mp, wfProperties, caProperties, Opt.some(true));
try {
// works because of same checksum
trx.commit();
} catch (SchedulerConflictException e) {
fail("Pre-conflict detection not working!");
}
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
assertEquals(1, result.getSize());
record = result.getRecords().head();
assertTrue(record.isSome());
assertEquals(new VersionImpl(1), record.get().getSnapshot().get().getVersion());
assertTrue(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
// Update with different checksum
schedSvc.updateEvent(mp.getIdentifier().compact(), Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.<MediaPackage>none(), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.some(Opt.some(false)), SchedulerService.ORIGIN);
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
assertEquals(1, result.getSize());
record = result.getRecords().head();
assertTrue(record.isSome());
assertEquals(new VersionImpl(1), record.get().getSnapshot().get().getVersion());
assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
assertTrue(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt("checksum")).isSome());
assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
assertEquals(SchedulerService.ORIGIN, record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
trx = schedSvc.createTransaction("new");
trx.addEvent(start, end, captureDeviceID, userIds, mp, wfProperties, caProperties, Opt.some(true));
try {
// creates conflict
trx.commit();
} catch (SchedulerConflictException e) {
fail("Pre-conflict detection not working!");
}
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
assertEquals(1, result.getSize());
record = result.getRecords().head();
assertTrue(record.isSome());
assertEquals(new VersionImpl(1), record.get().getSnapshot().get().getVersion());
assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
assertTrue(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt("last_conflict")).isSome());
assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
assertEquals(SchedulerService.ORIGIN, record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
// Commit again with no changes
trx = schedSvc.createTransaction("new");
trx.addEvent(start, end, captureDeviceID, userIds, mp, wfProperties, caProperties, Opt.some(true));
try {
// ignores conflict
trx.commit();
} catch (SchedulerConflictException e) {
fail("Pre-conflict detection not working!");
}
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
assertEquals(1, result.getSize());
record = result.getRecords().head();
assertTrue(record.isSome());
assertEquals(new VersionImpl(1), record.get().getSnapshot().get().getVersion());
assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
assertTrue(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt("last_conflict")).isSome());
assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
assertEquals(SchedulerService.ORIGIN, record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
// Commit again with changes
trx = schedSvc.createTransaction("new");
trx.addEvent(start, end, "newdevice", userIds, mp, wfProperties, caProperties, Opt.some(true));
try {
// override from existing
// creates new conflict
testConflictHandler.setStrategy(Strategy.OLD);
trx.commit();
} catch (SchedulerConflictException e) {
fail("Pre-conflict detection not working!");
}
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
assertEquals(1, result.getSize());
record = result.getRecords().head();
assertTrue(record.isSome());
assertEquals(new VersionImpl(1), record.get().getSnapshot().get().getVersion());
assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
assertTrue(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt("last_conflict")).isSome());
assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
assertEquals("demo", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("agent")));
assertEquals(SchedulerService.ORIGIN, record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
// Commit again with new changes
trx = schedSvc.createTransaction("new");
trx.addEvent(start, end, "newdevice", userIds, mp, wfProperties, caProperties, Opt.some(false));
try {
// override from transaction
testConflictHandler.setStrategy(Strategy.NEW);
trx.commit();
} catch (SchedulerConflictException e) {
fail("Pre-conflict detection not working!");
}
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
assertEquals(1, result.getSize());
record = result.getRecords().head();
assertTrue(record.isSome());
assertEquals(new VersionImpl(5), record.get().getSnapshot().get().getVersion());
assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt("last_conflict")).isSome());
assertEquals("newdevice", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("agent")));
assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
assertEquals("new", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
// Commit again with new changes
trx = schedSvc.createTransaction("new2");
trx.addEvent(start, end, captureDeviceID, userIds, mp, wfProperties, caProperties, Opt.some(true));
try {
// merge opt out only and keep agent id
testConflictHandler.setStrategy(Strategy.MERGED);
trx.commit();
} catch (SchedulerConflictException e) {
fail("Pre-conflict detection not working!");
}
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
assertEquals(1, result.getSize());
record = result.getRecords().head();
assertTrue(record.isSome());
assertEquals(new VersionImpl(7), record.get().getSnapshot().get().getVersion());
assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getBoolean("optout")));
assertFalse(record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getStringOpt("last_conflict")).isSome());
assertEquals(captureDeviceID, record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("agent")));
assertEquals("new2", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("source")));
assertEquals("new2", record.get().getProperties().apply(org.opencastproject.assetmanager.api.fn.Properties.getString("last_modified_origin")));
}
use of org.opencastproject.assetmanager.api.query.ARecord in project opencast by opencast.
the class SchedulerServiceImplTest method testTransactionCommitCollision.
@Test
public void testTransactionCommitCollision() throws Exception {
Date start = new Date();
Date end = new Date(System.currentTimeMillis() + 60000);
String captureDeviceID = "demo";
String seriesId = "series1";
Set<String> userIds = new HashSet<>();
userIds.add("user1");
userIds.add("user2");
MediaPackage mp = generateEvent(Opt.<String>none());
mp.setSeries(seriesId);
DublinCoreCatalog event = generateEvent(captureDeviceID, start, end);
addDublinCore(Opt.<String>none(), mp, event);
Map<String, String> caProperties = generateCaptureAgentMetadata("demo");
MediaPackage mp2 = generateEvent(Opt.<String>none());
try {
schedSvc.addEvent(start, end, captureDeviceID, userIds, mp2, wfPropertiesUpdated, caProperties, Opt.some(false), Opt.some("existing"), SchedulerService.ORIGIN);
} catch (SchedulerTransactionLockException e) {
fail("Transaction create lock not working!");
}
/* Test transaction collision of already existing event and new transaction event */
SchedulerTransaction trx = schedSvc.createTransaction("new");
assertEquals("new", trx.getSource());
AQueryBuilder query = assetManager.createQuery();
AResult result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
Opt<ARecord> record = result.getRecords().head();
assertFalse(record.isSome());
trx.addEvent(start, end, captureDeviceID, userIds, mp, wfPropertiesUpdated, caProperties, Opt.some(false));
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
record = result.getRecords().head();
assertTrue(record.isSome());
try {
trx.commit();
fail("Pre-conflict detection not working!");
} catch (SchedulerConflictException e) {
assertNotNull(e);
}
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
record = result.getRecords().head();
assertTrue(record.isSome());
try {
schedSvc.getTransaction(trx.getId());
} catch (NotFoundException e) {
fail("Transaction found!");
}
/* Test transaction collision of already existing event and new opted out transaction event */
MediaPackage mp4 = (MediaPackage) mp.clone();
mp4.setIdentifier(new IdImpl("newuuid"));
SchedulerTransaction trx2 = schedSvc.createTransaction("optedout");
assertEquals("optedout", trx2.getSource());
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp4.getIdentifier().compact()))).run();
record = result.getRecords().head();
assertFalse(record.isSome());
trx2.addEvent(start, end, captureDeviceID, userIds, mp4, wfPropertiesUpdated, caProperties, Opt.some(true));
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp4.getIdentifier().compact()))).run();
record = result.getRecords().head();
assertTrue(record.isSome());
try {
trx2.commit();
} catch (SchedulerConflictException e) {
fail("Pre-conflict detection not working!");
}
/* Test transaction collision of two transaction events */
schedSvc.removeEvent(mp2.getIdentifier().compact());
MediaPackage mp3 = generateEvent(Opt.<String>none());
trx.addEvent(start, end, captureDeviceID, userIds, mp3, wfPropertiesUpdated, caProperties, Opt.some(false));
try {
trx.commit();
fail("Pre-conflict detection not working!");
} catch (SchedulerConflictException e) {
assertNotNull(e);
}
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp.getIdentifier().compact()))).run();
record = result.getRecords().head();
assertTrue(record.isSome());
try {
schedSvc.getTransaction(trx.getId());
} catch (NotFoundException e) {
fail("Transaction found!");
}
/* Test transaction collision of two transaction events but one opted out */
MediaPackage mp5 = (MediaPackage) mp.clone();
mp5.setIdentifier(new IdImpl("newuuid2"));
SchedulerTransaction trx3 = schedSvc.createTransaction("optedout2");
assertEquals("optedout2", trx3.getSource());
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp5.getIdentifier().compact()))).run();
record = result.getRecords().head();
assertFalse(record.isSome());
trx3.addEvent(start, end, captureDeviceID, userIds, mp5, wfPropertiesUpdated, caProperties, Opt.some(false));
query = assetManager.createQuery();
result = query.select(query.snapshot(), query.properties()).where(query.organizationId().eq(new DefaultOrganization().getId()).and(query.mediaPackageId(mp5.getIdentifier().compact()))).run();
record = result.getRecords().head();
assertTrue(record.isSome());
MediaPackage mp6 = generateEvent(Opt.<String>none());
trx.addEvent(start, end, captureDeviceID, userIds, mp6, wfPropertiesUpdated, caProperties, Opt.some(true));
try {
trx3.commit();
} catch (SchedulerConflictException e) {
fail("Pre-conflict detection not working!");
}
}
use of org.opencastproject.assetmanager.api.query.ARecord in project opencast by opencast.
the class LiveScheduleServiceImpl method getSnapshot.
Snapshot getSnapshot(String mpId) throws LiveScheduleException {
AQueryBuilder query = assetManager.createQuery();
AResult result = query.select(query.snapshot()).where(query.mediaPackageId(mpId).and(query.version().isLatest())).run();
if (result.getSize() == 0) {
// Media package not archived?.
throw new LiveScheduleException(String.format("Unexpected error: media package %s has not been archived.", mpId));
}
Opt<ARecord> record = result.getRecords().head();
if (record.isNone()) {
// No snapshot?
throw new LiveScheduleException(String.format("Unexpected error: media package %s has not been archived.", mpId));
}
return record.get().getSnapshot().get();
}
use of org.opencastproject.assetmanager.api.query.ARecord in project opencast by opencast.
the class IBMWatsonTranscriptionServiceTest method testWorkflowDispatcherRunProgressState.
@Test
public void testWorkflowDispatcherRunProgressState() throws Exception {
InputStream stream = IBMWatsonTranscriptionServiceTest.class.getResourceAsStream("/" + PULLED_TRANSCRIPTION_FILE);
database.storeJobControl(MP_ID, TRACK_ID, JOB_ID, TranscriptionJobControl.Status.Progress.name(), 0);
database.storeJobControl("mpId2", "audioTrack2", "jobId2", TranscriptionJobControl.Status.Progress.name(), TRACK_DURATION);
EasyMock.expect(workspace.putInCollection(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(InputStream.class))).andReturn(new URI("http://anything"));
EasyMock.replay(workspace);
HttpEntity httpEntity = EasyMock.createNiceMock(HttpEntity.class);
EasyMock.expect(httpEntity.getContent()).andReturn(stream);
CloseableHttpResponse response = EasyMock.createNiceMock(CloseableHttpResponse.class);
StatusLine status = EasyMock.createNiceMock(StatusLine.class);
EasyMock.expect(response.getStatusLine()).andReturn(status).anyTimes();
EasyMock.expect(response.getEntity()).andReturn(httpEntity).anyTimes();
EasyMock.expect(status.getStatusCode()).andReturn(HttpStatus.SC_OK).anyTimes();
EasyMock.replay(httpEntity, response, status);
Capture<HttpGet> capturedGet = Capture.newInstance();
EasyMock.expect(httpClient.execute(EasyMock.capture(capturedGet))).andReturn(response);
EasyMock.replay(httpClient);
// enrich(q.select(q.snapshot()).where(q.mediaPackageId(mpId).and(q.version().isLatest())).run()).getSnapshots();
// Mocks for query, result, etc
Snapshot snapshot = EasyMock.createNiceMock(Snapshot.class);
EasyMock.expect(snapshot.getOrganizationId()).andReturn(org.getId());
ARecord aRec = EasyMock.createNiceMock(ARecord.class);
EasyMock.expect(aRec.getSnapshot()).andReturn(Opt.some(snapshot));
Stream<ARecord> recStream = Stream.mk(aRec);
Predicate p = EasyMock.createNiceMock(Predicate.class);
EasyMock.expect(p.and(p)).andReturn(p);
AResult r = EasyMock.createNiceMock(AResult.class);
EasyMock.expect(r.getSize()).andReturn(1L);
EasyMock.expect(r.getRecords()).andReturn(recStream);
Target t = EasyMock.createNiceMock(Target.class);
ASelectQuery selectQuery = EasyMock.createNiceMock(ASelectQuery.class);
EasyMock.expect(selectQuery.where(EasyMock.anyObject(Predicate.class))).andReturn(selectQuery);
EasyMock.expect(selectQuery.run()).andReturn(r);
AQueryBuilder query = EasyMock.createNiceMock(AQueryBuilder.class);
EasyMock.expect(query.snapshot()).andReturn(t);
EasyMock.expect(query.mediaPackageId(EasyMock.anyObject(String.class))).andReturn(p);
EasyMock.expect(query.select(EasyMock.anyObject(Target.class))).andReturn(selectQuery);
VersionField v = EasyMock.createNiceMock(VersionField.class);
EasyMock.expect(v.isLatest()).andReturn(p);
EasyMock.expect(query.version()).andReturn(v);
EasyMock.expect(assetManager.createQuery()).andReturn(query);
EasyMock.replay(snapshot, aRec, p, r, t, selectQuery, query, v, assetManager);
Capture<Set<String>> capturedMpIds = Capture.newInstance();
WorkflowDefinition wfDef = new WorkflowDefinitionImpl();
EasyMock.expect(wfService.getWorkflowDefinitionById(IBMWatsonTranscriptionService.DEFAULT_WF_DEF)).andReturn(wfDef);
List<WorkflowInstance> wfList = new ArrayList<WorkflowInstance>();
wfList.add(new WorkflowInstanceImpl());
Stream<WorkflowInstance> wfListStream = Stream.mk(wfList);
Workflows wfs = EasyMock.createNiceMock(Workflows.class);
EasyMock.expect(wfs.applyWorkflowToLatestVersion(EasyMock.capture(capturedMpIds), EasyMock.anyObject(ConfiguredWorkflow.class))).andReturn(wfListStream);
service.setWfUtil(wfs);
EasyMock.replay(wfService, wfs);
WorkflowDispatcher dispatcher = service.new WorkflowDispatcher();
dispatcher.run();
// Check if it called the external service to get the results
Assert.assertEquals("https://stream.watsonplatform.net/speech-to-text/api/v1/recognitions/" + JOB_ID, capturedGet.getValue().getURI().toString());
// Check if only one mp has a workflow created for it
Assert.assertEquals(1, capturedMpIds.getValue().size());
// And if it was the correct one
Assert.assertEquals(MP_ID, capturedMpIds.getValue().iterator().next());
// Check if status in db was updated
TranscriptionJobControl job = database.findByJob(JOB_ID);
Assert.assertNotNull(job);
Assert.assertEquals(TranscriptionJobControl.Status.Closed.name(), job.getStatus());
}
use of org.opencastproject.assetmanager.api.query.ARecord in project opencast by opencast.
the class SchedulerServiceImpl method preCollisionEventCheck.
private List<String> preCollisionEventCheck(String trxId, String schedulingSource) throws SchedulerException {
try {
AQueryBuilder query = assetManager.createQuery();
Props p = new Props(query);
TrxProps trxP = new TrxProps(query);
Predicate isSourceWithTrx = trxP.source().eq(schedulingSource).and(trxP.transactionId().eq(trxId));
Predicate hasProperties = p.agent().exists().and(p.start().exists()).and(p.end().exists());
Predicate isNotSource = p.source().eq(schedulingSource).not().and(hasProperties);
Predicate isNotOptedOut = p.optOut().eq(false).or(trxP.optOut().eq(false));
ASelectQuery select = query.select(trxP.optOut().target(), p.optOut().target(), p.agent().target(), p.start().target(), p.end().target(), trxP.agent().target(), trxP.start().target(), trxP.end().target(), trxP.transactionId().target()).where(withOrganization(query).and(isSourceWithTrx.or(isNotSource)).and(query.version().isLatest()).and(isNotOptedOut));
AResult result = select.run();
// Check for conflicts
List<String> conflictingRecords = new ArrayList<>();
Map<String, List<Interval>> invervalMap = new HashMap<>();
for (ARecord record : result.getRecords()) {
String agentId;
Date start;
Date end;
Opt<String> optTrxId = record.getProperties().apply(Properties.getStringOpt(TRANSACTION_ID_CONFIG));
if (optTrxId.isSome() && trxId.equals(optTrxId.get())) {
agentId = record.getProperties().filter(filterByNamespace._2(trxP.namespace())).apply(Properties.getString(AGENT_CONFIG));
start = record.getProperties().filter(filterByNamespace._2(trxP.namespace())).apply(Properties.getDate(START_DATE_CONFIG));
end = record.getProperties().filter(filterByNamespace._2(trxP.namespace())).apply(Properties.getDate(END_DATE_CONFIG));
} else {
agentId = record.getProperties().filter(filterByNamespace._2(p.namespace())).apply(Properties.getString(AGENT_CONFIG));
start = record.getProperties().filter(filterByNamespace._2(p.namespace())).apply(Properties.getDate(START_DATE_CONFIG));
end = record.getProperties().filter(filterByNamespace._2(p.namespace())).apply(Properties.getDate(END_DATE_CONFIG));
}
Interval currentInterval = new Interval(start.getTime(), end.getTime());
List<Interval> intervals = invervalMap.get(agentId);
if (intervals == null)
intervals = new ArrayList<>();
boolean overlaps = false;
for (Interval i : intervals) {
if (!i.overlaps(currentInterval))
continue;
overlaps = true;
break;
}
if (!overlaps) {
intervals.add(currentInterval);
} else {
conflictingRecords.add(record.getMediaPackageId());
}
invervalMap.put(agentId, intervals);
}
return conflictingRecords;
} catch (Exception e) {
logger.error("Failed to search for conflicting events: {}", getStackTrace(e));
throw new SchedulerException(e);
}
}
Aggregations