Search in sources :

Example 1 with Item

use of com.lyncode.xoai.dataprovider.model.Item 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 Item

use of com.lyncode.xoai.dataprovider.model.Item in project dataverse by IQSS.

the class XgetRecordHandler method handle.

@Override
public GetRecord handle(OAICompiledRequest parameters) throws OAIException, HandlerException {
    MetadataFormat format = getContext().formatForPrefix(parameters.getMetadataPrefix());
    Item item = getRepository().getItemRepository().getItem(parameters.getIdentifier());
    if (getContext().hasCondition() && !getContext().getCondition().getFilter(getRepository().getFilterResolver()).isItemShown(item))
        throw new IdDoesNotExistException("This context does not include this item");
    if (format.hasCondition() && !format.getCondition().getFilter(getRepository().getFilterResolver()).isItemShown(item))
        throw new CannotDisseminateRecordException("Format not applicable to this item");
    Xrecord record = this.createRecord(parameters, item);
    GetRecord result = new XgetRecord(record);
    return result;
}
Also used : Item(com.lyncode.xoai.dataprovider.model.Item) MetadataFormat(com.lyncode.xoai.dataprovider.model.MetadataFormat) IdDoesNotExistException(com.lyncode.xoai.dataprovider.exceptions.IdDoesNotExistException) CannotDisseminateRecordException(com.lyncode.xoai.dataprovider.exceptions.CannotDisseminateRecordException)

Example 3 with Item

use of com.lyncode.xoai.dataprovider.model.Item 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

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