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);
}
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();
}
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++;
}
}
}
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);
}
Aggregations