Skip to content
Snippets Groups Projects
Commit cf09a554 authored by vkovtun's avatar vkovtun
Browse files

SSDM-10226 Made the implementation of search with parents and search with...

SSDM-10226 Made the implementation of search with parents and search with containers more efficient.
parent bcee88a9
No related branches found
No related tags found
No related merge requests found
......@@ -92,45 +92,61 @@ public abstract class AbstractCompositeEntitySearchManager<CRITERIA extends Abst
}
final Set<Long> parentCriteriaIntermediateResults;
final Set<Long> containerCriteriaIntermediateResults;
if (!parentsCriteria.isEmpty())
{
parentCriteriaIntermediateResults = Arrays.stream(IGetRelationshipIdExecutor.RelationshipType.values())
.flatMap(relationshipType ->
{
final Collection<ISearchCriteria> filteredParentsCriteria =
getCriteriaByRelationshipType(parentsCriteria, relationshipType);
// The parents criteria can be or not recursive, they are resolved by a recursive call
final Set<Long> finalParentIds = findFinalRelationshipIds(userId, authorisationInformation,
finalSearchOperator, filteredParentsCriteria, tableMapper);
final Set<Long> finalParentIdsFiltered = filterIDsByUserRights(userId, authorisationInformation,
finalParentIds);
return getChildrenIdsOf(finalParentIdsFiltered, tableMapper,
relationshipType).stream();
}).collect(Collectors.toSet());
final Collection<ISearchCriteria> filteredParentsCriteria =
getCriteriaByRelationshipType(parentsCriteria,
IGetRelationshipIdExecutor.RelationshipType.PARENT_CHILD);
if (!filteredParentsCriteria.isEmpty())
{
final Set<Long> finalParentIds = findFinalRelationshipIds(userId, authorisationInformation,
finalSearchOperator, filteredParentsCriteria, tableMapper);
final Set<Long> finalParentIdsFiltered = filterIDsByUserRights(userId, authorisationInformation,
finalParentIds);
parentCriteriaIntermediateResults = getChildrenIdsOf(finalParentIdsFiltered, tableMapper,
IGetRelationshipIdExecutor.RelationshipType.PARENT_CHILD);
} else
{
parentCriteriaIntermediateResults = null;
}
final Collection<ISearchCriteria> filteredContainersCriteria =
getCriteriaByRelationshipType(parentsCriteria,
IGetRelationshipIdExecutor.RelationshipType.CONTAINER_COMPONENT);
if (!filteredContainersCriteria.isEmpty())
{
final Set<Long> finalContainerIds = findFinalRelationshipIds(userId, authorisationInformation,
finalSearchOperator, filteredContainersCriteria, tableMapper);
final Set<Long> finalContainerIdsFiltered = filterIDsByUserRights(userId, authorisationInformation,
finalContainerIds);
containerCriteriaIntermediateResults = getChildrenIdsOf(finalContainerIdsFiltered, tableMapper,
IGetRelationshipIdExecutor.RelationshipType.CONTAINER_COMPONENT);
} else
{
containerCriteriaIntermediateResults = null;
}
} else
{
parentCriteriaIntermediateResults = null;
containerCriteriaIntermediateResults = null;
}
final Set<Long> childrenCriteriaIntermediateResults;
if (!childrenCriteria.isEmpty())
{
childrenCriteriaIntermediateResults = Arrays.stream(IGetRelationshipIdExecutor.RelationshipType.values())
.flatMap(relationshipType ->
{
final Collection<ISearchCriteria> filteredChildrenCriteria =
getCriteriaByRelationshipType(childrenCriteria, relationshipType);
// The children criteria can be or not recursive, they are resolved by a recursive call
final Set<Long> finalChildrenIds = findFinalRelationshipIds(userId, authorisationInformation,
finalSearchOperator, filteredChildrenCriteria, tableMapper);
final Set<Long> finalChildrenIdsFiltered = filterIDsByUserRights(userId,
authorisationInformation, finalChildrenIds);
return getParentsIdsOf(finalChildrenIdsFiltered, tableMapper,
relationshipType).stream();
}).collect(Collectors.toSet());
final Collection<ISearchCriteria> filteredChildrenCriteria =
getCriteriaByRelationshipType(childrenCriteria,
IGetRelationshipIdExecutor.RelationshipType.PARENT_CHILD);
final Set<Long> finalChildrenIds = findFinalRelationshipIds(userId, authorisationInformation,
finalSearchOperator, filteredChildrenCriteria, tableMapper);
final Set<Long> finalChildrenIdsFiltered = filterIDsByUserRights(userId,
authorisationInformation, finalChildrenIds);
childrenCriteriaIntermediateResults = getParentsIdsOf(finalChildrenIdsFiltered, tableMapper,
IGetRelationshipIdExecutor.RelationshipType.PARENT_CHILD);
} else
{
childrenCriteriaIntermediateResults = null;
......@@ -138,14 +154,20 @@ public abstract class AbstractCompositeEntitySearchManager<CRITERIA extends Abst
// Reaching this point we have the intermediate results of all recursive queries
final Set<Long> results;
if (containsValues(mainCriteriaIntermediateResults) || containsValues(parentCriteriaIntermediateResults) ||
containsValues(childrenCriteriaIntermediateResults))
if (containsValues(mainCriteriaIntermediateResults) || containsValues(parentCriteriaIntermediateResults)
|| containsValues(containerCriteriaIntermediateResults)
|| containsValues(childrenCriteriaIntermediateResults))
{
// If we have results, we merge them
results = mergeResults(finalSearchOperator,
mainCriteriaIntermediateResults != null ? Collections.singleton(mainCriteriaIntermediateResults) : Collections.emptySet(),
childrenCriteriaIntermediateResults != null ? Collections.singleton(childrenCriteriaIntermediateResults) : Collections.emptySet(),
parentCriteriaIntermediateResults != null ? Collections.singleton(parentCriteriaIntermediateResults) : Collections.emptySet());
mainCriteriaIntermediateResults != null
? Collections.singleton(mainCriteriaIntermediateResults) : Collections.emptySet(),
childrenCriteriaIntermediateResults != null
? Collections.singleton(childrenCriteriaIntermediateResults) : Collections.emptySet(),
parentCriteriaIntermediateResults != null
? Collections.singleton(parentCriteriaIntermediateResults) : Collections.emptySet(),
containerCriteriaIntermediateResults != null
? Collections.singleton(containerCriteriaIntermediateResults) : Collections.emptySet());
} else if (mainCriteria.isEmpty() && parentsCriteria.isEmpty() && childrenCriteria.isEmpty())
{
// If we don't have results and criteria are empty, return all.
......
......@@ -49,7 +49,7 @@ public class SampleContainerSearchManager extends AbstractCompositeEntitySearchM
@Override
protected Class<? extends AbstractCompositeSearchCriteria> getParentsSearchCriteriaClass()
{
return SampleParentsSearchCriteria.class;
return null;
}
public Set<Long> searchForIDs(final Long userId, final AuthorisationInformation authorisationInformation,
......@@ -67,7 +67,7 @@ public class SampleContainerSearchManager extends AbstractCompositeEntitySearchM
@Override
protected Class<? extends AbstractCompositeSearchCriteria> getChildrenSearchCriteriaClass()
{
return SampleChildrenSearchCriteria.class;
return null;
}
@Override
......
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