use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class EventIndexUtilsTest method testUpdateSeriesNameInputSeriesEventuallyAddedToIndexExpectsSetsName.
@Test
@SuppressWarnings("unchecked")
public void testUpdateSeriesNameInputSeriesEventuallyAddedToIndexExpectsSetsName() throws SearchIndexException {
// Input data
String seriesId = "my_series";
String eventId = "my_event";
// Mocks
Series series = EasyMock.createMock(Series.class);
EasyMock.expect(series.getTitle()).andReturn(seriesId);
SearchResultItem<Series> seriesResult = EasyMock.createMock(SearchResultItem.class);
EasyMock.expect(seriesResult.getSource()).andReturn(series);
ArrayList<SearchResultItem<Series>> seriesCollection = new ArrayList<SearchResultItem<Series>>();
seriesCollection.add(seriesResult);
SearchResult<Series> eventuallyResult = EasyMock.createMock(SearchResult.class);
EasyMock.expect(eventuallyResult.getHitCount()).andReturn(0L);
EasyMock.expect(eventuallyResult.getHitCount()).andReturn(0L);
EasyMock.expect(eventuallyResult.getHitCount()).andReturn(1L);
EasyMock.expect(eventuallyResult.getItems()).andReturn(seriesCollection.toArray(new SearchResultItem[1]));
Event event = EasyMock.createMock(Event.class);
EasyMock.expect(event.getSeriesId()).andReturn(seriesId).anyTimes();
EasyMock.expect(event.getSeriesName()).andReturn(null).anyTimes();
EasyMock.expect(event.getIdentifier()).andReturn(eventId).anyTimes();
event.setSeriesName(seriesId);
EasyMock.expectLastCall();
AbstractSearchIndex searchIndex = EasyMock.createMock(AbstractSearchIndex.class);
EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(eventuallyResult);
EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(eventuallyResult);
EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(eventuallyResult);
EasyMock.replay(eventuallyResult, event, searchIndex, series, seriesResult);
// Run test
EventIndexUtils.updateSeriesName(event, defaultOrganization.getId(), user, searchIndex, 3, 50L);
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class EventIndexUtilsTest method testUpdateSeriesNameInputSeriesNotAddedToIndexExpectsGivesUp.
@Test
public void testUpdateSeriesNameInputSeriesNotAddedToIndexExpectsGivesUp() throws SearchIndexException {
// Input data
String seriesId = "my_series";
String eventId = "my_event";
// Mocks
@SuppressWarnings("unchecked") SearchResult<Series> emptyResult = EasyMock.createMock(SearchResult.class);
EasyMock.expect(emptyResult.getHitCount()).andReturn(0L).anyTimes();
Event event = EasyMock.createMock(Event.class);
EasyMock.expect(event.getSeriesId()).andReturn(seriesId).anyTimes();
EasyMock.expect(event.getSeriesName()).andReturn(null).anyTimes();
EasyMock.expect(event.getIdentifier()).andReturn(eventId).anyTimes();
AbstractSearchIndex searchIndex = EasyMock.createMock(AbstractSearchIndex.class);
EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(emptyResult);
EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(emptyResult);
EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(emptyResult);
EasyMock.replay(emptyResult, event, searchIndex);
// Run test
EventIndexUtils.updateSeriesName(event, defaultOrganization.getId(), user, searchIndex, 3, 50L);
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class SchedulerMessageReceiverImplTest method testUpdateCreator.
@Test
public void testUpdateCreator() throws Exception {
DublinCoreCatalog catalog = DublinCores.read(getClass().getResourceAsStream("/dublincore.xml"));
SchedulerItem schedulerItem = SchedulerItem.updateCatalog("uuid", catalog);
// Test initial set of creator
scheduler.execute(schedulerItem);
Event event = index.getEventResult();
assertNotNull(event);
assertEquals("Current user is expected to be creator as no other creator has been set explicitly", "Creator", event.getCreator());
// Test updating creator
event.setCreator("Hans");
index.setInitialEvent(event);
scheduler.execute(schedulerItem);
event = index.getEventResult();
assertNotNull(event);
assertEquals("Creator has been updated", "Hans", event.getCreator());
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class IndexServiceImpl method changeOptOutStatus.
@Override
public void changeOptOutStatus(String eventId, boolean optout, AbstractSearchIndex index) throws NotFoundException, SchedulerException, SearchIndexException, UnauthorizedException {
Opt<Event> optEvent = getEvent(eventId, index);
if (optEvent.isNone())
throw new NotFoundException("Cannot find an event with id " + eventId);
schedulerService.updateEvent(eventId, 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(optout)), SchedulerService.ORIGIN);
logger.debug("Setting event {} to opt out status of {}", eventId, optout);
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class IndexServiceImpl method updateEventMetadata.
@Override
public MetadataList updateEventMetadata(String id, MetadataList metadataList, AbstractSearchIndex index) throws IndexServiceException, SearchIndexException, NotFoundException, UnauthorizedException {
Opt<Event> optEvent = getEvent(id, index);
if (optEvent.isNone())
throw new NotFoundException("Cannot find an event with id " + id);
Event event = optEvent.get();
MediaPackage mediaPackage = getEventMediapackage(event);
Opt<Set<String>> presenters = Opt.none();
Opt<MetadataCollection> eventCatalog = metadataList.getMetadataByAdapter(getCommonEventCatalogUIAdapter());
if (eventCatalog.isSome()) {
presenters = updatePresenters(eventCatalog.get());
}
updateMediaPackageMetadata(mediaPackage, metadataList);
switch(getEventSource(event)) {
case WORKFLOW:
Opt<WorkflowInstance> workflowInstance = getCurrentWorkflowInstance(event.getIdentifier());
if (workflowInstance.isNone()) {
logger.error("No workflow instance for event {} found!", event.getIdentifier());
throw new IndexServiceException("No workflow instance found for event " + event.getIdentifier());
}
try {
WorkflowInstance instance = workflowInstance.get();
instance.setMediaPackage(mediaPackage);
updateWorkflowInstance(instance);
} catch (WorkflowException e) {
logger.error("Unable to update workflow event {} with metadata {} because {}", id, RestUtils.getJsonStringSilent(metadataList.toJSON()), getStackTrace(e));
throw new IndexServiceException("Unable to update workflow event " + id);
}
break;
case ARCHIVE:
assetManager.takeSnapshot(DEFAULT_OWNER, mediaPackage);
break;
case SCHEDULE:
try {
schedulerService.updateEvent(id, Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), presenters, Opt.some(mediaPackage), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
} catch (SchedulerException e) {
logger.error("Unable to update scheduled event {} with metadata {} because {}", id, RestUtils.getJsonStringSilent(metadataList.toJSON()), getStackTrace(e));
throw new IndexServiceException("Unable to update scheduled event " + id);
}
break;
default:
logger.error("Unkown event source!");
}
return metadataList;
}
Aggregations