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);
}
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);
}
}
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!");
}
}
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();
}
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);
}
}
Aggregations