diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorker.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorker.java index 64ddd692da6aff30e5b49feb5a26ed41c03830fe..8cbddd6bdb784b0c9943cff81a247103173c84c1 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorker.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorker.java @@ -472,6 +472,10 @@ final class SampleListingWorker extends AbstractLister private Iterable<SampleRecord> tryGetIteratorForParentSamples() { Collection<Long> ids = criteria.getChildrenSampleIds(); + if (ids.isEmpty()) + { + return null; + } return query.getParentSamplesForChildren(parentRelationhipTypeId, new LongOpenHashSet(ids)); } diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ListOrSearchSampleCriteria.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ListOrSearchSampleCriteria.java index 32e25a3d3aa535f94f01c8a9ffd24be959fe1832..272dce2175a5437e78fd5734d87dc02331849c25 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ListOrSearchSampleCriteria.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ListOrSearchSampleCriteria.java @@ -171,7 +171,7 @@ public final class ListOrSearchSampleCriteria extends ListSampleCriteria { if (listCriteria == null) { - return null; + return Collections.<Long>emptySet(); } Collection<Long> childrenSampleIds = listCriteria.getChildrenSampleIds(); if (childrenSampleIds != null) @@ -183,10 +183,7 @@ public final class ListOrSearchSampleCriteria extends ListSampleCriteria { return Collections.<Long>emptySet(); } - else - { - return Collections.<Long>singleton(childSampleId.getId()); - } + return Collections.<Long>singleton(childSampleId.getId()); } @Override diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorkerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorkerTest.java index 2bc20b5d9caddac71112b2009ae3331db486b595..733be13a729a9764acf51c657eccf3b44a841eff 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorkerTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/samplelister/SampleListingWorkerTest.java @@ -177,6 +177,34 @@ public class SampleListingWorkerTest extends AbstractDAOTest checkSpace(s); } } + + @Test + public void testListSamplesForChildren() + { + final ListSampleCriteria baseCriteria = + ListSampleCriteria.createForChildren(Arrays.asList(CHILDREN_IDS)); + final ListOrSearchSampleCriteria criteria = new ListOrSearchSampleCriteria(baseCriteria); + final SampleListingWorker worker = + SampleListingWorker.create(criteria, BASE_INDEX_URL, sampleListerDAO, secondaryDAO); + final List<Sample> list = worker.load(); + assertEquals(2, list.size()); + for (Sample s : list) + { + long sId = s.getId().longValue(); + long pId = s.getGeneratedFrom().getId().longValue(); + if (sId == PARENT1_ID) + { + assertTrue(pId == GRANDPARENT1_ID); + } else if (sId == PARENT2_ID) + { + assertTrue(pId == GRANDPARENT2_ID); + } else + { + fail("unexpected parent id " + pId); + } + checkSpace(s); + } + } @Test public void testListSamplesForExperiment()