Search in sources :

Example 1 with ListItemsResults

use of com.lyncode.xoai.dataprovider.handlers.results.ListItemsResults in project dataverse by IQSS.

the class XlistRecordsHandler method handle.

@Override
public ListRecords handle(OAICompiledRequest parameters) throws OAIException, HandlerException {
    XlistRecords res = new XlistRecords();
    int length = getRepository().getConfiguration().getMaxListRecords();
    if (parameters.hasSet() && !getRepository().getSetRepository().supportSets())
        throw new DoesNotSupportSetsException();
    int offset = getOffset(parameters);
    ListItemsResults result;
    if (!parameters.hasSet()) {
        if (parameters.hasFrom() && !parameters.hasUntil())
            result = itemRepositoryHelper.getItems(getContext(), offset, length, parameters.getMetadataPrefix(), parameters.getFrom());
        else if (!parameters.hasFrom() && parameters.hasUntil())
            result = itemRepositoryHelper.getItemsUntil(getContext(), offset, length, parameters.getMetadataPrefix(), parameters.getUntil());
        else if (parameters.hasFrom() && parameters.hasUntil())
            result = itemRepositoryHelper.getItems(getContext(), offset, length, parameters.getMetadataPrefix(), parameters.getFrom(), parameters.getUntil());
        else
            result = itemRepositoryHelper.getItems(getContext(), offset, length, parameters.getMetadataPrefix());
    } else {
        if (!setRepositoryHelper.exists(getContext(), parameters.getSet())) {
        // throw new NoMatchesException();
        }
        if (parameters.hasFrom() && !parameters.hasUntil())
            result = itemRepositoryHelper.getItems(getContext(), offset, length, parameters.getMetadataPrefix(), parameters.getSet(), parameters.getFrom());
        else if (!parameters.hasFrom() && parameters.hasUntil())
            result = itemRepositoryHelper.getItemsUntil(getContext(), offset, length, parameters.getMetadataPrefix(), parameters.getSet(), parameters.getUntil());
        else if (parameters.hasFrom() && parameters.hasUntil())
            result = itemRepositoryHelper.getItems(getContext(), offset, length, parameters.getMetadataPrefix(), parameters.getSet(), parameters.getFrom(), parameters.getUntil());
        else
            result = itemRepositoryHelper.getItems(getContext(), offset, length, parameters.getMetadataPrefix(), parameters.getSet());
    }
    List<Item> results = result.getResults();
    if (results.isEmpty())
        throw new NoMatchesException();
    for (Item i : results) res.withRecord(this.createRecord(parameters, i));
    ResumptionToken.Value currentResumptionToken = new ResumptionToken.Value();
    if (parameters.hasResumptionToken()) {
        currentResumptionToken = parameters.getResumptionToken();
    } else if (result.hasMore()) {
        currentResumptionToken = parameters.extractResumptionToken();
    }
    XresumptionTokenHelper resumptionTokenHelper = new XresumptionTokenHelper(currentResumptionToken, getRepository().getConfiguration().getMaxListRecords());
    res.withResumptionToken(resumptionTokenHelper.resolve(result.hasMore()));
    return res;
}
Also used : Item(com.lyncode.xoai.dataprovider.model.Item) ListItemsResults(com.lyncode.xoai.dataprovider.handlers.results.ListItemsResults)

Example 2 with ListItemsResults

use of com.lyncode.xoai.dataprovider.handlers.results.ListItemsResults 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

ListItemsResults (com.lyncode.xoai.dataprovider.handlers.results.ListItemsResults)2 Item (com.lyncode.xoai.dataprovider.model.Item)2 Dataset (edu.harvard.iq.dataverse.Dataset)1 OAIRecord (edu.harvard.iq.dataverse.harvest.server.OAIRecord)1 ArrayList (java.util.ArrayList)1