Search in sources :

Example 36 with Catalog

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

the class SchedulerUtil method toHumanReadableString.

/**
 * Converts a scheduler event to a human readable string
 *
 * @param workspace
 *          the workspace
 * @param catalogFlavors
 *          the event catalog flavors
 * @param event
 *          the scheduler event
 * @return a human readable string
 */
public static String toHumanReadableString(Workspace workspace, List<MediaPackageElementFlavor> catalogFlavors, SchedulerEvent event) {
    TechnicalMetadata technicalMetadata = event.getTechnicalMetadata();
    StringBuilder sb = new StringBuilder("Event: ").append(CharUtils.LF);
    sb.append("- ").append(event.getEventId()).append(CharUtils.LF);
    sb.append(CharUtils.LF);
    sb.append("Version").append(CharUtils.LF);
    sb.append("- ").append(event.getVersion()).append(CharUtils.LF);
    sb.append(CharUtils.LF);
    sb.append("Start").append(CharUtils.LF);
    sb.append("- ").append(DateTimeSupport.toUTC(technicalMetadata.getStartDate().getTime())).append(CharUtils.LF);
    sb.append(CharUtils.LF);
    sb.append("End").append(CharUtils.LF);
    sb.append("- ").append(DateTimeSupport.toUTC(technicalMetadata.getEndDate().getTime())).append(CharUtils.LF);
    sb.append(CharUtils.LF);
    sb.append("Room").append(CharUtils.LF);
    sb.append("- ").append(technicalMetadata.getAgentId()).append(CharUtils.LF);
    sb.append(CharUtils.LF);
    sb.append("Scheduling configuration").append(CharUtils.LF);
    sb.append("- optout: ").append(technicalMetadata.isOptOut()).append(CharUtils.LF);
    for (Entry<String, String> entry : technicalMetadata.getCaptureAgentConfiguration().entrySet()) {
        sb.append("- ").append(entry.getKey()).append(": ").append(entry.getValue()).append(CharUtils.LF);
    }
    sb.append(CharUtils.LF);
    sb.append("Presenters").append(CharUtils.LF);
    for (String presenter : technicalMetadata.getPresenters()) {
        sb.append("- ").append(presenter).append(CharUtils.LF);
    }
    sb.append(CharUtils.LF);
    sb.append("Workflow configuration").append(CharUtils.LF);
    for (Entry<String, String> entry : technicalMetadata.getWorkflowProperties().entrySet()) {
        sb.append("- ").append(entry.getKey()).append(": ").append(entry.getValue()).append(CharUtils.LF);
    }
    sb.append(CharUtils.LF);
    for (Catalog c : $(event.getMediaPackage().getCatalogs())) {
        if (!catalogFlavors.contains(c.getFlavor()))
            continue;
        DublinCoreCatalog dublinCore;
        try {
            dublinCore = DublinCoreUtil.loadDublinCore(workspace, c);
        } catch (Exception e) {
            logger.error("Unable to read event dublincore: {}", ExceptionUtils.getStackTrace(e));
            continue;
        }
        sb.append("Event metadata ").append("(").append(c.getFlavor().toString()).append(")").append(CharUtils.LF);
        for (Entry<EName, List<DublinCoreValue>> entry : dublinCore.getValues().entrySet()) {
            EName eName = entry.getKey();
            for (DublinCoreValue value : entry.getValue()) {
                sb.append("- ").append(eName.getNamespaceURI()).append(":").append(eName.getLocalName()).append(": ").append(value.getValue());
                boolean hasLanguageDefined = !DublinCore.LANGUAGE_UNDEFINED.equals(value.getLanguage());
                if (hasLanguageDefined || value.getEncodingScheme().isSome()) {
                    sb.append(" (");
                    if (hasLanguageDefined) {
                        sb.append("lang:").append(value.getLanguage());
                        if (value.getEncodingScheme().isSome())
                            sb.append("/");
                    }
                    for (EName schema : value.getEncodingScheme()) {
                        sb.append(schema.getLocalName());
                    }
                    sb.append(")");
                }
                sb.append(CharUtils.LF);
            }
        }
        sb.append(CharUtils.LF);
    }
    return sb.toString();
}
Also used : EName(org.opencastproject.mediapackage.EName) DublinCoreValue(org.opencastproject.metadata.dublincore.DublinCoreValue) ArrayList(java.util.ArrayList) AccessControlList(org.opencastproject.security.api.AccessControlList) List(java.util.List) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) TechnicalMetadata(org.opencastproject.scheduler.api.TechnicalMetadata) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 37 with Catalog

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

the class SchedulerUtil method calculateChecksum.

public static String calculateChecksum(Workspace workspace, List<MediaPackageElementFlavor> eventCatalogUIAdapterFlavors, Date startDateTime, Date endDateTime, String captureAgentId, Set<String> userIds, MediaPackage mediaPackage, Opt<DublinCoreCatalog> episodeDublincore, Map<String, String> wfProperties, Map<String, String> finalCaProperties, boolean optOut, AccessControlList acl) {
    List<String> userIdsList = new ArrayList<>(userIds);
    Collections.sort(userIdsList);
    final MessageDigest messageDigest = mkMd5MessageDigest();
    messageDigest.update(mkChecksumInput(startDateTime));
    messageDigest.update(mkChecksumInput(endDateTime));
    messageDigest.update(mkChecksumInput(captureAgentId));
    for (String user : userIdsList) {
        messageDigest.update(mkChecksumInput(user));
    }
    if (episodeDublincore.isSome()) {
        Catalog episodeCatalog = $(mediaPackage.getCatalogs()).filter(MediaPackageSupport.Filters.isEpisodeDublinCore.toFn()).head2();
        Checksum checksum = episodeCatalog.getChecksum();
        if (checksum == null) {
            checksum = DublinCoreUtil.calculateChecksum(episodeDublincore.get());
            episodeCatalog.setChecksum(checksum);
        }
        messageDigest.update(mkChecksumInput(checksum.toString()));
    }
    // Add extended metadata to calculation
    for (Catalog c : $(mediaPackage.getCatalogs()).sort(sortCatalogById)) {
        if (eventCatalogUIAdapterFlavors.contains(c.getFlavor())) {
            Checksum checksum = c.getChecksum();
            if (checksum == null) {
                DublinCoreCatalog dublinCore = DublinCoreUtil.loadDublinCore(workspace, c);
                checksum = DublinCoreUtil.calculateChecksum(dublinCore);
                c.setChecksum(checksum);
            }
            messageDigest.update(mkChecksumInput(checksum.toString()));
        }
    }
    messageDigest.update(mkChecksumInput(AccessControlUtil.calculateChecksum(acl).toString()));
    for (Entry<String, String> entry : new TreeMap<>(wfProperties).entrySet()) {
        messageDigest.update(mkChecksumInput(entry.getKey()));
        messageDigest.update(mkChecksumInput(entry.getValue()));
    }
    for (Entry<String, String> entry : new TreeMap<>(finalCaProperties).entrySet()) {
        messageDigest.update(mkChecksumInput(entry.getKey()));
        messageDigest.update(mkChecksumInput(entry.getValue()));
    }
    messageDigest.update(mkChecksumInput(optOut));
    return Checksum.convertToHex(messageDigest.digest());
}
Also used : Checksum(org.opencastproject.util.Checksum) ArrayList(java.util.ArrayList) MessageDigest(java.security.MessageDigest) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 38 with Catalog

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

the class SchedulerUtilTest method testSortByCatalogId.

@Test
public void testSortByCatalogId() throws Exception {
    String catalogId = "b";
    Catalog catalog = CatalogImpl.fromURI(new URI("location" + catalogId));
    catalog.setIdentifier(catalogId);
    String extendedCatalogId = "a";
    Catalog extendedCatalog = CatalogImpl.fromURI(new URI("location" + extendedCatalogId));
    extendedCatalog.setIdentifier(extendedCatalogId);
    Assert.assertEquals(1, SchedulerUtil.sortCatalogById.compare(catalog, extendedCatalog));
}
Also used : URI(java.net.URI) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Test(org.junit.Test)

Example 39 with Catalog

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

the class SchedulerRestService method addCatalog.

private MediaPackage addCatalog(Workspace workspace, InputStream in, String fileName, MediaPackageElementFlavor flavor, MediaPackage mediaPackage) throws IOException {
    Catalog[] catalogs = mediaPackage.getCatalogs(flavor);
    Catalog c = null;
    if (catalogs.length == 1)
        c = catalogs[0];
    // If catalog found, create a new one
    if (c == null) {
        c = (Catalog) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().newElement(MediaPackageElement.Type.Catalog, flavor);
        c.setIdentifier(UUID.randomUUID().toString());
        logger.info("Adding catalog with flavor {} to mediapackage {}", flavor, mediaPackage);
        mediaPackage.add(c);
    }
    // Update comments catalog
    try {
        URI catalogUrl = workspace.put(mediaPackage.getIdentifier().compact(), c.getIdentifier(), fileName, in);
        c.setURI(catalogUrl);
        // setting the URI to a new source so the checksum will most like be invalid
        c.setChecksum(null);
    } finally {
        IOUtils.closeQuietly(in);
    }
    return mediaPackage;
}
Also used : URI(java.net.URI) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog)

Example 40 with Catalog

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

the class CaptureNowProlongingService method prolongEvent.

/**
 * Extends the current recording.
 *
 * @param event
 *          the recording's media package
 * @param dublinCore
 *          the recording's dublin core catalog
 * @param agentId
 *          the agent
 * @throws UnauthorizedException
 *           if the event cannot be updated due to a lack of access rights
 * @throws NotFoundException
 *           if the event cannot be found
 * @throws SchedulerException
 *           if updating the scheduling data fails
 * @throws IOException
 *           if updating the calendar to the worksapce fails
 * @throws IllegalArgumentException
 *           if a URI cannot be created using the arguments provided
 */
public void prolongEvent(MediaPackage event, DublinCoreCatalog dublinCore, String agentId) throws UnauthorizedException, NotFoundException, SchedulerException, IllegalArgumentException, IOException {
    String eventId = event.getIdentifier().compact();
    DCMIPeriod period = EncodingSchemeUtils.decodeMandatoryPeriod(dublinCore.getFirst(DublinCore.PROPERTY_TEMPORAL));
    Date prolongedEndDate = new DateTime(period.getEnd()).plus(getProlongingTime()).toDate();
    dublinCore.set(PROPERTY_TEMPORAL, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(period.getStart(), prolongedEndDate), Precision.Second));
    List<MediaPackage> events = schedulerService.findConflictingEvents(agentId, period.getStart(), prolongedEndDate);
    for (MediaPackage conflictMediaPackage : events) {
        if (eventId.equals(conflictMediaPackage.getIdentifier().compact()))
            continue;
        Opt<DublinCoreCatalog> conflictingDc = DublinCoreUtil.loadEpisodeDublinCore(workspace, conflictMediaPackage);
        if (conflictingDc.isNone())
            continue;
        Date conflictingStartDate = EncodingSchemeUtils.decodeMandatoryPeriod(conflictingDc.get().getFirst(DublinCore.PROPERTY_TEMPORAL)).getStart();
        prolongedEndDate = new DateTime(conflictingStartDate).minusMinutes(1).toDate();
        dublinCore.set(PROPERTY_TEMPORAL, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(period.getStart(), prolongedEndDate), Precision.Second));
        logger.info("A scheduled event is preventing the current recording on agent '{}' to be further extended. Extending to one minute before the conflicting event", agentId);
        stop(agentId);
        break;
    }
    // Update the episode dublin core
    Catalog[] episodeCatalogs = event.getCatalogs(MediaPackageElements.EPISODE);
    if (episodeCatalogs.length > 0) {
        Catalog c = episodeCatalogs[0];
        String filename = FilenameUtils.getName(c.getURI().toString());
        URI uri = workspace.put(event.getIdentifier().toString(), c.getIdentifier(), filename, IOUtils.toInputStream(dublinCore.toXmlString(), "UTF-8"));
        c.setURI(uri);
        // setting the URI to a new source so the checksum will most like be invalid
        c.setChecksum(null);
    }
    schedulerService.updateEvent(eventId, Opt.<Date>none(), Opt.some(prolongedEndDate), Opt.<String>none(), Opt.<Set<String>>none(), Opt.some(event), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
}
Also used : DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) URI(java.net.URI) Date(java.util.Date) DateTime(org.joda.time.DateTime) 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