Search in sources :

Example 11 with SearchResult

use of org.opencastproject.oaipmh.persistence.SearchResult in project opencast by opencast.

the class OaiPmhRepositoryTest method oaiPmhPersistenceMock.

private static OaiPmhDatabase oaiPmhPersistenceMock(SearchResultItem... items) {
    final SearchResult result = EasyMock.createNiceMock(SearchResult.class);
    final List<SearchResultItem> db = list(items);
    EasyMock.expect(result.getItems()).andReturn(db).anyTimes();
    EasyMock.expect(result.size()).andReturn((long) items.length).anyTimes();
    EasyMock.replay(result);
    return new OaiPmhDatabase() {

        @Override
        public void store(MediaPackage mediaPackage, String repository) throws OaiPmhDatabaseException {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void delete(String mediaPackageId, String repository) throws OaiPmhDatabaseException, NotFoundException {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public SearchResult search(Query q) {
            return result;
        }
    };
}
Also used : Query(org.opencastproject.oaipmh.persistence.Query) SearchResultItem(org.opencastproject.oaipmh.persistence.SearchResultItem) MediaPackage(org.opencastproject.mediapackage.MediaPackage) SearchResult(org.opencastproject.oaipmh.persistence.SearchResult) XpathReturnType.returningAString(org.xmlmatchers.xpath.XpathReturnType.returningAString) OaiPmhDatabase(org.opencastproject.oaipmh.persistence.OaiPmhDatabase)

Example 12 with SearchResult

use of org.opencastproject.oaipmh.persistence.SearchResult in project opencast by opencast.

the class ListGenParams method handleGetRecord.

/**
 * Create the "GetRecord" response.
 */
private XmlGen handleGetRecord(final Params p) {
    if (p.getIdentifier().isNone() || p.getMetadataPrefix().isNone()) {
        return createBadArgumentResponse(p);
    } else {
        for (final MetadataProvider metadataProvider : p.getMetadataPrefix().bind(getMetadataProvider)) {
            final SearchResult res = getPersistence().search(queryRepo(getRepositoryId()).mediaPackageId(p.getIdentifier()).build());
            final List<SearchResultItem> items = res.getItems();
            switch(items.size()) {
                case 0:
                    return createIdDoesNotExistResponse(p);
                case 1:
                    final SearchResultItem item = items.get(0);
                    return new OaiVerbXmlGen(OaiPmhRepository.this, p) {

                        @Override
                        public Element create() {
                            // create the metadata for this item
                            Element metadata = metadataProvider.createMetadata(OaiPmhRepository.this, item, p.getSet());
                            return oai(request($a("identifier", p.getIdentifier().get()), metadataPrefixAttr(p)), verb(record(item, metadata)));
                        }
                    };
                default:
                    throw new RuntimeException("ERROR: Search index contains more than one item with id " + p.getIdentifier());
            }
        }
        // no metadata provider found
        return createCannotDisseminateFormatResponse(p);
    }
}
Also used : Element(org.w3c.dom.Element) SearchResultItem(org.opencastproject.oaipmh.persistence.SearchResultItem) SearchResult(org.opencastproject.oaipmh.persistence.SearchResult)

Aggregations

SearchResult (org.opencastproject.oaipmh.persistence.SearchResult)12 SearchResultItem (org.opencastproject.oaipmh.persistence.SearchResultItem)8 MediaPackage (org.opencastproject.mediapackage.MediaPackage)7 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 Job (org.opencastproject.job.api.Job)4 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)4 DistributionException (org.opencastproject.distribution.api.DistributionException)3 Publication (org.opencastproject.mediapackage.Publication)3 OaiPmhDatabaseException (org.opencastproject.oaipmh.persistence.OaiPmhDatabaseException)3 PublicationException (org.opencastproject.publication.api.PublicationException)3 HashSet (java.util.HashSet)2 OaiPmhDatabase (org.opencastproject.oaipmh.persistence.OaiPmhDatabase)2 Query (org.opencastproject.oaipmh.persistence.Query)2 NotFoundException (org.opencastproject.util.NotFoundException)2 URI (java.net.URI)1 Date (java.util.Date)1 Hashtable (java.util.Hashtable)1 Ignore (org.junit.Ignore)1 Catalog (org.opencastproject.mediapackage.Catalog)1