use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class ImportWorkflowPropertiesWOH method loadPropertiesElementFromMediaPackage.
static Opt<Attachment> loadPropertiesElementFromMediaPackage(MediaPackageElementFlavor sourceFlavor, WorkflowInstance wi) throws WorkflowOperationException {
final MediaPackage mp = wi.getMediaPackage();
final Attachment[] elements = mp.getAttachments(sourceFlavor);
if (elements.length < 1) {
logger.info("Cannot import workflow properties - no element with flavor '{}' found in media package '{}'", sourceFlavor, mp.getIdentifier());
return Opt.none();
} else if (elements.length > 1) {
throw new WorkflowOperationException(format("Found more than one element with flavor '%s' in media package '%s'", sourceFlavor, mp.getIdentifier()));
}
return Opt.some(elements[0]);
}
use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class ImportWorkflowPropertiesWOHTest method testStartOp.
@Test
public void testStartOp() throws Exception {
final WorkflowOperationInstance woi = createMock(WorkflowOperationInstance.class);
expect(woi.getConfiguration("source-flavor")).andStubReturn(FLAVOR);
expect(woi.getConfiguration("keys")).andStubReturn("chapter, presenter_position, cover_marker_in_s");
replay(woi);
final Attachment att = new AttachmentImpl();
att.setURI(new URI(WF_PROPS_ATT_URI));
att.setFlavor(MediaPackageElementFlavor.parseFlavor(FLAVOR));
final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
mp.add(att);
WorkflowInstance wi = createMock(WorkflowInstance.class);
expect(wi.getCurrentOperation()).andStubReturn(woi);
expect(wi.getMediaPackage()).andStubReturn(mp);
replay(wi);
try (InputStream is = ImportWorkflowPropertiesWOHTest.class.getResourceAsStream("/workflow-properties.xml")) {
Files.copy(is, tmpPropsFile, StandardCopyOption.REPLACE_EXISTING);
}
final Workspace workspace = createNiceMock(Workspace.class);
expect(workspace.get(new URI(WF_PROPS_ATT_URI))).andStubReturn(tmpPropsFile.toFile());
replay(workspace);
final ImportWorkflowPropertiesWOH woh = new ImportWorkflowPropertiesWOH();
woh.setWorkspace(workspace);
WorkflowOperationResult result = woh.start(wi, null);
Map<String, String> properties = result.getProperties();
Assert.assertTrue(properties.containsKey("chapter"));
Assert.assertEquals("true", properties.get("chapter"));
Assert.assertTrue(properties.containsKey("presenter_position"));
Assert.assertEquals("left", properties.get("presenter_position"));
Assert.assertTrue(properties.containsKey("cover_marker_in_s"));
Assert.assertEquals("30.674", properties.get("cover_marker_in_s"));
verify(wi);
}
use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class ExportWorkflowPropertiesWOHTest method testExport.
@Test
public void testExport() throws Exception {
final WorkflowOperationInstance woi = createMock(WorkflowOperationInstance.class);
expect(woi.getConfiguration("target-flavor")).andStubReturn(FLAVOR);
expect(woi.getConfiguration("target-tags")).andStubReturn("archive");
expect(woi.getConfiguration("keys")).andStubReturn("chapter,presenter_position");
replay(woi);
final Attachment att = new AttachmentImpl();
att.setURI(uri);
att.setFlavor(MediaPackageElementFlavor.parseFlavor(FLAVOR));
final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
mp.add(att);
WorkflowInstance wi = createMock(WorkflowInstance.class);
expect(wi.getCurrentOperation()).andStubReturn(woi);
expect(wi.getMediaPackage()).andStubReturn(mp);
Set<String> keys = new HashSet<>();
keys.add("presenter_position");
keys.add("cover_marker_in_s");
expect(wi.getConfigurationKeys()).andStubReturn(keys);
expect(wi.getConfiguration("presenter_position")).andStubReturn("right");
expect(wi.getConfiguration("cover_marker_in_s")).andStubReturn("30.674");
replay(wi);
final ExportWorkflowPropertiesWOH woh = new ExportWorkflowPropertiesWOH();
woh.setWorkspace(workspace);
WorkflowOperationResult result = woh.start(wi, null);
Attachment[] attachments = result.getMediaPackage().getAttachments();
Assert.assertTrue(attachments.length == 1);
Attachment attachment = attachments[0];
assertEquals("processing/defaults", attachment.getFlavor().toString());
assertEquals("archive", attachment.getTags()[0]);
Assert.assertNotNull(attachment.getURI());
File file = workspace.get(attachment.getURI());
Properties props = new Properties();
try (InputStream is = new FileInputStream(file)) {
props.loadFromXML(is);
}
assertEquals("30.674", props.get("cover_marker_in_s"));
assertEquals("right", props.get("presenter_position"));
Assert.assertFalse(props.contains("chapter"));
verify(wi);
}
use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class WaveformServiceImpl method process.
/**
* {@inheritDoc}
*
* @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
*/
@Override
protected String process(Job job) throws Exception {
Operation op = null;
String operation = job.getOperation();
List<String> arguments = job.getArguments();
try {
op = Operation.valueOf(operation);
switch(op) {
case Waveform:
Track track = (Track) MediaPackageElementParser.getFromXml(arguments.get(0));
Attachment waveformMpe = extractWaveform(track);
return MediaPackageElementParser.getAsXml(waveformMpe);
default:
throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'");
}
} catch (IndexOutOfBoundsException e) {
throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
} catch (MediaPackageException | WaveformServiceException e) {
throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
}
}
Aggregations