Search in sources :

Example 56 with Catalog

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

the class IndexServiceImpl method updateDublincCoreCatalog.

/**
 * @param mp
 *          the mediapackage to update
 * @param dc
 *          the dublincore metadata to use to update the mediapackage
 * @return the updated mediapackage
 * @throws IOException
 *           Thrown if an IO error occurred adding the dc catalog file
 * @throws MediaPackageException
 *           Thrown if an error occurred updating the mediapackage
 * @throws IngestException
 *           Thrown if an error occurred attaching the catalog to the mediapackage
 */
private MediaPackage updateDublincCoreCatalog(MediaPackage mp, DublinCoreCatalog dc) throws IOException, MediaPackageException, IngestException {
    try (InputStream inputStream = IOUtils.toInputStream(dc.toXmlString(), "UTF-8")) {
        // Update dublincore catalog
        Catalog[] catalogs = mp.getCatalogs(MediaPackageElements.EPISODE);
        if (catalogs.length > 0) {
            Catalog catalog = catalogs[0];
            URI uri = workspace.put(mp.getIdentifier().toString(), catalog.getIdentifier(), "dublincore.xml", inputStream);
            catalog.setURI(uri);
            // setting the URI to a new source so the checksum will most like be invalid
            catalog.setChecksum(null);
        } else {
            mp = ingestService.addCatalog(inputStream, "dublincore.xml", MediaPackageElements.EPISODE, mp);
        }
    }
    return mp;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) URI(java.net.URI) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog)

Example 57 with Catalog

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

the class IndexServiceImpl method updateMediaPackageCommentCatalog.

private void updateMediaPackageCommentCatalog(MediaPackage mediaPackage, List<EventComment> comments) throws EventCommentException, IOException {
    // Get the comments catalog
    Catalog[] commentCatalogs = mediaPackage.getCatalogs(MediaPackageElements.COMMENTS);
    Catalog c = null;
    if (commentCatalogs.length == 1)
        c = commentCatalogs[0];
    if (comments.size() > 0) {
        // If no comments catalog found, create a new one
        if (c == null) {
            c = (Catalog) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().newElement(Type.Catalog, MediaPackageElements.COMMENTS);
            c.setIdentifier(UUID.randomUUID().toString());
            mediaPackage.add(c);
        }
        // Update comments catalog
        InputStream in = null;
        try {
            String commentCatalog = EventCommentParser.getAsXml(comments);
            in = IOUtils.toInputStream(commentCatalog, "UTF-8");
            URI uri = workspace.put(mediaPackage.getIdentifier().toString(), c.getIdentifier(), "comments.xml", in);
            c.setURI(uri);
            // setting the URI to a new source so the checksum will most like be invalid
            c.setChecksum(null);
        } finally {
            IOUtils.closeQuietly(in);
        }
    } else {
        // Remove comments catalog
        if (c != null) {
            mediaPackage.remove(c);
            try {
                workspace.delete(c.getURI());
            } catch (NotFoundException e) {
                logger.warn("Comments catalog {} not found to delete!", c.getURI());
            }
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NotFoundException(org.opencastproject.util.NotFoundException) URI(java.net.URI) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog)

Example 58 with Catalog

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

the class EventIndexUtils method generatePublicationDoc.

/**
 * Generate the document structure for the publication element
 *
 * @param publication
 *          the source publication element
 * @return a map representing the ES document structure of the publication element
 */
private static HashMap<String, Object> generatePublicationDoc(Publication publication) {
    HashMap<String, Object> pMap = new HashMap<String, Object>();
    // Add first level elements
    pMap.put(PublicationIndexSchema.CHANNEL, publication.getChannel());
    addObjectStringtToMap(pMap, PublicationIndexSchema.MIMETYPE, publication.getMimeType());
    // Attachments
    Attachment[] attachments = publication.getAttachments();
    HashMap<String, Object>[] attachmentsArray = new HashMap[attachments.length];
    for (int i = 0; i < attachmentsArray.length; i++) {
        Attachment attachment = attachments[i];
        HashMap<String, Object> element = new HashMap<String, Object>();
        element.put(PublicationIndexSchema.ELEMENT_ID, attachment.getIdentifier());
        addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_MIMETYPE, attachment.getMimeType());
        addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_TYPE, attachment.getElementType());
        element.put(PublicationIndexSchema.ELEMENT_TAG, attachment.getTags());
        addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_URL, attachment.getURI());
        element.put(PublicationIndexSchema.ELEMENT_SIZE, attachment.getSize());
        attachmentsArray[i] = element;
    }
    pMap.put(PublicationIndexSchema.ATTACHMENT, attachmentsArray);
    // Catalogs
    Catalog[] catalogs = publication.getCatalogs();
    HashMap<String, Object>[] catalogsArray = new HashMap[catalogs.length];
    for (int i = 0; i < catalogsArray.length; i++) {
        Catalog catalog = catalogs[i];
        HashMap<String, Object> element = new HashMap<String, Object>();
        element.put(PublicationIndexSchema.ELEMENT_ID, catalog.getIdentifier());
        addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_MIMETYPE, catalog.getMimeType());
        addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_TYPE, catalog.getElementType());
        element.put(PublicationIndexSchema.ELEMENT_TAG, catalog.getTags());
        addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_URL, catalog.getURI());
        element.put(PublicationIndexSchema.ELEMENT_SIZE, catalog.getSize());
        catalogsArray[i] = element;
    }
    pMap.put(PublicationIndexSchema.CATALOG, catalogsArray);
    // Tracks
    Track[] tracks = publication.getTracks();
    HashMap<String, Object>[] tracksArray = new HashMap[tracks.length];
    for (int i = 0; i < tracksArray.length; i++) {
        Track track = tracks[i];
        HashMap<String, Object> element = new HashMap<String, Object>();
        element.put(PublicationIndexSchema.ELEMENT_ID, track.getIdentifier());
        addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_MIMETYPE, track.getMimeType());
        addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_TYPE, track.getElementType());
        element.put(PublicationIndexSchema.ELEMENT_TAG, track.getTags());
        addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_URL, track.getURI());
        element.put(PublicationIndexSchema.ELEMENT_SIZE, track.getSize());
        element.put(PublicationIndexSchema.TRACK_DURATION, track.getDuration());
        tracksArray[i] = element;
    }
    pMap.put(PublicationIndexSchema.TRACK, tracksArray);
    return pMap;
}
Also used : HashMap(java.util.HashMap) Attachment(org.opencastproject.mediapackage.Attachment) Catalog(org.opencastproject.mediapackage.Catalog) Track(org.opencastproject.mediapackage.Track)

Example 59 with Catalog

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

the class AssetManagerUpdatedEventHandler method handleEvent.

public void handleEvent(final SeriesItem seriesItem) {
    // A series or its ACL has been updated. Find any mediapackages with that series, and update them.
    logger.debug("Handling {}", seriesItem);
    String seriesId = seriesItem.getSeriesId();
    // We must be an administrative user to make this query
    final User prevUser = securityService.getUser();
    final Organization prevOrg = securityService.getOrganization();
    try {
        securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg));
        final AQueryBuilder q = assetManager.createQuery();
        final AResult result = q.select(q.snapshot()).where(q.seriesId().eq(seriesId).and(q.version().isLatest())).run();
        for (Snapshot snapshot : enrich(result).getSnapshots()) {
            final String orgId = snapshot.getOrganizationId();
            final Organization organization = organizationDirectoryService.getOrganization(orgId);
            if (organization == null) {
                logger.warn("Skipping update of episode {} since organization {} is unknown", snapshot.getMediaPackage().getIdentifier().compact(), orgId);
                continue;
            }
            securityService.setOrganization(organization);
            MediaPackage mp = snapshot.getMediaPackage();
            // Update the series XACML file
            if (SeriesItem.Type.UpdateAcl.equals(seriesItem.getType())) {
                // Build a new XACML file for this mediapackage
                authorizationService.setAcl(mp, AclScope.Series, seriesItem.getAcl());
            }
            // Update the series dublin core or extended metadata
            if (SeriesItem.Type.UpdateCatalog.equals(seriesItem.getType()) || SeriesItem.Type.UpdateElement.equals(seriesItem.getType())) {
                DublinCoreCatalog seriesDublinCore = null;
                MediaPackageElementFlavor catalogType = null;
                if (SeriesItem.Type.UpdateCatalog.equals(seriesItem.getType())) {
                    seriesDublinCore = seriesItem.getMetadata();
                    mp.setSeriesTitle(seriesDublinCore.getFirst(DublinCore.PROPERTY_TITLE));
                    catalogType = MediaPackageElements.SERIES;
                } else {
                    seriesDublinCore = seriesItem.getExtendedMetadata();
                    catalogType = MediaPackageElementFlavor.flavor(seriesItem.getElementType(), "series");
                }
                // Update the series dublin core
                Catalog[] seriesCatalogs = mp.getCatalogs(catalogType);
                if (seriesCatalogs.length == 1) {
                    Catalog c = seriesCatalogs[0];
                    String filename = FilenameUtils.getName(c.getURI().toString());
                    URI uri = workspace.put(mp.getIdentifier().toString(), c.getIdentifier(), filename, dublinCoreService.serialize(seriesDublinCore));
                    c.setURI(uri);
                    // setting the URI to a new source so the checksum will most like be invalid
                    c.setChecksum(null);
                }
            }
            // Remove the series catalogs and isPartOf from episode catalog
            if (SeriesItem.Type.Delete.equals(seriesItem.getType())) {
                mp.setSeries(null);
                mp.setSeriesTitle(null);
                for (Catalog seriesCatalog : mp.getCatalogs(MediaPackageElements.SERIES)) {
                    mp.remove(seriesCatalog);
                }
                authorizationService.removeAcl(mp, AclScope.Series);
                for (Catalog episodeCatalog : mp.getCatalogs(MediaPackageElements.EPISODE)) {
                    DublinCoreCatalog episodeDublinCore = DublinCoreUtil.loadDublinCore(workspace, episodeCatalog);
                    episodeDublinCore.remove(DublinCore.PROPERTY_IS_PART_OF);
                    String filename = FilenameUtils.getName(episodeCatalog.getURI().toString());
                    URI uri = workspace.put(mp.getIdentifier().toString(), episodeCatalog.getIdentifier(), filename, dublinCoreService.serialize(episodeDublinCore));
                    episodeCatalog.setURI(uri);
                    // setting the URI to a new source so the checksum will most like be invalid
                    episodeCatalog.setChecksum(null);
                }
                // here we don't know the series extended metadata types,
                // we assume that all series catalog flavors have a fixed subtype: series
                MediaPackageElementFlavor seriesFlavor = MediaPackageElementFlavor.flavor("*", "series");
                for (Catalog catalog : mp.getCatalogs()) {
                    if (catalog.getFlavor().matches(seriesFlavor))
                        mp.remove(catalog);
                }
            }
            try {
                // Update the asset manager with the modified mediapackage
                assetManager.takeSnapshot(snapshot.getOwner(), mp);
            } catch (AssetManagerException e) {
                logger.error("Error updating mediapackage {}", mp.getIdentifier().compact(), e);
            }
        }
    } catch (NotFoundException e) {
        logger.warn(e.getMessage());
    } catch (IOException e) {
        logger.warn(e.getMessage());
    } finally {
        securityService.setOrganization(prevOrg);
        securityService.setUser(prevUser);
    }
}
Also used : User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) NotFoundException(org.opencastproject.util.NotFoundException) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException) IOException(java.io.IOException) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Snapshot(org.opencastproject.assetmanager.api.Snapshot) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AResult(org.opencastproject.assetmanager.api.query.AResult) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 60 with Catalog

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

the class SeriesUpdatedEventHandler method updateEpisodeCatalog.

private boolean updateEpisodeCatalog(MediaPackage mp) throws DistributionException, MediaPackageException, NotFoundException, ServiceRegistryException, IllegalArgumentException, IOException {
    // Update the episode catalog
    for (Catalog episodeCatalog : mp.getCatalogs(MediaPackageElements.EPISODE)) {
        DublinCoreCatalog episodeDublinCore = DublinCoreUtil.loadDublinCore(workspace, episodeCatalog);
        episodeDublinCore.remove(DublinCore.PROPERTY_IS_PART_OF);
        String filename = FilenameUtils.getName(episodeCatalog.getURI().toString());
        URI uri = workspace.put(mp.getIdentifier().toString(), episodeCatalog.getIdentifier(), filename, dublinCoreService.serialize(episodeDublinCore));
        episodeCatalog.setURI(uri);
        // setting the URI to a new source so the checksum will most like be invalid
        episodeCatalog.setChecksum(null);
        // Distribute the updated episode dublincore
        Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, episodeCatalog.getIdentifier());
        JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
        Result jobResult = barrier.waitForJobs();
        if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
            mp.remove(episodeCatalog);
            mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
        } else {
            logger.error("Unable to distribute episode catalog {}", episodeCatalog.getIdentifier());
            return false;
        }
    }
    return true;
}
Also used : DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Job(org.opencastproject.job.api.Job) URI(java.net.URI) JobBarrier(org.opencastproject.job.api.JobBarrier) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Result(org.opencastproject.job.api.JobBarrier.Result) SearchResult(org.opencastproject.search.api.SearchResult)

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