diff --git a/src/main/java/org/broadinstitute/consent/http/resources/DatasetResource.java b/src/main/java/org/broadinstitute/consent/http/resources/DatasetResource.java index ea6da2ba75..553dd39fd0 100644 --- a/src/main/java/org/broadinstitute/consent/http/resources/DatasetResource.java +++ b/src/main/java/org/broadinstitute/consent/http/resources/DatasetResource.java @@ -37,6 +37,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.function.Predicate; import java.util.stream.Collectors; import org.apache.commons.collections4.CollectionUtils; import org.broadinstitute.consent.http.enumeration.UserRoles; @@ -481,12 +482,15 @@ public Response getDatasets(@QueryParam("ids") List datasetIds) { .collect(Collectors.toSet()); if (!foundIds.containsAll(datasetIds)) { // find the differences - List differences = new ArrayList<>(datasetIds); - differences.removeAll(foundIds); + List differences = new ArrayList<>(datasetIds) + .stream() + .filter(Objects::nonNull) + .filter(Predicate.not(foundIds::contains)) + .toList(); throw new NotFoundException( "Could not find datasets with ids: " + String.join(",", - differences.stream().map((i) -> i.toString()).collect(Collectors.toSet()))); + differences.stream().map(Object::toString).collect(Collectors.toSet()))); } return Response.ok(datasets).build(); diff --git a/src/test/java/org/broadinstitute/consent/http/resources/DatasetResourceTest.java b/src/test/java/org/broadinstitute/consent/http/resources/DatasetResourceTest.java index 6190d7b2f7..3f59d33f61 100644 --- a/src/test/java/org/broadinstitute/consent/http/resources/DatasetResourceTest.java +++ b/src/test/java/org/broadinstitute/consent/http/resources/DatasetResourceTest.java @@ -712,6 +712,29 @@ void testGetDatasetsNotFound() { assertFalse(((Error) response.getEntity()).message().contains("1")); } + @Test + void testGetDatasetsNotFoundNullValues() { + Dataset ds1 = new Dataset(); + ds1.setDataSetId(1); + Dataset ds3 = new Dataset(); + ds3.setDataSetId(3); + + when(datasetService.findDatasetsByIds(any())).thenReturn(List.of( + ds1, + ds3 + )); + + initResource(); + List input = new ArrayList<>(List.of(1, 2, 3, 4)); + input.add(null); + Response response = resource.getDatasets(input); + assertEquals(HttpStatusCodes.STATUS_CODE_NOT_FOUND, response.getStatus()); + assertTrue(((Error) response.getEntity()).message().contains("4")); + assertFalse(((Error) response.getEntity()).message().contains("3")); + assertTrue(((Error) response.getEntity()).message().contains("2")); + assertFalse(((Error) response.getEntity()).message().contains("1")); + } + @Test void testUpdateDatasetDataUse_OK() {