Search in sources :

Example 1 with Record

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;
}
Also used : Element(org.jdom2.Element) Record(org.mycore.oai.pmh.Record) SimpleMetadata(org.mycore.oai.pmh.SimpleMetadata)

Example 2 with 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;
}
Also used : OAIDataList(org.mycore.oai.pmh.OAIDataList) CompletableFuture(java.util.concurrent.CompletableFuture) MetadataFormat(org.mycore.oai.pmh.MetadataFormat) MCRSession(org.mycore.common.MCRSession) Header(org.mycore.oai.pmh.Header) Record(org.mycore.oai.pmh.Record) MCRTransactionableRunnable(org.mycore.util.concurrent.MCRTransactionableRunnable)

Example 3 with Record

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;
}
Also used : OAIDataList(org.mycore.oai.pmh.OAIDataList) Record(org.mycore.oai.pmh.Record)

Example 4 with Record

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);
}
Also used : DeletedRecordPolicy(org.mycore.oai.pmh.Identify.DeletedRecordPolicy) IdDoesNotExistException(org.mycore.oai.pmh.IdDoesNotExistException) Record(org.mycore.oai.pmh.Record)

Aggregations

Record (org.mycore.oai.pmh.Record)4 OAIDataList (org.mycore.oai.pmh.OAIDataList)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 Element (org.jdom2.Element)1 MCRSession (org.mycore.common.MCRSession)1 Header (org.mycore.oai.pmh.Header)1 IdDoesNotExistException (org.mycore.oai.pmh.IdDoesNotExistException)1 DeletedRecordPolicy (org.mycore.oai.pmh.Identify.DeletedRecordPolicy)1 MetadataFormat (org.mycore.oai.pmh.MetadataFormat)1 SimpleMetadata (org.mycore.oai.pmh.SimpleMetadata)1 MCRTransactionableRunnable (org.mycore.util.concurrent.MCRTransactionableRunnable)1