From e2fd33a0254b27a1cafabc8e96e7d0c4e073fe47 Mon Sep 17 00:00:00 2001 From: kaloyane <kaloyane> Date: Fri, 1 Apr 2011 12:05:07 +0000 Subject: [PATCH] [LMS-2163] fixed + unit test SVN: 20624 --- .../server/logic/WellContentLoader.java | 22 ++++++++++++++++++- .../server/logic/WellContentLoaderTest.java | 16 ++++---------- 2 files changed, 25 insertions(+), 13 deletions(-) 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 7b982c6e84a..b56b6aa5cb8 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 206614d133b..476971ddc86 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) -- GitLab