Search in sources :

Example 31 with Publication

use of org.opencastproject.mediapackage.Publication 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 32 with Publication

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

the class EventIndexUtils method toSearchMetadata.

/**
 * Creates search metadata from a recording event such that the event can be stored in the search index.
 *
 * @param event
 *          the recording event
 * @return the set of metadata
 */
public static SearchMetadataCollection toSearchMetadata(Event event) {
    SearchMetadataCollection metadata = new SearchMetadataCollection(event.getIdentifier().concat(event.getOrganization()), Event.DOCUMENT_TYPE);
    metadata.addField(EventIndexSchema.UID, event.getIdentifier(), true);
    metadata.addField(EventIndexSchema.ORGANIZATION, event.getOrganization(), false);
    metadata.addField(EventIndexSchema.OBJECT, event.toXML(), false);
    if (StringUtils.isNotBlank(event.getTitle()))
        metadata.addField(EventIndexSchema.TITLE, event.getTitle(), true);
    if (StringUtils.isNotBlank(event.getDescription()))
        metadata.addField(EventIndexSchema.DESCRIPTION, event.getDescription(), true);
    if (StringUtils.isNotBlank(event.getLocation()))
        metadata.addField(EventIndexSchema.LOCATION, event.getLocation(), true);
    if (StringUtils.isNotBlank(event.getSeriesId()))
        metadata.addField(EventIndexSchema.SERIES_ID, event.getSeriesId(), true);
    if (StringUtils.isNotBlank(event.getSeriesName()))
        metadata.addField(EventIndexSchema.SERIES_NAME, event.getSeriesName(), true);
    if (StringUtils.isNotBlank(event.getLanguage()))
        metadata.addField(EventIndexSchema.LANGUAGE, event.getLanguage(), true);
    if (StringUtils.isNotBlank(event.getSubject()))
        metadata.addField(EventIndexSchema.SUBJECT, event.getSubject(), true);
    if (StringUtils.isNotBlank(event.getSource()))
        metadata.addField(EventIndexSchema.SOURCE, event.getSource(), true);
    if (StringUtils.isNotBlank(event.getCreated()))
        metadata.addField(EventIndexSchema.CREATED, event.getCreated(), true);
    if (StringUtils.isNotBlank(event.getCreator()))
        metadata.addField(EventIndexSchema.CREATOR, event.getCreator(), true);
    if (StringUtils.isNotBlank(event.getLicense()))
        metadata.addField(EventIndexSchema.LICENSE, event.getLicense(), true);
    if (StringUtils.isNotBlank(event.getRights()))
        metadata.addField(EventIndexSchema.RIGHTS, event.getRights(), true);
    if (StringUtils.isNotBlank(event.getManagedAcl()))
        metadata.addField(EventIndexSchema.MANAGED_ACL, event.getManagedAcl(), true);
    if (StringUtils.isNotBlank(event.getWorkflowState()))
        metadata.addField(EventIndexSchema.WORKFLOW_STATE, event.getWorkflowState(), true);
    if (event.getWorkflowId() != null)
        metadata.addField(EventIndexSchema.WORKFLOW_ID, event.getWorkflowId(), true);
    if (StringUtils.isNotBlank(event.getWorkflowDefinitionId()))
        metadata.addField(EventIndexSchema.WORKFLOW_DEFINITION_ID, event.getWorkflowDefinitionId(), true);
    if (StringUtils.isNotBlank(event.getRecordingStartDate()))
        metadata.addField(EventIndexSchema.START_DATE, event.getRecordingStartDate(), true);
    if (StringUtils.isNotBlank(event.getRecordingEndDate()))
        metadata.addField(EventIndexSchema.END_DATE, event.getRecordingEndDate(), true);
    if (event.getDuration() != null)
        metadata.addField(EventIndexSchema.DURATION, event.getDuration(), true);
    if (StringUtils.isNotBlank(event.getReviewStatus()))
        metadata.addField(EventIndexSchema.REVIEW_STATUS, event.getReviewStatus(), true);
    if (StringUtils.isNotBlank(event.getReviewDate()))
        metadata.addField(EventIndexSchema.REVIEW_DATE, event.getReviewDate(), true);
    if (StringUtils.isNotBlank(event.getWorkflowScheduledDate()))
        metadata.addField(EventIndexSchema.WORKFLOW_SCHEDULED_DATETIME, event.getWorkflowScheduledDate(), true);
    if (event.getArchiveVersion() != null)
        metadata.addField(EventIndexSchema.ARCHIVE_VERSION, event.getArchiveVersion(), true);
    if (event.getOptedOut() != null)
        metadata.addField(EventIndexSchema.OPTED_OUT, event.getOptedOut(), true);
    if (event.getBlacklisted() != null)
        metadata.addField(EventIndexSchema.BLACKLISTED, event.getBlacklisted(), true);
    if (event.getSchedulingStatus() != null)
        metadata.addField(EventIndexSchema.SCHEDULING_STATUS, event.getSchedulingStatus(), true);
    if (event.getRecordingStatus() != null)
        metadata.addField(EventIndexSchema.RECORDING_STATUS, event.getRecordingStatus(), true);
    metadata.addField(EventIndexSchema.EVENT_STATUS, event.getEventStatus(), true);
    metadata.addField(EventIndexSchema.HAS_COMMENTS, event.hasComments(), true);
    metadata.addField(EventIndexSchema.HAS_OPEN_COMMENTS, event.hasOpenComments(), true);
    metadata.addField(EventIndexSchema.NEEDS_CUTTING, event.needsCutting(), true);
    if (event.getPublications() != null) {
        List<Publication> publications = event.getPublications();
        HashMap<String, Object>[] publicationsArray = new HashMap[publications.size()];
        for (int i = 0; i < publications.size(); i++) publicationsArray[i] = generatePublicationDoc(publications.get(i));
        metadata.addField(EventIndexSchema.PUBLICATION, publicationsArray, true);
    }
    if (event.getPresenters() != null) {
        List<String> presenters = event.getPresenters();
        metadata.addField(EventIndexSchema.PRESENTER, presenters.toArray(new String[presenters.size()]), true);
    }
    if (event.getContributors() != null) {
        List<String> contributors = event.getContributors();
        metadata.addField(EventIndexSchema.CONTRIBUTOR, contributors.toArray(new String[contributors.size()]), true);
    }
    if (event.getTrackMimetypes() != null) {
        List<String> trackMimetypes = event.getTrackMimetypes();
        metadata.addField(EventIndexSchema.TRACK_MIMETYPE, trackMimetypes.toArray(new String[trackMimetypes.size()]), true);
    }
    if (event.getTrackStreamResolution() != null) {
        List<String> trackStreamResolutions = event.getTrackStreamResolution();
        metadata.addField(EventIndexSchema.TRACK_STREAM_RESOLUTION, trackStreamResolutions.toArray(new String[trackStreamResolutions.size()]), true);
    }
    if (event.getTrackFlavors() != null) {
        List<String> trackFlavors = event.getTrackFlavors();
        metadata.addField(EventIndexSchema.TRACK_FLAVOR, trackFlavors.toArray(new String[trackFlavors.size()]), true);
    }
    if (event.getMetadataFlavors() != null) {
        List<String> metadataFlavors = event.getMetadataFlavors();
        metadata.addField(EventIndexSchema.METADATA_FLAVOR, metadataFlavors.toArray(new String[metadataFlavors.size()]), true);
    }
    if (event.getMetadataMimetypes() != null) {
        List<String> metadataMimetypes = event.getMetadataMimetypes();
        metadata.addField(EventIndexSchema.METADATA_MIMETYPE, metadataMimetypes.toArray(new String[metadataMimetypes.size()]), true);
    }
    if (event.getAttachmentFlavors() != null) {
        List<String> attachmentFlavors = event.getAttachmentFlavors();
        metadata.addField(EventIndexSchema.ATTACHMENT_FLAVOR, attachmentFlavors.toArray(new String[attachmentFlavors.size()]), true);
    }
    if (StringUtils.isNotBlank(event.getAccessPolicy())) {
        metadata.addField(EventIndexSchema.ACCESS_POLICY, event.getAccessPolicy(), true);
        addAuthorization(metadata, event.getAccessPolicy());
    }
    if (StringUtils.isNotBlank(event.getAgentId())) {
        metadata.addField(EventIndexSchema.AGENT_ID, event.getAgentId(), true);
    }
    if (StringUtils.isNotBlank(event.getTechnicalStartTime())) {
        metadata.addField(EventIndexSchema.TECHNICAL_START, event.getTechnicalStartTime(), true);
    }
    if (StringUtils.isNotBlank(event.getTechnicalEndTime())) {
        metadata.addField(EventIndexSchema.TECHNICAL_END, event.getTechnicalEndTime(), true);
    }
    if (event.getTechnicalPresenters() != null) {
        metadata.addField(EventIndexSchema.TECHNICAL_PRESENTERS, event.getTechnicalPresenters().toArray(new String[event.getTechnicalPresenters().size()]), true);
    }
    if (event.getAgentConfiguration() != null) {
        metadata.addField(EventIndexSchema.AGENT_CONFIGURATION, event.getAgentConfiguration(), false);
    }
    return metadata;
}
Also used : SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection) HashMap(java.util.HashMap) Publication(org.opencastproject.mediapackage.Publication)

Example 33 with Publication

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

the class OaiPmhPublicationServiceImpl method merge.

/**
 * Merges the updated media package with the one that is currently published in a way where the updated elements
 * replace existing ones in the published media package based on their flavor.
 * <p>
 * If <code>publishedMp</code> is <code>null</code>, this method returns the updated media package without any
 * modifications.
 *
 * @param updatedMp
 *          the updated media package
 * @param publishedMp
 *          the media package that is currently published
 * @return the merged media package
 */
public static MediaPackage merge(MediaPackage updatedMp, MediaPackage publishedMp) {
    if (publishedMp == null)
        return updatedMp;
    final MediaPackage mergedMp = MediaPackageSupport.copy(publishedMp);
    // Merge the elements
    for (final MediaPackageElement updatedElement : updatedMp.elements()) {
        for (final MediaPackageElementFlavor flavor : Opt.nul(updatedElement.getFlavor())) {
            for (final MediaPackageElement outdated : mergedMp.getElementsByFlavor(flavor)) {
                mergedMp.remove(outdated);
            }
            logger.debug(format("Update %s %s of type %s", updatedElement.getElementType().toString().toLowerCase(), updatedElement.getIdentifier(), updatedElement.getElementType()));
            mergedMp.add(updatedElement);
        }
    }
    // Remove publications
    for (final Publication p : mergedMp.getPublications()) mergedMp.remove(p);
    // Add updated publications
    for (final Publication updatedPublication : updatedMp.getPublications()) mergedMp.add(updatedPublication);
    // Merge media package fields
    updateMediaPackageFields(mergedMp, updatedMp);
    return mergedMp;
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Publication(org.opencastproject.mediapackage.Publication) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor)

Example 34 with Publication

use of org.opencastproject.mediapackage.Publication 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 35 with Publication

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

the class OaiPmhPublicationServiceImpl method process.

@Override
protected String process(Job job) throws Exception {
    if (!StringUtils.equalsIgnoreCase(JOB_TYPE, job.getJobType()))
        throw new IllegalArgumentException("Can not handle job type " + job.getJobType());
    Publication publication = null;
    MediaPackage mediaPackage = MediaPackageParser.getFromXml(job.getArguments().get(0));
    String repository = job.getArguments().get(1);
    boolean checkAvailability = false;
    switch(Operation.valueOf(job.getOperation())) {
        case Publish:
            String[] downloadElementIds = StringUtils.split(job.getArguments().get(2), SEPARATOR);
            String[] streamingElementIds = StringUtils.split(job.getArguments().get(3), SEPARATOR);
            checkAvailability = BooleanUtils.toBoolean(job.getArguments().get(4));
            publication = publish(job, mediaPackage, repository, Collections.set(downloadElementIds), Collections.set(streamingElementIds), checkAvailability);
            break;
        case Retract:
            publication = retract(job, mediaPackage, repository);
            break;
        case UpdateMetadata:
            checkAvailability = BooleanUtils.toBoolean(job.getArguments().get(4));
            String[] flavors = StringUtils.split(job.getArguments().get(2), SEPARATOR);
            String[] tags = StringUtils.split(job.getArguments().get(3), SEPARATOR);
            publication = updateMetadata(job, mediaPackage, repository, Collections.set(flavors), Collections.set(tags), checkAvailability);
            break;
        default:
            throw new IllegalArgumentException("Can not handle this type of operation: " + job.getOperation());
    }
    return publication != null ? MediaPackageElementParser.getAsXml(publication) : null;
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Publication(org.opencastproject.mediapackage.Publication)

Aggregations

Publication (org.opencastproject.mediapackage.Publication)37 MediaPackage (org.opencastproject.mediapackage.MediaPackage)21 ArrayList (java.util.ArrayList)17 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)15 Job (org.opencastproject.job.api.Job)12 URI (java.net.URI)11 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)9 HashSet (java.util.HashSet)8 SimpleElementSelector (org.opencastproject.mediapackage.selector.SimpleElementSelector)7 PublicationException (org.opencastproject.publication.api.PublicationException)7 Test (org.junit.Test)6 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)5 Ignore (org.junit.Ignore)4 DistributionException (org.opencastproject.distribution.api.DistributionException)4 Attachment (org.opencastproject.mediapackage.Attachment)4 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)4 PublicationImpl (org.opencastproject.mediapackage.PublicationImpl)4 Track (org.opencastproject.mediapackage.Track)4 NotFoundException (org.opencastproject.util.NotFoundException)4 Event (org.opencastproject.index.service.impl.index.event.Event)3