Skip to content
Snippets Groups Projects
Commit 6a550889 authored by buczekp's avatar buczekp
Browse files

[LMS-2148] simplify API for search using only child/parent subcriteria (no...

[LMS-2148] simplify API for search using only child/parent subcriteria (no need to specify main criteria)

SVN: 20603
parent 7b6b82c7
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment