use of org.opencastproject.metadata.dublincore.DublinCoreValue in project opencast by opencast.
the class ConfigurableEventDCCatalogUIAdapter method getFieldValuesFromDublinCoreCatalog.
private void getFieldValuesFromDublinCoreCatalog(DublinCoreMetadataCollection dublinCoreMetadata, Set<String> emptyFields, DublinCoreCatalog dc) {
for (EName propertyKey : dc.getValues().keySet()) {
for (String metdataFieldKey : dublinCoreProperties.keySet()) {
MetadataField<?> metadataField = dublinCoreProperties.get(metdataFieldKey);
String namespace = DublinCore.TERMS_NS_URI;
if (metadataField.getNamespace().isSome()) {
namespace = metadataField.getNamespace().get();
}
if (namespace.equalsIgnoreCase(propertyKey.getNamespaceURI()) && metadataField.getInputID().equalsIgnoreCase(propertyKey.getLocalName())) {
for (DublinCoreValue dublinCoreValue : dc.get(propertyKey)) {
emptyFields.remove(metdataFieldKey);
try {
dublinCoreMetadata.addField(metadataField, dublinCoreValue.getValue(), getListProvidersService());
} catch (IllegalArgumentException e) {
logger.error("Skipping metadata field '{}' because of error: {}", metadataField.getInputID(), ExceptionUtils.getStackTrace(e));
}
}
}
}
}
}
use of org.opencastproject.metadata.dublincore.DublinCoreValue in project opencast by opencast.
the class SeriesWorkflowOperationHandlerTest method testExtraMetadataDefaultNS.
@Test
public void testExtraMetadataDefaultNS() throws WorkflowOperationException {
final EName customProperty = new EName(DublinCores.OC_PROPERTY_NS_URI, "my-custom-property");
final String customValue = "my-custom-value";
// Add extra metadata to the series catalog.
seriesCatalog.set(DublinCore.PROPERTY_LANGUAGE, "Opencastian");
seriesCatalog.set(DublinCore.PROPERTY_CONTRIBUTOR, Arrays.asList(new DublinCoreValue[] { DublinCoreValue.mk("Mr. Contry Bute"), DublinCoreValue.mk("Mrs. Jane Doe") }));
seriesCatalog.set(customProperty, customValue);
// Prepare "copy metadata" property
// All field names without namespace
// However, in the series metadata, the third one has a different NS than the other two
String[] extraMetadata = { DublinCore.PROPERTY_LANGUAGE.getLocalName(), DublinCore.PROPERTY_CONTRIBUTOR.getLocalName(), customProperty.getLocalName() };
WorkflowInstanceImpl instance = new WorkflowInstanceImpl();
List<WorkflowOperationInstance> ops = new ArrayList<WorkflowOperationInstance>();
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
ops.add(operation);
instance.setOperations(ops);
instance.setMediaPackage(mp);
MediaPackage clone = (MediaPackage) mp.clone();
operation.setConfiguration(SeriesWorkflowOperationHandler.SERIES_PROPERTY, "series1");
operation.setConfiguration(SeriesWorkflowOperationHandler.ATTACH_PROPERTY, "*");
operation.setConfiguration(SeriesWorkflowOperationHandler.APPLY_ACL_PROPERTY, "false");
operation.setConfiguration(SeriesWorkflowOperationHandler.COPY_METADATA_PROPERTY, StringUtils.join(extraMetadata, ", "));
// Set the namespace of the third, custom property as the default
operation.setConfiguration(SeriesWorkflowOperationHandler.DEFAULT_NS_PROPERTY, DublinCores.OC_PROPERTY_NS_URI);
WorkflowOperationResult result = operationHandler.start(instance, null);
Assert.assertEquals(Action.CONTINUE, result.getAction());
MediaPackage resultingMediapackage = result.getMediaPackage();
Assert.assertEquals("series1", resultingMediapackage.getSeries());
Assert.assertEquals("Series 1", resultingMediapackage.getSeriesTitle());
Assert.assertEquals(clone.getElements().length + 1, resultingMediapackage.getElements().length);
// Get episode DublinCore
DublinCoreCatalog episodeCatalog = DublinCores.read(capturedStream.getValue());
// Only the later metadatum should have been resolved. The other had a different namespace.
Assert.assertFalse(episodeCatalog.hasValue(DublinCore.PROPERTY_CONTRIBUTOR));
Assert.assertFalse(episodeCatalog.hasValue(DublinCore.PROPERTY_LANGUAGE));
Assert.assertTrue(episodeCatalog.hasValue(customProperty));
Assert.assertEquals(seriesCatalog.get(customProperty), episodeCatalog.get(customProperty));
}
use of org.opencastproject.metadata.dublincore.DublinCoreValue in project opencast by opencast.
the class SeriesServiceImpl method updateSeries.
@Override
public DublinCoreCatalog updateSeries(DublinCoreCatalog dc) throws SeriesException, UnauthorizedException {
try {
for (DublinCoreCatalog dublinCore : isNew(notNull(dc, "dc"))) {
final String id = dublinCore.getFirst(DublinCore.PROPERTY_IDENTIFIER);
if (!dublinCore.hasValue(DublinCore.PROPERTY_CREATED)) {
DublinCoreValue date = EncodingSchemeUtils.encodeDate(new Date(), Precision.Minute);
dublinCore.set(DublinCore.PROPERTY_CREATED, date);
logger.debug("Setting series creation date to '{}'", date.getValue());
}
if (dublinCore.hasValue(DublinCore.PROPERTY_TITLE)) {
if (dublinCore.getFirst(DublinCore.PROPERTY_TITLE).length() > 255) {
dublinCore.set(DublinCore.PROPERTY_TITLE, dublinCore.getFirst(DublinCore.PROPERTY_TITLE).substring(0, 255));
logger.warn("Title was longer than 255 characters. Cutting excess off.");
}
}
logger.debug("Updating series {}", id);
index.updateIndex(dublinCore);
try {
final AccessControlList acl = persistence.getAccessControlList(id);
if (acl != null) {
index.updateSecurityPolicy(id, acl);
}
} catch (NotFoundException ignore) {
// Ignore not found since this is the first indexing
}
try {
index.updateOptOutStatus(id, persistence.isOptOut(id));
} catch (NotFoundException ignore) {
// Ignore not found since this is the first indexing
}
// Make sure store to persistence comes after index, return value can be null
DublinCoreCatalog updated = persistence.storeSeries(dublinCore);
messageSender.sendObjectMessage(SeriesItem.SERIES_QUEUE, MessageSender.DestinationType.Queue, SeriesItem.updateCatalog(dublinCore));
return (updated == null) ? null : dublinCore;
}
return dc;
} catch (Exception e) {
throw rethrow(e);
}
}
use of org.opencastproject.metadata.dublincore.DublinCoreValue in project opencast by opencast.
the class OaiXmlGen method getDublinCoreNodes.
private List<Node> getDublinCoreNodes(DublinCoreCatalog dc, EName eName) {
List<Node> nodes = new ArrayList<Node>();
List<DublinCoreValue> values = dc.get(eName);
for (DublinCoreValue dcValue : values) {
Element element = $e("dc:" + eName.getLocalName(), $langNode(dcValue.getLanguage()), $txt(dcValue.getValue()));
nodes.add(element);
}
return nodes;
}
Aggregations