use of org.opencastproject.util.data.Option 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.util.data.Option in project opencast by opencast.
the class OaiXmlGen method resumptionToken.
/**
* Create the resumption token and store the query.
*/
Node resumptionToken(final Option<String> resumptionToken, final String metadataPrefix, final SearchResult result, Date until, Option<String> set) {
// compute the token value...
final Option<Option<String>> token;
if (result.size() == result.getLimit()) {
SearchResultItem lastResult = result.getItems().get((int) (result.size() - 1));
// more to come...
token = some(some(repository.saveQuery(new ResumableQuery(metadataPrefix, lastResult.getModificationDate(), until, set))));
} else if (resumptionToken.isSome()) {
// last page reached
token = some(Option.<String>none());
} else {
token = none();
}
// ... then transform it into a node
return token.map(new Function<Option<String>, Node>() {
@Override
public Node apply(Option<String> token) {
return $e("resumptionToken", // $a("cursor", Integer.toString(offset)),
token.map(mkText).getOrElse(nodeZero));
}
}).getOrElse(nodeZero);
}
use of org.opencastproject.util.data.Option in project opencast by opencast.
the class BundleInfoRestEndpointTest method testBundleInfoJsonSerialization.
@Test
public void testBundleInfoJsonSerialization() {
final JsonPath p = JsonPath.from(bundleInfoJson(bundleInfo("host", "bundle", 1L, "version", some("sha"))).toJson());
run(BundleInfo.class, new BundleInfo() {
@Override
public String getHost() {
assertEquals("host", p.getString("host"));
return null;
}
@Override
public String getBundleSymbolicName() {
assertEquals("bundle", p.getString("bundleSymbolicName"));
return null;
}
@Override
public long getBundleId() {
assertEquals(1L, p.getLong("bundleId"));
return 0;
}
@Override
public String getBundleVersion() {
assertEquals("bundle", p.getString("bundleSymbolicName"));
return null;
}
@Override
public Option<String> getBuildNumber() {
assertEquals("sha", p.getString("buildNumber"));
return null;
}
@Override
public BundleVersion getVersion() {
assertEquals("sha", p.getString("buildNumber"));
return null;
}
});
}
use of org.opencastproject.util.data.Option in project opencast by opencast.
the class AbstractAclServiceRestEndpoint method applyAclToEpisode.
@POST
@Path("/apply/episode/{episodeId}")
@RestQuery(name = "applyAclToEpisode", description = "Immediate application of an ACL to an episode", returnDescription = "Status code", pathParameters = { @RestParameter(name = "episodeId", isRequired = true, description = "The episode ID", type = STRING) }, restParameters = { @RestParameter(name = "aclId", isRequired = false, description = "The ID of the ACL to apply. If missing the episode ACL will be deleted to fall back to the series ACL", type = INTEGER), @RestParameter(name = "workflowDefinitionId", isRequired = false, description = "The optional workflow to apply to the episode after", type = STRING), @RestParameter(name = "workflowParams", isRequired = false, description = "Parameters for the optional workflow", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has been successfully applied"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The ACL or the episode has not been found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Internal error") })
public Response applyAclToEpisode(@PathParam("episodeId") String episodeId, @FormParam("aclId") Long aclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams) {
final AclService aclService = aclService();
final Option<Option<ManagedAcl>> macl = option(aclId).map(getManagedAcl(aclService));
if (macl.isSome() && macl.get().isNone())
return notFound();
final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
try {
if (aclService.applyAclToEpisode(episodeId, Options.join(macl), workflow))
return ok();
else
return notFound();
} catch (AclServiceException e) {
logger.error("Error applying acl to episode {}", episodeId);
return serverError();
}
}
use of org.opencastproject.util.data.Option in project opencast by opencast.
the class IndexServiceImplTest method setupCommonCatalogUIAdapter.
private Tuple<CommonEventCatalogUIAdapter, VCell<Option<MetadataCollection>>> setupCommonCatalogUIAdapter(Workspace workspace) throws org.osgi.service.cm.ConfigurationException {
// Create Common Event Catalog UI Adapter
final VCell<Option<MetadataCollection>> metadataCell = VCell.ocell();
CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = new CommonEventCatalogUIAdapter() {
@Override
public Catalog storeFields(MediaPackage mediaPackage, MetadataCollection metadata) {
metadataCell.set(Option.some(metadata));
return super.storeFields(mediaPackage, metadata);
}
};
Properties episodeCatalogProperties = new Properties();
InputStream in = null;
try {
in = getClass().getResourceAsStream("/episode-catalog.properties");
episodeCatalogProperties.load(in);
} catch (IOException e) {
throw new ComponentException(e);
} finally {
IoSupport.closeQuietly(in);
}
commonEventCatalogUIAdapter.updated(PropertiesUtil.toDictionary(episodeCatalogProperties));
commonEventCatalogUIAdapter.setWorkspace(workspace);
return Tuple.tuple(commonEventCatalogUIAdapter, metadataCell);
}
Aggregations