Search in sources :

Example 11 with SearchResultItem

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

the class OaiPmhPersistenceTest method testModifyElement.

@Test
public void testModifyElement() throws Exception {
    oaiPmhDatabase.store(mp1, REPOSITORY_ID_1);
    MediaPackageElement catalog1 = mp1.getElementById("catalog-1");
    catalog1.setURI(URI.create("foo.xml"));
    catalog1.setChecksum(null);
    oaiPmhDatabase.store(mp1, REPOSITORY_ID_1);
    int count = 0;
    for (SearchResultItem searchResultItem : oaiPmhDatabase.search(queryRepo(REPOSITORY_ID_1).mediaPackageId(mp1).build()).getItems()) {
        count++;
        Assert.assertNotNull(searchResultItem.getMediaPackage());
        MediaPackageElement mpe = searchResultItem.getMediaPackage().getElementById("catalog-1");
        Assert.assertNotNull(mpe);
        Assert.assertEquals("foo.xml", mpe.getURI().toString());
    }
    Assert.assertEquals(1, count);
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) SearchResultItem(org.opencastproject.oaipmh.persistence.SearchResultItem) Test(org.junit.Test)

Example 12 with SearchResultItem

use of org.opencastproject.oaipmh.persistence.SearchResultItem 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 13 with SearchResultItem

use of org.opencastproject.oaipmh.persistence.SearchResultItem 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

SearchResultItem (org.opencastproject.oaipmh.persistence.SearchResultItem)13 SearchResult (org.opencastproject.oaipmh.persistence.SearchResult)8 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 MediaPackage (org.opencastproject.mediapackage.MediaPackage)4 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)4 OaiPmhDatabaseException (org.opencastproject.oaipmh.persistence.OaiPmhDatabaseException)4 Job (org.opencastproject.job.api.Job)3 HashSet (java.util.HashSet)2 DistributionException (org.opencastproject.distribution.api.DistributionException)2 Publication (org.opencastproject.mediapackage.Publication)2 OaiPmhDatabase (org.opencastproject.oaipmh.persistence.OaiPmhDatabase)2 Query (org.opencastproject.oaipmh.persistence.Query)2 SearchResultElementItem (org.opencastproject.oaipmh.persistence.SearchResultElementItem)2 PublicationException (org.opencastproject.publication.api.PublicationException)2 XpathReturnType.returningAString (org.xmlmatchers.xpath.XpathReturnType.returningAString)2 URI (java.net.URI)1 Date (java.util.Date)1 Hashtable (java.util.Hashtable)1 NoResultException (javax.persistence.NoResultException)1