use of org.opencastproject.publication.api.PublicationException 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.publication.api.PublicationException in project opencast by opencast.
the class OaiPmhPublicationServiceImpl method publish.
protected Publication publish(Job job, MediaPackage mediaPackage, String repository, Set<String> downloadElementIds, Set<String> streamingElementIds, boolean checkAvailability) throws PublicationException, MediaPackageException {
String mpId = mediaPackage.getIdentifier().compact();
SearchResult searchResult = oaiPmhDatabase.search(QueryBuilder.queryRepo(repository).mediaPackageId(mpId).isDeleted(false).build());
// retract oai-pmh if published
if (searchResult.size() > 0) {
try {
Publication p = retract(job, mediaPackage, repository);
if (mediaPackage.contains(p))
mediaPackage.remove(p);
} catch (NotFoundException e) {
logger.debug("No OAI-PMH publication found for media package {}.", mpId, e);
// this is ok
}
}
List<Job> distributionJobs = new ArrayList<>(2);
if (downloadElementIds != null && !downloadElementIds.isEmpty()) {
// select elements for download distribution
MediaPackage mpDownloadDist = (MediaPackage) mediaPackage.clone();
for (MediaPackageElement mpe : mpDownloadDist.getElements()) {
if (downloadElementIds.contains(mpe.getIdentifier()))
continue;
mpDownloadDist.remove(mpe);
}
// publish to download
if (mpDownloadDist.getElements().length > 0) {
try {
Job downloadDistributionJob = downloadDistributionService.distribute(getPublicationChannelName(repository), mpDownloadDist, downloadElementIds, checkAvailability);
if (downloadDistributionJob != null) {
distributionJobs.add(downloadDistributionJob);
}
} catch (DistributionException e) {
throw new PublicationException(format("Unable to distribute media package %s to download distribution.", mpId), e);
}
}
}
if (streamingElementIds != null && !streamingElementIds.isEmpty()) {
// select elements for streaming distribution
MediaPackage mpStreamingDist = (MediaPackage) mediaPackage.clone();
for (MediaPackageElement mpe : mpStreamingDist.getElements()) {
if (streamingElementIds.contains(mpe.getIdentifier()))
continue;
mpStreamingDist.remove(mpe);
}
// publish to streaming
if (mpStreamingDist.getElements().length > 0) {
try {
Job streamingDistributionJob = streamingDistributionService.distribute(getPublicationChannelName(repository), mpStreamingDist, streamingElementIds);
if (streamingDistributionJob != null) {
distributionJobs.add(streamingDistributionJob);
}
} catch (DistributionException e) {
throw new PublicationException(format("Unable to distribute media package %s to streaming distribution.", mpId), e);
}
}
}
if (distributionJobs.size() < 0) {
throw new IllegalStateException(format("The media package %s does not contain any elements for publishing to OAI-PMH", mpId));
}
// wait for distribution jobs
if (!waitForJobs(job, serviceRegistry, distributionJobs).isSuccess()) {
throw new PublicationException(format("Unable to distribute elements of media package %s to distribution channels.", mpId));
}
List<MediaPackageElement> distributedElements = new ArrayList<>();
for (Job distributionJob : distributionJobs) {
String distributedElementsXml = distributionJob.getPayload();
if (StringUtils.isNotBlank(distributedElementsXml)) {
for (MediaPackageElement distributedElement : MediaPackageElementParser.getArrayFromXml(distributedElementsXml)) {
distributedElements.add(distributedElement);
}
}
}
MediaPackage oaiPmhDistMp = (MediaPackage) mediaPackage.clone();
// cleanup media package elements
for (MediaPackageElement mpe : oaiPmhDistMp.getElements()) {
// keep publications
if (MediaPackageElement.Type.Publication == mpe.getElementType())
continue;
oaiPmhDistMp.remove(mpe);
}
// ...add the distributed elements
for (MediaPackageElement mpe : distributedElements) {
oaiPmhDistMp.add(mpe);
}
// publish to oai-pmh
try {
oaiPmhDatabase.store(oaiPmhDistMp, repository);
} catch (OaiPmhDatabaseException e) {
// todo: should we retract the elements from download and streaming here?
throw new PublicationException(format("Unable to distribute media package %s to OAI-PMH repository %s", mpId, repository), e);
}
return createPublicationElement(mpId, repository);
}
use of org.opencastproject.publication.api.PublicationException in project opencast by opencast.
the class YouTubeV3PublicationServiceImpl method retract.
@Override
public Job retract(final MediaPackage mediaPackage) throws PublicationException {
if (mediaPackage == null) {
throw new IllegalArgumentException("Mediapackage must be specified");
}
try {
List<String> arguments = new ArrayList<String>();
arguments.add(MediaPackageParser.getAsXml(mediaPackage));
return serviceRegistry.createJob(JOB_TYPE, Operation.Retract.toString(), arguments, youtubeRetractJobLoad);
} catch (ServiceRegistryException e) {
throw new PublicationException("Unable to create a job", e);
}
}
use of org.opencastproject.publication.api.PublicationException in project opencast by opencast.
the class YouTubeV3PublicationServiceImpl method retract.
/**
* Retracts the mediapackage from YouTube.
*
* @param job
* the associated job
* @param mediaPackage
* the mediapackage
* @throws PublicationException
* if retract did not work
*/
private Publication retract(final Job job, final MediaPackage mediaPackage) throws PublicationException {
logger.info("Retract video from YouTube: {}", mediaPackage);
Publication youtube = null;
for (Publication publication : mediaPackage.getPublications()) {
if (CHANNEL_NAME.equals(publication.getChannel())) {
youtube = publication;
break;
}
}
if (youtube == null) {
return null;
}
final YouTubePublicationAdapter contextStrategy = new YouTubePublicationAdapter(mediaPackage, workspace);
final String episodeName = contextStrategy.getEpisodeName();
try {
retract(mediaPackage.getSeriesTitle(), episodeName);
} catch (final Exception e) {
logger.error("Failure retracting YouTube media {}", e.getMessage());
throw new PublicationException("YouTube media retract failed on job: " + ToStringBuilder.reflectionToString(job, ToStringStyle.MULTI_LINE_STYLE), e);
}
return youtube;
}
Aggregations