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);
}
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;
}
};
}
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);
}
}
Aggregations