use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class InspectWorkflowOperationHandler method start.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(org.opencastproject.workflow.api.WorkflowInstance,
* JobContext)
*/
@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
MediaPackage mediaPackage = (MediaPackage) workflowInstance.getMediaPackage().clone();
// Inspect the tracks
long totalTimeInQueue = 0;
WorkflowOperationInstance operation = workflowInstance.getCurrentOperation();
boolean rewrite = "true".equalsIgnoreCase(operation.getConfiguration(OPT_OVERWRITE));
boolean acceptNoMedia = "true".equalsIgnoreCase(operation.getConfiguration(OPT_ACCEPT_NO_MEDIA));
final Map<String, String> options = new HashMap<String, String>();
if ("true".equalsIgnoreCase(operation.getConfiguration(OPT_ACCURATE_FRAME_COUNT))) {
logger.info("Using accurate frame count for inspection media package {}", mediaPackage);
options.put(MediaInspectionOptions.OPTION_ACCURATE_FRAME_COUNT, Boolean.TRUE.toString());
}
// Test if there are tracks in the mediapackage
if (mediaPackage.getTracks().length == 0) {
logger.warn("Recording {} contains no media", mediaPackage);
if (!acceptNoMedia)
throw new WorkflowOperationException("Mediapackage " + mediaPackage + " contains no media");
}
for (Track track : mediaPackage.getTracks()) {
logger.info("Inspecting track '{}' of {}", track.getIdentifier(), mediaPackage);
Job inspectJob = null;
Track inspectedTrack;
if (track != null && track.getURI() != null && (track.getURI().toString().endsWith(".vtt") || track.getURI().toString().endsWith(".srt"))) {
inspectedTrack = (Track) track.clone();
inspectedTrack.setMimeType(MimeType.mimeType("text", "vtt"));
logger.info("Track '{}' of {} contains captions", track.getIdentifier(), mediaPackage);
} else {
try {
inspectJob = inspectionService.enrich(track, rewrite, options);
if (!waitForStatus(inspectJob).isSuccess()) {
throw new WorkflowOperationException("Track " + track + " could not be inspected");
}
} catch (MediaInspectionException e) {
throw new WorkflowOperationException("Error inspecting media package", e);
} catch (MediaPackageException e) {
throw new WorkflowOperationException("Error parsing media package", e);
}
// add this receipt's queue and execution times to the total
long timeInQueue = inspectJob.getQueueTime() == null ? 0 : inspectJob.getQueueTime();
totalTimeInQueue += timeInQueue;
try {
inspectedTrack = (Track) MediaPackageElementParser.getFromXml(inspectJob.getPayload());
} catch (MediaPackageException e) {
throw new WorkflowOperationException("Unable to parse track from job " + inspectJob.getId(), e);
}
if (inspectedTrack == null)
throw new WorkflowOperationException("Track " + track + " could not be inspected");
if (inspectedTrack.getStreams().length == 0)
throw new WorkflowOperationException(format("Track %s does not contain any streams", track));
}
// Replace the original track with the inspected one
try {
mediaPackage.remove(track);
mediaPackage.add(inspectedTrack);
} catch (UnsupportedElementException e) {
logger.error("Error adding {} to media package", inspectedTrack, e);
}
}
// Update dublin core with metadata
try {
updateDublinCore(mediaPackage);
} catch (Exception e) {
logger.warn("Unable to update dublin core data: {}", e.getMessage(), e);
throw new WorkflowOperationException(e.getMessage());
}
return createResult(mediaPackage, Action.CONTINUE, totalTimeInQueue);
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class SeriesWorkflowOperationHandlerTest method testExtraMetadata.
@Test
public void testExtraMetadata() throws WorkflowOperationException {
final EName otherProperty = new EName(DublinCore.TERMS_NS_URI, "my-custom-property");
final String otherValue = "foobar";
// Add extra metadata to the series catalog.
seriesCatalog.set(DublinCore.PROPERTY_LANGUAGE, "Opencastian");
seriesCatalog.set(otherProperty, otherValue);
seriesCatalog.set(DublinCore.PROPERTY_CONTRIBUTOR, Arrays.asList(new DublinCoreValue[] { DublinCoreValue.mk("Mr. Contry Bute"), DublinCoreValue.mk("Mrs. Jane Doe") }));
// Prepare "copy metadata" property
String[] extraMetadata = { // Append a full metadata field, with NS
DublinCore.PROPERTY_LANGUAGE.toString(), // Field without namespace
DublinCore.PROPERTY_CONTRIBUTOR.getLocalName(), // Field with a namespace different than the default
otherProperty.toString(), // Field that does not exist in the series catalog
"does-not-exist" };
WorkflowInstanceImpl instance = new WorkflowInstanceImpl();
List<WorkflowOperationInstance> ops = new ArrayList<WorkflowOperationInstance>();
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
ops.add(operation);
instance.setOperations(ops);
instance.setMediaPackage(mp);
MediaPackage clone = (MediaPackage) mp.clone();
operation.setConfiguration(SeriesWorkflowOperationHandler.SERIES_PROPERTY, "series1");
operation.setConfiguration(SeriesWorkflowOperationHandler.ATTACH_PROPERTY, "*");
operation.setConfiguration(SeriesWorkflowOperationHandler.APPLY_ACL_PROPERTY, "false");
operation.setConfiguration(SeriesWorkflowOperationHandler.COPY_METADATA_PROPERTY, StringUtils.join(extraMetadata, ", "));
WorkflowOperationResult result = operationHandler.start(instance, null);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackage resultingMediapackage = result.getMediaPackage();
// Get episode DublinCore
DublinCoreCatalog episodeCatalog = DublinCores.read(capturedStream.getValue());
Assert.assertEquals("series1", resultingMediapackage.getSeries());
Assert.assertEquals("Series 1", resultingMediapackage.getSeriesTitle());
Assert.assertEquals(clone.getElements().length + 1, resultingMediapackage.getElements().length);
// Check the extra metadata were copied into the dublincore (only those present in the series catalog)
Assert.assertTrue(episodeCatalog.hasValue(DublinCore.PROPERTY_CONTRIBUTOR));
Assert.assertEquals(seriesCatalog.get(DublinCore.PROPERTY_CONTRIBUTOR), episodeCatalog.get(DublinCore.PROPERTY_CONTRIBUTOR));
Assert.assertTrue(episodeCatalog.hasValue(DublinCore.PROPERTY_LANGUAGE));
Assert.assertEquals(seriesCatalog.get(DublinCore.PROPERTY_LANGUAGE), episodeCatalog.get(DublinCore.PROPERTY_LANGUAGE));
Assert.assertTrue(episodeCatalog.hasValue(otherProperty));
Assert.assertEquals(seriesCatalog.get(otherProperty), episodeCatalog.get(otherProperty));
Assert.assertFalse(episodeCatalog.hasValue(new EName(DublinCore.TERMS_NS_URI, "does-not-exist")));
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class SeriesWorkflowOperationHandlerTest method testAttachExtendedOnly.
@Test
public void testAttachExtendedOnly() throws Exception {
WorkflowInstanceImpl instance = new WorkflowInstanceImpl();
List<WorkflowOperationInstance> ops = new ArrayList<WorkflowOperationInstance>();
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
ops.add(operation);
instance.setOperations(ops);
instance.setMediaPackage(mp);
MediaPackage clone = (MediaPackage) mp.clone();
operation.setConfiguration(SeriesWorkflowOperationHandler.SERIES_PROPERTY, "series1");
operation.setConfiguration(SeriesWorkflowOperationHandler.ATTACH_PROPERTY, "creativecommons/*");
operation.setConfiguration(SeriesWorkflowOperationHandler.APPLY_ACL_PROPERTY, "false");
WorkflowOperationResult result = operationHandler.start(instance, null);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackage resultingMediapackage = result.getMediaPackage();
Assert.assertEquals("series1", resultingMediapackage.getSeries());
Assert.assertEquals("Series 1", resultingMediapackage.getSeriesTitle());
Assert.assertEquals(clone.getElements().length + 1, resultingMediapackage.getElements().length);
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class TagWorkflowOperationHandlerTest method testAllTagsFlavors.
@Test
public void testAllTagsFlavors() throws Exception {
WorkflowInstanceImpl instance = new WorkflowInstanceImpl();
List<WorkflowOperationInstance> ops = new ArrayList<WorkflowOperationInstance>();
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
ops.add(operation);
instance.setOperations(ops);
instance.setMediaPackage(mp);
operation.setConfiguration(TagWorkflowOperationHandler.SOURCE_FLAVORS_PROPERTY, "presenter/source");
operation.setConfiguration(TagWorkflowOperationHandler.TARGET_FLAVOR_PROPERTY, "presenter/test");
operation.setConfiguration(TagWorkflowOperationHandler.TARGET_TAGS_PROPERTY, "tag1,tag2");
operation.setConfiguration(TagWorkflowOperationHandler.COPY_PROPERTY, "false");
WorkflowOperationResult result = operationHandler.start(instance, null);
MediaPackage resultingMediapackage = result.getMediaPackage();
Track track = resultingMediapackage.getTrack("track-2");
Assert.assertEquals("presenter/test", track.getFlavor().toString());
Assert.assertEquals("tag1", track.getTags()[0]);
Assert.assertEquals("tag2", track.getTags()[1]);
instance = new WorkflowInstanceImpl();
ops = new ArrayList<WorkflowOperationInstance>();
operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
ops.add(operation);
instance.setOperations(ops);
instance.setMediaPackage(resultingMediapackage);
operation.setConfiguration(TagWorkflowOperationHandler.SOURCE_TAGS_PROPERTY, "tag1");
operation.setConfiguration(TagWorkflowOperationHandler.TARGET_FLAVOR_PROPERTY, "presenter/source");
operation.setConfiguration(TagWorkflowOperationHandler.TARGET_TAGS_PROPERTY, "-tag1,+tag3");
operation.setConfiguration(TagWorkflowOperationHandler.COPY_PROPERTY, "false");
result = operationHandler.start(instance, null);
resultingMediapackage = result.getMediaPackage();
track = resultingMediapackage.getTrack("track-2");
Assert.assertEquals("presenter/source", track.getFlavor().toString());
Assert.assertEquals("tag2", track.getTags()[0]);
Assert.assertEquals("tag3", track.getTags()[1]);
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class DefaultsWorkflowOperationHandlerTest method setupInstance.
/**
* Setup a workflow instance to test the preset values.
*
* @param organization
* The {@link Organization} to use to get presets.
* @param seriesID
* The series id to get the presets.
* @param workflowConfiguration
* A workflow configuration to get the workflow keys and values.
* @param provideEventValue
* Whether to provide an event level value for the key
* @return A {@link WorkflowInstance} ready to run a test of {@link DefaultsWorkflowOperationHandler}
*/
private WorkflowInstance setupInstance(Organization organization, String seriesID, Map<String, String> workflowConfiguration, boolean provideEventValue) {
WorkflowOperationInstance operation = EasyMock.createMock(WorkflowOperationInstance.class);
EasyMock.expect(operation.getConfigurationKeys()).andReturn(workflowConfiguration.keySet());
EasyMock.expect(operation.getConfiguration(OPT_KEY)).andReturn(WORKFLOW_PRESET_VALUE);
EasyMock.replay(operation);
MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
EasyMock.expect(mediaPackage.getSeries()).andReturn(seriesID);
EasyMock.replay(mediaPackage);
WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
EasyMock.expect(workflowInstance.getId()).andReturn(1L).anyTimes();
EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(operation).anyTimes();
EasyMock.expect(workflowInstance.getOrganization()).andReturn(organization).anyTimes();
EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
if (provideEventValue) {
EasyMock.expect(workflowInstance.getConfiguration(OPT_KEY)).andReturn(EVENT_PRESET_VALUE);
} else {
EasyMock.expect(workflowInstance.getConfiguration(OPT_KEY)).andReturn(null);
}
EasyMock.replay(workflowInstance);
return workflowInstance;
}
Aggregations