Search in sources :

Example 1 with Set

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

the class XlistRecordsHandler method createRecord.

private Record createRecord(OAICompiledRequest parameters, Item item) throws BadArgumentException, CannotDisseminateRecordException, OAIException, NoMetadataFormatsException, CannotDisseminateFormatException {
    MetadataFormat format = getContext().formatForPrefix(parameters.getMetadataPrefix());
    Header header = new Header();
    Dataset dataset = ((Xitem) item).getDataset();
    Xrecord xrecord = new Xrecord().withFormatName(parameters.getMetadataPrefix()).withDataset(dataset);
    header.withIdentifier(item.getIdentifier());
    ItemHelper itemHelperWrap = new ItemHelper(item);
    header.withDatestamp(item.getDatestamp());
    for (Set set : itemHelperWrap.getSets(getContext(), getRepository().getFilterResolver())) header.withSetSpec(set.getSpec());
    if (item.isDeleted())
        header.withStatus(Header.Status.DELETED);
    xrecord.withHeader(header);
    xrecord.withMetadata(item.getMetadata());
    return xrecord;
}
Also used : ItemHelper(com.lyncode.xoai.dataprovider.handlers.helpers.ItemHelper) MetadataFormat(com.lyncode.xoai.dataprovider.model.MetadataFormat) Set(com.lyncode.xoai.dataprovider.model.Set) Dataset(edu.harvard.iq.dataverse.Dataset)

Example 2 with Set

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

the class XgetRecordHandler method createRecord.

private Xrecord createRecord(OAICompiledRequest parameters, Item item) throws BadArgumentException, CannotDisseminateRecordException, OAIException, NoMetadataFormatsException, CannotDisseminateFormatException {
    MetadataFormat format = getContext().formatForPrefix(parameters.getMetadataPrefix());
    Header header = new Header();
    Dataset dataset = ((Xitem) item).getDataset();
    Xrecord xrecord = new Xrecord().withFormatName(parameters.getMetadataPrefix()).withDataset(dataset);
    header.withIdentifier(item.getIdentifier());
    ItemHelper itemHelperWrap = new ItemHelper(item);
    header.withDatestamp(item.getDatestamp());
    for (Set set : itemHelperWrap.getSets(getContext(), getRepository().getFilterResolver())) header.withSetSpec(set.getSpec());
    if (item.isDeleted())
        header.withStatus(Header.Status.DELETED);
    xrecord.withHeader(header);
    xrecord.withMetadata(item.getMetadata());
    return xrecord;
}
Also used : ItemHelper(com.lyncode.xoai.dataprovider.handlers.helpers.ItemHelper) MetadataFormat(com.lyncode.xoai.dataprovider.model.MetadataFormat) Set(com.lyncode.xoai.dataprovider.model.Set) Dataset(edu.harvard.iq.dataverse.Dataset)

Example 3 with Set

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

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

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

the class XsetRepository method retrieveSets.

@Override
public ListSetsResult retrieveSets(int offset, int length) {
    logger.fine("calling retrieveSets()");
    List<OAISet> dataverseOAISets = setService.findAll();
    List<Set> XOAISets = new ArrayList<Set>();
    if (dataverseOAISets != null) {
        for (int i = 0; i < dataverseOAISets.size(); i++) {
            OAISet dataverseSet = dataverseOAISets.get(i);
            Set xoaiSet = new Set(dataverseSet.getSpec());
            xoaiSet.withName(dataverseSet.getName());
            XOAIMetadata xMetadata = new XOAIMetadata();
            Element element = new Element("description");
            element.withField("description", dataverseSet.getDescription());
            xMetadata.getElements().add(element);
            xoaiSet.withDescription(xMetadata);
            XOAISets.add(xoaiSet);
        }
    }
    return new ListSetsResult(offset + length < XOAISets.size(), XOAISets.subList(offset, Math.min(offset + length, XOAISets.size())));
}
Also used : Set(com.lyncode.xoai.dataprovider.model.Set) OAISet(edu.harvard.iq.dataverse.harvest.server.OAISet) ListSetsResult(com.lyncode.xoai.dataprovider.handlers.results.ListSetsResult) Element(com.lyncode.xoai.model.xoai.Element) ArrayList(java.util.ArrayList) XOAIMetadata(com.lyncode.xoai.model.xoai.XOAIMetadata) OAISet(edu.harvard.iq.dataverse.harvest.server.OAISet)

Aggregations

Set (com.lyncode.xoai.dataprovider.model.Set)5 Dataset (edu.harvard.iq.dataverse.Dataset)3 ItemHelper (com.lyncode.xoai.dataprovider.handlers.helpers.ItemHelper)2 MetadataFormat (com.lyncode.xoai.dataprovider.model.MetadataFormat)2 OAIRecord (edu.harvard.iq.dataverse.harvest.server.OAIRecord)2 ArrayList (java.util.ArrayList)2 IdDoesNotExistException (com.lyncode.xoai.dataprovider.exceptions.IdDoesNotExistException)1 ListSetsResult (com.lyncode.xoai.dataprovider.handlers.results.ListSetsResult)1 Element (com.lyncode.xoai.model.xoai.Element)1 XOAIMetadata (com.lyncode.xoai.model.xoai.XOAIMetadata)1 OAISet (edu.harvard.iq.dataverse.harvest.server.OAISet)1 List (java.util.List)1