Search in sources :

Example 1 with DeletedRecordPolicy

use of org.mycore.oai.pmh.Identify.DeletedRecordPolicy in project mycore by MyCoRe-Org.

the class MCROAIDeletedSearcher method searchDeleted.

/**
 * Returns a list with identifiers of the deleted objects within the given date boundary.
 * If the record policy indicates that there is no support for tracking deleted an empty
 * list is returned.
 *
 * @param from from date
 * @param until to date
 *
 * @return a list with identifiers of the deleted objects
 */
protected List<Header> searchDeleted(Instant from, Instant until) {
    DeletedRecordPolicy deletedRecordPolicy = this.identify.getDeletedRecordPolicy();
    if (from == null || DeletedRecordPolicy.No.equals(deletedRecordPolicy) || DeletedRecordPolicy.Transient.equals(deletedRecordPolicy)) {
        return new ArrayList<>();
    }
    LOGGER.info("Getting identifiers of deleted items");
    Map<MCRObjectID, Instant> deletedItems = MCRMetadataHistoryManager.getDeletedItems(from, Optional.ofNullable(until));
    List<String> types = getConfig().getStrings(getConfigPrefix() + "DeletedRecordTypes", null);
    if (types == null || types.isEmpty()) {
        return deletedItems.entrySet().stream().map(this::toHeader).collect(Collectors.toList());
    }
    return deletedItems.entrySet().stream().filter(e -> types.contains(e.getKey().getTypeId())).map(this::toHeader).collect(Collectors.toList());
}
Also used : DeletedRecordPolicy(org.mycore.oai.pmh.Identify.DeletedRecordPolicy) Instant(java.time.Instant) ArrayList(java.util.ArrayList) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 2 with DeletedRecordPolicy

use of org.mycore.oai.pmh.Identify.DeletedRecordPolicy 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

DeletedRecordPolicy (org.mycore.oai.pmh.Identify.DeletedRecordPolicy)2 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)1 IdDoesNotExistException (org.mycore.oai.pmh.IdDoesNotExistException)1 Record (org.mycore.oai.pmh.Record)1