q.associatedChildGroups.size() == 0 &&
q.usersAssociated.size() == 0 &&
q.usersConnectedByRole.size() == 0 &&
q.usersRelated.size() == 0)
{
throw new QueryException("Not enought information to perform a query. Cannot query groups without at least " +
"group type");
//TODO: extend API for that maybe
}
if (q.groupId != null)
{
uniqueResult = identitySession.getPersistenceManager().
findGroup(q.groupId.getName(), q.groupId.getType());
}
// Process each condition
if (q.associatedParentGroups.size() > 0)
{
for (Group group : q.associatedParentGroups)
{
addAllPreservingDuplicates(resultsAssociatedParentGroups, identitySession.getRelationshipManager().findAssociatedGroups(
group, q.groupType, true, false, q.searchCriteria));
}
}
if (q.associatedChildGroups.size() > 0)
{
for (Group group : q.associatedChildGroups)
{
addAllPreservingDuplicates(resultsAssociatedChildGroups, identitySession.getRelationshipManager().findAssociatedGroups(
group, q.groupType, false, false, q.searchCriteria));
}
}
if (q.usersAssociated.size() > 0)
{
for (User user : q.usersAssociated)
{
addAllPreservingDuplicates(resultsUsersAssociated,identitySession.getRelationshipManager().findAssociatedGroups(
user, q.groupType, q.searchCriteria));
}
}
if (q.usersRelated.size() > 0)
{
for (User user : q.usersRelated)
{
addAllPreservingDuplicates(resultsUsersRelated, identitySession.getRelationshipManager().
findRelatedGroups(user, q.groupType, q.searchCriteria));
}
}
if (q.usersConnectedByRole.size() > 0)
{
for (User user : q.usersConnectedByRole)
{
addAllPreservingDuplicates(resultsUsersConnectedByRole, identitySession.getRoleManager().
findGroupsWithRelatedRole(user, q.groupType, q.searchCriteria));
}
}
// If only one search was performed then return it as search criteria are applied correctly
if (q.groupId == null &&
uniqueResult == null &&
q.associatedChildGroups.size() == 0 &&
resultsAssociatedChildGroups.size() == 0 &&
q.associatedParentGroups.size() == 0 &&
resultsAssociatedParentGroups.size() == 0 &&
q.usersAssociated.size() == 0 &&
resultsUsersAssociated.size() == 0 &&
q.usersConnectedByRole.size() == 0 &&
resultsUsersConnectedByRole.size() == 0 &&
q.usersRelated.size() == 0 &&
resultsUsersRelated.size() == 0)
{
return mainResults;
}
else if (q.groupId != null &&
uniqueResult != null &&
q.associatedChildGroups.size() == 0 &&
resultsAssociatedChildGroups.size() == 0 &&
q.associatedParentGroups.size() == 0 &&
resultsAssociatedParentGroups.size() == 0 &&
q.usersAssociated.size() == 0 &&
resultsUsersAssociated.size() == 0 &&
q.usersConnectedByRole.size() == 0 &&
resultsUsersConnectedByRole.size() == 0 &&
q.usersRelated.size() == 0 &&
resultsUsersRelated.size() == 0)
{
mainResults.add(uniqueResult);
IdentitySearchCriteriaImpl.applyCriteria(identitySession, q.searchCriteria, mainResults);
return mainResults;
}
else if (q.groupId == null &&
uniqueResult == null &&
q.associatedChildGroups.size() != 0 &&
resultsAssociatedChildGroups.size() != 0 &&
q.associatedParentGroups.size() == 0 &&
resultsAssociatedParentGroups.size() == 0 &&
q.usersAssociated.size() == 0 &&
resultsUsersAssociated.size() == 0 &&
q.usersConnectedByRole.size() == 0 &&
resultsUsersConnectedByRole.size() == 0 &&
q.usersRelated.size() == 0 &&
resultsUsersRelated.size() == 0)
{
return resultsAssociatedChildGroups;
}
else if (q.groupId == null &&
uniqueResult == null &&
q.associatedChildGroups.size() == 0 &&
resultsAssociatedChildGroups.size() == 0 &&
q.associatedParentGroups.size() != 0 &&
resultsAssociatedParentGroups.size() != 0 &&
q.usersAssociated.size() == 0 &&
resultsUsersAssociated.size() == 0 &&
q.usersConnectedByRole.size() == 0 &&
resultsUsersConnectedByRole.size() == 0 &&
q.usersRelated.size() == 0 &&
resultsUsersRelated.size() == 0)
{
return resultsAssociatedParentGroups;
}
else if (q.groupId == null &&
uniqueResult == null &&
q.associatedChildGroups.size() == 0 &&
resultsAssociatedChildGroups.size() == 0 &&
q.associatedParentGroups.size() == 0 &&
resultsAssociatedParentGroups.size() == 0 &&
q.usersAssociated.size() != 0 &&
resultsUsersAssociated.size() != 0 &&
q.usersConnectedByRole.size() == 0 &&
resultsUsersConnectedByRole.size() == 0 &&
q.usersRelated.size() == 0 &&
resultsUsersRelated.size() == 0)
{
return resultsUsersAssociated;
}
else if (q.groupId == null &&
uniqueResult == null &&
q.associatedChildGroups.size() == 0 &&
resultsAssociatedChildGroups.size() == 0 &&
q.associatedParentGroups.size() == 0 &&
resultsAssociatedParentGroups.size() == 0 &&
q.usersAssociated.size() == 0 &&
resultsUsersAssociated.size() == 0 &&
q.usersConnectedByRole.size() != 0 &&
resultsUsersConnectedByRole.size() != 0 &&
q.usersRelated.size() == 0 &&
resultsUsersRelated.size() == 0)
{
return resultsUsersConnectedByRole;
}
else if (q.groupId == null &&
uniqueResult == null &&
q.associatedChildGroups.size() == 0 &&
resultsAssociatedChildGroups.size() == 0 &&
q.associatedParentGroups.size() == 0 &&
resultsAssociatedParentGroups.size() == 0 &&
q.usersAssociated.size() == 0 &&
resultsUsersAssociated.size() == 0 &&
q.usersConnectedByRole.size() == 0 &&
resultsUsersConnectedByRole.size() == 0 &&
q.usersRelated.size() != 0 &&
resultsUsersRelated.size() != 0)
{
return resultsUsersRelated;
}
// Merge with logical AND
boolean first = true;
if (q.groupId != null)
{
first = false;
mainResults.add(uniqueResult);
}
if (q.associatedChildGroups.size() > 0)
{
if (first)
{
first = false;
mainResults = resultsAssociatedChildGroups;
}
else
{
mainResults = mergeIdentityTypeWithAND(mainResults, resultsAssociatedChildGroups);
}
}
if (q.associatedParentGroups.size() > 0)
{
if (first)
{
first = false;
mainResults = resultsAssociatedParentGroups;
}
else
{
mainResults = mergeIdentityTypeWithAND(mainResults, resultsAssociatedParentGroups);
}
}
if (q.usersAssociated.size() > 0)
{
if (first)
{
first = false;
mainResults = resultsUsersAssociated;
}
else
{
mainResults = mergeIdentityTypeWithAND(mainResults, resultsUsersAssociated);
}
}
if (q.usersConnectedByRole.size() > 0)
{
if (first)
{
first = false;
mainResults = resultsUsersConnectedByRole;
}
else
{
mainResults = mergeIdentityTypeWithAND(mainResults, resultsUsersConnectedByRole);
}
}
if (q.usersRelated.size() > 0)
{
if (first)
{
first = false;
mainResults = resultsUsersRelated;
}
else
{
mainResults = mergeIdentityTypeWithAND(mainResults, resultsUsersRelated);
}
}
IdentitySearchCriteriaImpl.applyCriteria(identitySession, q.searchCriteria, mainResults);
}
catch (Exception e)
{
throw new QueryException("Failed to execute query", e);
}
return mainResults;
}