Search in sources :

Example 1 with MediapackageMetadataImpl

use of org.opencastproject.metadata.api.MediapackageMetadataImpl in project opencast by opencast.

the class DublinCoreCatalogService method getMetadata.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.metadata.api.MetadataService#getMetadata(org.opencastproject.mediapackage.MediaPackage)
 */
@Override
public MediaPackageMetadata getMetadata(MediaPackage mp) {
    MediapackageMetadataImpl metadata = new MediapackageMetadataImpl();
    for (Catalog catalog : Stream.$(mp.getCatalogs(DublinCoreCatalog.ANY_DUBLINCORE)).sort(COMPARE_BY_FLAVOR)) {
        DublinCoreCatalog dc = DublinCoreUtil.loadDublinCore(workspace, catalog);
        if (MediaPackageElements.EPISODE.equals(catalog.getFlavor())) {
            // Title
            metadata.setTitle(dc.getFirst(DublinCore.PROPERTY_TITLE));
            // use started date as created date (see MH-12250)
            if (dc.hasValue(DublinCore.PROPERTY_TEMPORAL) && dc.getFirst(PROPERTY_TEMPORAL) != null) {
                DCMIPeriod period = EncodingSchemeUtils.decodeMandatoryPeriod(dc.getFirst(PROPERTY_TEMPORAL));
                metadata.setDate(period.getStart());
            } else {
                // ...and only if started date is not available the created date
                if (dc.hasValue(DublinCore.PROPERTY_CREATED))
                    metadata.setDate(EncodingSchemeUtils.decodeDate(dc.get(DublinCore.PROPERTY_CREATED).get(0)));
            }
            // Series id
            if (dc.hasValue(DublinCore.PROPERTY_IS_PART_OF))
                metadata.setSeriesIdentifier(dc.get(DublinCore.PROPERTY_IS_PART_OF).get(0).getValue());
            // Creator
            if (dc.hasValue(DublinCore.PROPERTY_CREATOR)) {
                List<String> creators = new ArrayList<String>();
                for (DublinCoreValue creator : dc.get(DublinCore.PROPERTY_CREATOR)) {
                    creators.add(creator.getValue());
                }
                metadata.setCreators(creators.toArray(new String[creators.size()]));
            }
            // Contributor
            if (dc.hasValue(DublinCore.PROPERTY_CONTRIBUTOR)) {
                List<String> contributors = new ArrayList<String>();
                for (DublinCoreValue contributor : dc.get(DublinCore.PROPERTY_CONTRIBUTOR)) {
                    contributors.add(contributor.getValue());
                }
                metadata.setContributors(contributors.toArray(new String[contributors.size()]));
            }
            // Subject
            if (dc.hasValue(DublinCore.PROPERTY_SUBJECT)) {
                List<String> subjects = new ArrayList<String>();
                for (DublinCoreValue subject : dc.get(DublinCore.PROPERTY_SUBJECT)) {
                    subjects.add(subject.getValue());
                }
                metadata.setSubjects(subjects.toArray(new String[subjects.size()]));
            }
            // License
            metadata.setLicense(dc.getFirst(DublinCore.PROPERTY_LICENSE));
            // Language
            metadata.setLanguage(dc.getFirst(DublinCore.PROPERTY_LANGUAGE));
        } else if (MediaPackageElements.SERIES.equals(catalog.getFlavor())) {
            // Series Title and Identifier
            metadata.setSeriesTitle(dc.getFirst(DublinCore.PROPERTY_TITLE));
            metadata.setSeriesIdentifier(dc.getFirst(DublinCore.PROPERTY_IDENTIFIER));
        } else {
            logger.debug("Excluding unknown catalog flavor '{}' from the top level metadata of mediapackage '{}'", catalog.getFlavor(), mp.getIdentifier());
        }
    }
    return metadata;
}
Also used : ArrayList(java.util.ArrayList) MediapackageMetadataImpl(org.opencastproject.metadata.api.MediapackageMetadataImpl) Catalog(org.opencastproject.mediapackage.Catalog)

Example 2 with MediapackageMetadataImpl

use of org.opencastproject.metadata.api.MediapackageMetadataImpl in project opencast by opencast.

the class MetadataExtractionTest method setUp.

@Before
public void setUp() throws Exception {
    // set up service
    service = new WorkflowServiceImpl();
    // set up mock metadata and metadata service providing it
    metadata = new MediapackageMetadataImpl();
    metadata.setTitle(TITLE);
    metadata.setSeriesTitle(SERIES);
    metadataService = EasyMock.createNiceMock(MediaPackageMetadataService.class);
    EasyMock.expect(metadataService.getMetadata((MediaPackage) EasyMock.anyObject())).andReturn(metadata);
    EasyMock.replay(metadataService);
    service.addMetadataService(metadataService);
}
Also used : MediaPackageMetadataService(org.opencastproject.metadata.api.MediaPackageMetadataService) MediapackageMetadataImpl(org.opencastproject.metadata.api.MediapackageMetadataImpl) Before(org.junit.Before)

Aggregations

MediapackageMetadataImpl (org.opencastproject.metadata.api.MediapackageMetadataImpl)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Catalog (org.opencastproject.mediapackage.Catalog)1 MediaPackageMetadataService (org.opencastproject.metadata.api.MediaPackageMetadataService)1