Search in sources :

Example 1 with OAIRecord

use of edu.harvard.iq.dataverse.harvest.server.OAIRecord in project dataverse by IQSS.

the class XitemRepository method getItemIdentifiers.

@Override
public ListItemIdentifiersResult getItemIdentifiers(List<ScopedFilter> filters, int offset, int length, String setSpec, Date from, Date until) throws OAIException {
    logger.fine("calling getItemIdentifiers; offset=" + offset + ", length=" + length + ", setSpec=" + setSpec + ", from=" + from + ", until=" + until);
    List<OAIRecord> oaiRecords = recordService.findOaiRecordsBySetName(setSpec, from, until);
    logger.fine("total " + oaiRecords.size() + " returned");
    List<ItemIdentifier> xoaiItems = new ArrayList<>();
    if (oaiRecords != null && !oaiRecords.isEmpty()) {
        for (int i = offset; i < offset + length && i < oaiRecords.size(); i++) {
            OAIRecord record = oaiRecords.get(i);
            xoaiItems.add(new Xitem(record));
        }
        // formatted output in the header:
        if (!StringUtil.isEmpty(setSpec)) {
            addExtraSets(xoaiItems, setSpec, from, until);
        }
        boolean hasMore = offset + length < oaiRecords.size();
        ListItemIdentifiersResult result = new ListItemIdentifiersResult(hasMore, xoaiItems);
        logger.fine("returning result with " + xoaiItems.size() + " items.");
        return result;
    }
    return new ListItemIdentifiersResult(false, xoaiItems);
}
Also used : ItemIdentifier(com.lyncode.xoai.dataprovider.model.ItemIdentifier) OAIRecord(edu.harvard.iq.dataverse.harvest.server.OAIRecord) ArrayList(java.util.ArrayList) ListItemIdentifiersResult(com.lyncode.xoai.dataprovider.handlers.results.ListItemIdentifiersResult)

Example 2 with OAIRecord

use of edu.harvard.iq.dataverse.harvest.server.OAIRecord in project dataverse by IQSS.

the class XitemRepository method getItem.

@Override
public Item getItem(String identifier) throws IdDoesNotExistException, OAIException {
    logger.fine("getItem; calling findOaiRecordsByGlobalId, identifier " + identifier);
    List<OAIRecord> oaiRecords = recordService.findOaiRecordsByGlobalId(identifier);
    if (oaiRecords != null && !oaiRecords.isEmpty()) {
        Xitem xoaiItem = null;
        for (OAIRecord record : oaiRecords) {
            if (xoaiItem == null) {
                Dataset dataset = datasetService.findByGlobalId(record.getGlobalId());
                if (dataset != null) {
                    xoaiItem = new Xitem(record).withDataset(dataset);
                }
            } else {
                // is part of multiple sets:
                if (!StringUtil.isEmpty(record.getSetName())) {
                    xoaiItem.getSets().add(new Set(record.getSetName()));
                }
            }
        }
        if (xoaiItem != null) {
            return xoaiItem;
        }
    }
    throw new IdDoesNotExistException();
}
Also used : Set(com.lyncode.xoai.dataprovider.model.Set) OAIRecord(edu.harvard.iq.dataverse.harvest.server.OAIRecord) Dataset(edu.harvard.iq.dataverse.Dataset) IdDoesNotExistException(com.lyncode.xoai.dataprovider.exceptions.IdDoesNotExistException)

Example 3 with OAIRecord

use of edu.harvard.iq.dataverse.harvest.server.OAIRecord in project dataverse by IQSS.

the class XitemRepository method addExtraSets.

private void addExtraSets(Object xoaiItemsList, String setSpec, Date from, Date until) {
    List<Xitem> xoaiItems = (List<Xitem>) xoaiItemsList;
    List<OAIRecord> oaiRecords = recordService.findOaiRecordsNotInThisSet(setSpec, from, until);
    if (oaiRecords == null || oaiRecords.isEmpty()) {
        return;
    }
    // Make a second pass through the list of xoaiItems already found for this set,
    // and add any other sets in which this item occurs:
    int j = 0;
    for (int i = 0; i < xoaiItems.size(); i++) {
        // fast-forward the second list, until we find a record with this identifier,
        // or until we are past this record (both lists are sorted alphabetically by
        // the identifier:
        Xitem xitem = xoaiItems.get(i);
        while (j < oaiRecords.size() && xitem.getIdentifier().compareTo(oaiRecords.get(j).getGlobalId()) > 0) {
            j++;
        }
        while (j < oaiRecords.size() && xitem.getIdentifier().equals(oaiRecords.get(j).getGlobalId())) {
            xoaiItems.get(i).getSets().add(new Set(oaiRecords.get(j).getSetName()));
            j++;
        }
    }
}
Also used : Set(com.lyncode.xoai.dataprovider.model.Set) OAIRecord(edu.harvard.iq.dataverse.harvest.server.OAIRecord) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with OAIRecord

use of edu.harvard.iq.dataverse.harvest.server.OAIRecord in project dataverse by IQSS.

the class XitemRepository method getItems.

@Override
public ListItemsResults getItems(List<ScopedFilter> filters, int offset, int length, String setSpec, Date from, Date until) throws OAIException {
    logger.fine("calling getItems; offset=" + offset + ", length=" + length + ", setSpec=" + setSpec + ", from=" + from + ", until=" + until);
    List<OAIRecord> oaiRecords = recordService.findOaiRecordsBySetName(setSpec, from, until);
    logger.fine("total " + oaiRecords.size() + " returned");
    List<Item> xoaiItems = new ArrayList<>();
    if (oaiRecords != null && !oaiRecords.isEmpty()) {
        for (int i = offset; i < offset + length && i < oaiRecords.size(); i++) {
            OAIRecord oaiRecord = oaiRecords.get(i);
            Dataset dataset = datasetService.findByGlobalId(oaiRecord.getGlobalId());
            if (dataset != null) {
                Xitem xItem = new Xitem(oaiRecord).withDataset(dataset);
                xoaiItems.add(xItem);
            }
        }
        if (!StringUtil.isEmpty(setSpec)) {
            addExtraSets(xoaiItems, setSpec, from, until);
        }
        boolean hasMore = offset + length < oaiRecords.size();
        ListItemsResults result = new ListItemsResults(hasMore, xoaiItems);
        logger.fine("returning result with " + xoaiItems.size() + " items.");
        return result;
    }
    return new ListItemsResults(false, xoaiItems);
}
Also used : Item(com.lyncode.xoai.dataprovider.model.Item) OAIRecord(edu.harvard.iq.dataverse.harvest.server.OAIRecord) Dataset(edu.harvard.iq.dataverse.Dataset) ArrayList(java.util.ArrayList) ListItemsResults(com.lyncode.xoai.dataprovider.handlers.results.ListItemsResults)

Aggregations

OAIRecord (edu.harvard.iq.dataverse.harvest.server.OAIRecord)4 ArrayList (java.util.ArrayList)3 Set (com.lyncode.xoai.dataprovider.model.Set)2 Dataset (edu.harvard.iq.dataverse.Dataset)2 IdDoesNotExistException (com.lyncode.xoai.dataprovider.exceptions.IdDoesNotExistException)1 ListItemIdentifiersResult (com.lyncode.xoai.dataprovider.handlers.results.ListItemIdentifiersResult)1 ListItemsResults (com.lyncode.xoai.dataprovider.handlers.results.ListItemsResults)1 Item (com.lyncode.xoai.dataprovider.model.Item)1 ItemIdentifier (com.lyncode.xoai.dataprovider.model.ItemIdentifier)1 List (java.util.List)1