Search in sources :

Example 71 with DublinCoreCatalog

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());
}
Also used : EName(org.opencastproject.mediapackage.EName) ConfigurableEventDCCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.ConfigurableEventDCCatalogUIAdapter) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Test(org.junit.Test)

Example 72 with DublinCoreCatalog

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));
    }
}
Also used : DublinCoreValue(org.opencastproject.metadata.dublincore.DublinCoreValue) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 73 with DublinCoreCatalog

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);
}
Also used : MediaPackageMetadata(org.opencastproject.metadata.api.MediaPackageMetadata) MediaInspectionService(org.opencastproject.inspection.api.MediaInspectionService) URI(java.net.URI) DublinCoreCatalogService(org.opencastproject.metadata.dublincore.DublinCoreCatalogService) Date(java.util.Date) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Job(org.opencastproject.job.api.Job) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 74 with DublinCoreCatalog

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);
}
Also used : WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) URI(java.net.URI) LinkedList(java.util.LinkedList) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) Incident(org.opencastproject.job.api.Incident) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Tuple(org.opencastproject.util.data.Tuple) Before(org.junit.Before)

Example 75 with DublinCoreCatalog

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;
    }
}
Also used : DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Aggregations

DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)117 MediaPackage (org.opencastproject.mediapackage.MediaPackage)51 NotFoundException (org.opencastproject.util.NotFoundException)46 Test (org.junit.Test)44 Date (java.util.Date)40 IOException (java.io.IOException)30 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)29 URI (java.net.URI)23 AccessControlList (org.opencastproject.security.api.AccessControlList)22 SeriesException (org.opencastproject.series.api.SeriesException)20 ArrayList (java.util.ArrayList)18 Catalog (org.opencastproject.mediapackage.Catalog)18 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)18 EName (org.opencastproject.mediapackage.EName)17 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)17 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)15 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)15 InputStream (java.io.InputStream)14 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)14