Search in sources :

Example 11 with DCMIPeriod

use of org.opencastproject.metadata.dublincore.DCMIPeriod 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)

Example 12 with DCMIPeriod

use of org.opencastproject.metadata.dublincore.DCMIPeriod in project opencast by opencast.

the class LiveScheduleServiceImpl method setDuration.

void setDuration(MediaPackage mp, DublinCoreCatalog dc) {
    DCMIPeriod period = EncodingSchemeUtils.decodeMandatoryPeriod(dc.getFirst(DublinCore.PROPERTY_TEMPORAL));
    long duration = period.getEnd().getTime() - period.getStart().getTime();
    mp.setDuration(duration);
    logger.debug("Live media package {} has start {} and duration {}", mp.getIdentifier(), mp.getDate(), mp.getDuration());
}
Also used : DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod)

Example 13 with DCMIPeriod

use of org.opencastproject.metadata.dublincore.DCMIPeriod in project opencast by opencast.

the class SchedulerMigrationService method getSchedulingDate.

Tuple<Date, Date> getSchedulingDate(DublinCoreCatalog dc) {
    String eventId = dc.getFirst(DublinCore.PROPERTY_IDENTIFIER);
    DCMIPeriod period = EncodingSchemeUtils.decodeMandatoryPeriod(dc.getFirst(DublinCore.PROPERTY_TEMPORAL));
    if (!period.hasStart()) {
        logger.error("Couldn't get startdate from event {}!", eventId);
    }
    if (!period.hasEnd()) {
        logger.error("Couldn't get enddate from event {}!", eventId);
    }
    return Tuple.tuple(period.getStart(), period.getEnd());
}
Also used : DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod)

Example 14 with DCMIPeriod

use of org.opencastproject.metadata.dublincore.DCMIPeriod in project opencast by opencast.

the class DublinCoreMetadataCollection method addField.

public void addField(MetadataField<?> metadataField, String value, ListProvidersService listProvidersService) {
    String defaultKey = getCollectionDefault(metadataField, listProvidersService);
    if (StringUtils.isBlank(value) && StringUtils.isNotBlank(defaultKey)) {
        value = defaultKey;
    }
    switch(metadataField.getType()) {
        case BOOLEAN:
            MetadataField<Boolean> booleanField = MetadataField.createBooleanMetadata(metadataField.getInputID(), Opt.some(metadataField.getOutputID()), metadataField.getLabel(), metadataField.isReadOnly(), metadataField.isRequired(), metadataField.getOrder(), metadataField.getNamespace());
            if (StringUtils.isNotBlank(value)) {
                booleanField.setValue(Boolean.parseBoolean(value));
            }
            addField(booleanField);
            break;
        case DATE:
            if (metadataField.getPattern().isNone()) {
                metadataField.setPattern(Opt.some("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"));
            }
            MetadataField<Date> dateField = MetadataField.createDateMetadata(metadataField.getInputID(), Opt.some(metadataField.getOutputID()), metadataField.getLabel(), metadataField.isReadOnly(), metadataField.isRequired(), metadataField.getPattern().get(), metadataField.getOrder(), metadataField.getNamespace());
            if (StringUtils.isNotBlank(value)) {
                dateField.setValue(EncodingSchemeUtils.decodeDate(value));
            }
            addField(dateField);
            break;
        case DURATION:
            MetadataField<String> durationField = MetadataField.createDurationMetadataField(metadataField.getInputID(), Opt.some(metadataField.getOutputID()), metadataField.getLabel(), metadataField.isReadOnly(), metadataField.isRequired(), getCollectionIsTranslatable(metadataField, listProvidersService), getCollection(metadataField, listProvidersService), metadataField.getCollectionID(), metadataField.getOrder(), metadataField.getNamespace());
            DCMIPeriod period = EncodingSchemeUtils.decodePeriod(value);
            Long longValue = -1L;
            // Check to see if it is from the front end
            String[] durationParts = value.split(":");
            if (durationParts.length == 3) {
                Integer hours = Integer.parseInt(durationParts[0]);
                Integer minutes = Integer.parseInt(durationParts[1]);
                Integer seconds = Integer.parseInt(durationParts[2]);
                longValue = ((hours.longValue() * 60 + minutes.longValue()) * 60 + seconds.longValue()) * 1000;
            } else if (period != null && period.hasStart() && period.hasEnd()) {
                longValue = period.getEnd().getTime() - period.getStart().getTime();
            } else {
                try {
                    longValue = Long.parseLong(value);
                } catch (NumberFormatException e) {
                    logger.debug("Unable to parse duration '{}' value as either a period or millisecond duration.", value);
                    longValue = -1L;
                }
            }
            if (longValue > 0) {
                durationField.setValue(longValue.toString());
            }
            addField(durationField);
            break;
        case ITERABLE_TEXT:
            // Add an iterable text style field
            MetadataField<Iterable<String>> iterableTextField = MetadataField.createIterableStringMetadataField(metadataField.getInputID(), Opt.some(metadataField.getOutputID()), metadataField.getLabel(), metadataField.isReadOnly(), metadataField.isRequired(), getCollectionIsTranslatable(metadataField, listProvidersService), getCollection(metadataField, listProvidersService), metadataField.getCollectionID(), metadataField.getOrder(), metadataField.getNamespace());
            if (StringUtils.isNotBlank(value)) {
                List<String> valueList = Arrays.asList(StringUtils.split(value, ","));
                iterableTextField.setValue(valueList);
            }
            addField(iterableTextField);
            break;
        case MIXED_TEXT:
            // Add an iterable text style field
            MetadataField<Iterable<String>> mixedIterableTextField = MetadataField.createMixedIterableStringMetadataField(metadataField.getInputID(), Opt.some(metadataField.getOutputID()), metadataField.getLabel(), metadataField.isReadOnly(), metadataField.isRequired(), getCollectionIsTranslatable(metadataField, listProvidersService), getCollection(metadataField, listProvidersService), metadataField.getCollectionID(), metadataField.getOrder(), metadataField.getNamespace());
            if (StringUtils.isNotBlank(value)) {
                List<String> valueList = Arrays.asList(StringUtils.split(value, ","));
                mixedIterableTextField.setValue(valueList);
            }
            addField(mixedIterableTextField);
            break;
        case LONG:
            MetadataField<Long> longField = MetadataField.createLongMetadataField(metadataField.getInputID(), Opt.some(metadataField.getOutputID()), metadataField.getLabel(), metadataField.isReadOnly(), metadataField.isRequired(), getCollectionIsTranslatable(metadataField, listProvidersService), getCollection(metadataField, listProvidersService), metadataField.getCollectionID(), metadataField.getOrder(), metadataField.getNamespace());
            if (StringUtils.isNotBlank(value)) {
                longField.setValue(Long.parseLong(value));
            }
            addField(longField);
            break;
        case TEXT:
            MetadataField<String> textField = MetadataField.createTextMetadataField(metadataField.getInputID(), Opt.some(metadataField.getOutputID()), metadataField.getLabel(), metadataField.isReadOnly(), metadataField.isRequired(), getCollectionIsTranslatable(metadataField, listProvidersService), getCollection(metadataField, listProvidersService), metadataField.getCollectionID(), metadataField.getOrder(), metadataField.getNamespace());
            if (StringUtils.isNotBlank(value)) {
                textField.setValue(value);
            }
            addField(textField);
            break;
        case TEXT_LONG:
            MetadataField<String> textLongField = MetadataField.createTextLongMetadataField(metadataField.getInputID(), Opt.some(metadataField.getOutputID()), metadataField.getLabel(), metadataField.isReadOnly(), metadataField.isRequired(), getCollectionIsTranslatable(metadataField, listProvidersService), getCollection(metadataField, listProvidersService), metadataField.getCollectionID(), metadataField.getOrder(), metadataField.getNamespace());
            if (StringUtils.isNotBlank(value)) {
                textLongField.setValue(value);
            }
            addField(textLongField);
            break;
        case START_DATE:
            if (metadataField.getPattern().isNone()) {
                metadataField.setPattern(Opt.some("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"));
            }
            MetadataField<String> startDate = MetadataField.createTemporalStartDateMetadata(metadataField.getInputID(), Opt.some(metadataField.getOutputID()), metadataField.getLabel(), metadataField.isReadOnly(), metadataField.isRequired(), metadataField.getPattern().get(), metadataField.getOrder(), metadataField.getNamespace());
            if (StringUtils.isNotBlank(value)) {
                startDate.setValue(value);
            }
            addField(startDate);
            break;
        case ORDERED_TEXT:
            MetadataField<String> orderedTextField = MetadataField.createOrderedTextMetadataField(metadataField.getInputID(), Opt.some(metadataField.getOutputID()), metadataField.getLabel(), metadataField.isReadOnly(), metadataField.isRequired(), getCollectionIsTranslatable(metadataField, listProvidersService), getCollection(metadataField, listProvidersService), metadataField.getCollectionID(), metadataField.getOrder(), metadataField.getNamespace());
            if (StringUtils.isNotBlank(value)) {
                orderedTextField.setValue(value);
            }
            addField(orderedTextField);
            break;
        default:
            throw new IllegalArgumentException("Unknown metadata type! " + metadataField.getType());
    }
}
Also used : DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) Date(java.util.Date)

Example 15 with DCMIPeriod

use of org.opencastproject.metadata.dublincore.DCMIPeriod in project opencast by opencast.

the class DublinCoreMetadataUtil method getPeriodFromCatalog.

private static Opt<DCMIPeriod> getPeriodFromCatalog(DublinCoreCatalog dc, EName ename) {
    List<DublinCoreValue> periodStrings = dc.get(ename);
    Opt<DCMIPeriod> p = Opt.<DCMIPeriod>none();
    for (DublinCoreValue periodString : periodStrings) {
        p = Opt.some(EncodingSchemeUtils.decodePeriod(periodString.getValue()));
    }
    return p;
}
Also used : DublinCoreValue(org.opencastproject.metadata.dublincore.DublinCoreValue) DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod)

Aggregations

DCMIPeriod (org.opencastproject.metadata.dublincore.DCMIPeriod)17 Date (java.util.Date)12 IOException (java.io.IOException)8 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)8 MediaPackage (org.opencastproject.mediapackage.MediaPackage)6 NotFoundException (org.opencastproject.util.NotFoundException)6 ParseException (java.text.ParseException)4 DateTime (org.joda.time.DateTime)4 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)4 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)4 DublinCoreValue (org.opencastproject.metadata.dublincore.DublinCoreValue)4 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)4 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)4 HashMap (java.util.HashMap)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)3 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)3 LinkedHashMap (java.util.LinkedHashMap)2 Properties (java.util.Properties)2 Path (javax.ws.rs.Path)2