Search in sources :

Example 61 with Attachment

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]);
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Attachment(org.opencastproject.mediapackage.Attachment)

Example 62 with Attachment

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);
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) InputStream(java.io.InputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 63 with Attachment

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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Attachment(org.opencastproject.mediapackage.Attachment) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Properties(java.util.Properties) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) FileInputStream(java.io.FileInputStream) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 64 with Attachment

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);
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) WaveformServiceException(org.opencastproject.waveform.api.WaveformServiceException) Attachment(org.opencastproject.mediapackage.Attachment) Track(org.opencastproject.mediapackage.Track) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Aggregations

Attachment (org.opencastproject.mediapackage.Attachment)64 MediaPackage (org.opencastproject.mediapackage.MediaPackage)28 URI (java.net.URI)24 IOException (java.io.IOException)20 Job (org.opencastproject.job.api.Job)20 NotFoundException (org.opencastproject.util.NotFoundException)19 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)18 Track (org.opencastproject.mediapackage.Track)16 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)16 Test (org.junit.Test)15 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)15 Catalog (org.opencastproject.mediapackage.Catalog)14 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)12 InputStream (java.io.InputStream)11 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)10 File (java.io.File)9 FileNotFoundException (java.io.FileNotFoundException)8 ArrayList (java.util.ArrayList)8 AttachmentImpl (org.opencastproject.mediapackage.attachment.AttachmentImpl)8 Workspace (org.opencastproject.workspace.api.Workspace)8