diff --git a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoader.java b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoader.java index 7b982c6e84a8d2625d80214eb9a80e94f45ad51c..b56b6aa5cb848e8a34f8f17ea7830153f5592c44 100644 --- a/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoader.java +++ b/screening/source/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoader.java @@ -201,11 +201,30 @@ public class WellContentLoader private List<WellContent> loadLocationsAndEnrich(WellSearchCriteria materialCriteria) { List<WellContent> locations = loadLocations(materialCriteria); - List<WellContent> withProperties = enrichWithWellProperties(locations); + List<WellContent> uniqueLocations = filterWellDuplicates(locations); + List<WellContent> withProperties = enrichWithWellProperties(uniqueLocations); List<WellContent> withPropsAndDataSets = enrichWithDatasets(withProperties); return enrichWithFeatureVectors(withPropsAndDataSets); } + private List<WellContent> filterWellDuplicates(List<WellContent> wellContents) + { + Set<String> seenPermIds = new HashSet<String>(); + ArrayList<WellContent> filtered = new ArrayList<WellContent>(); + + for (WellContent content : wellContents) + { + String wellPermId = content.getWell().getPermId(); + if (false == seenPermIds.contains(wellPermId)) + { + seenPermIds.add(wellPermId); + filtered.add(content); + } + } + + return filtered; + } + private List<WellContent> enrichWithWellProperties(List<WellContent> locations) { Map<Long /* id */, WellContent> wellContents = new HashMap<Long/* id */, WellContent>(); @@ -754,6 +773,7 @@ public class WellContentLoader DataIterator<ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.WellContent> locations) { List<WellContent> wellLocations = new ArrayList<WellContent>(); + for (ch.systemsx.cisd.openbis.plugin.screening.server.dataaccess.WellContent location : locations) { wellLocations.add(convert(location)); diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoaderTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoaderTest.java index 206614d133b79ad20eba42b6af98f12f2e07c577..476971ddc86273091d4a044686a804353cea72c4 100644 --- a/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoaderTest.java +++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/plugin/screening/server/logic/WellContentLoaderTest.java @@ -71,19 +71,15 @@ public class WellContentLoaderTest extends AbstractScreeningDAOTest List<WellContent> wellContents = WellContentLoader.load(session, businessObjectFactory, daoFactory, searchCriteria); - // the test database contains two matching wells assertEquals(1, wellContents.size()); - for (WellContent wc : wellContents) - { - assertPropertiesPresent(wc); - } + assertPropertiesPresent(wellContents.get(0)); } /** * Test that the same well is not displayed twice if the search query matches two different * materials inside the well. */ - @Test(enabled = false) + @Test public void testDuplicateWellsFilteredOut() { String[] materialCodes = new String[] @@ -100,12 +96,8 @@ public class WellContentLoaderTest extends AbstractScreeningDAOTest List<WellContent> wellContents = WellContentLoader.load(session, businessObjectFactory, daoFactory, searchCriteria); - // the test database contains two matching wells - assertEquals(2, wellContents.size()); - for (WellContent wc : wellContents) - { - assertPropertiesPresent(wc); - } + assertEquals(1, wellContents.size()); + assertPropertiesPresent(wellContents.get(0)); } private void assertPropertiesPresent(WellContent wellContent)