use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class OaiPmhUpdatedEventHandlerTest method testEpisodeNotKnownByOaiPmh.
/**
* Tests if publishing to OAI-PMH is skipped, if the episode is not known by OAI-PMH.
*/
@Test
public void testEpisodeNotKnownByOaiPmh() throws Exception {
Catalog episodeCatalog = CatalogImpl.newInstance();
episodeCatalog.setURI(URI.create("/episode.xml"));
episodeCatalog.setFlavor(MediaPackageElementFlavor.parseFlavor("dublincore/episode"));
episodeCatalog.addTag("archive");
MediaPackage updatedMp = createMediaPackage(episodeCatalog);
// these are the interactions we expect with the security service
mockSecurityService();
// mock the OAI-PMH database
SearchResult searchResultMock = mock(MockType.NICE, SearchResult.class);
expect(searchResultMock.getItems()).andReturn(Collections.EMPTY_LIST).anyTimes();
queryCapture = Capture.newInstance();
expect(oaiPmhDatabaseMock.search(capture(queryCapture))).andReturn(searchResultMock);
replayAll();
cut.handleEvent(createSnapshot(updatedMp));
// the OAI-PMH publication service should not be called as the media package isn't mocked in the OAI-PMH database
verifyAll();
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class OaiPmhUpdatedEventHandlerTest method testNoElementsWithGivenFlavorAndTags.
/**
* The media package does not contains elements with the configured tag, the publication should be skipped
*/
@Test
public void testNoElementsWithGivenFlavorAndTags() throws Exception {
Catalog episodeCatalog = CatalogImpl.newInstance();
episodeCatalog.setURI(URI.create("/episode.xml"));
episodeCatalog.setFlavor(MediaPackageElementFlavor.parseFlavor("dublincore/episode"));
// the episode catalog isn't tagged with archive
MediaPackage updatedMp = createMediaPackage();
// these are the interactions we expect with the security service
mockSecurityService();
replayAll();
cut.handleEvent(createSnapshot(updatedMp));
// the OAI-PMH publication service should not be called as the media package isn't mocked in the OAI-PMH database
verifyAll();
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class PartialImportWorkflowOperationHandler method getSmilDocumentFromMediaPackage.
private SMILDocument getSmilDocumentFromMediaPackage(MediaPackage mp, String smilFlavor) throws WorkflowOperationException {
final AbstractMediaPackageElementSelector<Catalog> smilSelector = new CatalogSelector();
try {
smilSelector.addFlavor(MediaPackageElementFlavor.parseFlavor(smilFlavor));
} catch (IllegalArgumentException e) {
throw new WorkflowOperationException("Smil flavor '" + smilFlavor + "' is malformed");
}
final Collection<Catalog> smilCatalog = smilSelector.select(mp, false);
if (smilCatalog.size() == 1) {
return getSmilDocument(smilCatalog.iterator().next());
} else {
logger.error("More or less than one smil catalog found: {}", smilCatalog);
throw new WorkflowOperationException("More or less than one smil catalog found!");
}
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class SegmentPreviewsWorkflowOperationHandler method start.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(org.opencastproject.workflow.api.WorkflowInstance,
* JobContext)
*/
@Override
public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
logger.debug("Running segments preview workflow operation on {}", workflowInstance);
// Check if there is an mpeg-7 catalog containing video segments
MediaPackage src = (MediaPackage) workflowInstance.getMediaPackage().clone();
Catalog[] segmentCatalogs = src.getCatalogs(MediaPackageElements.SEGMENTS);
if (segmentCatalogs.length == 0) {
logger.info("Media package {} does not contain segment information", src);
return createResult(Action.CONTINUE);
}
// Create the images
try {
return createPreviews(src, workflowInstance.getCurrentOperation());
} catch (Exception e) {
throw new WorkflowOperationException(e);
}
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class WorkflowPermissionsUpdatedEventHandler method handleEvent.
public void handleEvent(final SeriesItem seriesItem) {
// A series or its ACL has been updated. Find any mediapackages with that series, and update them.
logger.debug("Handling {}", seriesItem);
String seriesId = seriesItem.getSeriesId();
// We must be an administrative user to make this query
final User prevUser = securityService.getUser();
final Organization prevOrg = securityService.getOrganization();
try {
securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg));
// Note: getWorkflowInstances will only return a given number of results (default 20)
WorkflowQuery q = new WorkflowQuery().withSeriesId(seriesId);
WorkflowSet result = workflowService.getWorkflowInstancesForAdministrativeRead(q);
Integer offset = 0;
while (result.size() > 0) {
for (WorkflowInstance instance : result.getItems()) {
if (!instance.isActive())
continue;
Organization org = instance.getOrganization();
securityService.setOrganization(org);
MediaPackage mp = instance.getMediaPackage();
// Update the series XACML file
if (SeriesItem.Type.UpdateAcl.equals(seriesItem.getType())) {
// Build a new XACML file for this mediapackage
authorizationService.setAcl(mp, AclScope.Series, seriesItem.getAcl());
}
// Update the series dublin core
if (SeriesItem.Type.UpdateCatalog.equals(seriesItem.getType())) {
DublinCoreCatalog seriesDublinCore = seriesItem.getMetadata();
mp.setSeriesTitle(seriesDublinCore.getFirst(DublinCore.PROPERTY_TITLE));
// Update the series dublin core
Catalog[] seriesCatalogs = mp.getCatalogs(MediaPackageElements.SERIES);
if (seriesCatalogs.length == 1) {
Catalog c = seriesCatalogs[0];
String filename = FilenameUtils.getName(c.getURI().toString());
URI uri = workspace.put(mp.getIdentifier().toString(), c.getIdentifier(), filename, dublinCoreService.serialize(seriesDublinCore));
c.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
c.setChecksum(null);
}
}
// Remove the series catalog and isPartOf from episode catalog
if (SeriesItem.Type.Delete.equals(seriesItem.getType())) {
mp.setSeries(null);
mp.setSeriesTitle(null);
for (Catalog c : mp.getCatalogs(MediaPackageElements.SERIES)) {
mp.remove(c);
try {
workspace.delete(c.getURI());
} catch (NotFoundException e) {
logger.info("No series catalog to delete found {}", c.getURI());
}
}
for (Catalog episodeCatalog : mp.getCatalogs(MediaPackageElements.EPISODE)) {
DublinCoreCatalog episodeDublinCore = DublinCoreUtil.loadDublinCore(workspace, episodeCatalog);
episodeDublinCore.remove(DublinCore.PROPERTY_IS_PART_OF);
String filename = FilenameUtils.getName(episodeCatalog.getURI().toString());
URI uri = workspace.put(mp.getIdentifier().toString(), episodeCatalog.getIdentifier(), filename, dublinCoreService.serialize(episodeDublinCore));
episodeCatalog.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
episodeCatalog.setChecksum(null);
}
}
// Update the search index with the modified mediapackage
workflowService.update(instance);
}
offset++;
q = q.withStartPage(offset);
result = workflowService.getWorkflowInstancesForAdministrativeRead(q);
}
} catch (WorkflowException e) {
logger.warn(e.getMessage());
} catch (UnauthorizedException e) {
logger.warn(e.getMessage());
} catch (IOException e) {
logger.warn(e.getMessage());
} finally {
securityService.setOrganization(prevOrg);
securityService.setUser(prevUser);
}
}
Aggregations