Search in sources :

Example 71 with Catalog

use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.

the class TagByDublinCoreTermWOHTest method testMatchPresentDCTerm.

@Test
public void testMatchPresentDCTerm() throws Exception {
    operation.setConfiguration(TagByDublinCoreTermWOH.SOURCE_FLAVORS_PROPERTY, "dublincore/*");
    operation.setConfiguration(TagByDublinCoreTermWOH.DCCATALOG_PROPERTY, "episode");
    operation.setConfiguration(TagByDublinCoreTermWOH.DCTERM_PROPERTY, "publisher");
    operation.setConfiguration(TagByDublinCoreTermWOH.MATCH_VALUE_PROPERTY, "University of Opencast");
    operation.setConfiguration(TagByDublinCoreTermWOH.TARGET_TAGS_PROPERTY, "tag1,tag2");
    operation.setConfiguration(TagByDublinCoreTermWOH.COPY_PROPERTY, "false");
    WorkflowOperationResult result = operationHandler.start(instance, null);
    MediaPackage resultingMediapackage = result.getMediaPackage();
    Catalog catalog = resultingMediapackage.getCatalog("catalog-1");
    Assert.assertEquals("tag1", catalog.getTags()[0]);
    Assert.assertEquals("tag2", catalog.getTags()[1]);
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Catalog(org.opencastproject.mediapackage.Catalog) Test(org.junit.Test)

Example 72 with Catalog

use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.

the class TagByDublinCoreTermWOHTest method testNoMatchConfiguredDCTerm.

@Test
public void testNoMatchConfiguredDCTerm() throws Exception {
    // No Match or Default Value
    // without dcterm or default the match should always fail
    operation.setConfiguration(TagByDublinCoreTermWOH.SOURCE_FLAVORS_PROPERTY, "dublincore/*");
    operation.setConfiguration(TagByDublinCoreTermWOH.DCCATALOG_PROPERTY, "episode");
    operation.setConfiguration(TagByDublinCoreTermWOH.DCTERM_PROPERTY, "source");
    operation.setConfiguration(TagByDublinCoreTermWOH.TARGET_TAGS_PROPERTY, "tag1,tag2");
    operation.setConfiguration(TagByDublinCoreTermWOH.COPY_PROPERTY, "false");
    WorkflowOperationResult result = operationHandler.start(instance, null);
    MediaPackage resultingMediapackage = result.getMediaPackage();
    Catalog catalog = resultingMediapackage.getCatalog("catalog-1");
    Assert.assertEquals(1, catalog.getTags().length);
    Assert.assertEquals("archive", catalog.getTags()[0]);
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Catalog(org.opencastproject.mediapackage.Catalog) Test(org.junit.Test)

Example 73 with Catalog

use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.

the class SilenceDetectionWorkflowOperationHandler method start.

@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
    MediaPackage mp = workflowInstance.getMediaPackage();
    logger.debug("Start silence detection workflow operation for mediapackage {}", mp.getIdentifier().compact());
    String sourceFlavors = StringUtils.trimToNull(workflowInstance.getCurrentOperation().getConfiguration(SOURCE_FLAVORS_PROPERTY));
    String sourceFlavor = StringUtils.trimToNull(workflowInstance.getCurrentOperation().getConfiguration(SOURCE_FLAVOR_PROPERTY));
    String smilFlavorSubType = StringUtils.trimToNull(workflowInstance.getCurrentOperation().getConfiguration(SMIL_FLAVOR_SUBTYPE_PROPERTY));
    String smilTargetFlavorString = StringUtils.trimToNull(workflowInstance.getCurrentOperation().getConfiguration(SMIL_TARGET_FLAVOR_PROPERTY));
    MediaPackageElementFlavor smilTargetFlavor = null;
    if (smilTargetFlavorString != null)
        smilTargetFlavor = MediaPackageElementFlavor.parseFlavor(smilTargetFlavorString);
    if (sourceFlavor == null && sourceFlavors == null) {
        throw new WorkflowOperationException(String.format("No %s or %s have been specified", SOURCE_FLAVOR_PROPERTY, SOURCE_FLAVORS_PROPERTY));
    }
    if (smilFlavorSubType == null && smilTargetFlavor == null) {
        throw new WorkflowOperationException(String.format("No %s or %s have been specified", SMIL_FLAVOR_SUBTYPE_PROPERTY, SMIL_TARGET_FLAVOR_PROPERTY));
    }
    if (sourceFlavors != null && smilTargetFlavor != null) {
        throw new WorkflowOperationException(String.format("Can't use %s and %s together", SOURCE_FLAVORS_PROPERTY, SMIL_TARGET_FLAVOR_PROPERTY));
    }
    final String finalSourceFlavors;
    if (smilTargetFlavor != null) {
        finalSourceFlavors = sourceFlavor;
    } else {
        finalSourceFlavors = sourceFlavors;
    }
    String referenceTracksFlavor = StringUtils.trimToNull(workflowInstance.getCurrentOperation().getConfiguration(REFERENCE_TRACKS_FLAVOR_PROPERTY));
    if (referenceTracksFlavor == null)
        referenceTracksFlavor = finalSourceFlavors;
    TrackSelector trackSelector = new TrackSelector();
    for (String flavor : asList(finalSourceFlavors)) {
        trackSelector.addFlavor(flavor);
    }
    Collection<Track> sourceTracks = trackSelector.select(mp, false);
    if (sourceTracks.isEmpty()) {
        logger.info("No source tracks found, skip silence detection");
        return createResult(mp, Action.SKIP);
    }
    trackSelector = new TrackSelector();
    for (String flavor : asList(referenceTracksFlavor)) {
        trackSelector.addFlavor(flavor);
    }
    Collection<Track> referenceTracks = trackSelector.select(mp, false);
    if (referenceTracks.isEmpty()) {
        // REFERENCE_TRACKS_FLAVOR_PROPERTY was set to wrong value
        throw new WorkflowOperationException(String.format("No tracks found filtered by flavor(s) '%s'", referenceTracksFlavor));
    }
    MediaPackageElementBuilder mpeBuilder = MediaPackageElementBuilderFactory.newInstance().newElementBuilder();
    for (Track sourceTrack : sourceTracks) {
        // Skip over track with no audio stream
        if (!sourceTrack.hasAudio()) {
            logger.info("Skipping silence detection of track {} since it has no audio", sourceTrack);
            continue;
        }
        logger.info("Executing silence detection on track {}", sourceTrack.getIdentifier());
        try {
            Job detectionJob = detetionService.detect(sourceTrack, referenceTracks.toArray(new Track[referenceTracks.size()]));
            if (!waitForStatus(detectionJob).isSuccess()) {
                throw new WorkflowOperationException("Silence Detection failed");
            }
            Smil smil = smilService.fromXml(detectionJob.getPayload()).getSmil();
            InputStream is = null;
            try {
                is = IOUtils.toInputStream(smil.toXML(), "UTF-8");
                URI smilURI = workspace.put(mp.getIdentifier().compact(), smil.getId(), TARGET_FILE_NAME, is);
                MediaPackageElementFlavor smilFlavor = smilTargetFlavor;
                if (smilFlavor == null)
                    smilFlavor = new MediaPackageElementFlavor(sourceTrack.getFlavor().getType(), smilFlavorSubType);
                Catalog catalog = (Catalog) mpeBuilder.elementFromURI(smilURI, MediaPackageElement.Type.Catalog, smilFlavor);
                catalog.setIdentifier(smil.getId());
                mp.add(catalog);
            } catch (Exception ex) {
                throw new WorkflowOperationException(String.format("Failed to put smil into workspace. Silence detection for track %s failed", sourceTrack.getIdentifier()), ex);
            } finally {
                IOUtils.closeQuietly(is);
            }
            logger.info("Finished silence detection on track {}", sourceTrack.getIdentifier());
        } catch (SilenceDetectionFailedException ex) {
            throw new WorkflowOperationException(String.format("Failed to create silence detection job for track %s", sourceTrack.getIdentifier()));
        } catch (SmilException ex) {
            throw new WorkflowOperationException(String.format("Failed to get smil from silence detection job for track %s", sourceTrack.getIdentifier()));
        }
    }
    logger.debug("Finished silence detection workflow operation for mediapackage {}", mp.getIdentifier().compact());
    return createResult(mp, Action.CONTINUE);
}
Also used : SilenceDetectionFailedException(org.opencastproject.silencedetection.api.SilenceDetectionFailedException) InputStream(java.io.InputStream) TrackSelector(org.opencastproject.mediapackage.selector.TrackSelector) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) Catalog(org.opencastproject.mediapackage.Catalog) SmilException(org.opencastproject.smil.api.SmilException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) SilenceDetectionFailedException(org.opencastproject.silencedetection.api.SilenceDetectionFailedException) MediaPackageElementBuilder(org.opencastproject.mediapackage.MediaPackageElementBuilder) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Smil(org.opencastproject.smil.entity.api.Smil) SmilException(org.opencastproject.smil.api.SmilException) Job(org.opencastproject.job.api.Job) Track(org.opencastproject.mediapackage.Track)

Example 74 with Catalog

use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.

the class SchedulerServiceImplTest method addDublinCore.

private String addDublinCore(Opt<String> id, MediaPackage mediaPackage, final DublinCoreCatalog initalEvent) throws URISyntaxException, IOException {
    String catalogId = UUID.randomUUID().toString();
    Catalog catalog = null;
    if (id.isSome()) {
        catalogId = id.get();
        catalog = mediaPackage.getCatalog(catalogId);
    }
    URI uri = workspace.put(mediaPackage.getIdentifier().compact(), catalogId, "dublincore.xml", IOUtils.toInputStream(initalEvent.toXmlString(), StandardCharsets.UTF_8.name()));
    if (catalog == null) {
        catalog = (Catalog) mediaPackage.add(uri, Type.Catalog, initalEvent.getFlavor());
        catalog.setIdentifier(catalogId);
    }
    catalog.setChecksum(null);
    return catalogId;
}
Also used : URI(java.net.URI) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog)

Example 75 with Catalog

use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.

the class SilenceDetectionWorkflowOperationHandlerTest method testStartOperation.

@Test
public void testStartOperation() throws WorkflowOperationException, SilenceDetectionFailedException, NotFoundException, ServiceRegistryException, MediaPackageException, SmilException, MalformedURLException, JAXBException, SAXException, IOException {
    Smil smil = smilService.fromXml(new File(smilURI)).getSmil();
    Job job = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(job.getPayload()).andReturn(smil.toXML()).anyTimes();
    EasyMock.expect(job.getStatus()).andReturn(Job.Status.FINISHED);
    EasyMock.expect(silenceDetectionServiceMock.detect((Track) EasyMock.anyObject(), (Track[]) EasyMock.anyObject())).andReturn(job);
    EasyMock.expect(workspaceMock.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(smilURI);
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    silenceDetectionOperationHandler.setServiceRegistry(serviceRegistry);
    EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job);
    EasyMock.replay(job, serviceRegistry, silenceDetectionServiceMock, workspaceMock);
    WorkflowInstanceImpl workflowInstance = getWorkflowInstance(mp, getDefaultConfiguration());
    WorkflowOperationResult result = silenceDetectionOperationHandler.start(workflowInstance, null);
    Assert.assertNotNull("SilenceDetectionWorkflowOperationHandler workflow operation returns null " + "but should be an instantiated WorkflowOperationResult", result);
    EasyMock.verify(silenceDetectionServiceMock, workspaceMock);
    WorkflowOperationInstance worflowOperationInstance = workflowInstance.getCurrentOperation();
    String smilFlavorSubtypeProperty = worflowOperationInstance.getConfiguration("smil-flavor-subtype");
    // test media package contains new smil catalog
    MediaPackageElementFlavor smilPartialFlavor = new MediaPackageElementFlavor("*", smilFlavorSubtypeProperty);
    Catalog[] smilCatalogs = mp.getCatalogs(smilPartialFlavor);
    Assert.assertTrue("Media package should contain a smil catalog", smilCatalogs != null && smilCatalogs.length > 0);
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) Smil(org.opencastproject.smil.entity.api.Smil) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) File(java.io.File) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Track(org.opencastproject.mediapackage.Track) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Catalog(org.opencastproject.mediapackage.Catalog) Test(org.junit.Test)

Aggregations

Catalog (org.opencastproject.mediapackage.Catalog)77 MediaPackage (org.opencastproject.mediapackage.MediaPackage)35 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)34 URI (java.net.URI)32 Test (org.junit.Test)24 InputStream (java.io.InputStream)21 IOException (java.io.IOException)18 Job (org.opencastproject.job.api.Job)17 NotFoundException (org.opencastproject.util.NotFoundException)17 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)16 Track (org.opencastproject.mediapackage.Track)15 Attachment (org.opencastproject.mediapackage.Attachment)14 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)11 Mpeg7Catalog (org.opencastproject.metadata.mpeg7.Mpeg7Catalog)11 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)11 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)10 File (java.io.File)9 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)9 ArrayList (java.util.ArrayList)8 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)8