use of org.opencastproject.metadata.dublincore.DublinCoreValue 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();
}
use of org.opencastproject.metadata.dublincore.DublinCoreValue in project opencast by opencast.
the class TagByDublinCoreTermWOH method start.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(org.opencastproject.workflow.api.WorkflowInstance,
* JobContext)
*/
@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
MediaPackage mediaPackage = workflowInstance.getMediaPackage();
WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation();
String configuredSourceFlavors = StringUtils.trimToEmpty(currentOperation.getConfiguration(SOURCE_FLAVORS_PROPERTY));
String configuredSourceTags = StringUtils.trimToEmpty(currentOperation.getConfiguration(SOURCE_TAGS_PROPERTY));
String configuredCatalog = StringUtils.trimToEmpty(currentOperation.getConfiguration(DCCATALOG_PROPERTY));
String configuredDCTerm = StringUtils.trimToEmpty(currentOperation.getConfiguration(DCTERM_PROPERTY));
String configuredDefaultValue = StringUtils.trimToNull(currentOperation.getConfiguration(DEFAULT_VALUE_PROPERTY));
String configuredMatchValue = StringUtils.trimToEmpty(currentOperation.getConfiguration(MATCH_VALUE_PROPERTY));
String configuredTargetFlavor = StringUtils.trimToNull(currentOperation.getConfiguration(TARGET_FLAVOR_PROPERTY));
String configuredTargetTags = StringUtils.trimToEmpty(currentOperation.getConfiguration(TARGET_TAGS_PROPERTY));
boolean copy = BooleanUtils.toBoolean(currentOperation.getConfiguration(COPY_PROPERTY));
String[] sourceTags = StringUtils.split(configuredSourceTags, ",");
String[] targetTags = StringUtils.split(configuredTargetTags, ",");
String[] sourceFlavors = StringUtils.split(configuredSourceFlavors, ",");
SimpleElementSelector elementSelector = new SimpleElementSelector();
for (String flavor : sourceFlavors) {
elementSelector.addFlavor(MediaPackageElementFlavor.parseFlavor(flavor));
}
for (String tag : sourceTags) {
elementSelector.addTag(tag);
}
List<String> removeTags = new ArrayList<>();
List<String> addTags = new ArrayList<>();
List<String> overrideTags = new ArrayList<>();
for (String tag : targetTags) {
if (tag.startsWith(MINUS)) {
removeTags.add(tag);
} else if (tag.startsWith(PLUS)) {
addTags.add(tag);
} else {
overrideTags.add(tag);
}
}
// Find Catalog
Catalog[] catalogs = mediaPackage.getCatalogs(new MediaPackageElementFlavor("dublincore", StringUtils.lowerCase(configuredCatalog)));
if (catalogs != null && catalogs.length > 0) {
Boolean foundValue = false;
EName dcterm = new EName(TERMS_NS_URI, configuredDCTerm);
// Find DCTerm
for (Catalog catalog : catalogs) {
DublinCoreCatalog dc = DublinCoreUtil.loadDublinCore(workspace, catalog);
// Match Value
List<DublinCoreValue> values = dc.get(dcterm);
if (values.isEmpty()) {
// Use default
if (configuredDefaultValue != null) {
foundValue = configuredDefaultValue.equals(configuredMatchValue);
}
} else {
foundValue = values.contains(DublinCoreValue.mk(configuredMatchValue));
}
}
if (foundValue) {
if (copy) {
logger.info("Retagging mediapackage elements as a copy");
} else {
logger.info("Retagging mediapackage elements");
}
Collection<MediaPackageElement> elements = elementSelector.select(mediaPackage, false);
for (MediaPackageElement e : elements) {
MediaPackageElement element = e;
if (copy) {
element = (MediaPackageElement) e.clone();
element.setIdentifier(null);
// use the same URI as the original
element.setURI(e.getURI());
}
if (configuredTargetFlavor != null) {
element.setFlavor(MediaPackageElementFlavor.parseFlavor(configuredTargetFlavor));
}
if (overrideTags.size() > 0) {
element.clearTags();
for (String tag : overrideTags) {
element.addTag(tag);
}
} else {
for (String tag : removeTags) {
element.removeTag(tag.substring(MINUS.length()));
}
for (String tag : addTags) {
element.addTag(tag.substring(PLUS.length()));
}
}
if (copy) {
mediaPackage.addDerived(element, e);
}
}
}
// if foundValue
}
return createResult(mediaPackage, Action.CONTINUE);
}
use of org.opencastproject.metadata.dublincore.DublinCoreValue in project opencast by opencast.
the class ConfigureByDublinCoreTermWOH method start.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(org.opencastproject.workflow.api.WorkflowInstance,
* JobContext)
*/
@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
MediaPackage mediaPackage = workflowInstance.getMediaPackage();
WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation();
String configuredCatalog = StringUtils.trimToEmpty(currentOperation.getConfiguration(DCCATALOG_PROPERTY));
String configuredDCTerm = StringUtils.trimToEmpty(currentOperation.getConfiguration(DCTERM_PROPERTY));
String configuredDefaultValue = StringUtils.trimToNull(currentOperation.getConfiguration(DEFAULT_VALUE_PROPERTY));
String configuredMatchValue = StringUtils.trimToEmpty(currentOperation.getConfiguration(MATCH_VALUE_PROPERTY));
// Find Catalog
Catalog[] catalogs = mediaPackage.getCatalogs(new MediaPackageElementFlavor("dublincore", StringUtils.lowerCase(configuredCatalog)));
if (catalogs != null && catalogs.length > 0) {
Boolean foundValue = false;
EName dcterm = new EName(TERMS_NS_URI, configuredDCTerm);
// Find DCTerm
for (Catalog catalog : catalogs) {
DublinCoreCatalog dc = DublinCoreUtil.loadDublinCore(workspace, catalog);
// Match Value
List<DublinCoreValue> values = dc.get(dcterm);
if (values.isEmpty()) {
// Use default
if (configuredDefaultValue != null) {
foundValue = configuredDefaultValue.equals(configuredMatchValue);
}
} else {
foundValue = values.contains(DublinCoreValue.mk(configuredMatchValue));
}
}
if (foundValue) {
Map<String, String> properties = new HashMap<>();
for (String key : currentOperation.getConfigurationKeys()) {
// Ignore this operations configuration
if (DCCATALOG_PROPERTY.equals(key) || DCTERM_PROPERTY.equals(key) || DEFAULT_VALUE_PROPERTY.equals(key) || MATCH_VALUE_PROPERTY.equals(key)) {
continue;
}
String value = currentOperation.getConfiguration(key);
properties.put(key, value);
logger.info("Configuration key '{}' of workflow {} is set to value '{}'", key, workflowInstance.getId(), value);
}
return createResult(mediaPackage, properties, Action.CONTINUE, 0);
}
// if foundValue
}
return createResult(mediaPackage, Action.CONTINUE);
}
use of org.opencastproject.metadata.dublincore.DublinCoreValue in project opencast by opencast.
the class InspectWorkflowOperationHandler method updateDublinCore.
/**
* Updates those dublin core fields that can be gathered from the technical metadata.
*
* @param mediaPackage
* the media package
*/
protected void updateDublinCore(MediaPackage mediaPackage) throws Exception {
// Complete episode dublin core catalog (if available)
Catalog[] dcCatalogs = mediaPackage.getCatalogs(MediaPackageElements.EPISODE, MediaPackageReferenceImpl.ANY_MEDIAPACKAGE);
if (dcCatalogs.length > 0) {
DublinCoreCatalog dublinCore = loadDublinCoreCatalog(dcCatalogs[0]);
// Extent
if (mediaPackage.getDuration() != null && !dublinCore.hasValue(DublinCore.PROPERTY_EXTENT)) {
DublinCoreValue extent = EncodingSchemeUtils.encodeDuration(mediaPackage.getDuration());
dublinCore.set(DublinCore.PROPERTY_EXTENT, extent);
logger.debug("Setting dc:extent to '{}'", extent.getValue());
}
// Date created
if (mediaPackage.getDate() != null && !dublinCore.hasValue(DublinCore.PROPERTY_CREATED)) {
DublinCoreValue date = EncodingSchemeUtils.encodeDate(mediaPackage.getDate(), Precision.Minute);
dublinCore.set(DublinCore.PROPERTY_CREATED, date);
logger.debug("Setting dc:date to '{}'", date.getValue());
}
// Serialize changed dublin core
InputStream in = dcService.serialize(dublinCore);
String mpId = mediaPackage.getIdentifier().toString();
String elementId = dcCatalogs[0].getIdentifier();
workspace.put(mpId, elementId, FilenameUtils.getName(dcCatalogs[0].getURI().getPath()), in);
dcCatalogs[0].setURI(workspace.getURI(mpId, elementId));
}
}
use of org.opencastproject.metadata.dublincore.DublinCoreValue 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;
}
Aggregations