use of org.opencastproject.metadata.api.StaticMetadata in project opencast by opencast.
the class SolrIndexManager method createEpisodeInputDocument.
/**
* Creates a solr input document for the episode metadata of the media package.
*
* @param mediaPackage
* the media package
* @param acl
* the access control list for this mediapackage
* @return an input document ready to be posted to solr
* @throws MediaPackageException
* if serialization of the media package fails
*/
private SolrInputDocument createEpisodeInputDocument(MediaPackage mediaPackage, AccessControlList acl) throws MediaPackageException, IOException {
SolrInputDocument doc = new SolrInputDocument();
String mediaPackageId = mediaPackage.getIdentifier().toString();
// Fill the input document
Schema.setId(doc, mediaPackageId);
// /
// OC specific fields
Schema.setOcMediatype(doc, SearchResultItemType.AudioVisual.toString());
Schema.setOrganization(doc, securityService.getOrganization().getId());
Schema.setOcMediapackage(doc, MediaPackageParser.getAsXml(mediaPackage));
Schema.setOcElementtags(doc, tags(mediaPackage));
Schema.setOcElementflavors(doc, flavors(mediaPackage));
// Add cover
Attachment[] cover = mediaPackage.getAttachments(MediaPackageElements.MEDIAPACKAGE_COVER_FLAVOR);
if (cover != null && cover.length > 0) {
Schema.setOcCover(doc, cover[0].getURI().toString());
}
// naive approach. works as long as only setters, not adders are available in the schema
for (StaticMetadata md : getMetadata(mdServices, mediaPackage)) addEpisodeMetadata(doc, md);
// /
// Add mpeg7
logger.debug("Looking for mpeg-7 catalogs containing segment texts");
Catalog[] mpeg7Catalogs = mediaPackage.getCatalogs(MediaPackageElements.TEXTS);
if (mpeg7Catalogs.length == 0) {
logger.debug("No text catalogs found, trying segments only");
mpeg7Catalogs = mediaPackage.getCatalogs(MediaPackageElements.SEGMENTS);
}
// TODO: merge the segments from each mpeg7 if there is more than one mpeg7 catalog
if (mpeg7Catalogs.length > 0) {
try {
Mpeg7Catalog mpeg7Catalog = loadMpeg7Catalog(mpeg7Catalogs[0]);
addMpeg7Metadata(doc, mediaPackage, mpeg7Catalog);
} catch (IOException e) {
logger.error("Error loading mpeg7 catalog. Skipping catalog: {}", e.getMessage());
}
} else {
logger.debug("No segmentation catalog found");
}
// /
// Add authorization
setAuthorization(doc, securityService, acl);
return doc;
}
use of org.opencastproject.metadata.api.StaticMetadata 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.StaticMetadata in project opencast by opencast.
the class StaticMetadataServiceDublinCoreImplTest method testExtractMetadata.
@Test
public void testExtractMetadata() throws Exception {
MediaPackage mp = newMediaPackage("/manifest-simple.xml");
StaticMetadataServiceDublinCoreImpl ms = newStaticMetadataService();
StaticMetadata md = ms.getMetadata(mp);
assertEquals("Land and Vegetation: Key players on the Climate Scene", find(md.getTitles(), new Predicate<MetadataValue<String>>() {
@Override
public Boolean apply(MetadataValue<String> v) {
return v.getLanguage().equals(MetadataValues.LANGUAGE_UNDEFINED);
}
}).map(new Function<MetadataValue<String>, String>() {
@Override
public String apply(MetadataValue<String> v) {
return v.getValue();
}
}).getOrElse(""));
assertEquals(createDate(2007, 12, 5, 0, 0, 0), md.getCreated().get());
}
use of org.opencastproject.metadata.api.StaticMetadata in project opencast by opencast.
the class CoverImageWorkflowOperationHandlerBase method getMetadataXml.
protected String getMetadataXml(MediaPackage mp) {
StaticMetadata metadata = getStaticMetadataService().getMetadata(mp);
StringBuilder xml = new StringBuilder();
xml.append("<metadata xmlns:dcterms=\"http://purl.org/dc/terms/\">");
for (String title : getFirstMetadataValue(metadata.getTitles())) appendXml(xml, "title", title);
for (String description : getFirstMetadataValue(metadata.getDescription())) appendXml(xml, "description", description);
for (String language : metadata.getLanguage()) appendXml(xml, "language", language);
for (Date created : metadata.getCreated()) /* Method formatDate of org.apache.xalan.lib.ExsltDatetime requires the format CCYY-MM-DDThh:mm:ss */
appendXml(xml, "date", new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ss").format(created));
for (Date[] period : metadata.getTemporalPeriod()) {
if (period[0] != null) {
appendXml(xml, "start", new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ss").format(period[0]));
}
if (period[1] != null) {
appendXml(xml, "end", new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ss").format(period[1]));
}
}
for (Date instant : metadata.getTemporalInstant()) appendXml(xml, "start", new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ss").format(instant));
for (Long duration : metadata.getTemporalDuration()) appendXml(xml, "duration", new SimpleDateFormat("HH:mm:ss").format(new Date(duration)));
for (String license : getFirstMetadataValue(metadata.getLicenses())) appendXml(xml, "license", license);
for (String isPartOf : metadata.getIsPartOf()) appendXml(xml, "series", isPartOf);
for (String contributors : getFirstMetadataValue(metadata.getContributors())) appendXml(xml, "contributors", contributors);
for (String creators : getFirstMetadataValue(metadata.getCreators())) appendXml(xml, "creators", creators);
for (String subjects : getFirstMetadataValue(metadata.getSubjects())) appendXml(xml, "subjects", subjects);
xml.append("</metadata>");
return xml.toString();
}
Aggregations