Search in sources :

Example 11 with PublicationException

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);
}
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 12 with PublicationException

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);
}
Also used : PublicationException(org.opencastproject.publication.api.PublicationException) OaiPmhDatabaseException(org.opencastproject.oaipmh.persistence.OaiPmhDatabaseException) ArrayList(java.util.ArrayList) Publication(org.opencastproject.mediapackage.Publication) NotFoundException(org.opencastproject.util.NotFoundException) SearchResult(org.opencastproject.oaipmh.persistence.SearchResult) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DistributionException(org.opencastproject.distribution.api.DistributionException) Job(org.opencastproject.job.api.Job)

Example 13 with PublicationException

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);
    }
}
Also used : PublicationException(org.opencastproject.publication.api.PublicationException) ArrayList(java.util.ArrayList) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 14 with PublicationException

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;
}
Also used : PublicationException(org.opencastproject.publication.api.PublicationException) Publication(org.opencastproject.mediapackage.Publication) PublicationException(org.opencastproject.publication.api.PublicationException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Aggregations

PublicationException (org.opencastproject.publication.api.PublicationException)14 ArrayList (java.util.ArrayList)9 Job (org.opencastproject.job.api.Job)7 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)7 MediaPackage (org.opencastproject.mediapackage.MediaPackage)6 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)6 Publication (org.opencastproject.mediapackage.Publication)6 HttpResponse (org.apache.http.HttpResponse)5 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)5 HttpPost (org.apache.http.client.methods.HttpPost)5 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)5 HashSet (java.util.HashSet)4 DistributionException (org.opencastproject.distribution.api.DistributionException)3 OaiPmhDatabaseException (org.opencastproject.oaipmh.persistence.OaiPmhDatabaseException)3 SearchResult (org.opencastproject.oaipmh.persistence.SearchResult)3 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)3 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)3 SimpleElementSelector (org.opencastproject.mediapackage.selector.SimpleElementSelector)2 SearchResultItem (org.opencastproject.oaipmh.persistence.SearchResultItem)2 ConfigurationException (org.osgi.service.cm.ConfigurationException)2