Search in sources :

Example 6 with Catalog

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

the class CommonEventCatalogUIAdapter method storeFields.

@Override
public Catalog storeFields(MediaPackage mediaPackage, MetadataCollection abstractMetadata) {
    Catalog storeFields = super.storeFields(mediaPackage, abstractMetadata);
    // Update the metadata stored in the mediapackage
    MetadataField<?> presenters = abstractMetadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName());
    if (presenters != null && presenters.isUpdated() && presenters.getValue() instanceof Iterable<?>) {
        String[] creators = mediaPackage.getCreators();
        for (String creator : creators) {
            mediaPackage.removeCreator(creator);
        }
        for (String presenter : MetadataUtils.getIterableStringMetadata(presenters)) {
            mediaPackage.addCreator(presenter);
        }
    }
    MetadataField<?> series = abstractMetadata.getOutputFields().get(DublinCore.PROPERTY_IS_PART_OF.getLocalName());
    if (series.getValue().isSome() && series.isUpdated()) {
        if (isNotBlank(series.getValue().get().toString())) {
            mediaPackage.setSeries(series.getValue().get().toString());
            final Opt<String> seriesTitle = getSeriesTitle(series);
            if (seriesTitle.isSome())
                mediaPackage.setSeriesTitle(seriesTitle.get());
        } else {
            mediaPackage.setSeries(null);
            mediaPackage.setSeriesTitle(null);
        }
    }
    Opt<Date> startDate = MetadataUtils.getUpdatedDateMetadata(abstractMetadata, "startDate");
    if (startDate != null && startDate.isSome())
        mediaPackage.setDate(startDate.get());
    // Update all the metadata related to the episode dublin core catalog
    MetadataField<?> title = abstractMetadata.getOutputFields().get(DublinCore.PROPERTY_TITLE.getLocalName());
    if (title != null && title.isUpdated()) {
        mediaPackage.setTitle(title.getValue().get().toString());
    }
    return storeFields;
}
Also used : Catalog(org.opencastproject.mediapackage.Catalog) Date(java.util.Date)

Example 7 with Catalog

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

the class IndexServiceImpl method removeCatalogByFlavor.

@Override
public void removeCatalogByFlavor(Event event, MediaPackageElementFlavor flavor) throws IndexServiceException, NotFoundException, UnauthorizedException {
    MediaPackage mediaPackage = getEventMediapackage(event);
    Catalog[] catalogs = mediaPackage.getCatalogs(flavor);
    if (catalogs.length == 0) {
        throw new NotFoundException(String.format("Cannot find a catalog with flavor '%s' for event with id '%s'.", flavor.toString(), event.getIdentifier()));
    }
    for (Catalog catalog : catalogs) {
        mediaPackage.remove(catalog);
    }
    switch(getEventSource(event)) {
        case WORKFLOW:
            Opt<WorkflowInstance> workflowInstance = getCurrentWorkflowInstance(event.getIdentifier());
            if (workflowInstance.isNone()) {
                logger.error("No workflow instance for event {} found!", event.getIdentifier());
                throw new IndexServiceException("No workflow instance found for event " + event.getIdentifier());
            }
            try {
                WorkflowInstance instance = workflowInstance.get();
                instance.setMediaPackage(mediaPackage);
                updateWorkflowInstance(instance);
            } catch (WorkflowException e) {
                logger.error("Unable to remove catalog with flavor {} by updating workflow event {} because {}", flavor, event.getIdentifier(), getStackTrace(e));
                throw new IndexServiceException("Unable to update workflow event " + event.getIdentifier());
            }
            break;
        case ARCHIVE:
            assetManager.takeSnapshot(DEFAULT_OWNER, mediaPackage);
            break;
        case SCHEDULE:
            try {
                schedulerService.updateEvent(event.getIdentifier(), Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.some(mediaPackage), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
            } catch (SchedulerException e) {
                logger.error("Unable to remove catalog with flavor {} by updating scheduled event {} because {}", flavor, event.getIdentifier(), getStackTrace(e));
                throw new IndexServiceException("Unable to update scheduled event " + event.getIdentifier());
            }
            break;
        default:
            throw new IndexServiceException(String.format("Unable to handle event source type '%s'", getEventSource(event)));
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException)

Example 8 with Catalog

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

the class EventIndexUtils method updateEvent.

/**
 * Update the given {@link Event} with the given {@link MediaPackage}.
 *
 * @param event
 *          the event to update
 * @param mp
 *          the mediapackage containing the metadata for the update
 * @return the updated event
 */
public static Event updateEvent(Event event, MediaPackage mp) {
    // Tracks
    List<String> trackMimeTypes = new ArrayList<String>();
    List<String> trackStreamResolutions = new ArrayList<String>();
    List<String> trackFlavors = new ArrayList<String>();
    for (Track t : mp.getTracks()) {
        if (t.getMimeType() != null)
            trackMimeTypes.add(t.getMimeType().toString());
        if (t.getFlavor() != null)
            trackFlavors.add(t.getFlavor().toString());
        VideoStream[] streams = TrackSupport.byType(t.getStreams(), VideoStream.class);
        for (VideoStream s : streams) {
            trackStreamResolutions.add(s.getFrameWidth() + "x" + s.getFrameHeight());
        }
    }
    event.setTrackMimetypes(trackMimeTypes);
    event.setTrackStreamResolutions(trackStreamResolutions);
    event.setTrackFlavors(trackFlavors);
    // Metadata
    List<String> metadataFlavors = new ArrayList<String>();
    List<String> metadataMimetypes = new ArrayList<String>();
    for (Catalog c : mp.getCatalogs()) {
        if (c.getFlavor() != null)
            metadataFlavors.add(c.getFlavor().toString());
        if (c.getMimeType() != null)
            metadataMimetypes.add(c.getMimeType().toString());
    }
    event.setMetadataFlavors(metadataFlavors);
    event.setMetadataMimetypes(metadataMimetypes);
    // Attachments
    List<String> attachmentFlavors = new ArrayList<String>();
    for (Attachment a : mp.getAttachments()) {
        if (a.getFlavor() != null)
            attachmentFlavors.add(a.getFlavor().toString());
    }
    event.setAttachmentFlavors(attachmentFlavors);
    // Publications
    List<Publication> publications = new ArrayList<Publication>();
    for (Publication p : mp.getPublications()) {
        publications.add(p);
    }
    event.setPublications(publications);
    event.setSeriesName(mp.getSeriesTitle());
    return event;
}
Also used : ArrayList(java.util.ArrayList) VideoStream(org.opencastproject.mediapackage.VideoStream) Publication(org.opencastproject.mediapackage.Publication) Attachment(org.opencastproject.mediapackage.Attachment) Track(org.opencastproject.mediapackage.Track) Catalog(org.opencastproject.mediapackage.Catalog)

Example 9 with Catalog

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

the class ConfigurableEventDCCatalogUIAdapter method getFields.

@Override
public MetadataCollection getFields(MediaPackage mediapackage) {
    DublinCoreMetadataCollection dublinCoreMetadata = new DublinCoreMetadataCollection();
    Set<String> emptyFields = new TreeSet<>(dublinCoreProperties.keySet());
    if (mediapackage != null) {
        for (Catalog catalog : mediapackage.getCatalogs(getFlavor())) {
            getFieldValuesFromCatalog(dublinCoreMetadata, emptyFields, catalog);
        }
    }
    populateEmptyFields(dublinCoreMetadata, emptyFields);
    return dublinCoreMetadata;
}
Also used : DublinCoreMetadataCollection(org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataCollection) TreeSet(java.util.TreeSet) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 10 with Catalog

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

the class ConfigurableEventDCCatalogUIAdapter method storeFields.

@Override
public Catalog storeFields(MediaPackage mediaPackage, MetadataCollection abstractMetadata) {
    Catalog[] catalogs = mediaPackage.getCatalogs(getFlavor());
    final Catalog catalog;
    final DublinCoreCatalog dc;
    final String filename;
    if (catalogs.length == 0) {
        catalog = (Catalog) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().newElement(org.opencastproject.mediapackage.MediaPackageElement.Type.Catalog, getFlavor());
        catalog.setIdentifier(UUID.randomUUID().toString());
        mediaPackage.add(catalog);
        dc = DublinCores.mkSimple();
        dc.addBindings(config.getXmlNamespaceContext());
        dc.setRootTag(new EName(config.getCatalogXmlRootNamespace(), config.getCatalogXmlRootElementName()));
        filename = "dublincore.xml";
    } else {
        catalog = catalogs[0];
        dc = DublinCoreUtil.loadDublinCore(getWorkspace(), catalog);
        dc.addBindings(config.getXmlNamespaceContext());
        filename = FilenameUtils.getName(catalog.getURI().toString());
    }
    DublinCoreMetadataUtil.updateDublincoreCatalog(dc, abstractMetadata);
    URI uri;
    InputStream inputStream = null;
    try {
        inputStream = IOUtils.toInputStream(dc.toXmlString(), "UTF-8");
        uri = getWorkspace().put(mediaPackage.getIdentifier().toString(), catalog.getIdentifier(), filename, inputStream);
        catalog.setURI(uri);
        // setting the URI to a new source so the checksum will most like be invalid
        catalog.setChecksum(null);
    } catch (IOException e) {
        logger.error("Unable to store catalog {} metadata to workspace: {}", catalog, ExceptionUtils.getStackTrace(e));
    } finally {
        IoSupport.closeQuietly(inputStream);
    }
    return catalog;
}
Also used : EName(org.opencastproject.mediapackage.EName) InputStream(java.io.InputStream) IOException(java.io.IOException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) URI(java.net.URI) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Aggregations

Catalog (org.opencastproject.mediapackage.Catalog)77 MediaPackage (org.opencastproject.mediapackage.MediaPackage)35 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)34 URI (java.net.URI)32 Test (org.junit.Test)24 InputStream (java.io.InputStream)21 IOException (java.io.IOException)18 Job (org.opencastproject.job.api.Job)17 NotFoundException (org.opencastproject.util.NotFoundException)17 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)16 Track (org.opencastproject.mediapackage.Track)15 Attachment (org.opencastproject.mediapackage.Attachment)14 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)11 Mpeg7Catalog (org.opencastproject.metadata.mpeg7.Mpeg7Catalog)11 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)11 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)10 File (java.io.File)9 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)9 ArrayList (java.util.ArrayList)8 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)8