-
Notifications
You must be signed in to change notification settings - Fork 487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quick fix for adding extra set names to the ListIdentifiers/ListRecords #3806
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,13 @@ | |
import com.lyncode.xoai.dataprovider.handlers.results.ListItemsResults; | ||
import com.lyncode.xoai.dataprovider.model.Item; | ||
import com.lyncode.xoai.dataprovider.model.ItemIdentifier; | ||
import com.lyncode.xoai.dataprovider.model.Set; | ||
import com.lyncode.xoai.dataprovider.repository.ItemRepository; | ||
import edu.harvard.iq.dataverse.Dataset; | ||
import edu.harvard.iq.dataverse.DatasetServiceBean; | ||
import edu.harvard.iq.dataverse.harvest.server.OAIRecord; | ||
import edu.harvard.iq.dataverse.harvest.server.OAIRecordServiceBean; | ||
import edu.harvard.iq.dataverse.util.StringUtil; | ||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
@@ -47,12 +49,26 @@ public XitemRepository (OAIRecordServiceBean recordService, DatasetServiceBean d | |
|
||
@Override | ||
public Item getItem(String identifier) throws IdDoesNotExistException, OAIException { | ||
logger.fine("getItem; calling findOAIRecordBySetNameandGlobalId, identifier " + identifier); | ||
OAIRecord oaiRecord = recordService.findOAIRecordBySetNameandGlobalId(null, identifier); | ||
if (oaiRecord != null) { | ||
Dataset dataset = datasetService.findByGlobalId(oaiRecord.getGlobalId()); | ||
if (dataset != null) { | ||
return new Xitem(oaiRecord).withDataset(dataset); | ||
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 { | ||
// Adding extra set specs to the XOAI Item, if this record | ||
// is part of multiple sets: | ||
if (!StringUtil.isEmpty(record.getSetName())) { | ||
xoaiItem.getSets().add(new Set(record.getSetName())); | ||
} | ||
} | ||
} | ||
if (xoaiItem != null) { | ||
return xoaiItem; | ||
} | ||
} | ||
|
||
|
@@ -113,6 +129,14 @@ public ListItemIdentifiersResult getItemIdentifiers(List<ScopedFilter> filters, | |
OAIRecord record = oaiRecords.get(i); | ||
xoaiItems.add(new Xitem(record)); | ||
} | ||
|
||
// Run a second pass, looking for records in this set that occur | ||
// in *other* sets. Then we'll add these multiple sets to the | ||
// 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."); | ||
|
@@ -180,6 +204,11 @@ public ListItemsResults getItems(List<ScopedFilter> filters, int offset, int len | |
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."); | ||
|
@@ -188,4 +217,36 @@ public ListItemsResults getItems(List<ScopedFilter> filters, int offset, int len | |
|
||
return new ListItemsResults(false, xoaiItems); | ||
} | ||
|
||
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()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the |
||
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++; | ||
} | ||
} | ||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 307, using
as h
is inconsistent with line 291 where theas
is removedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first change requested - yes, it needed to be an "OR" of course, great catch; in practical terms, the way that method was being called, the OAIrecords list was never passed to it when null. So there wouldn't be any nullpointer exceptions right away; but it could definitely bite us in the butt in the future.
The second one... that "as" was definitely meaningless there. It's an old line of code too, imported from pre-Dataverse 4 implementation. So yes, I noticed and removed that "as" in line 291, but not in the other one.
Checked in a change that makes it consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I meant to say, "when null or empty anyway")