Skip to content

Commit

Permalink
DSC-1455 improve handling of not existings ID and test that findByIds…
Browse files Browse the repository at this point in the history
… consider distinct uuid
  • Loading branch information
abollini committed Jan 12, 2024
1 parent ced78d3 commit 8c1fa8a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1844,7 +1844,7 @@ public boolean isItemListedForUser(Context context, Item item) {
@Override
public Iterator<Item> findByIds(Context context, List<String> ids) throws SQLException {
return itemDAO.findByIds(context,
ids.stream().map(uuid -> UUID.fromString(uuid)).collect(Collectors.toList()));
ids.stream().map(uuid -> UUID.fromString(uuid)).distinct().collect(Collectors.toList()));
}

@Override
Expand Down
11 changes: 10 additions & 1 deletion dspace-api/src/main/java/org/dspace/core/UUIDIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ public UUIDIterator(Context ctx, List<UUID> uuids, Class<T> clazz, AbstractHiber
@Override
protected T computeNext() {
try {
return iterator.hasNext() ? dao.findByID(ctx, clazz, iterator.next()) : endOfData();
if (iterator.hasNext()) {
T item = dao.findByID(ctx, clazz, iterator.next());
if (item != null) {
return item;
} else {
return computeNext();
}
} else {
return endOfData();
}
} catch (SQLException e) {
throw new SQLRuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ public void findAllByIdTest() throws Exception {
getClient(token).perform(get("/api/core/items/search/findAllById")
.param("id",
publicItem1.getID().toString(),
publicItem1.getID().toString(),
UUID.randomUUID().toString(),
publicItem2.getID().toString(),
UUID.randomUUID().toString()
))
Expand Down

0 comments on commit 8c1fa8a

Please sign in to comment.