From 6a550889ffb59ceb34f246f92e75e92105f9b8a9 Mon Sep 17 00:00:00 2001 From: buczekp <buczekp> Date: Thu, 31 Mar 2011 09:14:09 +0000 Subject: [PATCH] [LMS-2148] simplify API for search using only child/parent subcriteria (no need to specify main criteria) SVN: 20603 --- .../business/DetailedSearchManager.java | 22 ++++++++++++++----- .../api/v1/GeneralInformationServiceTest.java | 21 ++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/DetailedSearchManager.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/DetailedSearchManager.java index f3f69c066e5..74e1501b10d 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/DetailedSearchManager.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/DetailedSearchManager.java @@ -32,10 +32,12 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IHibernateSearchDAO; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchAssociationCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchCriterion; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchField; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DetailedSearchSubCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ListOrSearchSampleCriteria; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Sample; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.SampleAttributeSearchFieldKind; import ch.systemsx.cisd.openbis.generic.shared.translator.DtoConverters; /** @@ -95,7 +97,6 @@ public class DetailedSearchManager listParentsChildrenAndFilterParents(childSampleIds, mainSampleIds, filteredSampleIds); } - } else { filteredSampleIds.addAll(mainSampleIds); @@ -106,7 +107,8 @@ public class DetailedSearchManager private void listChildrensParentsAndFilterChildren(final List<Long> allChildrenIds, final List<Long> allParentIds, final Set<Long> filteredChildrenIds) { - Map<Long, Set<Long>> childToParentIds = sampleLister.getChildToParentsIdsMap(allChildrenIds); + Map<Long, Set<Long>> childToParentIds = + sampleLister.getChildToParentsIdsMap(allChildrenIds); for (Entry<Long, Set<Long>> entry : childToParentIds.entrySet()) { Long childId = entry.getKey(); @@ -122,7 +124,8 @@ public class DetailedSearchManager private void listParentsChildrenAndFilterParents(final List<Long> allChildrenIds, final List<Long> allParentIds, final Set<Long> filteredParentIds) { - Map<Long, Set<Long>> parentToChildIds = sampleLister.getParentToChildrenIdsMap(allParentIds); + Map<Long, Set<Long>> parentToChildIds = + sampleLister.getParentToChildrenIdsMap(allParentIds); for (Entry<Long, Set<Long>> entry : parentToChildIds.entrySet()) { Long parentId = entry.getKey(); @@ -138,7 +141,8 @@ public class DetailedSearchManager private void listParentsChildrenAndFilterChildren(final List<Long> allChildrenIds, final List<Long> allParentIds, final Set<Long> filteredChildrenIds) { - Map<Long, Set<Long>> parentToChildIds = sampleLister.getParentToChildrenIdsMap(allParentIds); + Map<Long, Set<Long>> parentToChildIds = + sampleLister.getParentToChildrenIdsMap(allParentIds); for (Set<Long> childrenIds : parentToChildIds.values()) { filteredChildrenIds.addAll(childrenIds); @@ -149,7 +153,8 @@ public class DetailedSearchManager private void listChildrensParentsAndFilterParents(final List<Long> allChildrenIds, final List<Long> allParentIds, final Set<Long> filteredParentsIds) { - Map<Long, Set<Long>> childToParentIds = sampleLister.getChildToParentsIdsMap(allChildrenIds); + Map<Long, Set<Long>> childToParentIds = + sampleLister.getChildToParentsIdsMap(allChildrenIds); for (Set<Long> parentIds : childToParentIds.values()) { filteredParentsIds.addAll(parentIds); @@ -197,6 +202,13 @@ public class DetailedSearchManager { associations.add(findAssociatedEntities(subCriteria)); } + if (subCriterias.isEmpty() && criteria.isEmpty()) + { + // if no criteria were provided find all samples + criteria.getCriteria().add( + new DetailedSearchCriterion(DetailedSearchField + .createAttributeField(SampleAttributeSearchFieldKind.CODE), "*")); + } final List<Long> sampleIds = searchDAO.searchForEntityIds(criteria, DtoConverters.convertEntityKind(EntityKind.SAMPLE), associations); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationServiceTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationServiceTest.java index 030b5ce6207..5b3214d1307 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationServiceTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/systemtest/api/v1/GeneralInformationServiceTest.java @@ -121,6 +121,20 @@ public class GeneralInformationServiceTest extends SystemTestCase fail("result didn't contain sample " + expectedSampleIdentifier); } + @Test(dependsOnMethods = "testSearchForSamples") + public void testSearchForSamplesWithNoCriterion() + { + SearchCriteria sc = new SearchCriteria(); + sc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "*")); + List<Sample> result = generalInformationService.searchForSamples(sessionToken, sc); + + // if no criterion was specified all samples should be returned as well + SearchCriteria scWithNoCriterion = new SearchCriteria(); + List<Sample> resultWithNoCriterion = + generalInformationService.searchForSamples(sessionToken, scWithNoCriterion); + assertEquals(result, resultWithNoCriterion); + } + @Test public void testSearchForSamplesByProperty() { @@ -136,7 +150,6 @@ public class GeneralInformationServiceTest extends SystemTestCase { // Search for Samples with only experiment's code limiting the results SearchCriteria sc = new SearchCriteria(); - sc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "*")); SearchCriteria ec = new SearchCriteria(); ec.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "EXP-TEST-1")); sc.addSubCriteria(SearchSubCriteria.createExperimentCriteria(ec)); @@ -150,7 +163,6 @@ public class GeneralInformationServiceTest extends SystemTestCase { // Search for Samples with only experiment's property limiting the results SearchCriteria sc = new SearchCriteria(); - sc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "*")); SearchCriteria ec = new SearchCriteria(); ec.addMatchClause(MatchClause.createPropertyMatch("DESCRIPTION", "A simple experiment")); sc.addSubCriteria(SearchSubCriteria.createExperimentCriteria(ec)); @@ -163,7 +175,6 @@ public class GeneralInformationServiceTest extends SystemTestCase { // Search for Samples with only parent's code limiting the results SearchCriteria sc = new SearchCriteria(); - sc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "*")); SearchCriteria pc = new SearchCriteria(); pc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "MP002-1")); sc.addSubCriteria(SearchSubCriteria.createSampleParentCriteria(pc)); @@ -176,7 +187,6 @@ public class GeneralInformationServiceTest extends SystemTestCase { // Search for Samples with only child's code limiting the results SearchCriteria sc = new SearchCriteria(); - sc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "*")); SearchCriteria cc = new SearchCriteria(); cc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "3VCP*")); sc.addSubCriteria(SearchSubCriteria.createSampleChildCriteria(cc)); @@ -189,7 +199,6 @@ public class GeneralInformationServiceTest extends SystemTestCase { // Search for Samples with only container's code limiting the results SearchCriteria sc = new SearchCriteria(); - sc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "*")); SearchCriteria cc = new SearchCriteria(); cc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "CL1")); sc.addSubCriteria(SearchSubCriteria.createSampleContainerCriteria(cc)); @@ -206,7 +215,6 @@ public class GeneralInformationServiceTest extends SystemTestCase { // Search for Samples first SearchCriteria sc = new SearchCriteria(); - sc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "*")); List<Sample> result = generalInformationService.searchForSamples(sessionToken, sc); assertEquals(true, result.size() > 1000); // Add experiment criteria limiting results to 7 @@ -228,7 +236,6 @@ public class GeneralInformationServiceTest extends SystemTestCase { // Search for Samples first SearchCriteria sc = new SearchCriteria(); - sc.addMatchClause(MatchClause.createAttributeMatch(MatchClauseAttribute.CODE, "*")); List<Sample> samples = generalInformationService.searchForSamples(sessionToken, sc); List<DataSet> result = generalInformationService.listDataSets(sessionToken, samples); assertEquals(true, result.size() > 0); -- GitLab