Search in sources :

Example 41 with Catalog

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

the class SeriesWorkflowOperationHandler 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 series workflow operation");
    MediaPackage mediaPackage = workflowInstance.getMediaPackage();
    Opt<String> optSeries = getOptConfig(workflowInstance.getCurrentOperation(), SERIES_PROPERTY);
    Opt<String> optAttachFlavors = getOptConfig(workflowInstance.getCurrentOperation(), ATTACH_PROPERTY);
    Boolean applyAcl = getOptConfig(workflowInstance.getCurrentOperation(), APPLY_ACL_PROPERTY).map(toBoolean).getOr(false);
    Opt<String> optCopyMetadata = getOptConfig(workflowInstance.getCurrentOperation(), COPY_METADATA_PROPERTY);
    String defaultNamespace = getOptConfig(workflowInstance.getCurrentOperation(), DEFAULT_NS_PROPERTY).getOr(DublinCore.TERMS_NS_URI);
    logger.debug("Using default namespace: '{}'", defaultNamespace);
    if (optSeries.isSome() && !optSeries.get().equals(mediaPackage.getSeries())) {
        logger.info("Changing series id from '{}' to '{}'", StringUtils.trimToEmpty(mediaPackage.getSeries()), optSeries.get());
        mediaPackage.setSeries(optSeries.get());
    }
    String seriesId = mediaPackage.getSeries();
    if (seriesId == null) {
        logger.info("No series set, skip operation");
        return createResult(mediaPackage, Action.SKIP);
    }
    DublinCoreCatalog series;
    try {
        series = seriesService.getSeries(seriesId);
    } catch (NotFoundException e) {
        logger.info("No series with the identifier '{}' found, skip operation", seriesId);
        return createResult(mediaPackage, Action.SKIP);
    } catch (UnauthorizedException e) {
        logger.warn("Not authorized to get series with identifier '{}' found, skip operation", seriesId);
        return createResult(mediaPackage, Action.SKIP);
    } catch (SeriesException e) {
        logger.error("Unable to get series with identifier '{}', skip operation: {}", seriesId, ExceptionUtils.getStackTrace(e));
        throw new WorkflowOperationException(e);
    }
    mediaPackage.setSeriesTitle(series.getFirst(DublinCore.PROPERTY_TITLE));
    // Process extra metadata
    HashSet<EName> extraMetadata = new HashSet<>();
    if (optCopyMetadata.isSome()) {
        for (String strEName : optCopyMetadata.get().split(",+\\s*")) try {
            if (!strEName.isEmpty()) {
                extraMetadata.add(EName.fromString(strEName, defaultNamespace));
            }
        } catch (IllegalArgumentException iae) {
            logger.warn("Ignoring incorrect dublincore metadata property: '{}'", strEName);
        }
    }
    // Update the episode catalog
    for (Catalog episodeCatalog : mediaPackage.getCatalogs(MediaPackageElements.EPISODE)) {
        DublinCoreCatalog episodeDublinCore = DublinCoreUtil.loadDublinCore(workspace, episodeCatalog);
        // Make sure the MP catalog has bindings defined
        episodeDublinCore.addBindings(XmlNamespaceContext.mk(XmlNamespaceBinding.mk(DublinCore.TERMS_NS_PREFIX, DublinCore.TERMS_NS_URI)));
        episodeDublinCore.addBindings(XmlNamespaceContext.mk(XmlNamespaceBinding.mk(DublinCore.ELEMENTS_1_1_NS_PREFIX, DublinCore.ELEMENTS_1_1_NS_URI)));
        episodeDublinCore.addBindings(XmlNamespaceContext.mk(XmlNamespaceBinding.mk(DublinCores.OC_PROPERTY_NS_PREFIX, DublinCores.OC_PROPERTY_NS_URI)));
        episodeDublinCore.set(DublinCore.PROPERTY_IS_PART_OF, seriesId);
        for (EName property : extraMetadata) {
            if (!episodeDublinCore.hasValue(property) && series.hasValue(property)) {
                episodeDublinCore.set(property, series.get(property));
            }
        }
        try (InputStream in = IOUtils.toInputStream(episodeDublinCore.toXmlString(), "UTF-8")) {
            String filename = FilenameUtils.getName(episodeCatalog.getURI().toString());
            URI uri = workspace.put(mediaPackage.getIdentifier().toString(), episodeCatalog.getIdentifier(), filename, in);
            episodeCatalog.setURI(uri);
            // setting the URI to a new source so the checksum will most like be invalid
            episodeCatalog.setChecksum(null);
        } catch (Exception e) {
            logger.error("Unable to update episode catalog isPartOf field: {}", ExceptionUtils.getStackTrace(e));
            throw new WorkflowOperationException(e);
        }
    }
    // Attach series catalogs
    if (optAttachFlavors.isSome()) {
        // Remove existing series catalogs
        AbstractMediaPackageElementSelector<Catalog> catalogSelector = new CatalogSelector();
        String[] seriesFlavors = StringUtils.split(optAttachFlavors.get(), ",");
        for (String flavor : seriesFlavors) {
            if ("*".equals(flavor)) {
                catalogSelector.addFlavor("*/*");
            } else {
                catalogSelector.addFlavor(flavor);
            }
        }
        for (Catalog c : catalogSelector.select(mediaPackage, false)) {
            if (MediaPackageElements.SERIES.equals(c.getFlavor()) || "series".equals(c.getFlavor().getSubtype())) {
                mediaPackage.remove(c);
            }
        }
        List<SeriesCatalogUIAdapter> adapters = getSeriesCatalogUIAdapters();
        for (String flavorString : seriesFlavors) {
            MediaPackageElementFlavor flavor;
            if ("*".equals(flavorString)) {
                flavor = MediaPackageElementFlavor.parseFlavor("*/*");
            } else {
                flavor = MediaPackageElementFlavor.parseFlavor(flavorString);
            }
            for (SeriesCatalogUIAdapter a : adapters) {
                MediaPackageElementFlavor adapterFlavor = MediaPackageElementFlavor.parseFlavor(a.getFlavor());
                if (flavor.matches(adapterFlavor)) {
                    if (MediaPackageElements.SERIES.eq(a.getFlavor())) {
                        addDublinCoreCatalog(series, MediaPackageElements.SERIES, mediaPackage);
                    } else {
                        try {
                            Opt<byte[]> seriesElementData = seriesService.getSeriesElementData(seriesId, adapterFlavor.getType());
                            if (seriesElementData.isSome()) {
                                DublinCoreCatalog catalog = DublinCores.read(new ByteArrayInputStream(seriesElementData.get()));
                                addDublinCoreCatalog(catalog, adapterFlavor, mediaPackage);
                            } else {
                                logger.warn("No extended series catalog found for flavor '{}' and series '{}', skip adding catalog", adapterFlavor.getType(), seriesId);
                            }
                        } catch (SeriesException e) {
                            logger.error("Unable to load extended series metadata for flavor {}", adapterFlavor.getType());
                            throw new WorkflowOperationException(e);
                        }
                    }
                }
            }
        }
    }
    if (applyAcl) {
        try {
            AccessControlList acl = seriesService.getSeriesAccessControl(seriesId);
            if (acl != null)
                authorizationService.setAcl(mediaPackage, AclScope.Series, acl);
        } catch (Exception e) {
            logger.error("Unable to update series ACL: {}", ExceptionUtils.getStackTrace(e));
            throw new WorkflowOperationException(e);
        }
    }
    return createResult(mediaPackage, Action.CONTINUE);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) EName(org.opencastproject.mediapackage.EName) NotFoundException(org.opencastproject.util.NotFoundException) URI(java.net.URI) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) CatalogSelector(org.opencastproject.mediapackage.selector.CatalogSelector) HashSet(java.util.HashSet) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SeriesException(org.opencastproject.series.api.SeriesException) SeriesCatalogUIAdapter(org.opencastproject.metadata.dublincore.SeriesCatalogUIAdapter) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) SeriesException(org.opencastproject.series.api.SeriesException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 42 with Catalog

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

the class TagByDublinCoreTermWOH 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 = workflowInstance.getMediaPackage();
    WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation();
    String configuredSourceFlavors = StringUtils.trimToEmpty(currentOperation.getConfiguration(SOURCE_FLAVORS_PROPERTY));
    String configuredSourceTags = StringUtils.trimToEmpty(currentOperation.getConfiguration(SOURCE_TAGS_PROPERTY));
    String configuredCatalog = StringUtils.trimToEmpty(currentOperation.getConfiguration(DCCATALOG_PROPERTY));
    String configuredDCTerm = StringUtils.trimToEmpty(currentOperation.getConfiguration(DCTERM_PROPERTY));
    String configuredDefaultValue = StringUtils.trimToNull(currentOperation.getConfiguration(DEFAULT_VALUE_PROPERTY));
    String configuredMatchValue = StringUtils.trimToEmpty(currentOperation.getConfiguration(MATCH_VALUE_PROPERTY));
    String configuredTargetFlavor = StringUtils.trimToNull(currentOperation.getConfiguration(TARGET_FLAVOR_PROPERTY));
    String configuredTargetTags = StringUtils.trimToEmpty(currentOperation.getConfiguration(TARGET_TAGS_PROPERTY));
    boolean copy = BooleanUtils.toBoolean(currentOperation.getConfiguration(COPY_PROPERTY));
    String[] sourceTags = StringUtils.split(configuredSourceTags, ",");
    String[] targetTags = StringUtils.split(configuredTargetTags, ",");
    String[] sourceFlavors = StringUtils.split(configuredSourceFlavors, ",");
    SimpleElementSelector elementSelector = new SimpleElementSelector();
    for (String flavor : sourceFlavors) {
        elementSelector.addFlavor(MediaPackageElementFlavor.parseFlavor(flavor));
    }
    for (String tag : sourceTags) {
        elementSelector.addTag(tag);
    }
    List<String> removeTags = new ArrayList<>();
    List<String> addTags = new ArrayList<>();
    List<String> overrideTags = new ArrayList<>();
    for (String tag : targetTags) {
        if (tag.startsWith(MINUS)) {
            removeTags.add(tag);
        } else if (tag.startsWith(PLUS)) {
            addTags.add(tag);
        } else {
            overrideTags.add(tag);
        }
    }
    // Find Catalog
    Catalog[] catalogs = mediaPackage.getCatalogs(new MediaPackageElementFlavor("dublincore", StringUtils.lowerCase(configuredCatalog)));
    if (catalogs != null && catalogs.length > 0) {
        Boolean foundValue = false;
        EName dcterm = new EName(TERMS_NS_URI, configuredDCTerm);
        // Find DCTerm
        for (Catalog catalog : catalogs) {
            DublinCoreCatalog dc = DublinCoreUtil.loadDublinCore(workspace, catalog);
            // Match Value
            List<DublinCoreValue> values = dc.get(dcterm);
            if (values.isEmpty()) {
                // Use default
                if (configuredDefaultValue != null) {
                    foundValue = configuredDefaultValue.equals(configuredMatchValue);
                }
            } else {
                foundValue = values.contains(DublinCoreValue.mk(configuredMatchValue));
            }
        }
        if (foundValue) {
            if (copy) {
                logger.info("Retagging mediapackage elements as a copy");
            } else {
                logger.info("Retagging mediapackage elements");
            }
            Collection<MediaPackageElement> elements = elementSelector.select(mediaPackage, false);
            for (MediaPackageElement e : elements) {
                MediaPackageElement element = e;
                if (copy) {
                    element = (MediaPackageElement) e.clone();
                    element.setIdentifier(null);
                    // use the same URI as the original
                    element.setURI(e.getURI());
                }
                if (configuredTargetFlavor != null) {
                    element.setFlavor(MediaPackageElementFlavor.parseFlavor(configuredTargetFlavor));
                }
                if (overrideTags.size() > 0) {
                    element.clearTags();
                    for (String tag : overrideTags) {
                        element.addTag(tag);
                    }
                } else {
                    for (String tag : removeTags) {
                        element.removeTag(tag.substring(MINUS.length()));
                    }
                    for (String tag : addTags) {
                        element.addTag(tag.substring(PLUS.length()));
                    }
                }
                if (copy) {
                    mediaPackage.addDerived(element, e);
                }
            }
        }
    // if foundValue
    }
    return createResult(mediaPackage, Action.CONTINUE);
}
Also used : EName(org.opencastproject.mediapackage.EName) DublinCoreValue(org.opencastproject.metadata.dublincore.DublinCoreValue) ArrayList(java.util.ArrayList) SimpleElementSelector(org.opencastproject.mediapackage.selector.SimpleElementSelector) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 43 with Catalog

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

the class ConfigureByDublinCoreTermWOH 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 = workflowInstance.getMediaPackage();
    WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation();
    String configuredCatalog = StringUtils.trimToEmpty(currentOperation.getConfiguration(DCCATALOG_PROPERTY));
    String configuredDCTerm = StringUtils.trimToEmpty(currentOperation.getConfiguration(DCTERM_PROPERTY));
    String configuredDefaultValue = StringUtils.trimToNull(currentOperation.getConfiguration(DEFAULT_VALUE_PROPERTY));
    String configuredMatchValue = StringUtils.trimToEmpty(currentOperation.getConfiguration(MATCH_VALUE_PROPERTY));
    // Find Catalog
    Catalog[] catalogs = mediaPackage.getCatalogs(new MediaPackageElementFlavor("dublincore", StringUtils.lowerCase(configuredCatalog)));
    if (catalogs != null && catalogs.length > 0) {
        Boolean foundValue = false;
        EName dcterm = new EName(TERMS_NS_URI, configuredDCTerm);
        // Find DCTerm
        for (Catalog catalog : catalogs) {
            DublinCoreCatalog dc = DublinCoreUtil.loadDublinCore(workspace, catalog);
            // Match Value
            List<DublinCoreValue> values = dc.get(dcterm);
            if (values.isEmpty()) {
                // Use default
                if (configuredDefaultValue != null) {
                    foundValue = configuredDefaultValue.equals(configuredMatchValue);
                }
            } else {
                foundValue = values.contains(DublinCoreValue.mk(configuredMatchValue));
            }
        }
        if (foundValue) {
            Map<String, String> properties = new HashMap<>();
            for (String key : currentOperation.getConfigurationKeys()) {
                // Ignore this operations configuration
                if (DCCATALOG_PROPERTY.equals(key) || DCTERM_PROPERTY.equals(key) || DEFAULT_VALUE_PROPERTY.equals(key) || MATCH_VALUE_PROPERTY.equals(key)) {
                    continue;
                }
                String value = currentOperation.getConfiguration(key);
                properties.put(key, value);
                logger.info("Configuration key '{}' of workflow {} is set to value '{}'", key, workflowInstance.getId(), value);
            }
            return createResult(mediaPackage, properties, Action.CONTINUE, 0);
        }
    // if foundValue
    }
    return createResult(mediaPackage, Action.CONTINUE);
}
Also used : EName(org.opencastproject.mediapackage.EName) DublinCoreValue(org.opencastproject.metadata.dublincore.DublinCoreValue) HashMap(java.util.HashMap) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 44 with Catalog

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

the class VideoEditorWorkflowOperationHandler method resume.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.ResumableWorkflowOperationHandler#resume(org.opencastproject.workflow.api.WorkflowInstance,
 *      JobContext, java.util.Map)
 */
@Override
public WorkflowOperationResult resume(WorkflowInstance workflowInstance, JobContext context, Map<String, String> properties) throws WorkflowOperationException {
    MediaPackage mp = workflowInstance.getMediaPackage();
    logger.info("Resume video editor operation for mediapackage {}", mp.getIdentifier().compact());
    // Get configuration
    WorkflowOperationInstance worflowOperationInstance = workflowInstance.getCurrentOperation();
    String sourceTrackFlavorsProperty = StringUtils.trimToNull(worflowOperationInstance.getConfiguration(SOURCE_FLAVORS_PROPERTY));
    if (sourceTrackFlavorsProperty == null) {
        throw new WorkflowOperationException(format("Required configuration property %s not set.", SOURCE_FLAVORS_PROPERTY));
    }
    String targetSmilFlavorProperty = StringUtils.trimToNull(worflowOperationInstance.getConfiguration(TARGET_SMIL_FLAVOR_PROPERTY));
    if (targetSmilFlavorProperty == null) {
        throw new WorkflowOperationException(format("Required configuration property %s not set.", TARGET_SMIL_FLAVOR_PROPERTY));
    }
    String targetFlavorSybTypeProperty = StringUtils.trimToNull(worflowOperationInstance.getConfiguration(TARGET_FLAVOR_SUBTYPE_PROPERTY));
    if (targetFlavorSybTypeProperty == null) {
        throw new WorkflowOperationException(format("Required configuration property %s not set.", TARGET_FLAVOR_SUBTYPE_PROPERTY));
    }
    boolean skipIfNoTrim = BooleanUtils.toBoolean(worflowOperationInstance.getConfiguration(SKIP_NOT_TRIMMED_PROPERTY));
    // Get source tracks
    TrackSelector trackSelector = new TrackSelector();
    for (String flavor : asList(sourceTrackFlavorsProperty)) {
        trackSelector.addFlavor(flavor);
    }
    Collection<Track> sourceTracks = trackSelector.select(mp, false);
    if (sourceTracks.isEmpty()) {
        throw new WorkflowOperationException(format("No source tracks found in mediapacksge %s with flavors %s.", mp.getIdentifier().compact(), sourceTrackFlavorsProperty));
    }
    // Get SMIL file
    MediaPackageElementFlavor smilTargetFlavor = MediaPackageElementFlavor.parseFlavor(targetSmilFlavorProperty);
    Catalog[] smilCatalogs = mp.getCatalogs(smilTargetFlavor);
    if (smilCatalogs == null || smilCatalogs.length == 0) {
        throw new WorkflowOperationException(format("No SMIL catalog found in mediapackage %s with flavor %s.", mp.getIdentifier().compact(), targetSmilFlavorProperty));
    }
    File smilFile = null;
    Smil smil = null;
    try {
        smilFile = workspace.get(smilCatalogs[0].getURI());
        smil = smilService.fromXml(smilFile).getSmil();
        smil = replaceAllTracksWith(smil, sourceTracks.toArray(new Track[sourceTracks.size()]));
        InputStream is = null;
        try {
            is = IOUtils.toInputStream(smil.toXML(), "UTF-8");
            // Remove old SMIL
            workspace.delete(mp.getIdentifier().compact(), smilCatalogs[0].getIdentifier());
            mp.remove(smilCatalogs[0]);
            // put modified SMIL into workspace
            URI newSmilUri = workspace.put(mp.getIdentifier().compact(), smil.getId(), SMIL_FILE_NAME, is);
            Catalog catalog = (Catalog) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().elementFromURI(newSmilUri, MediaPackageElement.Type.Catalog, smilCatalogs[0].getFlavor());
            catalog.setIdentifier(smil.getId());
            mp.add(catalog);
        } catch (Exception ex) {
            throw new WorkflowOperationException(ex);
        } finally {
            IOUtils.closeQuietly(is);
        }
    } catch (NotFoundException ex) {
        throw new WorkflowOperationException(format("Failed to get SMIL catalog %s from mediapackage %s.", smilCatalogs[0].getIdentifier(), mp.getIdentifier().compact()), ex);
    } catch (IOException ex) {
        throw new WorkflowOperationException(format("Can't open SMIL catalog %s from mediapackage %s.", smilCatalogs[0].getIdentifier(), mp.getIdentifier().compact()), ex);
    } catch (SmilException ex) {
        throw new WorkflowOperationException(ex);
    }
    if (skipIfNoTrim) {
        // We should not modify the SMIL file as we traverse through its elements, so we make a copy and modify it instead
        try {
            Smil filteredSmil = smilService.fromXml(smil.toXML()).getSmil();
            for (SmilMediaObject element : smil.getBody().getMediaElements()) {
                // body should contain par elements
                if (element.isContainer()) {
                    SmilMediaContainer container = (SmilMediaContainer) element;
                    if (SmilMediaContainer.ContainerType.PAR == container.getContainerType()) {
                        continue;
                    }
                }
                filteredSmil = smilService.removeSmilElement(filteredSmil, element.getId()).getSmil();
            }
            // one that takes the whole video size
            switch(filteredSmil.getBody().getMediaElements().size()) {
                case 0:
                    logger.info("Skipping SMIL job generation for mediapackage '{}', " + "because the SMIL does not define any trimming points", mp.getIdentifier());
                    return skip(workflowInstance, context);
                case 1:
                    // component represents the whole duration or not, therefore we don't bother to try
                    if (mp.getDuration() < 0)
                        break;
                    SmilMediaContainer parElement = (SmilMediaContainer) filteredSmil.getBody().getMediaElements().get(0);
                    boolean skip = true;
                    for (SmilMediaObject elementChild : parElement.getElements()) {
                        if (!elementChild.isContainer()) {
                            SmilMediaElement media = (SmilMediaElement) elementChild;
                            // If they don't represent the whole length, then we break --we have a trimming point
                            if ((media.getClipBeginMS() != 0) || (media.getClipEndMS() != mp.getDuration())) {
                                skip = false;
                                break;
                            }
                        }
                    }
                    if (skip) {
                        logger.info("Skipping SMIL job generation for mediapackage '{}', " + "because the trimming points in the SMIL correspond " + "to the beginning and the end of the video", mp.getIdentifier());
                        return skip(workflowInstance, context);
                    }
                    break;
                default:
                    break;
            }
        } catch (MalformedURLException | SmilException | JAXBException | SAXException e) {
            logger.warn("Error parsing input SMIL to determine if it has trimpoints. " + "We will assume it does and go on creating jobs.");
        }
    }
    // Create video edit jobs and run them
    List<Job> jobs = null;
    try {
        logger.info("Create processing jobs for SMIL file: {}", smilCatalogs[0].getIdentifier());
        jobs = videoEditorService.processSmil(smil);
        if (!waitForStatus(jobs.toArray(new Job[jobs.size()])).isSuccess()) {
            throw new WorkflowOperationException(format("Processing SMIL file failed: %s", smilCatalogs[0].getIdentifier()));
        }
        logger.info("Finished processing of SMIL file: {}", smilCatalogs[0].getIdentifier());
    } catch (ProcessFailedException ex) {
        throw new WorkflowOperationException(format("Finished processing of SMIL file: %s", smilCatalogs[0].getIdentifier()), ex);
    }
    // Move edited tracks to work location and set target flavor
    Track editedTrack = null;
    boolean mpAdded = false;
    for (Job job : jobs) {
        try {
            editedTrack = (Track) MediaPackageElementParser.getFromXml(job.getPayload());
            MediaPackageElementFlavor editedTrackFlavor = editedTrack.getFlavor();
            editedTrack.setFlavor(new MediaPackageElementFlavor(editedTrackFlavor.getType(), targetFlavorSybTypeProperty));
            URI editedTrackNewUri = workspace.moveTo(editedTrack.getURI(), mp.getIdentifier().compact(), editedTrack.getIdentifier(), FilenameUtils.getName(editedTrack.getURI().toString()));
            editedTrack.setURI(editedTrackNewUri);
            for (Track track : sourceTracks) {
                if (track.getFlavor().getType().equals(editedTrackFlavor.getType())) {
                    mp.addDerived(editedTrack, track);
                    mpAdded = true;
                    break;
                }
            }
            if (!mpAdded) {
                mp.add(editedTrack);
            }
        } catch (MediaPackageException ex) {
            throw new WorkflowOperationException("Failed to get information about the edited track(s)", ex);
        } catch (NotFoundException | IOException | IllegalArgumentException ex) {
            throw new WorkflowOperationException("Moving edited track to work location failed.", ex);
        } catch (Exception ex) {
            throw new WorkflowOperationException(ex);
        }
    }
    logger.info("VideoEdit workflow {} finished", workflowInstance.getId());
    return createResult(mp, Action.CONTINUE);
}
Also used : MalformedURLException(java.net.MalformedURLException) TrackSelector(org.opencastproject.mediapackage.selector.TrackSelector) NotFoundException(org.opencastproject.util.NotFoundException) URI(java.net.URI) SAXException(org.xml.sax.SAXException) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) SmilException(org.opencastproject.smil.api.SmilException) SmilMediaObject(org.opencastproject.smil.entity.media.api.SmilMediaObject) Job(org.opencastproject.job.api.Job) SmilMediaContainer(org.opencastproject.smil.entity.media.container.api.SmilMediaContainer) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) InputStream(java.io.InputStream) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Catalog(org.opencastproject.mediapackage.Catalog) SmilException(org.opencastproject.smil.api.SmilException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) ProcessFailedException(org.opencastproject.videoeditor.api.ProcessFailedException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Smil(org.opencastproject.smil.entity.api.Smil) SmilMediaElement(org.opencastproject.smil.entity.media.element.api.SmilMediaElement) ProcessFailedException(org.opencastproject.videoeditor.api.ProcessFailedException) File(java.io.File) Track(org.opencastproject.mediapackage.Track)

Example 45 with Catalog

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

the class LiveScheduleServiceImplTest method testAddAndDistributeElements.

@Test
public void testAddAndDistributeElements() throws Exception {
    URI catalogURI = LiveScheduleServiceImplTest.class.getResource("/series.xml").toURI();
    DublinCoreCatalog seriesDC = DublinCores.read(catalogURI.toURL().openStream());
    EasyMock.expect(seriesService.getSeries(SERIES_ID)).andReturn(seriesDC).anyTimes();
    Job job = createJob(1L, "anything", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"9ad6ebcb-b414-4b15-ab62-5e5ddede447e\" type=\"dublincore/episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/episode.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"23113662-1a84-457a-85d5-0b3e32d2413a\" type=\"dublincore/series\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/series.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<attachment id=\"security-policy-episode\" type=\"security/xacml+episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml</url></attachment>");
    EasyMock.expect(downloadDistributionService.distribute(EasyMock.anyString(), EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(Set.class), EasyMock.anyBoolean())).andReturn(job).once();
    EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job).anyTimes();
    URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp.xml").toURI();
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    replayServices();
    Snapshot s = EasyMock.createNiceMock(Snapshot.class);
    EasyMock.expect(s.getMediaPackage()).andReturn(mp);
    EasyMock.replay(s);
    service.setDownloadDistributionService(downloadDistributionService);
    MediaPackage mp1 = service.addAndDistributeElements(s);
    Catalog[] catalogs = mp1.getCatalogs(MediaPackageElements.EPISODE);
    Assert.assertNotNull(catalogs);
    Assert.assertEquals(1, catalogs.length);
    Catalog catalog = catalogs[0];
    Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/episode.xml", catalog.getURI().toString());
    Assert.assertEquals("dublincore/episode", catalog.getFlavor().toString());
    catalogs = mp1.getCatalogs(MediaPackageElements.SERIES);
    Assert.assertNotNull(catalogs);
    Assert.assertEquals(1, catalogs.length);
    catalog = catalogs[0];
    Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/series.xml", catalog.getURI().toString());
    Assert.assertEquals("dublincore/series", catalog.getFlavor().toString());
    Attachment[] atts = mp1.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE);
    Assert.assertNotNull(atts);
    Assert.assertEquals(1, atts.length);
    Attachment att = atts[0];
    Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml", att.getURI().toString());
    Assert.assertEquals("security/xacml+episode", att.getFlavor().toString());
    EasyMock.verify(downloadDistributionService, workspace);
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Job(org.opencastproject.job.api.Job) URI(java.net.URI) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) 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