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