use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class DublinCoreCatalogUIAdapterTest method testStoreFields.
@Test
public void testStoreFields() throws Exception {
String temporal = "temporal";
String expectedTemporal = "start=2016-03-01T09:27:35Z; end=2016-03-01T11:43:12Z; scheme=W3C-DTF;";
String expectedTitle = "New Value for Title";
String expectedMissing = "New Value for Missing";
ConfigurableEventDCCatalogUIAdapter configurationDublinCoreCatalogUIAdapter = new ConfigurableEventDCCatalogUIAdapter();
configurationDublinCoreCatalogUIAdapter.setListProvidersService(listProvidersService);
configurationDublinCoreCatalogUIAdapter.setWorkspace(workspace);
configurationDublinCoreCatalogUIAdapter.updated(eventProperties);
DublinCoreMetadataCollection dublinCoreMetadata = new DublinCoreMetadataCollection();
MetadataField<String> titleField = MetadataField.createTextMetadataField(title, Opt.some(title), "New Label for Title", true, false, Opt.<Boolean>none(), Opt.<Map<String, String>>none(), Opt.<String>none(), Opt.<Integer>none(), Opt.<String>none());
dublinCoreMetadata.addField(titleField, expectedTitle, listProvidersService);
MetadataField<String> missingField = MetadataField.createTextMetadataField("missing", Opt.<String>none(), "The Missing's Label", false, false, Opt.<Boolean>none(), Opt.<Map<String, String>>none(), Opt.<String>none(), Opt.<Integer>none(), Opt.<String>none());
dublinCoreMetadata.addField(missingField, expectedMissing, listProvidersService);
MetadataField<String> durationField = MetadataField.createDurationMetadataField(temporal, Opt.some("duration"), label, true, true, Opt.<Integer>none(), Opt.<String>none());
dublinCoreMetadata.addField(durationField, "02:15:37", listProvidersService);
MetadataField<String> startDate = MetadataField.createTemporalStartDateMetadata(temporal, Opt.some("startDate"), label, true, true, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Opt.<Integer>none(), Opt.<String>none());
dublinCoreMetadata.addField(startDate, "2016-03-01T09:27:35.000Z", listProvidersService);
configurationDublinCoreCatalogUIAdapter.storeFields(mediapackage, dublinCoreMetadata);
assertTrue(writtenCatalog.hasCaptured());
DublinCoreCatalog updatedCatalog = DublinCores.read(writtenCatalog.getValue());
assertEquals(expectedTitle, updatedCatalog.get(new EName(DublinCore.TERMS_NS_URI, "title")).get(0).getValue());
assertEquals(expectedMissing, updatedCatalog.get(new EName(DublinCore.TERMS_NS_URI, "missing")).get(0).getValue());
assertEquals(expectedTemporal, updatedCatalog.get(new EName(DublinCore.TERMS_NS_URI, temporal)).get(0).getValue());
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog 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.DublinCoreCatalog in project opencast by opencast.
the class InspectWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
// test resources
uriMP = InspectWorkflowOperationHandler.class.getResource("/inspect_mediapackage.xml").toURI();
uriMPUpdated = InspectWorkflowOperationHandler.class.getResource("/inspect_mediapackage_updated.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
mpUpdatedDC = builder.loadFromXml(uriMPUpdated.toURL().openStream());
newTrack = (Track) mpUpdatedDC.getTracks()[0];
// set up service
operationHandler = new InspectWorkflowOperationHandler();
operationHandler.setJobBarrierPollingInterval(0);
// set up mock metadata and metadata service providing it
metadata = EasyMock.createNiceMock(MediaPackageMetadata.class);
EasyMock.expect(metadata.getDate()).andReturn(DATE);
EasyMock.expect(metadata.getLanguage()).andReturn(LANGUAGE);
EasyMock.expect(metadata.getLicense()).andReturn(LICENSE);
EasyMock.expect(metadata.getSeriesIdentifier()).andReturn(SERIES);
EasyMock.expect(metadata.getSeriesTitle()).andReturn(SERIES_TITLE);
EasyMock.expect(metadata.getTitle()).andReturn(TITLE);
EasyMock.replay(metadata);
// set up mock dublin core and dcService providing it
DublinCoreCatalog dc = EasyMock.createStrictMock(DublinCoreCatalog.class);
EasyMock.expect(dc.hasValue(DublinCore.PROPERTY_EXTENT)).andReturn(false);
dc.set((EName) EasyMock.anyObject(), (DublinCoreValue) EasyMock.anyObject());
EasyMock.expect(dc.hasValue(DublinCore.PROPERTY_CREATED)).andReturn(false);
dc.set((EName) EasyMock.anyObject(), (DublinCoreValue) EasyMock.anyObject());
dc.toXml((ByteArrayOutputStream) EasyMock.anyObject(), EasyMock.anyBoolean());
// EasyMock.expect(dc.getIdentifier()).andReturn("123");
EasyMock.replay(dc);
dcService = EasyMock.createNiceMock(DublinCoreCatalogService.class);
EasyMock.expect(dcService.getMetadata((MediaPackage) EasyMock.anyObject())).andReturn(metadata);
EasyMock.expect(dcService.load((InputStream) EasyMock.anyObject())).andReturn(dc);
EasyMock.replay(dcService);
operationHandler.setDublincoreService(dcService);
// set up mock receipt and inspect service providing it
job = EasyMock.createNiceMock(Job.class);
EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(newTrack)).anyTimes();
EasyMock.expect(job.getId()).andReturn(new Long(123));
EasyMock.expect(job.getStatus()).andReturn(Status.FINISHED);
EasyMock.expect(job.getDateCreated()).andReturn(new Date());
EasyMock.expect(job.getDateStarted()).andReturn(new Date());
EasyMock.replay(job);
// set up mock service registry
ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job).anyTimes();
EasyMock.replay(serviceRegistry);
operationHandler.setServiceRegistry(serviceRegistry);
inspectionService = EasyMock.createNiceMock(MediaInspectionService.class);
EasyMock.expect(inspectionService.enrich((Track) EasyMock.anyObject(), EasyMock.anyBoolean(), (Map<String, String>) EasyMock.anyObject())).andReturn(job);
EasyMock.replay(inspectionService);
operationHandler.setInspectionService(inspectionService);
// set up mock workspace
workspace = EasyMock.createNiceMock(Workspace.class);
// workspace.delete((String) EasyMock.anyObject(), (String) EasyMock.anyObject());
URI newURI = new URI(NEW_DC_URL);
EasyMock.expect(workspace.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(newURI);
EasyMock.expect(workspace.getURI((String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(newURI);
EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(new File(getClass().getResource("/dublincore.xml").toURI()));
EasyMock.replay(workspace);
operationHandler.setWorkspace(workspace);
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class EmailDataTest method setUp.
@Before
public void setUp() throws Exception {
MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
uriMP = EmailDataTest.class.getResource("/email_mediapackage.xml").toURI();
mp = builder.loadFromXml(uriMP.toURL().openStream());
URI episodeURI = EmailDataTest.class.getResource("/episode_dublincore.xml").toURI();
URI seriesURI = EmailDataTest.class.getResource("/series_dublincore.xml").toURI();
DublinCoreCatalog episodeDc = DublinCores.read(episodeURI.toURL().openStream());
catalogs.put("episode", buildCatalogHash(episodeDc));
DublinCoreCatalog seriesDc = DublinCores.read(seriesURI.toURL().openStream());
catalogs.put("series", buildCatalogHash(seriesDc));
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.setId("wfdef");
Map<String, String> props = new HashMap<String, String>();
props.put("emailAddress", "user@domain.com");
// Create some incidents
incident1 = EasyMock.createNiceMock(Incident.class);
List<Tuple<String, String>> details = new LinkedList<Tuple<String, String>>();
Tuple<String, String> detail = new Tuple<String, String>("detail-type", "error in operation1");
details.add(detail);
EasyMock.expect(incident1.getDetails()).andReturn(details);
incident2 = EasyMock.createNiceMock(Incident.class);
details = new LinkedList<Tuple<String, String>>();
detail = new Tuple<String, String>("detail-type", "error in operation2");
details.add(detail);
EasyMock.expect(incident2.getDetails()).andReturn(details);
// Link the incident and the subtree
incidents = new LinkedList<Incident>();
incidents.add(incident1);
incidents.add(incident2);
workflowInstance = new WorkflowInstanceImpl(def, null, null, null, null, props);
workflowInstance.setId(1);
workflowInstance.setState(WorkflowState.RUNNING);
workflowInstance.setMediaPackage(mp);
failedOperation = new WorkflowOperationInstanceImpl("operation1", OperationState.FAILED);
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("email", OperationState.RUNNING);
List<WorkflowOperationInstance> operationList = new ArrayList<WorkflowOperationInstance>();
operationList.add(failedOperation);
operationList.add(operation);
workflowInstance.setOperations(operationList);
EasyMock.replay(incident1, incident2);
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class ConfigurableSeriesDCCatalogUIAdapter method storeFields.
@Override
public boolean storeFields(String seriesId, MetadataCollection metadata) {
final Opt<DublinCoreCatalog> optDCCatalog = loadDublinCoreCatalog(RequireUtil.requireNotBlank(seriesId, "seriesId"));
if (optDCCatalog.isSome()) {
final DublinCoreCatalog dc = optDCCatalog.get();
dc.addBindings(config.getXmlNamespaceContext());
DublinCoreMetadataUtil.updateDublincoreCatalog(dc, metadata);
saveDublinCoreCatalog(seriesId, dc);
return true;
} else {
return false;
}
}
Aggregations