Search in sources :

Example 71 with WorkflowOperationException

use of org.opencastproject.workflow.api.WorkflowOperationException in project opencast by opencast.

the class RepublishOaiPmhWorkflowOperationHandler method start.

@Override
public WorkflowOperationResult start(WorkflowInstance wi, JobContext context) throws WorkflowOperationException {
    final MediaPackage mp = wi.getMediaPackage();
    // The flavors of the elements that are to be published
    final Set<String> flavors = new HashSet<>();
    // Check which flavors have been configured
    final List<String> configuredFlavors = getOptConfig(wi, OPT_SOURCE_FLAVORS).bind(trimToNone).map(asList.toFn()).getOr(Collections.<String>nil());
    for (String flavor : configuredFlavors) {
        flavors.add(flavor);
    }
    // Get the configured tags
    final Set<String> tags = set(getOptConfig(wi, OPT_SOURCE_TAGS).getOr(""));
    // repository
    final String repository = getConfig(wi, OPT_REPOSITORY);
    logger.debug("Start updating metadata of the media package {} in OAI-PMH repository {}", mp.getIdentifier().compact(), repository);
    try {
        Job updateMetadataJob = oaiPmhPublicationService.updateMetadata(mp, repository, flavors, tags, true);
        if (updateMetadataJob == null) {
            logger.info("Unable to create an OAI-PMH update metadata job for the media package {} in repository {}", mp.getIdentifier().compact(), repository);
            return createResult(mp, Action.CONTINUE);
        }
        if (!waitForJobs(serviceRegistry, updateMetadataJob).isSuccess()) {
            throw new WorkflowOperationException(format("OAI-PMH update metadata job for the media package %s did not end successfully", mp.getIdentifier().compact()));
        }
    } catch (MediaPackageException | PublicationException | IllegalArgumentException | IllegalStateException e) {
        throw new WorkflowOperationException(format("Unable to create an OAI-PMH update metadata job for the media package %s in repository %s", mp.getIdentifier().compact(), repository), e);
    }
    logger.debug("Updating metadata of the media package {} in OAI-PMH repository {} done", mp.getIdentifier().compact(), repository);
    return createResult(mp, Action.CONTINUE);
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) PublicationException(org.opencastproject.publication.api.PublicationException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Job(org.opencastproject.job.api.Job) HashSet(java.util.HashSet)

Example 72 with WorkflowOperationException

use of org.opencastproject.workflow.api.WorkflowOperationException in project opencast by opencast.

the class RetractOaiPmhWorkflowOperationHandler method start.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(WorkflowInstance, JobContext)
 */
@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
    MediaPackage mediaPackage = workflowInstance.getMediaPackage();
    String repository = StringUtils.trimToNull(workflowInstance.getCurrentOperation().getConfiguration(REPOSITORY));
    if (repository == null)
        throw new IllegalArgumentException("No repository has been specified");
    try {
        logger.info("Retracting media package {} from OAI-PMH publication repository", mediaPackage);
        // Wait for OAI-PMH retraction to finish
        Job retractJob = publicationService.retract(mediaPackage, repository);
        if (!waitForStatus(retractJob).isSuccess())
            throw new WorkflowOperationException("The OAI-PMH retract job did not complete successfully");
        logger.debug("Retraction from OAI-PMH operation complete");
        // Remove the retracted elements from the mediapackage
        Job job = serviceRegistry.getJob(retractJob.getId());
        if (job.getPayload() != null) {
            logger.info("Removing OAI-PMH publication element from media package {}", mediaPackage);
            Publication retractedElement = (Publication) MediaPackageElementParser.getFromXml(job.getPayload());
            mediaPackage.remove(retractedElement);
            logger.debug("Remove OAI-PMH publication element '{}' complete", retractedElement);
        } else {
            logger.info("No OAI-PMH publication found to retract in mediapackage {}!", mediaPackage);
            return createResult(mediaPackage, Action.CONTINUE);
        }
        return createResult(mediaPackage, Action.CONTINUE);
    } catch (Throwable t) {
        throw new WorkflowOperationException(t);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Publication(org.opencastproject.mediapackage.Publication) Job(org.opencastproject.job.api.Job)

Example 73 with WorkflowOperationException

use of org.opencastproject.workflow.api.WorkflowOperationException in project opencast by opencast.

the class PartialImportWorkflowOperationHandler method getSmilDocumentFromMediaPackage.

private SMILDocument getSmilDocumentFromMediaPackage(MediaPackage mp, String smilFlavor) throws WorkflowOperationException {
    final AbstractMediaPackageElementSelector<Catalog> smilSelector = new CatalogSelector();
    try {
        smilSelector.addFlavor(MediaPackageElementFlavor.parseFlavor(smilFlavor));
    } catch (IllegalArgumentException e) {
        throw new WorkflowOperationException("Smil flavor '" + smilFlavor + "' is malformed");
    }
    final Collection<Catalog> smilCatalog = smilSelector.select(mp, false);
    if (smilCatalog.size() == 1) {
        return getSmilDocument(smilCatalog.iterator().next());
    } else {
        logger.error("More or less than one smil catalog found: {}", smilCatalog);
        throw new WorkflowOperationException("More or less than one smil catalog found!");
    }
}
Also used : WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) CatalogSelector(org.opencastproject.mediapackage.selector.CatalogSelector) Catalog(org.opencastproject.mediapackage.Catalog)

Example 74 with WorkflowOperationException

use of org.opencastproject.workflow.api.WorkflowOperationException in project opencast by opencast.

the class PartialImportWorkflowOperationHandler method trimEnd.

private long trimEnd(MediaPackage mediaPackage, EncodingProfile trimProfile, Track track, double duration, List<MediaPackageElement> elementsToClean) throws EncoderException, MediaPackageException, WorkflowOperationException, NotFoundException, ServiceRegistryException, IOException {
    Job trimJob = composerService.trim(track, trimProfile.getIdentifier(), 0, (long) (duration * 1000));
    if (!waitForStatus(trimJob).isSuccess())
        throw new WorkflowOperationException("Trimming of track " + track + " failed");
    trimJob = serviceRegistry.getJob(trimJob.getId());
    Track trimmedTrack = (Track) MediaPackageElementParser.getFromXml(trimJob.getPayload());
    if (trimmedTrack == null)
        throw new WorkflowOperationException("Trimming track " + track + " failed to produce a track");
    URI uri = workspace.moveTo(trimmedTrack.getURI(), mediaPackage.getIdentifier().compact(), trimmedTrack.getIdentifier(), FilenameUtils.getName(track.getURI().toString()));
    trimmedTrack.setURI(uri);
    trimmedTrack.setFlavor(track.getFlavor());
    elementsToClean.add(track);
    mediaPackage.remove(track);
    mediaPackage.add(trimmedTrack);
    return trimJob.getQueueTime();
}
Also used : WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Job(org.opencastproject.job.api.Job) URI(java.net.URI) Track(org.opencastproject.mediapackage.Track)

Example 75 with WorkflowOperationException

use of org.opencastproject.workflow.api.WorkflowOperationException in project opencast by opencast.

the class PartialImportWorkflowOperationHandler method getSilentAudio.

private Track getSilentAudio(final double time, final List<MediaPackageElement> elementsToClean, final Long operationId) throws EncoderException, MediaPackageException, WorkflowOperationException, NotFoundException, IOException {
    final URI uri = workspace.putInCollection(COLLECTION_ID, operationId + "-silent", new ByteArrayInputStream(EMPTY_VALUE.getBytes()));
    final Attachment emptyAttachment = (Attachment) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().elementFromURI(uri, Type.Attachment, MediaPackageElementFlavor.parseFlavor("audio/silent"));
    elementsToClean.add(emptyAttachment);
    final Job silentAudioJob = composerService.imageToVideo(emptyAttachment, SILENT_AUDIO_PROFILE, time);
    if (!waitForStatus(silentAudioJob).isSuccess())
        throw new WorkflowOperationException("Silent audio job did not complete successfully");
    // Get the latest copy
    try {
        for (final String payload : getPayload(serviceRegistry, silentAudioJob)) {
            final Track silentAudio = (Track) MediaPackageElementParser.getFromXml(payload);
            elementsToClean.add(silentAudio);
            return silentAudio;
        }
        // none
        throw new WorkflowOperationException(format("Job %s has no payload or cannot be updated", silentAudioJob));
    } catch (ServiceRegistryException ex) {
        throw new WorkflowOperationException(ex);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Attachment(org.opencastproject.mediapackage.Attachment) Job(org.opencastproject.job.api.Job) URI(java.net.URI) Track(org.opencastproject.mediapackage.Track) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Aggregations

WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)103 MediaPackage (org.opencastproject.mediapackage.MediaPackage)57 Job (org.opencastproject.job.api.Job)47 Track (org.opencastproject.mediapackage.Track)34 IOException (java.io.IOException)31 URI (java.net.URI)28 ArrayList (java.util.ArrayList)28 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)28 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)28 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)27 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)27 NotFoundException (org.opencastproject.util.NotFoundException)27 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)18 HashMap (java.util.HashMap)17 File (java.io.File)16 InputStream (java.io.InputStream)15 Attachment (org.opencastproject.mediapackage.Attachment)15 TrackSelector (org.opencastproject.mediapackage.selector.TrackSelector)15 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)13 HashSet (java.util.HashSet)12