use of org.mycore.oai.pmh.Record in project mycore by MyCoRe-Org.
the class MCROAIObjectManager method getRecord.
public Record getRecord(Header header, MetadataFormat format) {
Element recordElement;
if (header.isDeleted()) {
return new Record(header);
}
try {
recordElement = getJDOMRecord(getMyCoReId(header.getId()), format);
} catch (Exception exc) {
LOGGER.error("unable to get record {} ({})", header.getId(), format.getPrefix(), exc);
return null;
}
Record record = new Record(header);
if (recordElement.getNamespace().equals(OAIConstants.NS_OAI)) {
Element metadataElement = recordElement.getChild("metadata", OAIConstants.NS_OAI);
if (metadataElement != null && !metadataElement.getChildren().isEmpty()) {
Element metadataChild = metadataElement.getChildren().get(0);
record.setMetadata(new SimpleMetadata(metadataChild.detach()));
}
Element aboutElement = recordElement.getChild("about", OAIConstants.NS_OAI);
if (aboutElement != null) {
for (Element aboutChild : aboutElement.getChildren()) {
record.getAboutList().add(aboutChild.detach());
}
}
} else {
// handle as metadata
record.setMetadata(new SimpleMetadata(recordElement));
}
return record;
}
use of org.mycore.oai.pmh.Record in project mycore by MyCoRe-Org.
the class MCROAISearchManager method getRecordListParallel.
private OAIDataList<Record> getRecordListParallel(MCROAISearcher searcher, MCROAIResult result) {
List<Header> headerList = result.list();
int listSize = headerList.size();
Record[] records = new Record[listSize];
@SuppressWarnings("rawtypes") CompletableFuture[] futures = new CompletableFuture[listSize];
MetadataFormat metadataFormat = searcher.getMetadataFormat();
MCRSession mcrSession = MCRSessionMgr.getCurrentSession();
for (int i = 0; i < listSize; i++) {
Header header = headerList.get(i);
int resultIndex = i;
MCRTransactionableRunnable r = new MCRTransactionableRunnable(() -> records[resultIndex] = this.objManager.getRecord(header, metadataFormat), mcrSession);
CompletableFuture<Void> future = CompletableFuture.runAsync(r, executorService);
futures[i] = future;
}
CompletableFuture.allOf(futures).join();
OAIDataList<Record> recordList = new OAIDataList<>();
recordList.addAll(Arrays.asList(records));
return recordList;
}
use of org.mycore.oai.pmh.Record in project mycore by MyCoRe-Org.
the class MCROAISearchManager method getRecordListSequential.
private OAIDataList<Record> getRecordListSequential(MCROAISearcher searcher, MCROAIResult result) {
OAIDataList<Record> recordList = new OAIDataList<>();
result.list().forEach(header -> {
Record record = this.objManager.getRecord(header, searcher.getMetadataFormat());
recordList.add(record);
});
return recordList;
}
use of org.mycore.oai.pmh.Record in project mycore by MyCoRe-Org.
the class MCROAIAdapter method getRecord.
/*
* (non-Javadoc)
* @see org.mycore.oai.pmh.dataprovider.OAIAdapter#getRecord(java.lang.String, org.mycore.oai.pmh.MetadataFormat)
*/
@Override
public Record getRecord(String identifier, MetadataFormat format) throws CannotDisseminateFormatException, IdDoesNotExistException {
// Update set for response header
getSetManager().getDirectList();
Optional<Record> possibleRecord = getSearchManager().getHeader(identifier).map(h -> objectManager.getRecord(h, format));
if (possibleRecord.isPresent()) {
return possibleRecord.get();
}
if (!objectManager.exists(identifier)) {
DeletedRecordPolicy rP = getIdentify().getDeletedRecordPolicy();
if (DeletedRecordPolicy.Persistent.equals(rP)) {
// get deleted item
Record deletedRecord = objectManager.getDeletedRecord(objectManager.getMyCoReId(identifier));
if (deletedRecord != null) {
return deletedRecord;
}
}
}
throw new IdDoesNotExistException(identifier);
}
Aggregations