use of org.opencastproject.metadata.api.util.Interval in project opencast by opencast.
the class StaticMetadataServiceDublinCoreImpl method newStaticMetadataFromEpisode.
private static StaticMetadata newStaticMetadataFromEpisode(DublinCoreCatalog episode) {
// Ensure that the mandatory properties are present
final Option<String> id = option(episode.getFirst(PROPERTY_IDENTIFIER));
final Option<Date> created = option(episode.getFirst(PROPERTY_CREATED)).map(new Function<String, Date>() {
@Override
public Date apply(String a) {
final Date date = EncodingSchemeUtils.decodeDate(a);
return date != null ? date : Misc.<Date>chuck(new RuntimeException(a + " does not conform to W3C-DTF encoding scheme."));
}
});
final Option temporalOpt = option(episode.getFirstVal(PROPERTY_TEMPORAL)).map(dc2temporalValueOption());
final Option<Date> start;
if (episode.getFirst(PROPERTY_TEMPORAL) != null) {
DCMIPeriod period = EncodingSchemeUtils.decodeMandatoryPeriod(episode.getFirst(PROPERTY_TEMPORAL));
start = option(period.getStart());
} else {
start = created;
}
final Option<String> language = option(episode.getFirst(PROPERTY_LANGUAGE));
final Option<Long> extent = head(episode.get(PROPERTY_EXTENT)).map(new Function<DublinCoreValue, Long>() {
@Override
public Long apply(DublinCoreValue a) {
final Long extent = EncodingSchemeUtils.decodeDuration(a);
return extent != null ? extent : Misc.<Long>chuck(new RuntimeException(a + " does not conform to ISO8601 encoding scheme for durations."));
}
});
final Option<String> type = option(episode.getFirst(PROPERTY_TYPE));
final Option<String> isPartOf = option(episode.getFirst(PROPERTY_IS_PART_OF));
final Option<String> replaces = option(episode.getFirst(PROPERTY_REPLACES));
final Option<Interval> available = head(episode.get(PROPERTY_AVAILABLE)).flatMap(new Function<DublinCoreValue, Option<Interval>>() {
@Override
public Option<Interval> apply(DublinCoreValue v) {
final DCMIPeriod p = EncodingSchemeUtils.decodePeriod(v);
return p != null ? some(Interval.fromValues(p.getStart(), p.getEnd())) : Misc.<Option<Interval>>chuck(new RuntimeException(v + " does not conform to W3C-DTF encoding scheme for periods"));
}
});
final NonEmptyList<MetadataValue<String>> titles = new NonEmptyList<MetadataValue<String>>(mlist(episode.get(PROPERTY_TITLE)).map(dc2mvString(PROPERTY_TITLE.getLocalName())).value());
final List<MetadataValue<String>> subjects = mlist(episode.get(PROPERTY_SUBJECT)).map(dc2mvString(PROPERTY_SUBJECT.getLocalName())).value();
final List<MetadataValue<String>> creators = mlist(episode.get(PROPERTY_CREATOR)).map(dc2mvString(PROPERTY_CREATOR.getLocalName())).value();
final List<MetadataValue<String>> publishers = mlist(episode.get(PROPERTY_PUBLISHER)).map(dc2mvString(PROPERTY_PUBLISHER.getLocalName())).value();
final List<MetadataValue<String>> contributors = mlist(episode.get(PROPERTY_CONTRIBUTOR)).map(dc2mvString(PROPERTY_CONTRIBUTOR.getLocalName())).value();
final List<MetadataValue<String>> description = mlist(episode.get(PROPERTY_DESCRIPTION)).map(dc2mvString(PROPERTY_DESCRIPTION.getLocalName())).value();
final List<MetadataValue<String>> rightsHolders = mlist(episode.get(PROPERTY_RIGHTS_HOLDER)).map(dc2mvString(PROPERTY_RIGHTS_HOLDER.getLocalName())).value();
final List<MetadataValue<String>> spatials = mlist(episode.get(PROPERTY_SPATIAL)).map(dc2mvString(PROPERTY_SPATIAL.getLocalName())).value();
final List<MetadataValue<String>> accessRights = mlist(episode.get(PROPERTY_ACCESS_RIGHTS)).map(dc2mvString(PROPERTY_ACCESS_RIGHTS.getLocalName())).value();
final List<MetadataValue<String>> licenses = mlist(episode.get(PROPERTY_LICENSE)).map(dc2mvString(PROPERTY_LICENSE.getLocalName())).value();
return new StaticMetadata() {
@Override
public Option<String> getId() {
return id;
}
@Override
public Option<Date> getCreated() {
// so data will be kept correctly there, and only be "exported" to DC_CREATED for compatibility reasons here.
return start;
}
@Override
public Option<Date[]> getTemporalPeriod() {
if (temporalOpt.isSome()) {
if (temporalOpt.get() instanceof DCMIPeriod) {
DCMIPeriod p = (DCMIPeriod) temporalOpt.get();
return option(new Date[] { p.getStart(), p.getEnd() });
}
}
return Option.none();
}
@Override
public Option<Date> getTemporalInstant() {
if (temporalOpt.isSome()) {
if (temporalOpt.get() instanceof Date) {
return temporalOpt;
}
}
return Option.none();
}
@Override
public Option<Long> getTemporalDuration() {
if (temporalOpt.isSome()) {
if (temporalOpt.get() instanceof Long) {
return temporalOpt;
}
}
return Option.none();
}
@Override
public Option<Long> getExtent() {
return extent;
}
@Override
public Option<String> getLanguage() {
return language;
}
@Override
public Option<String> getIsPartOf() {
return isPartOf;
}
@Override
public Option<String> getReplaces() {
return replaces;
}
@Override
public Option<String> getType() {
return type;
}
@Override
public Option<Interval> getAvailable() {
return available;
}
@Override
public NonEmptyList<MetadataValue<String>> getTitles() {
return titles;
}
@Override
public List<MetadataValue<String>> getSubjects() {
return subjects;
}
@Override
public List<MetadataValue<String>> getCreators() {
return creators;
}
@Override
public List<MetadataValue<String>> getPublishers() {
return publishers;
}
@Override
public List<MetadataValue<String>> getContributors() {
return contributors;
}
@Override
public List<MetadataValue<String>> getDescription() {
return description;
}
@Override
public List<MetadataValue<String>> getRightsHolders() {
return rightsHolders;
}
@Override
public List<MetadataValue<String>> getSpatials() {
return spatials;
}
@Override
public List<MetadataValue<String>> getAccessRights() {
return accessRights;
}
@Override
public List<MetadataValue<String>> getLicenses() {
return licenses;
}
};
}
use of org.opencastproject.metadata.api.util.Interval in project opencast by opencast.
the class IntervalTest method testInterval.
@Test
public void testInterval() {
Interval closed = boundedInterval(new Date(), new Date());
assertTrue(closed.isBounded());
assertFalse(closed.isLeftInfinite());
assertFalse(closed.isRightInfinite());
Interval.Match<Integer> visitor = new Interval.Match<Integer>() {
@Override
public Integer bounded(Date leftBound, Date rightBound) {
return 1;
}
@Override
public Integer leftInfinite(Date rightBound) {
return 2;
}
@Override
public Integer rightInfinite(Date leftBound) {
return 3;
}
};
assertSame(1, closed.fold(visitor));
Interval leftOpen = rightBoundedInterval(new Date());
assertFalse(leftOpen.isBounded());
assertTrue(leftOpen.isLeftInfinite());
assertFalse(leftOpen.isRightInfinite());
assertSame(2, leftOpen.fold(visitor));
Interval rightOpen = leftBoundedInterval(new Date());
assertFalse(rightOpen.isBounded());
assertFalse(rightOpen.isLeftInfinite());
assertTrue(rightOpen.isRightInfinite());
assertSame(3, rightOpen.fold(visitor));
}
Aggregations