Author: bdaw
Date: 2009-05-08 16:46:17 -0400 (Fri, 08 May 2009)
New Revision: 480
Added:
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/GroupQueryBuilder.java
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/QueryBuilder.java
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/RoleQueryBuilder.java
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/UserQueryBuilder.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/AbstractQueryBuilder.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/AbstractQueryExecutor.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/GroupQueryBuilderImpl.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/GroupQueryExecutorImpl.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/RoleQueryBuilderImpl.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/RoleQueryExecutorImpl.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/UserQueryBuilderImpl.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/UserQueryExecutorImpl.java
Modified:
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/IdentitySession.java
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/RelationshipManager.java
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/RoleType.java
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/GroupQuery.java
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/RoleQuery.java
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/UserQuery.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/model/SimpleRole.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/model/SimpleUser.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/AbstractQuery.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/GroupQueryImpl.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/RoleQueryImpl.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/UserQueryImpl.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/session/IdentitySessionImpl.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/session/managers/RelationshipManagerImpl.java
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/session/managers/RoleManagerImpl.java
idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/APITestCase.java
idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/GroupQueryTest.java
idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/RoleQueryTest.java
idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/UserQueryTest.java
Log:
query api refactoring
Modified:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/model/SimpleRole.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/model/SimpleRole.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/model/SimpleRole.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -56,13 +56,47 @@
return group;
}
- public String getDescription()
+ public RoleType getRoleType()
{
- return null;
+ return type;
}
- public RoleType getRoleType()
+ @Override
+ public boolean equals(Object o)
{
- return type;
+ if (this == o)
+ {
+ return true;
+ }
+ if (!(o instanceof SimpleRole))
+ {
+ return false;
+ }
+
+ SimpleRole that = (SimpleRole)o;
+
+ if (group != null ? !group.equals(that.group) : that.group != null)
+ {
+ return false;
+ }
+ if (identity != null ? !identity.equals(that.identity) : that.identity != null)
+ {
+ return false;
+ }
+ if (type != null ? !type.equals(that.type) : that.type != null)
+ {
+ return false;
+ }
+
+ return true;
}
+
+ @Override
+ public int hashCode()
+ {
+ int result = type != null ? type.hashCode() : 0;
+ result = 31 * result + (identity != null ? identity.hashCode() : 0);
+ result = 31 * result + (group != null ? group.hashCode() : 0);
+ return result;
+ }
}
Modified:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/model/SimpleUser.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/model/SimpleUser.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/model/SimpleUser.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -70,4 +70,6 @@
{
return id != null ? id.hashCode() : 0;
}
+
+
}
Modified:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/AbstractQuery.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/AbstractQuery.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/AbstractQuery.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -46,175 +46,41 @@
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
* @version : 0.1 $
*/
-public class AbstractQuery implements Query
+public abstract class AbstractQuery implements Query
{
- //TODO: query should check criteria with features description
- protected IdentitySessionImpl identitySession;
-
protected IdentitySearchCriteriaImpl searchCriteria = new
IdentitySearchCriteriaImpl();
- public AbstractQuery(IdentitySessionImpl identitySession)
+ public AbstractQuery(IdentitySearchCriteriaImpl searchCriteria)
{
- this.identitySession = identitySession;
+ this.searchCriteria = searchCriteria;
}
- public Query sort(SortOrder order) throws UnsupportedQueryCriterium
+ @Override
+ public boolean equals(Object o)
{
- try
+ if (this == o)
{
- searchCriteria.sort(order);
+ return true;
}
- catch (UnsupportedCriterium unsupportedCriterium)
+ if (!(o instanceof AbstractQuery))
{
- throw new UnsupportedQueryCriterium(unsupportedCriterium);
+ return false;
}
- return this;
- }
- public Query sortAttributeName(String name) throws UnsupportedQueryCriterium
- {
- try
- {
- searchCriteria.sortAttributeName(name);
- }
- catch (UnsupportedCriterium unsupportedCriterium)
- {
- throw new UnsupportedQueryCriterium(unsupportedCriterium);
- }
- return this;
- }
+ AbstractQuery that = (AbstractQuery)o;
- public Query page(int firstResult, int maxResults) throws UnsupportedQueryCriterium
- {
- try
+ if (!searchCriteria.equals(that.searchCriteria))
{
- searchCriteria.page(firstResult, maxResults);
+ return false;
}
- catch (UnsupportedCriterium unsupportedCriterium)
- {
- throw new UnsupportedQueryCriterium(unsupportedCriterium);
- }
- return this;
- }
- public Query attributeValuesFilter(String attributeName, String[] attributeValue)
throws UnsupportedQueryCriterium
- {
- try
- {
- searchCriteria.attributeValuesFilter(attributeName, attributeValue);
- }
- catch (UnsupportedCriterium unsupportedCriterium)
- {
- throw new UnsupportedQueryCriterium(unsupportedCriterium);
- }
- return this;
+ return true;
}
-
- protected void checkNotNullArgument(Object arg, String name)
+ @Override
+ public int hashCode()
{
- if (arg == null)
- {
- throw new IllegalArgumentException(name + " cannot be null");
- }
+ return searchCriteria.hashCode();
}
-
- protected Group createGroupFromId(String id)
- {
- return new SimpleGroup(new GroupId(id));
- }
-
- protected IdentityType createIdentityTypeFromId(String id)
- {
- if (GroupId.validateId(id))
- {
- GroupId groupId = new GroupId(id);
-
- return new SimpleGroup(groupId);
- }
- else
- {
- return new SimpleUser(id);
- }
- }
-
- protected List<IdentityType> mergeIdentityTypeWithAND(List<IdentityType>
first, List<IdentityType> second)
- {
- List<IdentityType> results = new LinkedList<IdentityType>();
-
- for (IdentityType identityType : first)
- {
- if (second.contains(identityType))
- {
- results.add(identityType);
- }
- }
-
- return results;
- }
-
- protected List<User> mergeUsersWithAND(List<User> first, List<User>
second)
- {
- List<User> results = new LinkedList<User>();
-
- for (User user : first)
- {
- if (second.contains(user))
- {
- results.add(user);
- }
- }
-
- return results;
- }
-
- protected List<Group> mergeGroupsWithAND(List<Group> first,
List<Group> second)
- {
- List<Group> results = new LinkedList<Group>();
-
- for (Group group : first)
- {
- if (second.contains(group))
- {
- results.add(group);
- }
- }
-
- return results;
- }
-
- protected List<User> applyCriteriaUsers(List<User> users)
- {
-// List<User> results = new LinkedList<User>();
-//
-// // First pass - filters
-// if(searchCriteria.isFiltered())
-// {
-// for (User user : users)
-// {
-// if (searchCriteria.getFilter() != null)
-// {
-//
-// }
-// }
-//
-// }
-
- return users;
- }
-
- protected List<Role> applyCriteriaRoles(List<Role> roles)
- {
- //TODO:
- return roles;
- }
-
- protected List<Group> applyCriteriaGroups(List<Group> roles)
- {
- //TODO:
- return roles;
- }
-
-
}
Added:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/AbstractQueryBuilder.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/AbstractQueryBuilder.java
(rev 0)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/AbstractQueryBuilder.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -0,0 +1,128 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.idm.impl.api.query;
+
+import org.jboss.identity.idm.impl.api.IdentitySearchCriteriaImpl;
+import org.jboss.identity.idm.impl.api.model.SimpleGroup;
+import org.jboss.identity.idm.impl.api.model.GroupId;
+import org.jboss.identity.idm.impl.api.model.SimpleUser;
+import org.jboss.identity.idm.api.query.Query;
+import org.jboss.identity.idm.api.query.UnsupportedQueryCriterium;
+import org.jboss.identity.idm.api.query.QueryBuilder;
+import org.jboss.identity.idm.api.SortOrder;
+import org.jboss.identity.idm.api.UnsupportedCriterium;
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.IdentityType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class AbstractQueryBuilder implements QueryBuilder
+{
+
+ //TODO: query should check criteria with features description
+
+ protected IdentitySearchCriteriaImpl searchCriteria = new
IdentitySearchCriteriaImpl();
+
+ public QueryBuilder sort(SortOrder order) throws UnsupportedQueryCriterium
+ {
+ try
+ {
+ searchCriteria.sort(order);
+ }
+ catch (UnsupportedCriterium unsupportedCriterium)
+ {
+ throw new UnsupportedQueryCriterium(unsupportedCriterium);
+ }
+ return this;
+ }
+
+ public QueryBuilder sortAttributeName(String name) throws UnsupportedQueryCriterium
+ {
+ try
+ {
+ searchCriteria.sortAttributeName(name);
+ }
+ catch (UnsupportedCriterium unsupportedCriterium)
+ {
+ throw new UnsupportedQueryCriterium(unsupportedCriterium);
+ }
+ return this;
+ }
+
+ public QueryBuilder page(int firstResult, int maxResults) throws
UnsupportedQueryCriterium
+ {
+ try
+ {
+ searchCriteria.page(firstResult, maxResults);
+ }
+ catch (UnsupportedCriterium unsupportedCriterium)
+ {
+ throw new UnsupportedQueryCriterium(unsupportedCriterium);
+ }
+ return this;
+ }
+
+ public QueryBuilder attributeValuesFilter(String attributeName, String[]
attributeValue) throws UnsupportedQueryCriterium
+ {
+ try
+ {
+ searchCriteria.attributeValuesFilter(attributeName, attributeValue);
+ }
+ catch (UnsupportedCriterium unsupportedCriterium)
+ {
+ throw new UnsupportedQueryCriterium(unsupportedCriterium);
+ }
+ return this;
+ }
+
+
+ protected void checkNotNullArgument(Object arg, String name)
+ {
+ if (arg == null)
+ {
+ throw new IllegalArgumentException(name + " cannot be null");
+ }
+ }
+
+ protected Group createGroupFromId(String id)
+ {
+ return new SimpleGroup(new GroupId(id));
+ }
+
+ protected IdentityType createIdentityTypeFromId(String id)
+ {
+ if (GroupId.validateId(id))
+ {
+ GroupId groupId = new GroupId(id);
+
+ return new SimpleGroup(groupId);
+ }
+ else
+ {
+ return new SimpleUser(id);
+ }
+ }
+
+}
Added:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/AbstractQueryExecutor.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/AbstractQueryExecutor.java
(rev 0)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/AbstractQueryExecutor.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -0,0 +1,323 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.idm.impl.api.query;
+
+import org.jboss.identity.idm.api.IdentityType;
+import org.jboss.identity.idm.api.User;
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.Role;
+import org.jboss.identity.idm.api.IdentitySession;
+import org.jboss.identity.idm.api.Attribute;
+import org.jboss.identity.idm.spi.search.IdentityObjectSearchCriteria;
+import org.jboss.identity.idm.spi.model.IdentityObject;
+import org.jboss.identity.idm.impl.helper.Tools;
+
+import java.util.List;
+import java.util.LinkedList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public abstract class AbstractQueryExecutor
+{
+
+ protected IdentitySession identitySession;
+
+ protected AbstractQueryExecutor(IdentitySession identitySession)
+ {
+ this.identitySession = identitySession;
+ }
+
+ protected <T extends IdentityType> List<T>
mergeIdentityTypeWithAND(List<T> first, List<T> second)
+ {
+ List<T> results = new LinkedList<T>();
+
+ for (T identityType : first)
+ {
+ if (second.contains(identityType))
+ {
+ results.add(identityType);
+ }
+ }
+
+ return results;
+ }
+
+ protected <T extends IdentityType> void
addAllPreservingDuplicates(Collection<T> first, Collection<T> second)
+ {
+ for (T t : second)
+ {
+ if (!first.contains(t))
+ {
+ first.add(t);
+ }
+ }
+ }
+
+
+ protected <T extends IdentityType> List<T>
applyCriteria(IdentityObjectSearchCriteria criteria, List<T> types) throws
Exception
+ {
+
+ // First pass - filters
+
+ if(criteria.isFiltered())
+ {
+ if (criteria.getFilter() != null)
+ {
+ filterByIdFilter(types, criteria.getFilter());
+ }
+
+ if (criteria.getValues() != null && criteria.getValues().size() > 0)
+ {
+ filterByAttributesValues(types, criteria.getValues());
+ }
+
+ }
+
+ // Second pass - sort
+
+ if (criteria.isSorted())
+ {
+ if (criteria.getSortAttributeName() != null)
+ {
+ sortByAttributeName(types, criteria.getSortAttributeName(),
criteria.isAscending());
+ }
+ else
+ {
+ sortByName(types, criteria.isAscending());
+ }
+ }
+
+ List<T> results = types;
+
+ // Third pass - cut the page
+
+ if (criteria.isPaged())
+ {
+ results = cutPageFromResults(results, criteria);
+ }
+
+ return results;
+ }
+
+ protected List<Role> applyCriteriaRoles(IdentityObjectSearchCriteria criteria,
List<Role> roles)
+ {
+ //TODO: No criteria in RoleQueryBuilder for now...
+
+ return roles;
+ }
+
+ //TODO: quick impl. should be reviewed
+ private void filterByAttributesValues(Collection<? extends IdentityType> types,
Map<String, String[]> attrs) throws Exception
+ {
+ Set<IdentityType> toRemove = new HashSet<IdentityType>();
+
+ for (IdentityType type : types)
+ {
+ //TODO: AttributeManager should have .getAttributes(type, names) to improve and
not obtain everything
+ Map<String, Attribute> presentAttrs =
identitySession.getAttributesManager().getAttributes(type);
+
+ for (Map.Entry<String, String[]> entry : attrs.entrySet())
+ {
+ if (presentAttrs.containsKey(entry.getKey()))
+ {
+ Set<String> given = new
HashSet<String>(Arrays.asList(entry.getValue()));
+ Attribute attr = presentAttrs.get(entry.getKey());
+
+ Collection present = null;
+
+ if (attr != null)
+ {
+ present = attr.getValues();
+ }
+ else
+ {
+ present = Collections.emptySet();
+ }
+
+ for (String s : given)
+ {
+ if (!present.contains(s))
+ {
+ toRemove.add(type);
+ break;
+ }
+ }
+
+ }
+ else
+ {
+ toRemove.add(type);
+ break;
+
+ }
+ }
+ }
+
+ for (IdentityType type : toRemove)
+ {
+ types.remove(type);
+ }
+
+ }
+
+ //TODO: quick impl. should be reviewed
+ private void filterByIdFilter(List<? extends IdentityType> types, String filter)
throws Exception
+ {
+ Set<IdentityType> toRemove = new HashSet<IdentityType>();
+
+ String regex = Tools.wildcardToRegex(filter);
+
+
+ for (IdentityType type : types)
+ {
+ String id = null;
+
+ if (type instanceof User)
+ {
+ id = type.getId();
+ }
+ else if (type instanceof Group)
+ {
+ id = ((Group)type).getName();
+ }
+ else
+ {
+ // shouldn't happen
+ throw new IllegalStateException();
+ }
+
+ if (!id.matches(regex))
+ {
+ toRemove.add(type);
+ }
+ }
+
+ for (IdentityType type : toRemove)
+ {
+ types.remove(type);
+ }
+
+ }
+
+ private <T extends IdentityType> void sortByName(List<T> objects, final
boolean ascending)
+ {
+ Collections.sort(objects, new Comparator<T>(){
+ public int compare(T o1, T o2)
+ {
+ if (o1 instanceof User && o2 instanceof User)
+ {
+ if (ascending)
+ {
+ return o1.getId().compareTo(o2.getId());
+ }
+ else
+ {
+ return o2.getId().compareTo(o1.getId());
+ }
+ }
+ else
+ {
+ Group g1 = (Group)o1;
+ Group g2 = (Group)o2;
+
+ if (ascending)
+ {
+ return g1.getName().compareTo(g2.getName());
+ }
+ else
+ {
+ return g2.getName().compareTo(g1.getName());
+ }
+
+ }
+ }
+ });
+ }
+
+ private <T extends IdentityType> void sortByAttributeName(List<T> objects,
String attributeName, final boolean ascending)
+ throws Exception
+ {
+
+ //TODO: Check if attribute has "text" type and delegate to name sort if
not
+
+ // Pre fetch attributes
+ final Map<T, String> attributes = new HashMap<T, String>();
+
+ for (T object : objects)
+ {
+ Attribute attr = identitySession.getAttributesManager().getAttribute(object,
attributeName);
+
+ if (attr != null && attr.getValue() != null)
+ {
+ attributes.put(object, attr.getValue().toString());
+ }
+ else
+ {
+ attributes.put(object, "");
+ }
+ }
+
+
+
+ Collections.sort(objects, new Comparator<T>(){
+ public int compare(T o1, T o2)
+ {
+ String a1 = attributes.get(o1);
+ String a2 = attributes.get(o2);
+
+ if (ascending)
+ {
+ return a1.compareTo(a2);
+ }
+ else
+ {
+ return a2.compareTo(a1);
+ }
+ }
+ });
+ }
+
+ //TODO: dummy and inefficient...
+ private <T extends IdentityType> List<T> cutPageFromResults(List<T>
objects, IdentityObjectSearchCriteria criteria)
+ {
+ List<T> results = new LinkedList<T>();
+ for (int i = criteria.getFirstResult(); i < criteria.getFirstResult() +
criteria.getMaxResults(); i++)
+ {
+ if (i < objects.size())
+ {
+ results.add(objects.get(i));
+ }
+ }
+ return results;
+ }
+}
Added:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/GroupQueryBuilderImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/GroupQueryBuilderImpl.java
(rev 0)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/GroupQueryBuilderImpl.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -0,0 +1,299 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.idm.impl.api.query;
+
+import org.jboss.identity.idm.api.query.GroupQueryBuilder;
+import org.jboss.identity.idm.api.query.QueryException;
+import org.jboss.identity.idm.api.query.GroupQuery;
+import org.jboss.identity.idm.api.query.UnsupportedQueryCriterium;
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.User;
+import org.jboss.identity.idm.api.SortOrder;
+import org.jboss.identity.idm.impl.api.model.GroupId;
+import org.jboss.identity.idm.impl.api.model.SimpleGroup;
+import org.jboss.identity.idm.impl.api.model.SimpleUser;
+import org.jboss.identity.idm.impl.api.IdentitySearchCriteriaImpl;
+import org.jboss.identity.idm.impl.NotYetImplementedException;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class GroupQueryBuilderImpl extends AbstractQueryBuilder implements
GroupQueryBuilder
+{
+ private GroupId groupId;
+
+ private String groupName;
+
+ private String groupType;
+
+ private Set<Group> associatedParentGroups = new HashSet<Group>();
+
+ private Set<Group> associatedChildGroups = new HashSet<Group>();
+
+ private Set<User> usersAssociated = new HashSet<User>();
+
+ private Set<User> usersRelated = new HashSet<User>();
+
+ private Set<User> usersConnectedByRole = new HashSet<User>();
+
+ private void prepare()
+ {
+ if (groupId == null && (groupName != null && groupType != null))
+ {
+ groupId = new GroupId(groupName, groupType);
+ }
+
+ }
+
+ public GroupQuery createQuery()
+ {
+ prepare();
+
+ return new GroupQueryImpl(
+ searchCriteria,
+ groupId,
+ groupName,
+ groupType,
+ associatedParentGroups,
+ associatedChildGroups,
+ usersAssociated,
+ usersRelated,
+ usersConnectedByRole);
+ }
+
+ public GroupQueryBuilder reset()
+ {
+ searchCriteria = new IdentitySearchCriteriaImpl();
+ groupId = null;
+ groupName = null;
+ groupType = null;
+ associatedParentGroups = new HashSet<Group>();
+ associatedChildGroups = new HashSet<Group>();
+ usersAssociated = new HashSet<User>();
+ usersRelated = new HashSet<User>();
+ usersConnectedByRole = new HashSet<User>();
+
+ return this;
+ }
+
+ public GroupQueryBuilder setId(String id)
+ {
+ groupId = new GroupId(id);
+ return this;
+ }
+
+ public GroupQueryBuilder setNameAndType(String name, String type)
+ {
+ groupId = new GroupId(name, type);
+ groupName = name;
+ groupType = type;
+
+ return this;
+ }
+
+ public GroupQueryBuilder setName(String name)
+ {
+ checkNotNullArgument(name, "Group name");
+ groupName = name;
+ return this;
+ }
+
+ public GroupQueryBuilder setType(String type)
+ {
+ checkNotNullArgument(type, "Group type");
+ groupType = type;
+ return this;
+ }
+
+ public GroupQueryBuilder addAssociatedGroup(Group group, boolean parent)
+ {
+ checkNotNullArgument(group, "Group");
+ if (parent)
+ {
+ associatedParentGroups.add(group);
+ }
+ else
+ {
+ associatedChildGroups.add(group);
+ }
+ return this;
+ }
+
+ public GroupQueryBuilder addAssociatedGroup(String id, boolean parent)
+ {
+ checkNotNullArgument(id, "Group id");
+
+ Group group = new SimpleGroup(new GroupId(id));
+
+ if (parent)
+ {
+ associatedParentGroups.add(group);
+ }
+ else
+ {
+ associatedChildGroups.add(group);
+ }
+
+
+ return this;
+ }
+
+ public GroupQueryBuilder addAssociatedGroups(Collection<Group> groups, boolean
parent)
+ {
+ checkNotNullArgument(groups, "Groups");
+
+ if (parent)
+ {
+ associatedParentGroups.addAll(groups);
+ }
+ else
+ {
+ associatedChildGroups.addAll(groups);
+ }
+
+ return this;
+ }
+
+ public GroupQueryBuilder addAssociatedGroupsIds(Collection<String> ids, boolean
parent)
+ {
+ checkNotNullArgument(ids, "Groups ids");
+ for (String groupId : ids)
+ {
+ Group group = new SimpleGroup(new GroupId(groupId));
+
+ if (parent)
+ {
+ associatedParentGroups.add(group);
+ }
+ else
+ {
+ associatedChildGroups.add(group);
+ }
+ }
+
+ return this;
+ }
+
+ public GroupQueryBuilder addAssociatedUser(User user)
+ {
+ checkNotNullArgument(user, "User");
+ usersAssociated.add(user);
+ return this;
+ }
+
+ public GroupQueryBuilder addAssociatedUser(String id)
+ {
+ checkNotNullArgument(id, "User id");
+ usersAssociated.add(new SimpleUser(id));
+ return this;
+ }
+
+ public GroupQueryBuilder addAssociatedUsers(Collection<User> users)
+ {
+ checkNotNullArgument(users, "Users");
+ usersAssociated.addAll(users);
+ return this;
+ }
+
+ public GroupQueryBuilder addAssociatedUsersIds(Collection<String> ids)
+ {
+ checkNotNullArgument(ids, "Users ids");
+ for (String id : ids)
+ {
+ usersAssociated.add(new SimpleUser(id));
+ }
+ return this;
+ }
+
+ public GroupQueryBuilder addUserConnectedByRole(User user)
+ {
+ checkNotNullArgument(user, "User");
+ usersConnectedByRole.add(user);
+ return this;
+ }
+
+ public GroupQueryBuilder addUserConnectedByRole(String id)
+ {
+ checkNotNullArgument(id, "User id");
+ usersConnectedByRole.add(new SimpleUser(id));
+ return this;
+ }
+
+ public GroupQueryBuilder addUsersConnectedByRole(Collection<User> users)
+ {
+ checkNotNullArgument(users, "Users");
+ usersConnectedByRole.addAll(users);
+ return this;
+ }
+
+ public GroupQueryBuilder addUsersIdsConnectedByRole(Collection<String> ids)
+ {
+ checkNotNullArgument(ids, "Users ids");
+ for (String id : ids)
+ {
+ usersConnectedByRole.add(new SimpleUser(id));
+ }
+ return this;
+ }
+
+ public GroupQueryBuilder addRelatedUser(User user)
+ {
+ checkNotNullArgument(user, "User");
+ usersRelated.add(user);
+ return this;
+ }
+
+ public GroupQueryBuilder addRelatedUser(String id)
+ {
+ checkNotNullArgument(id, "User id");
+ usersRelated.add(new SimpleUser(id));
+ return this;
+ }
+
+ public GroupQueryBuilder sort(SortOrder order) throws UnsupportedQueryCriterium
+ {
+ return (GroupQueryBuilder)super.sort(order);
+ }
+
+ public GroupQueryBuilder sortAttributeName(String name) throws
UnsupportedQueryCriterium
+ {
+ return (GroupQueryBuilder)super.sortAttributeName(name);
+ }
+
+ public GroupQueryBuilder page(int firstResult, int maxResults) throws
UnsupportedQueryCriterium
+ {
+ return (GroupQueryBuilder)super.page(firstResult, maxResults);
+ }
+
+ public GroupQueryBuilder attributeValuesFilter(String attributeName, String[]
attributeValue) throws UnsupportedQueryCriterium
+ {
+ return (GroupQueryBuilder)super.attributeValuesFilter(attributeName,
attributeValue);
+ }
+
+}
Added:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/GroupQueryExecutorImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/GroupQueryExecutorImpl.java
(rev 0)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/GroupQueryExecutorImpl.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -0,0 +1,361 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.idm.impl.api.query;
+
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.User;
+import org.jboss.identity.idm.api.IdentitySession;
+import org.jboss.identity.idm.api.query.QueryException;
+import org.jboss.identity.idm.impl.NotYetImplementedException;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.LinkedList;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class GroupQueryExecutorImpl extends AbstractQueryExecutor
+{
+
+ public GroupQueryExecutorImpl(IdentitySession identitySession)
+ {
+ super(identitySession);
+ }
+
+ public Collection<Group> execute(GroupQueryImpl q) throws QueryException
+ {
+ List<Group> mainResults = new LinkedList<Group>();
+
+ try
+ {
+ Group uniqueResult = null;
+
+ List<Group> resultsAssociatedParentGroups = new
LinkedList<Group>();
+ List<Group> resultsAssociatedChildGroups = new LinkedList<Group>();
+ List<Group> resultsUsersAssociated = new LinkedList<Group>();
+ List<Group> resultsUsersRelated = new LinkedList<Group>();
+ List<Group> resultsUsersConnectedByRole = new LinkedList<Group>();
+
+ // If no conditions
+
+ if (q.groupId == null &&
+ q.groupName == null &&
+ q.groupType == null &&
+ q.associatedParentGroups.size() == 0 &&
+ 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);
+ applyCriteria(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);
+ }
+ }
+
+ applyCriteria(q.searchCriteria, mainResults);
+ }
+ catch (Exception e)
+ {
+ throw new QueryException("Failed to execute query", e);
+ }
+
+ return mainResults;
+ }
+
+ public Group uniqueResult(GroupQueryImpl groupQuery) throws QueryException
+ {
+ Collection<Group> results = execute(groupQuery);
+
+ if (results.size() > 1)
+ {
+ throw new QueryException("More than one result returned");
+ }
+ else if (results.size() == 1)
+ {
+ return results.iterator().next();
+ }
+
+ return null;
+ }
+
+ public List<Group> list(GroupQueryImpl groupQuery) throws QueryException
+ {
+ Collection<Group> results = execute(groupQuery);
+
+ if (results instanceof List)
+ {
+ return (List<Group>)results;
+ }
+
+ //TODO:
+ throw new NotYetImplementedException();
+ }
+
+
+}
Modified:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/GroupQueryImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/GroupQueryImpl.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/GroupQueryImpl.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -34,6 +34,7 @@
import org.jboss.identity.idm.impl.api.model.GroupId;
import org.jboss.identity.idm.impl.api.model.SimpleGroup;
import org.jboss.identity.idm.impl.api.model.SimpleUser;
+import org.jboss.identity.idm.impl.api.IdentitySearchCriteriaImpl;
import org.jboss.identity.idm.exception.IdentityException;
import java.util.Collection;
@@ -41,6 +42,7 @@
import java.util.Set;
import java.util.HashSet;
import java.util.LinkedList;
+import java.util.Collections;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
@@ -48,438 +50,141 @@
*/
public class GroupQueryImpl extends AbstractQuery implements GroupQuery
{
- private GroupId groupId;
+ public final GroupId groupId;
- private String groupName;
+ public final String groupName;
- private String groupType;
+ public final String groupType;
- private Set<Group> associatedParentGroups = new HashSet<Group>();
+ public final Set<Group> associatedParentGroups;
- private Set<Group> associatedChildGroups = new HashSet<Group>();
+ public final Set<Group> associatedChildGroups;
- private Set<User> usersAssociated = new HashSet<User>();
+ public final Set<User> usersAssociated;
- private Set<User> usersRelated = new HashSet<User>();
+ public final Set<User> usersRelated;
- private Set<User> usersConnectedByRole = new HashSet<User>();
+ public final Set<User> usersConnectedByRole;
- public GroupQueryImpl(IdentitySessionImpl identitySession)
+ public GroupQueryImpl(IdentitySearchCriteriaImpl searchCriteria, GroupId groupId,
String groupName, String groupType, Set<Group> associatedParentGroups,
Set<Group> associatedChildGroups, Set<User> usersAssociated, Set<User>
usersRelated, Set<User> usersConnectedByRole)
{
- super(identitySession);
- }
+ super(searchCriteria);
+ this.groupId = groupId;
+ this.groupName = groupName;
+ this.groupType = groupType;
- public Collection<Group> execute() throws QueryException
- {
- prepare();
-
- List<Group> mainResults = new LinkedList<Group>();
-
- try
+ if (associatedParentGroups != null)
{
- Group uniqueResult = null;
-
- List<Group> resultsAssociatedParentGroups = new
LinkedList<Group>();
- List<Group> resultsAssociatedChildGroups = new LinkedList<Group>();
- List<Group> resultsUsersAssociated = new LinkedList<Group>();
- List<Group> resultsUsersRelated = new LinkedList<Group>();
- List<Group> resultsUsersConnectedByRole = new LinkedList<Group>();
-
- if (groupId != null)
- {
- uniqueResult =
identitySession.getPersistenceManager().findGroup(groupId.getName(), groupId.getType());
- }
-
- // Process each condition
-
- if (associatedParentGroups.size() > 0)
- {
- for (Group group : associatedParentGroups)
- {
-
resultsAssociatedParentGroups.addAll(identitySession.getRelationshipManager().findAssociatedGroups(
- group, groupType, true, false, searchCriteria));
- }
- }
-
- if (associatedChildGroups.size() > 0)
- {
- for (Group group : associatedChildGroups)
- {
-
resultsAssociatedChildGroups.addAll(identitySession.getRelationshipManager().findAssociatedGroups(
- group, groupType, false, false, searchCriteria));
- }
- }
-
-
- if (usersAssociated.size() > 0)
- {
- for (User user : usersAssociated)
- {
-
resultsUsersAssociated.addAll(identitySession.getRelationshipManager().findAssociatedGroups(
- user, groupType, searchCriteria));
- }
- }
-
- if (usersRelated.size() > 0)
- {
- for (User user : usersRelated)
- {
-
resultsUsersRelated.addAll(identitySession.getRelationshipManager().findRelatedGroups(user,
groupType, searchCriteria));
- }
- }
-
- if (usersConnectedByRole.size() > 0)
- {
- for (User user : usersConnectedByRole)
- {
-
resultsUsersConnectedByRole.addAll(identitySession.getRoleManager().findGroupsWithRelatedRole(user,
groupType, searchCriteria));
- }
- }
-
- // If only one search was performed then return it as search criteria are
applied correctly
-
- if (uniqueResult == null &&
- resultsAssociatedChildGroups.size() == 0 &&
- resultsAssociatedParentGroups.size() == 0 &&
- resultsUsersAssociated.size() == 0 &&
- resultsUsersConnectedByRole.size() == 0 &&
- resultsUsersRelated.size() == 0)
- {
- return mainResults;
-
- }
- else if (uniqueResult != null &&
- resultsAssociatedChildGroups.size() == 0 &&
- resultsAssociatedParentGroups.size() == 0 &&
- resultsUsersAssociated.size() == 0 &&
- resultsUsersConnectedByRole.size() == 0 &&
- resultsUsersRelated.size() == 0)
- {
-
- mainResults.add(uniqueResult);
- //TODO: apply constraints...
- return mainResults;
- }
- else if (uniqueResult == null &&
- resultsAssociatedChildGroups.size() != 0 &&
- resultsAssociatedParentGroups.size() == 0 &&
- resultsUsersAssociated.size() == 0 &&
- resultsUsersConnectedByRole.size() == 0 &&
- resultsUsersRelated.size() == 0)
- {
- return resultsAssociatedChildGroups;
-
- }
- else if (uniqueResult == null &&
- resultsAssociatedChildGroups.size() == 0 &&
- resultsAssociatedParentGroups.size() != 0 &&
- resultsUsersAssociated.size() == 0 &&
- resultsUsersConnectedByRole.size() == 0 &&
- resultsUsersRelated.size() == 0)
- {
- return resultsAssociatedParentGroups;
- }
- else if (uniqueResult == null &&
- resultsAssociatedChildGroups.size() == 0 &&
- resultsAssociatedParentGroups.size() == 0 &&
- resultsUsersAssociated.size() != 0 &&
- resultsUsersConnectedByRole.size() == 0 &&
- resultsUsersRelated.size() == 0)
- {
- return resultsUsersAssociated;
- }
- else if (uniqueResult == null &&
- resultsAssociatedChildGroups.size() == 0 &&
- resultsAssociatedParentGroups.size() == 0 &&
- resultsUsersAssociated.size() == 0 &&
- resultsUsersConnectedByRole.size() != 0 &&
- resultsUsersRelated.size() == 0)
- {
- return resultsUsersConnectedByRole;
- }
- else if (uniqueResult == null &&
- resultsAssociatedChildGroups.size() == 0 &&
- resultsAssociatedParentGroups.size() == 0 &&
- resultsUsersAssociated.size() == 0 &&
- resultsUsersConnectedByRole.size() == 0 &&
- resultsUsersRelated.size() != 0)
- {
- return resultsUsersRelated;
- }
-
- // Merge with logical AND
-
- if (uniqueResult != null)
- {
- mainResults.add(uniqueResult);
- }
-
- if (resultsAssociatedChildGroups.size() > 0)
- {
- mainResults = mergeGroupsWithAND(mainResults, resultsAssociatedChildGroups);
- }
-
- if (resultsAssociatedParentGroups.size() > 0)
- {
- mainResults = mergeGroupsWithAND(mainResults,
resultsAssociatedParentGroups);
- }
-
- if (resultsUsersAssociated.size() > 0)
- {
- mainResults = mergeGroupsWithAND(mainResults, resultsUsersAssociated);
- }
-
- if (resultsUsersConnectedByRole.size() > 0)
- {
- mainResults = mergeGroupsWithAND(mainResults, resultsUsersConnectedByRole);
- }
-
- if (resultsUsersRelated.size() > 0);
- {
- mainResults = mergeGroupsWithAND(mainResults, resultsUsersRelated);
- }
-
- mainResults = applyCriteriaGroups(mainResults);
+ this.associatedParentGroups =
Collections.unmodifiableSet(associatedParentGroups);
}
- catch (Exception e)
+ else
{
- throw new QueryException("Failed to execute query", e);
+ this.associatedParentGroups = Collections.emptySet();
}
-
-
- return mainResults;
- }
-
- private void prepare()
- {
- if (groupId == null && (groupName != null && groupType != null))
+ if (associatedChildGroups != null)
{
- groupId = new GroupId(groupName, groupType);
+ this.associatedChildGroups =
Collections.unmodifiableSet(associatedChildGroups);
}
-
- }
-
- public Group uniqueResult() throws QueryException
- {
- Collection<Group> results = execute();
-
- if (results.size() > 1)
+ else
{
- throw new QueryException("More than one result returned");
+ this.associatedChildGroups = Collections.emptySet();
}
- else if (results.size() == 1)
+
+ if (usersAssociated != null)
{
- return results.iterator().next();
+ this.usersAssociated = Collections.unmodifiableSet(usersAssociated);
}
-
- return null;
- }
-
- public List<Group> list() throws QueryException
- {
- Collection<Group> results = execute();
-
- if (results instanceof List)
+ else
{
- return (List<Group>)results;
+ this.usersAssociated = Collections.emptySet();
}
- //TODO:
- throw new NotYetImplementedException();
- }
-
- public GroupQuery setId(String id)
- {
- groupId = new GroupId(id);
- return this;
- }
-
- public GroupQuery setNameAndType(String name, String type)
- {
- groupId = new GroupId(name, type);
- groupName = name;
- groupType = type;
-
- return this;
- }
-
- public GroupQuery setName(String name)
- {
- checkNotNullArgument(name, "Group name");
- groupName = name;
- return this;
- }
-
- public GroupQuery setType(String type)
- {
- checkNotNullArgument(type, "Group type");
- groupType = type;
- return this;
- }
-
- public GroupQuery addAssociatedGroup(Group group, boolean parent)
- {
- checkNotNullArgument(group, "Group");
- if (parent)
+ if (usersRelated != null)
{
- associatedParentGroups.add(group);
+ this.usersRelated = Collections.unmodifiableSet(usersRelated);
}
else
{
- associatedChildGroups.add(group);
+ this.usersRelated = Collections.emptySet();
}
- return this;
- }
- public GroupQuery addAssociatedGroup(String id, boolean parent)
- {
- checkNotNullArgument(id, "Group id");
-
- Group group = new SimpleGroup(new GroupId(id));
-
- if (parent)
+ if (usersConnectedByRole != null)
{
- associatedParentGroups.add(group);
+ this.usersConnectedByRole = Collections.unmodifiableSet(usersConnectedByRole);
}
else
{
- associatedChildGroups.add(group);
+ this.usersConnectedByRole = Collections.emptySet();
}
-
-
- return this;
}
- public GroupQuery addAssociatedGroups(Collection<Group> groups, boolean parent)
+ @Override
+ public boolean equals(Object o)
{
- checkNotNullArgument(groups, "Groups");
-
- if (parent)
+ if (this == o)
{
- associatedParentGroups.addAll(groups);
+ return true;
}
- else
+ if (!(o instanceof GroupQueryImpl))
{
- associatedChildGroups.addAll(groups);
+ return false;
}
-
- return this;
- }
-
- public GroupQuery addAssociatedGroupsIds(Collection<String> ids, boolean
parent)
- {
- checkNotNullArgument(ids, "Groups ids");
- for (String groupId : ids)
+ if (!super.equals(o))
{
- Group group = new SimpleGroup(new GroupId(groupId));
-
- if (parent)
- {
- associatedParentGroups.add(group);
- }
- else
- {
- associatedChildGroups.add(group);
- }
+ return false;
}
- return this;
- }
+ GroupQueryImpl that = (GroupQueryImpl)o;
- public GroupQuery addAssociatedUser(User user)
- {
- checkNotNullArgument(user, "User");
- usersAssociated.add(user);
- return this;
- }
-
- public GroupQuery addAssociatedUser(String id)
- {
- checkNotNullArgument(id, "User id");
- usersAssociated.add(new SimpleUser(id));
- return this;
- }
-
- public GroupQuery addAssociatedUsers(Collection<User> users)
- {
- checkNotNullArgument(users, "Users");
- usersAssociated.addAll(users);
- return this;
- }
-
- public GroupQuery addAssociatedUsersIds(Collection<String> ids)
- {
- checkNotNullArgument(ids, "Users ids");
- for (String id : ids)
+ if (!associatedChildGroups.equals(that.associatedChildGroups))
{
- usersAssociated.add(new SimpleUser(id));
+ return false;
}
- return this;
- }
-
- public GroupQuery addUserConnectedByRole(User user)
- {
- checkNotNullArgument(user, "User");
- usersConnectedByRole.add(user);
- return this;
- }
-
- public GroupQuery addUserConnectedByRole(String id)
- {
- checkNotNullArgument(id, "User id");
- usersConnectedByRole.add(new SimpleUser(id));
- return this;
- }
-
- public GroupQuery addUsersConnectedByRole(Collection<User> users)
- {
- checkNotNullArgument(users, "Users");
- usersConnectedByRole.addAll(users);
- return this;
- }
-
- public GroupQuery addUsersIdsConnectedByRole(Collection<String> ids)
- {
- checkNotNullArgument(ids, "Users ids");
- for (String id : ids)
+ if (!associatedParentGroups.equals(that.associatedParentGroups))
{
- usersConnectedByRole.add(new SimpleUser(id));
+ return false;
}
- return this;
- }
+ if (groupId != null ? !groupId.equals(that.groupId) : that.groupId != null)
+ {
+ return false;
+ }
+ if (groupName != null ? !groupName.equals(that.groupName) : that.groupName !=
null)
+ {
+ return false;
+ }
+ if (groupType != null ? !groupType.equals(that.groupType) : that.groupType !=
null)
+ {
+ return false;
+ }
+ if (!usersAssociated.equals(that.usersAssociated))
+ {
+ return false;
+ }
+ if (!usersConnectedByRole.equals(that.usersConnectedByRole))
+ {
+ return false;
+ }
+ if (!usersRelated.equals(that.usersRelated))
+ {
+ return false;
+ }
- public GroupQuery addRelatedUser(User user)
- {
- checkNotNullArgument(user, "User");
- usersRelated.add(user);
- return this;
+ return true;
}
- public GroupQuery addRelatedUser(String id)
+ @Override
+ public int hashCode()
{
- checkNotNullArgument(id, "User id");
- usersRelated.add(new SimpleUser(id));
- return this;
+ int result = super.hashCode();
+ result = 31 * result + (groupId != null ? groupId.hashCode() : 0);
+ result = 31 * result + (groupName != null ? groupName.hashCode() : 0);
+ result = 31 * result + (groupType != null ? groupType.hashCode() : 0);
+ result = 31 * result + associatedParentGroups.hashCode();
+ result = 31 * result + associatedChildGroups.hashCode();
+ result = 31 * result + usersAssociated.hashCode();
+ result = 31 * result + usersRelated.hashCode();
+ result = 31 * result + usersConnectedByRole.hashCode();
+ return result;
}
-
- public GroupQuery sort(SortOrder order) throws UnsupportedQueryCriterium
- {
- return (GroupQuery)super.sort(order);
- }
-
- public GroupQuery sortAttributeName(String name) throws UnsupportedQueryCriterium
- {
- return (GroupQuery)super.sortAttributeName(name);
- }
-
- public GroupQuery page(int firstResult, int maxResults) throws
UnsupportedQueryCriterium
- {
- return (GroupQuery)super.page(firstResult, maxResults);
- }
-
- public GroupQuery attributeValuesFilter(String attributeName, String[] attributeValue)
throws UnsupportedQueryCriterium
- {
- return (GroupQuery)super.attributeValuesFilter(attributeName, attributeValue);
- }
}
Added:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/RoleQueryBuilderImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/RoleQueryBuilderImpl.java
(rev 0)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/RoleQueryBuilderImpl.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -0,0 +1,155 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.idm.impl.api.query;
+
+import org.jboss.identity.idm.api.query.RoleQueryBuilder;
+import org.jboss.identity.idm.api.query.RoleQuery;
+import org.jboss.identity.idm.api.query.UnsupportedQueryCriterium;
+import org.jboss.identity.idm.api.User;
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.RoleType;
+import org.jboss.identity.idm.api.IdentityType;
+import org.jboss.identity.idm.api.SortOrder;
+import org.jboss.identity.idm.impl.api.model.SimpleUser;
+import org.jboss.identity.idm.impl.api.model.SimpleGroup;
+import org.jboss.identity.idm.impl.api.model.GroupId;
+import org.jboss.identity.idm.impl.api.model.SimpleRoleType;
+import org.jboss.identity.idm.impl.api.IdentitySearchCriteriaImpl;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class RoleQueryBuilderImpl extends AbstractQueryBuilder implements
RoleQueryBuilder
+{
+
+ private User user;
+
+ private Group group;
+
+ private RoleType roleType;
+
+ public RoleQuery createQuery()
+ {
+ return new RoleQueryImpl(
+ searchCriteria,
+ user,
+ group,
+ roleType
+ );
+ }
+
+ public RoleQueryBuilder reset()
+ {
+ searchCriteria = new IdentitySearchCriteriaImpl();
+ user = null;
+ group = null;
+ roleType = null;
+
+ return this;
+ }
+
+ public RoleQueryBuilder setUser(User user)
+ {
+ checkNotNullArgument(user, "User");
+ this.user = user;
+ return this;
+ }
+
+ public RoleQueryBuilder setUser(String id)
+ {
+ checkNotNullArgument(id, "User id");
+ this.user = new SimpleUser(id);
+ return this;
+ }
+
+ public RoleQueryBuilder setGroup(Group group)
+ {
+ checkNotNullArgument(group, "Group");
+ this.group = group;
+ return this;
+ }
+
+ public RoleQueryBuilder setGroup(String id)
+ {
+ checkNotNullArgument(id, "Group id");
+ this.group = new SimpleGroup(new GroupId(id));
+ return this;
+ }
+
+ public RoleQueryBuilder setRoleType(RoleType roleType)
+ {
+ checkNotNullArgument(roleType, "RoleType");
+ this.roleType = roleType;
+ return this;
+ }
+
+ public RoleQueryBuilder setRoleType(String roleTypeName)
+ {
+ checkNotNullArgument(roleTypeName, "RoleType name");
+ this.roleType = new SimpleRoleType(roleTypeName);
+ return this;
+ }
+
+ public RoleQueryBuilder setIdentityType(IdentityType identityType)
+ {
+ checkNotNullArgument(identityType, "IdentityType");
+ if (identityType instanceof User)
+ {
+ this.user = (User)identityType;
+ }
+ else
+ {
+ this.group = (Group)identityType;
+ }
+ return this;
+ }
+
+ public RoleQueryBuilder setIdentityTypeId(String id)
+ {
+ checkNotNullArgument(id, "IdentityType id");
+ IdentityType identityType = createIdentityTypeFromId(id);
+ return setIdentityType(identityType);
+ }
+
+ public RoleQueryBuilder sort(SortOrder order) throws UnsupportedQueryCriterium
+ {
+ return (RoleQueryBuilder)super.sort(order);
+ }
+
+ public RoleQueryBuilder sortAttributeName(String name) throws
UnsupportedQueryCriterium
+ {
+ return (RoleQueryBuilder)super.sortAttributeName(name);
+ }
+
+ public RoleQueryBuilder page(int firstResult, int maxResults) throws
UnsupportedQueryCriterium
+ {
+ return (RoleQueryBuilder)super.page(firstResult, maxResults);
+ }
+
+ public RoleQueryBuilder attributeValuesFilter(String attributeName, String[]
attributeValue) throws UnsupportedQueryCriterium
+ {
+ return (RoleQueryBuilder)super.attributeValuesFilter(attributeName,
attributeValue);
+ }
+
+}
Added:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/RoleQueryExecutorImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/RoleQueryExecutorImpl.java
(rev 0)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/RoleQueryExecutorImpl.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -0,0 +1,159 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.idm.impl.api.query;
+
+import org.jboss.identity.idm.api.IdentitySession;
+import org.jboss.identity.idm.api.Role;
+import org.jboss.identity.idm.api.RoleType;
+import org.jboss.identity.idm.api.query.QueryException;
+import org.jboss.identity.idm.impl.api.model.SimpleRole;
+import org.jboss.identity.idm.impl.NotYetImplementedException;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.LinkedList;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class RoleQueryExecutorImpl extends AbstractQueryExecutor
+{
+ public RoleQueryExecutorImpl(IdentitySession identitySession)
+ {
+ super(identitySession);
+ }
+
+ public Collection<Role> execute(RoleQueryImpl roleQuery) throws QueryException
+ {
+ List<Role> mainResults = new LinkedList<Role>();
+
+
+ try
+ {
+ // Check all constraints combinations
+
+ if (roleQuery.user == null &&
+ roleQuery.group == null &&
+ roleQuery.roleType == null)
+ {
+ // TODO: return all roles
+
+ return mainResults;
+ }
+ else if (roleQuery.user != null &&
+ roleQuery.group != null &&
+ roleQuery.roleType != null)
+ {
+ Role role = identitySession.getRoleManager().getRole(roleQuery.roleType,
roleQuery.user, roleQuery.group);
+ if (role != null)
+ {
+ mainResults.add(role);
+ }
+ return mainResults;
+
+ }
+ else if (roleQuery.user != null &&
+ roleQuery.group == null &&
+ roleQuery.roleType == null)
+ {
+ return identitySession.getRoleManager().findRoles(roleQuery.user, null);
+ }
+ else if (roleQuery.user != null &&
+ roleQuery.group == null &&
+ roleQuery.roleType != null)
+ {
+ return identitySession.getRoleManager().findRoles(roleQuery.user,
roleQuery.roleType);
+ }
+ else if (roleQuery.user == null &&
+ roleQuery.group != null &&
+ roleQuery.roleType == null)
+ {
+ return identitySession.getRoleManager().findRoles(roleQuery.group, null);
+ }
+ else if (roleQuery.user == null &&
+ roleQuery.group != null &&
+ roleQuery.roleType != null)
+ {
+ return identitySession.getRoleManager().findRoles(roleQuery.group,
roleQuery.roleType);
+ }
+ else if (roleQuery.user == null &&
+ roleQuery.group == null &&
+ roleQuery.roleType != null)
+ {
+ //TODO: reconsider if this should be supported
+ throw new QueryException("Not enought information to perform a query.
Cannot query roles only with a given RoleType");
+ }
+ else if (roleQuery.user != null &&
+ roleQuery.group != null &&
+ roleQuery.roleType == null)
+ {
+ Collection<RoleType> roleTypes = identitySession.getRoleManager().
+ findRoleTypes(roleQuery.user, roleQuery.group, roleQuery.searchCriteria);
+ for (RoleType type : roleTypes)
+ {
+ mainResults.add(new SimpleRole(type, roleQuery.user, roleQuery.group));
+ }
+ return mainResults;
+ }
+ }
+ catch (Exception e)
+ {
+ throw new QueryException("Failed to execute query", e);
+ }
+
+ mainResults = applyCriteriaRoles(roleQuery.searchCriteria, mainResults);
+
+ return mainResults;
+
+ }
+
+ public Role uniqueResult(RoleQueryImpl roleQuery) throws QueryException
+ {
+ Collection<Role> results = execute(roleQuery);
+
+ if (results.size() > 1)
+ {
+ throw new QueryException("More than one result returned");
+ }
+ else if (results.size() == 1)
+ {
+ return results.iterator().next();
+ }
+
+ return null;
+ }
+
+ public List<Role> list(RoleQueryImpl roleQuery) throws QueryException
+ {
+ Collection<Role> results = execute(roleQuery);
+
+ if (results instanceof List)
+ {
+ return (List<Role>)results;
+ }
+
+ //TODO:
+ throw new NotYetImplementedException();
+ }
+}
Modified:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/RoleQueryImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/RoleQueryImpl.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/RoleQueryImpl.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -38,6 +38,7 @@
import org.jboss.identity.idm.impl.api.model.SimpleGroup;
import org.jboss.identity.idm.impl.api.model.SimpleRoleType;
import org.jboss.identity.idm.impl.api.model.SimpleRole;
+import org.jboss.identity.idm.impl.api.IdentitySearchCriteriaImpl;
import org.jboss.identity.idm.impl.NotYetImplementedException;
import org.jboss.identity.idm.exception.IdentityException;
import org.jboss.identity.idm.exception.FeatureNotSupportedException;
@@ -53,207 +54,61 @@
public class RoleQueryImpl extends AbstractQuery implements RoleQuery
{
- private User user;
+ public final User user;
- private Group group;
+ public final Group group;
- private RoleType roleType;
+ public final RoleType roleType;
- public RoleQueryImpl(IdentitySessionImpl identitySession)
+ public RoleQueryImpl(IdentitySearchCriteriaImpl searchCriteria, User user, Group
group, RoleType roleType)
{
- super(identitySession);
+ super(searchCriteria);
+ this.user = user;
+ this.group = group;
+ this.roleType = roleType;
}
- public Collection<Role> execute() throws QueryException
+ @Override
+ public boolean equals(Object o)
{
- List<Role> mainResults = new LinkedList<Role>();
-
-
- try
+ if (this == o)
{
- // Check all constraints combinations
-
- if (user == null &&
- group == null &&
- roleType == null)
- {
- return mainResults;
- }
- else if (user != null &&
- group != null &&
- roleType != null)
- {
- Role role = identitySession.getRoleManager().getRole(roleType, user, group);
- if (role != null)
- {
- mainResults.add(role);
- }
- return mainResults;
-
- }
- else if (user != null &&
- group == null &&
- roleType == null)
- {
- return identitySession.getRoleManager().findRoles(user, null);
- }
- else if (user != null &&
- group == null &&
- roleType != null)
- {
- return identitySession.getRoleManager().findRoles(user, roleType);
- }
- else if (user == null &&
- group != null &&
- roleType == null)
- {
- return identitySession.getRoleManager().findRoles(group, null);
- }
- else if (user == null &&
- group != null &&
- roleType != null)
- {
- return identitySession.getRoleManager().findRoles(group, roleType);
- }
- else if (user == null &&
- group == null &&
- roleType != null)
- {
- //TODO: reconsider if this should be supported
- throw new QueryException("Not enought information to perform a query.
Cannot query roles only with a given RoleType");
- }
- else if (user != null &&
- group != null &&
- roleType == null)
- {
- Collection<RoleType> roleTypes =
identitySession.getRoleManager().findRoleTypes(user, group, searchCriteria);
- for (RoleType type : roleTypes)
- {
- mainResults.add(new SimpleRole(type, user, group));
- }
- return mainResults;
- }
+ return true;
}
- catch (Exception e)
+ if (!(o instanceof RoleQueryImpl))
{
- throw new QueryException("Failed to execute query", e);
+ return false;
}
-
- mainResults = applyCriteriaRoles(mainResults);
-
- return mainResults;
-
- }
-
- public Role uniqueResult() throws QueryException
- {
- Collection<Role> results = execute();
-
- if (results.size() > 1)
+ if (!super.equals(o))
{
- throw new QueryException("More than one result returned");
+ return false;
}
- else if (results.size() == 1)
- {
- return results.iterator().next();
- }
- return null;
- }
+ RoleQueryImpl roleQuery = (RoleQueryImpl)o;
- public List<Role> list() throws QueryException
- {
- Collection<Role> results = execute();
-
- if (results instanceof List)
+ if (group != null ? !group.equals(roleQuery.group) : roleQuery.group != null)
{
- return (List<Role>)results;
+ return false;
}
-
- //TODO:
- throw new NotYetImplementedException();
- }
-
- public RoleQuery setUser(User user)
- {
- checkNotNullArgument(user, "User");
- this.user = user;
- return this;
- }
-
- public RoleQuery setUser(String id)
- {
- checkNotNullArgument(id, "User id");
- this.user = new SimpleUser(id);
- return this;
- }
-
- public RoleQuery setGroup(Group group)
- {
- checkNotNullArgument(group, "Group");
- this.group = group;
- return this;
- }
-
- public RoleQuery setGroup(String id)
- {
- checkNotNullArgument(id, "Group id");
- this.group = new SimpleGroup(new GroupId(id));
- return this;
- }
-
- public RoleQuery setRoleType(RoleType roleType)
- {
- checkNotNullArgument(roleType, "RoleType");
- this.roleType = roleType;
- return this;
- }
-
- public RoleQuery setRoleType(String roleTypeName)
- {
- checkNotNullArgument(roleTypeName, "RoleType name");
- this.roleType = new SimpleRoleType(roleTypeName);
- return this;
- }
-
- public RoleQuery setIdentityType(IdentityType identityType)
- {
- checkNotNullArgument(identityType, "IdentityType");
- if (identityType instanceof User)
+ if (roleType != null ? !roleType.equals(roleQuery.roleType) : roleQuery.roleType !=
null)
{
- this.user = (User)identityType;
+ return false;
}
- else
+ if (user != null ? !user.equals(roleQuery.user) : roleQuery.user != null)
{
- this.group = (Group)identityType;
+ return false;
}
- return this;
- }
- public RoleQuery setIdentityTypeId(String id)
- {
- checkNotNullArgument(id, "IdentityType id");
- IdentityType identityType = createIdentityTypeFromId(id);
- return setIdentityType(identityType);
+ return true;
}
- public RoleQuery sort(SortOrder order) throws UnsupportedQueryCriterium
+ @Override
+ public int hashCode()
{
- return (RoleQuery)super.sort(order);
+ int result = super.hashCode();
+ result = 31 * result + (user != null ? user.hashCode() : 0);
+ result = 31 * result + (group != null ? group.hashCode() : 0);
+ result = 31 * result + (roleType != null ? roleType.hashCode() : 0);
+ return result;
}
-
- public RoleQuery sortAttributeName(String name) throws UnsupportedQueryCriterium
- {
- return (RoleQuery)super.sortAttributeName(name);
- }
-
- public RoleQuery page(int firstResult, int maxResults) throws
UnsupportedQueryCriterium
- {
- return (RoleQuery)super.page(firstResult, maxResults);
- }
-
- public RoleQuery attributeValuesFilter(String attributeName, String[] attributeValue)
throws UnsupportedQueryCriterium
- {
- return (RoleQuery)super.attributeValuesFilter(attributeName, attributeValue);
- }
}
Added:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/UserQueryBuilderImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/UserQueryBuilderImpl.java
(rev 0)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/UserQueryBuilderImpl.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -0,0 +1,191 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.idm.impl.api.query;
+
+import org.jboss.identity.idm.api.query.UserQueryBuilder;
+import org.jboss.identity.idm.api.query.UserQuery;
+import org.jboss.identity.idm.api.query.UnsupportedQueryCriterium;
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.SortOrder;
+import org.jboss.identity.idm.impl.api.IdentitySearchCriteriaImpl;
+
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class UserQueryBuilderImpl extends AbstractQueryBuilder implements
UserQueryBuilder
+{
+ private String userId;
+
+ private Set<Group> groupsAssociatedWith = new HashSet<Group>();
+
+ private Set<Group> groupsConnectedWithRole = new HashSet<Group>();
+
+ private Set<Group> groupsRelated = new HashSet<Group>();
+
+ public UserQuery createQuery()
+ {
+ return new UserQueryImpl(
+ searchCriteria,
+ userId,
+ groupsAssociatedWith,
+ groupsConnectedWithRole,
+ groupsRelated
+ );
+ }
+
+ public UserQueryBuilder reset()
+ {
+ searchCriteria = new IdentitySearchCriteriaImpl();
+ userId = null;
+ groupsAssociatedWith = new HashSet<Group>();
+ groupsConnectedWithRole = new HashSet<Group>();
+ groupsRelated = new HashSet<Group>();
+
+ return this;
+ }
+
+ public UserQueryBuilder withUserId(String id)
+ {
+ checkNotNullArgument(id, "User id");
+ userId = id;
+ return this;
+ }
+
+ public UserQueryBuilder addAssociatedGroup(Group group)
+ {
+ checkNotNullArgument(group, "Group");
+ groupsAssociatedWith.add(group);
+ return this;
+ }
+
+ public UserQueryBuilder addAssociatedGroup(String id)
+ {
+ checkNotNullArgument(id, "Group id");
+ groupsAssociatedWith.add(createGroupFromId(id));
+ return this;
+ }
+
+ public UserQueryBuilder addAssociatedGroups(Collection<Group> groups)
+ {
+ checkNotNullArgument(groups, "Groups");
+ groupsAssociatedWith.addAll(groups);
+ return this;
+ }
+
+ public UserQueryBuilder addAssociatedGroupsIds(Collection<String> groups)
+ {
+ checkNotNullArgument(groups, "Groups");
+ for (String groupId : groups)
+ {
+ groupsAssociatedWith.add(createGroupFromId(groupId));
+ }
+ return this;
+ }
+
+ public UserQueryBuilder addGroupConnectedWithRole(Group group)
+ {
+ checkNotNullArgument(group, "Group");
+ groupsConnectedWithRole.add(group);
+ return this;
+ }
+
+ public UserQueryBuilder addGroupConnectedWithRole(String id)
+ {
+ checkNotNullArgument(id, "Group id");
+ groupsConnectedWithRole.add(createGroupFromId(id));
+ return this;
+ }
+
+ public UserQueryBuilder addGroupsConnectedWithRole(Collection<Group> groups)
+ {
+ checkNotNullArgument(groups, "Groups");
+ groupsConnectedWithRole.addAll(groups);
+ return this;
+ }
+
+ public UserQueryBuilder addGroupsIdsConnectedWithRole(Collection<String>
groups)
+ {
+ checkNotNullArgument(groups, "Groups");
+ for (String groupId : groups)
+ {
+ groupsConnectedWithRole.add(createGroupFromId(groupId));
+ }
+ return this;
+ }
+
+ public UserQueryBuilder addRelatedGroup(Group group)
+ {
+ checkNotNullArgument(group, "Group");
+ groupsRelated.add(group);
+ return this;
+ }
+
+ public UserQueryBuilder addRelatedGroup(String id)
+ {
+ checkNotNullArgument(id, "Group id");
+ groupsRelated.add(createGroupFromId(id));
+ return this;
+ }
+
+ public UserQueryBuilder addRelatedGroups(Collection<Group> group)
+ {
+ checkNotNullArgument(group, "Group");
+ groupsRelated.addAll(group);
+ return this;
+ }
+
+ public UserQueryBuilder addRelatedGroupsIds(Collection<String> ids)
+ {
+ checkNotNullArgument(ids, "Groups ids");
+ for (String id : ids)
+ {
+ groupsRelated.add(createGroupFromId(id));
+ }
+ return this;
+ }
+
+ public UserQueryBuilder sort(SortOrder order) throws UnsupportedQueryCriterium
+ {
+ return (UserQueryBuilder)super.sort(order);
+ }
+
+ public UserQueryBuilder sortAttributeName(String name) throws
UnsupportedQueryCriterium
+ {
+ return (UserQueryBuilder)super.sortAttributeName(name);
+ }
+
+ public UserQueryBuilder page(int firstResult, int maxResults) throws
UnsupportedQueryCriterium
+ {
+ return (UserQueryBuilder)super.page(firstResult, maxResults);
+ }
+
+ public UserQueryBuilder attributeValuesFilter(String attributeName, String[]
attributeValue) throws UnsupportedQueryCriterium
+ {
+ return (UserQueryBuilder)super.attributeValuesFilter(attributeName,
attributeValue);
+ }
+}
Added:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/UserQueryExecutorImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/UserQueryExecutorImpl.java
(rev 0)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/UserQueryExecutorImpl.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -0,0 +1,247 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.idm.impl.api.query;
+
+import org.jboss.identity.idm.api.User;
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.IdentitySession;
+import org.jboss.identity.idm.api.query.QueryException;
+import org.jboss.identity.idm.impl.NotYetImplementedException;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.LinkedList;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public class UserQueryExecutorImpl extends AbstractQueryExecutor
+{
+ public UserQueryExecutorImpl(IdentitySession identitySession)
+ {
+ super(identitySession);
+ }
+
+ public Collection<User> execute(UserQueryImpl q) throws QueryException
+ {
+
+ List<User> resultsMain = new LinkedList<User>();
+
+ try
+ {
+
+ User uniqueUser = null;
+ List<User> resultsAssociatedGroups = new LinkedList<User>();
+ List<User> resultsConnectedWithRoleGroups = new LinkedList<User>();
+ List<User> resultsRelatedGroups = new LinkedList<User>();
+
+ // if no conditions perform full search
+ if (q.userId == null &&
+ q.groupsAssociatedWith.size() == 0 &&
+ q.groupsConnectedWithRole.size() == 0 &&
+ q.groupsRelated.size() == 0)
+ {
+ return identitySession.getPersistenceManager().findUser(q.searchCriteria);
+ }
+
+ // Process each condition separately
+
+ if (q.userId != null)
+ {
+ uniqueUser = identitySession.getPersistenceManager().findUser(q.userId);
+ }
+
+ if (q.groupsAssociatedWith.size() > 0)
+ {
+ for (Group group : q.groupsAssociatedWith)
+ {
+ addAllPreservingDuplicates(resultsAssociatedGroups,
identitySession.getRelationshipManager().
+ findAssociatedUsers(group, false, q.searchCriteria));
+ }
+ }
+
+ if (q.groupsConnectedWithRole.size() > 0)
+ {
+ for (Group group : q.groupsConnectedWithRole)
+ {
+ addAllPreservingDuplicates(resultsConnectedWithRoleGroups,
identitySession.getRoleManager().
+ findUsersWithRelatedRole(group, q.searchCriteria));
+ }
+ }
+
+ if (q.groupsRelated.size() > 0)
+ {
+ for (Group group : q.groupsRelated)
+ {
+ addAllPreservingDuplicates(resultsRelatedGroups,
identitySession.getRelationshipManager().
+ findRelatedUsers(group, q.searchCriteria));
+ }
+ }
+
+ // If only one condition was present just return it
+
+ if (q.userId != null &&
+ uniqueUser != null &&
+ q.groupsAssociatedWith.size() == 0 &&
+ resultsAssociatedGroups.size() == 0 &&
+ q.groupsConnectedWithRole.size() == 0 &&
+ resultsConnectedWithRoleGroups.size() == 0 &&
+ q.groupsRelated.size() == 0 &&
+ resultsRelatedGroups.size() == 0)
+ {
+ resultsMain.add(uniqueUser);
+ resultsMain = applyCriteria(q.searchCriteria, resultsMain);
+ return resultsMain;
+ }
+ else if (q.userId == null &&
+ uniqueUser == null &&
+ q.groupsAssociatedWith.size() > 0 &&
+ resultsAssociatedGroups.size() > 0 &&
+ q.groupsConnectedWithRole.size() == 0 &&
+ resultsConnectedWithRoleGroups.size() == 0 &&
+ q.groupsRelated.size() == 0 &&
+ resultsRelatedGroups.size() == 0)
+ {
+ return resultsAssociatedGroups;
+ }
+ else if (q.userId == null &&
+ uniqueUser == null &&
+ q.groupsAssociatedWith.size() == 0 &&
+ resultsAssociatedGroups.size() == 0 &&
+ q.groupsConnectedWithRole.size() > 0 &&
+ resultsConnectedWithRoleGroups.size() > 0 &&
+ q.groupsRelated.size() == 0 &&
+ resultsRelatedGroups.size() == 0)
+ {
+ return resultsConnectedWithRoleGroups;
+ }
+ else if (q.userId == null &&
+ uniqueUser == null &&
+ q.groupsAssociatedWith.size() == 0 &&
+ resultsAssociatedGroups.size() == 0 &&
+ q.groupsConnectedWithRole.size() == 0 &&
+ resultsConnectedWithRoleGroups.size() == 0 &&
+ q.groupsRelated.size() > 0 &&
+ resultsRelatedGroups.size() > 0)
+ {
+ return resultsRelatedGroups;
+ }
+
+
+ // Merge results with logical AND
+
+ boolean first = true;
+
+ if (q.userId != null && uniqueUser != null)
+ {
+ first = false;
+ resultsMain.add(uniqueUser);
+ }
+
+ if (q.groupsAssociatedWith.size() > 0)
+ {
+ if (first)
+ {
+ resultsMain = resultsAssociatedGroups;
+ first = false;
+
+ }
+ else
+ {
+ resultsMain = mergeIdentityTypeWithAND(resultsMain,
resultsAssociatedGroups);
+ }
+ }
+
+ if (q.groupsConnectedWithRole.size() > 0)
+ {
+ if (first)
+ {
+ resultsMain = resultsConnectedWithRoleGroups;
+ first = false;
+
+ }
+ else
+ {
+ resultsMain = mergeIdentityTypeWithAND(resultsMain,
resultsConnectedWithRoleGroups);
+ }
+ }
+
+ if (q.groupsRelated.size() > 0)
+ {
+ if (first)
+ {
+ resultsMain = resultsRelatedGroups;
+ first = false;
+ }
+ else
+ {
+ resultsMain = mergeIdentityTypeWithAND(resultsMain,
resultsRelatedGroups);
+ }
+ }
+
+ // As results were merged criteria need to be applied separately
+ if (resultsMain.size() > 0)
+ {
+ resultsMain = applyCriteria(q.searchCriteria, resultsMain);
+ }
+
+ }
+ catch (Exception e)
+ {
+ throw new QueryException("Failed to execute query", e);
+ }
+
+ return resultsMain;
+ }
+
+ public User uniqueResult(UserQueryImpl userQuery) throws QueryException
+ {
+
+ Collection<User> results = execute(userQuery);
+
+ if (results.size() > 1)
+ {
+ throw new QueryException("More than one result returned");
+ }
+ else if (results.size() == 1)
+ {
+ return results.iterator().next();
+ }
+
+ return null;
+ }
+
+ public List<User> list(UserQueryImpl userQuery) throws QueryException
+ {
+ Collection<User> results = execute(userQuery);
+
+ if (results instanceof List)
+ {
+ return (List<User>)results;
+ }
+
+ //TODO:
+ throw new NotYetImplementedException();
+ }
+}
Modified:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/UserQueryImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/UserQueryImpl.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/query/UserQueryImpl.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -29,6 +29,7 @@
import org.jboss.identity.idm.api.Group;
import org.jboss.identity.idm.api.SortOrder;
import org.jboss.identity.idm.impl.api.session.IdentitySessionImpl;
+import org.jboss.identity.idm.impl.api.IdentitySearchCriteriaImpl;
import org.jboss.identity.idm.impl.NotYetImplementedException;
import org.jboss.identity.idm.exception.IdentityException;
@@ -37,6 +38,7 @@
import java.util.Set;
import java.util.HashSet;
import java.util.LinkedList;
+import java.util.Collections;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
@@ -45,280 +47,93 @@
public class UserQueryImpl extends AbstractQuery implements UserQuery
{
- private String userId;
+ public final String userId;
- private Set<Group> groupsAssociatedWith = new HashSet<Group>();
+ public final Set<Group> groupsAssociatedWith;
- private Set<Group> groupsConnectedWithRole = new HashSet<Group>();
+ public final Set<Group> groupsConnectedWithRole;
- private Set<Group> groupsRelated = new HashSet<Group>();
+ public final Set<Group> groupsRelated;
- public UserQueryImpl(IdentitySessionImpl identitySession)
+ public UserQueryImpl(IdentitySearchCriteriaImpl searchCriteria, String userId,
Set<Group> groupsAssociatedWith, Set<Group> groupsConnectedWithRole,
Set<Group> groupsRelated)
{
- super(identitySession);
- }
+ super(searchCriteria);
+ this.userId = userId;
- public Collection<User> execute() throws QueryException
- {
-
- List<User> resultsMain = new LinkedList<User>();
-
- try
+ if (groupsAssociatedWith != null)
{
-
- User uniqueUser = null;
- List<User> resultsAssociatedGroups = new LinkedList<User>();
- List<User> resultsConnectedWithRoleGroups = new LinkedList<User>();
- List<User> resultsRelatedGroups = new LinkedList<User>();
-
- // Process each condition separately
-
- if (userId != null)
- {
- uniqueUser = identitySession.getPersistenceManager().findUser(userId);
- }
-
- if (groupsAssociatedWith.size() > 0)
- {
- for (Group group : groupsAssociatedWith)
- {
-
resultsAssociatedGroups.addAll(identitySession.getRelationshipManager().findAssociatedUsers(group,
false, searchCriteria));
- }
- }
-
- if (groupsConnectedWithRole.size() > 0)
- {
- for (Group group : groupsConnectedWithRole)
- {
-
resultsConnectedWithRoleGroups.addAll(identitySession.getRoleManager().findUsersWithRelatedRole(group,
searchCriteria));
- }
- }
-
- if (groupsRelated.size() > 0)
- {
- for (Group group : groupsRelated)
- {
-
resultsRelatedGroups.addAll(identitySession.getRelationshipManager().findRelatedUsers(group,
searchCriteria));
- }
- }
-
- // If only one condition was present just return it
-
- if (uniqueUser != null &&
- resultsAssociatedGroups.size() == 0 &&
- resultsConnectedWithRoleGroups.size() == 0 &&
- resultsRelatedGroups.size() == 0)
- {
- resultsMain.add(uniqueUser);
- //TODO: apply constraints...
- return resultsMain;
- }
- else if (uniqueUser == null &&
- resultsAssociatedGroups.size() > 0 &&
- resultsConnectedWithRoleGroups.size() == 0 &&
- resultsRelatedGroups.size() == 0)
- {
- return resultsAssociatedGroups;
- }
- else if (uniqueUser == null &&
- resultsAssociatedGroups.size() == 0 &&
- resultsConnectedWithRoleGroups.size() > 0 &&
- resultsRelatedGroups.size() == 0)
- {
- return resultsConnectedWithRoleGroups;
- }
- else if (uniqueUser == null &&
- resultsAssociatedGroups.size() == 0 &&
- resultsConnectedWithRoleGroups.size() == 0 &&
- resultsRelatedGroups.size() > 0)
- {
- return resultsRelatedGroups;
- }
-
- // Merge results with logical AND
-
- if (uniqueUser != null)
- {
- resultsMain.add(uniqueUser);
- }
-
- if (resultsAssociatedGroups.size() > 0)
- {
- resultsMain = mergeUsersWithAND(resultsMain, resultsAssociatedGroups);
- }
-
- if (resultsConnectedWithRoleGroups.size() > 0)
- {
- resultsMain = mergeUsersWithAND(resultsMain,
resultsConnectedWithRoleGroups);
- }
-
- if (resultsRelatedGroups.size() > 0)
- {
- resultsMain = mergeUsersWithAND(resultsMain, resultsRelatedGroups);
- }
-
- // As results were merged criteria need to be applied separately
- if (resultsMain.size() > 0)
- {
- resultsMain = applyCriteriaUsers(resultsMain);
- }
-
+ this.groupsAssociatedWith = Collections.unmodifiableSet(groupsAssociatedWith);
}
- catch (Exception e)
+ else
{
- throw new QueryException("Failed to execute query", e);
+ this.groupsAssociatedWith = Collections.emptySet();
}
- return resultsMain;
- }
-
- public User uniqueResult() throws QueryException
- {
-
- Collection<User> results = execute();
-
- if (results.size() > 1)
+ if (groupsConnectedWithRole != null)
{
- throw new QueryException("More than one result returned");
+ this.groupsConnectedWithRole =
Collections.unmodifiableSet(groupsConnectedWithRole);
}
- else if (results.size() == 1)
+ else
{
- return results.iterator().next();
+ this.groupsConnectedWithRole = Collections.emptySet();
}
- return null;
- }
-
- public List<User> list() throws QueryException
- {
- Collection<User> results = execute();
-
- if (results instanceof List)
+ if (groupsRelated != null)
{
- return (List<User>)results;
+ this.groupsRelated = Collections.unmodifiableSet(groupsRelated);
}
-
- //TODO:
- throw new NotYetImplementedException();
- }
-
- public UserQuery withUserId(String id)
- {
- checkNotNullArgument(id, "User id");
- userId = id;
- return this;
- }
-
- public UserQuery addAssociatedGroup(Group group)
- {
- checkNotNullArgument(group, "Group");
- groupsAssociatedWith.add(group);
- return this;
- }
-
- public UserQuery addAssociatedGroup(String id)
- {
- checkNotNullArgument(id, "Group id");
- groupsAssociatedWith.add(createGroupFromId(id));
- return this;
- }
-
- public UserQuery addAssociatedGroups(Collection<Group> groups)
- {
- checkNotNullArgument(groups, "Groups");
- groupsAssociatedWith.addAll(groups);
- return this;
- }
-
- public UserQuery addAssociatedGroupsIds(Collection<String> groups)
- {
- checkNotNullArgument(groups, "Groups");
- for (String groupId : groups)
+ else
{
- groupsAssociatedWith.add(createGroupFromId(groupId));
+ this.groupsRelated = Collections.emptySet();
}
- return this;
}
- public UserQuery addGroupConnectedWithRole(Group group)
+ @Override
+ public boolean equals(Object o)
{
- checkNotNullArgument(group, "Group");
- groupsConnectedWithRole.add(group);
- return this;
- }
-
- public UserQuery addGroupConnectedWithRole(String id)
- {
- checkNotNullArgument(id, "Group id");
- groupsConnectedWithRole.add(createGroupFromId(id));
- return this;
- }
-
- public UserQuery addGroupsConnectedWithRole(Collection<Group> groups)
- {
- checkNotNullArgument(groups, "Groups");
- groupsConnectedWithRole.addAll(groups);
- return this;
- }
-
- public UserQuery addGroupsIdsConnectedWithRole(Collection<String> groups)
- {
- checkNotNullArgument(groups, "Groups");
- for (String groupId : groups)
+ if (this == o)
{
- groupsConnectedWithRole.add(createGroupFromId(groupId));
+ return true;
}
- return this;
- }
+ if (!(o instanceof UserQueryImpl))
+ {
+ return false;
+ }
+ if (!super.equals(o))
+ {
+ return false;
+ }
- public UserQuery addRelatedGroup(Group group)
- {
- checkNotNullArgument(group, "Group");
- groupsRelated.add(group);
- return this;
- }
+ UserQueryImpl userQuery = (UserQueryImpl)o;
- public UserQuery addRelatedGroup(String id)
- {
- checkNotNullArgument(id, "Group id");
- groupsRelated.add(createGroupFromId(id));
- return this;
- }
-
- public UserQuery addRelatedGroups(Collection<Group> group)
- {
- checkNotNullArgument(group, "Group");
- groupsRelated.addAll(group);
- return this;
- }
-
- public UserQuery addRelatedGroupsIds(Collection<String> ids)
- {
- checkNotNullArgument(ids, "Groups ids");
- for (String id : ids)
+ if (!groupsAssociatedWith.equals(userQuery.groupsAssociatedWith))
{
- groupsRelated.add(createGroupFromId(id));
+ return false;
}
- return this;
- }
+ if (!groupsConnectedWithRole.equals(userQuery.groupsConnectedWithRole))
+ {
+ return false;
+ }
+ if (!groupsRelated.equals(userQuery.groupsRelated))
+ {
+ return false;
+ }
+ if (userId != null ? !userId.equals(userQuery.userId) : userQuery.userId != null)
+ {
+ return false;
+ }
- public UserQuery sort(SortOrder order) throws UnsupportedQueryCriterium
- {
- return (UserQuery)super.sort(order);
+ return true;
}
- public UserQuery sortAttributeName(String name) throws UnsupportedQueryCriterium
+ @Override
+ public int hashCode()
{
- return (UserQuery)super.sortAttributeName(name);
+ int result = super.hashCode();
+ result = 31 * result + (userId != null ? userId.hashCode() : 0);
+ result = 31 * result + groupsAssociatedWith.hashCode();
+ result = 31 * result + groupsConnectedWithRole.hashCode();
+ result = 31 * result + groupsRelated.hashCode();
+ return result;
}
-
- public UserQuery page(int firstResult, int maxResults) throws
UnsupportedQueryCriterium
- {
- return (UserQuery)super.page(firstResult, maxResults);
- }
-
- public UserQuery attributeValuesFilter(String attributeName, String[] attributeValue)
throws UnsupportedQueryCriterium
- {
- return (UserQuery)super.attributeValuesFilter(attributeName, attributeValue);
- }
}
Modified:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/session/IdentitySessionImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/session/IdentitySessionImpl.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/session/IdentitySessionImpl.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -23,6 +23,8 @@
package org.jboss.identity.idm.impl.api.session;
import java.io.Serializable;
+import java.util.Collection;
+import java.util.List;
import org.jboss.identity.idm.api.IdentitySession;
import org.jboss.identity.idm.api.Transaction;
@@ -30,9 +32,16 @@
import org.jboss.identity.idm.api.RelationshipManager;
import org.jboss.identity.idm.api.AttributesManager;
import org.jboss.identity.idm.api.RoleManager;
+import org.jboss.identity.idm.api.User;
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.Role;
import org.jboss.identity.idm.api.query.UserQuery;
import org.jboss.identity.idm.api.query.GroupQuery;
import org.jboss.identity.idm.api.query.RoleQuery;
+import org.jboss.identity.idm.api.query.UserQueryBuilder;
+import org.jboss.identity.idm.api.query.GroupQueryBuilder;
+import org.jboss.identity.idm.api.query.RoleQueryBuilder;
+import org.jboss.identity.idm.api.query.QueryException;
import org.jboss.identity.idm.exception.IdentityException;
import org.jboss.identity.idm.exception.FeatureNotSupportedException;
import org.jboss.identity.idm.spi.store.IdentityStoreSession;
@@ -51,6 +60,12 @@
import org.jboss.identity.idm.impl.api.query.UserQueryImpl;
import org.jboss.identity.idm.impl.api.query.GroupQueryImpl;
import org.jboss.identity.idm.impl.api.query.RoleQueryImpl;
+import org.jboss.identity.idm.impl.api.query.UserQueryExecutorImpl;
+import org.jboss.identity.idm.impl.api.query.GroupQueryExecutorImpl;
+import org.jboss.identity.idm.impl.api.query.RoleQueryExecutorImpl;
+import org.jboss.identity.idm.impl.api.query.UserQueryBuilderImpl;
+import org.jboss.identity.idm.impl.api.query.GroupQueryBuilderImpl;
+import org.jboss.identity.idm.impl.api.query.RoleQueryBuilderImpl;
import org.jboss.identity.idm.impl.NotYetImplementedException;
/**
@@ -74,6 +89,12 @@
private final RoleManager roleManager;
+ private final UserQueryExecutorImpl userQueryExecutor;
+
+ private final GroupQueryExecutorImpl groupQueryExecutor;
+
+ private final RoleQueryExecutorImpl roleQueryExecutor;
+
public IdentitySessionContext getSessionContext()
{
return sessionContext;
@@ -102,7 +123,11 @@
this.relationshipManager = new RelationshipManagerImpl(this);
this.profileManager = new AttributesManagerImpl(this);
this.roleManager = new RoleManagerImpl(this);
+ this.userQueryExecutor = new UserQueryExecutorImpl(this);
+ this.groupQueryExecutor = new GroupQueryExecutorImpl(this);
+ this.roleQueryExecutor = new RoleQueryExecutorImpl(this);
+
}
@@ -172,25 +197,70 @@
return roleManager;
}
- public UserQuery createUserQuery()
+ public UserQueryBuilder createUserQueryBuilder()
{
- return new UserQueryImpl(this);
+ return new UserQueryBuilderImpl();
}
- public GroupQuery createGroupQuery()
+ public GroupQueryBuilder createGroupQueryBuilder()
{
- return new GroupQueryImpl(this);
+ return new GroupQueryBuilderImpl();
}
- public RoleQuery createRoleQuery() throws FeatureNotSupportedException
+ public RoleQueryBuilder createRoleQueryBuilder() throws FeatureNotSupportedException
{
if
(!getSessionContext().getIdentityStoreRepository().getSupportedFeatures().isNamedRelationshipsSupported())
{
throw new FeatureNotSupportedException("Role management not supported by
underlaying configured identity stores");
}
- return new RoleQueryImpl(this);
+ return new RoleQueryBuilderImpl();
}
+
+ public Collection<User> execute(UserQuery userQuery) throws QueryException
+ {
+ return userQueryExecutor.execute((UserQueryImpl)userQuery);
+ }
+
+ public User uniqueResult(UserQuery userQuery) throws QueryException
+ {
+ return userQueryExecutor.uniqueResult((UserQueryImpl)userQuery);
+ }
+
+ public List<User> list(UserQuery userQuery) throws QueryException
+ {
+ return userQueryExecutor.list((UserQueryImpl)userQuery);
+ }
+
+ public Collection<Group> execute(GroupQuery groupQuery) throws QueryException
+ {
+ return groupQueryExecutor.execute((GroupQueryImpl)groupQuery);
+ }
+
+ public Group uniqueResult(GroupQuery groupQuery) throws QueryException
+ {
+ return groupQueryExecutor.uniqueResult((GroupQueryImpl)groupQuery);
+ }
+
+ public List<Group> list(GroupQuery groupQuery) throws QueryException
+ {
+ return groupQueryExecutor.list((GroupQueryImpl)groupQuery);
+ }
+
+ public Collection<Role> execute(RoleQuery roleQuery) throws QueryException
+ {
+ return roleQueryExecutor.execute((RoleQueryImpl)roleQuery);
+ }
+
+ public Role uniqueResult(RoleQuery roleQuery) throws QueryException
+ {
+ return roleQueryExecutor.uniqueResult((RoleQueryImpl)roleQuery);
+ }
+
+ public List<Role> list(RoleQuery roleQuery) throws QueryException
+ {
+ return roleQueryExecutor.list((RoleQueryImpl)roleQuery);
+ }
}
Modified:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/session/managers/RelationshipManagerImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/session/managers/RelationshipManagerImpl.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/session/managers/RelationshipManagerImpl.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -467,7 +467,7 @@
return true;
}
- public Collection<Group> findAssociatedGroups(Group group, String groupType,
boolean parent, boolean inherited, IdentitySearchCriteria controls) throws
IdentityException
+ public Collection<Group> findAssociatedGroups(Group group, String groupType,
boolean parent, boolean cascade, IdentitySearchCriteria controls) throws
IdentityException
{
checkNotNullArgument(group, "Group");
@@ -477,10 +477,10 @@
IdentityObjectType iot = groupType != null ? getIdentityObjectType(groupType) :
null;
- //TODO Handle inherited
- if (inherited)
+ //TODO Handle cascade
+ if (cascade)
{
- throw new NotYetImplementedException("Support for 'inherited'
argument is not yet implemented. Please use 'false' value for now");
+ throw new NotYetImplementedException("Support for 'cascade'
argument is not yet implemented. Please use 'false' value for now");
}
Collection<IdentityObject> ios =
getRepository().findIdentityObject(getInvocationContext(), createIdentityObject(group),
MEMBER, parent, convertSearchControls(controls));
@@ -497,22 +497,22 @@
}
- public Collection<Group> findAssociatedGroups(String groupId, String groupType,
boolean parent, boolean inherited, IdentitySearchCriteria controls) throws
IdentityException
+ public Collection<Group> findAssociatedGroups(String groupId, String groupType,
boolean parent, boolean cascade, IdentitySearchCriteria controls) throws
IdentityException
{
checkNotNullArgument(groupId, "Group Id");
// checkNotNullArgument(groupType, "Group type");
Group group = createGroupFromId(groupId);
- return findAssociatedGroups(group, groupType, parent, inherited, controls);
+ return findAssociatedGroups(group, groupType, parent, cascade, controls);
}
- public Collection<Group> findAssociatedGroups(Group group, String groupType,
boolean parent, boolean inherited) throws IdentityException
+ public Collection<Group> findAssociatedGroups(Group group, String groupType,
boolean parent, boolean cascade) throws IdentityException
{
checkNotNullArgument(group, "Group");
// checkNotNullArgument(groupType, "Group type");
- return findAssociatedGroups(group, groupType, parent, inherited, null);
+ return findAssociatedGroups(group, groupType, parent, cascade, null);
}
public Collection<Group> findAssociatedGroups(User identity, String groupType,
IdentitySearchCriteria controls) throws IdentityException
@@ -593,16 +593,16 @@
return findAssociatedGroups(identity, (IdentitySearchCriteria)null);
}
- public Collection<User> findAssociatedUsers(Group group, boolean inherited,
IdentitySearchCriteria controls) throws IdentityException
+ public Collection<User> findAssociatedUsers(Group group, boolean cascade,
IdentitySearchCriteria controls) throws IdentityException
{
checkNotNullArgument(group, "Group");
List<User> identities = new LinkedList<User>();
- //TODO Handle inherited
- if (inherited)
+ //TODO Handle cascade
+ if (cascade)
{
- throw new NotYetImplementedException("Support for 'inherited'
argument is not yet implemented. Please use 'false' value for now");
+ throw new NotYetImplementedException("Support for 'cascade'
argument is not yet implemented. Please use 'false' value for now");
}
Collection<IdentityObject> ios =
getRepository().findIdentityObject(getInvocationContext(), createIdentityObject(group),
MEMBER, true, convertSearchControls(controls));
@@ -621,20 +621,20 @@
return identities;
}
- public Collection<User> findAssociatedUsers(String groupId, boolean inherited,
IdentitySearchCriteria controls) throws IdentityException
+ public Collection<User> findAssociatedUsers(String groupId, boolean cascade,
IdentitySearchCriteria controls) throws IdentityException
{
checkNotNullArgument(groupId, "Group Id");
Group group = createGroupFromId(groupId);
- return findAssociatedUsers(group, inherited, controls);
+ return findAssociatedUsers(group, cascade, controls);
}
- public Collection<User> findAssociatedUsers(Group group, boolean inherited)
throws IdentityException
+ public Collection<User> findAssociatedUsers(Group group, boolean cascade) throws
IdentityException
{
checkNotNullArgument(group, "Group");
- return findAssociatedUsers(group, inherited, null);
+ return findAssociatedUsers(group, cascade, null);
}
public Collection<Group> findRelatedGroups(User user, String groupType,
IdentitySearchCriteria controls) throws IdentityException
Modified:
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/session/managers/RoleManagerImpl.java
===================================================================
---
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/session/managers/RoleManagerImpl.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/main/java/org/jboss/identity/idm/impl/api/session/managers/RoleManagerImpl.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -295,19 +295,22 @@
if (rels.size() == 0)
{
- throw new IdentityException("No such role present");
+ return null;
}
- if (rels.size() > 1)
+ for (IdentityObjectRelationship relationship : rels)
{
- throw new IdentityException("More than one role definition present -
illegal state!");
+ if (roleType.getName().equals(relationship.getName()))
+ {
+ return new SimpleRole(new SimpleRoleType(relationship.getName()),
+ createUser(relationship.getToIdentityObject()),
+ createGroup(relationship.getFromIdentityObject()));
+ }
}
- IdentityObjectRelationship relationship = rels.iterator().next();
+ return null;
- return new SimpleRole(new SimpleRoleType(relationship.getType().getName()),
- createUser(relationship.getFromIdentityObject()),
- createGroup(relationship.getToIdentityObject()));
+
}
public Role getRole(String roleTypeName, String userId, String groupId) throws
IdentityException
Modified: idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/APITestCase.java
===================================================================
---
idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/APITestCase.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/APITestCase.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -117,16 +117,19 @@
roleManagerTest.testMethods(getRealmName());
}
+ @Test
public void testUserQuery() throws Exception
{
userQueryTest.testQuery(getRealmName());
}
+ @Test
public void testGroupQuery() throws Exception
{
groupQueryTest.testQuery(getRealmName());
}
+ @Test
public void testRoleQuery() throws Exception
{
roleQueryTest.testQuery(getRealmName());
Modified: idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/GroupQueryTest.java
===================================================================
---
idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/GroupQueryTest.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/GroupQueryTest.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -22,14 +22,26 @@
package org.jboss.identity.idm.impl.api;
+import org.jboss.identity.idm.api.IdentitySession;
+import org.jboss.identity.idm.api.User;
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.RoleType;
+import org.jboss.identity.idm.api.Role;
+import org.jboss.identity.idm.api.query.GroupQueryBuilder;
+import junit.framework.Assert;
+
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
* @version : 0.1 $
*/
-public class GroupQueryTest
+public class GroupQueryTest extends Assert
{
private APITestContext ctx;
+ private String ORGANIZATION = "ORGANIZATION";
+ private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
+ private String DEPARTMENT = "DEPARTMENT";
+
public GroupQueryTest(APITestContext testContext)
{
this.ctx = testContext;
@@ -39,8 +51,78 @@
{
ctx.begin();
+ IdentitySession ids =
ctx.getIdentitySessionFactory().getCurrentIdentitySession(realmName);
+ // Create stuff
+ User user1 = ids.getPersistenceManager().createUser("user1");
+ User user2 = ids.getPersistenceManager().createUser("user2");
+ User user3 = ids.getPersistenceManager().createUser("user3");
+ User user4 = ids.getPersistenceManager().createUser("user4");
+
+ Group group1 = ids.getPersistenceManager().createGroup("group1",
ORGANIZATION);
+ Group group2 = ids.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
+ Group group3 = ids.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
+ Group group4 = ids.getPersistenceManager().createGroup("group4",
DEPARTMENT);
+ Group group5 = ids.getPersistenceManager().createGroup("group5",
DEPARTMENT);
+
+ ids.getRelationshipManager().associateUser(group1, user1);
+ ids.getRelationshipManager().associateUser(group1, user2);
+ ids.getRelationshipManager().associateUser(group2, user3);
+ ids.getRelationshipManager().associateGroups(group2, group3);
+
+ RoleType rt1 = ids.getRoleManager().createRoleType("rt1");
+ RoleType rt2 = ids.getRoleManager().createRoleType("rt2");
+ RoleType rt3 = ids.getRoleManager().createRoleType("rt3");
+ RoleType rt4 = ids.getRoleManager().createRoleType("rt4");
+
+ Role role1 = ids.getRoleManager().createRole(rt1, user1, group1);
+ Role role2 = ids.getRoleManager().createRole(rt1, user1, group2);
+ Role role3 = ids.getRoleManager().createRole("rt2", user1.getId(),
group1.getId());
+
+ // Assertions
+
+ GroupQueryBuilder qb = ids.createGroupQueryBuilder();
+
+ qb.addAssociatedUser(user1);
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+ assertEquals(group1, ids.uniqueResult(qb.createQuery()));
+
+ //
+ qb.reset();
+
+ qb.addAssociatedUser(user1);
+ qb.addAssociatedUser(user2);
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedUser(user1);
+ qb.addRelatedUser(user2);
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedUser(user1);
+ qb.addRelatedUser(user4);
+
+ assertEquals(0, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedUser(user3);
+ qb.addAssociatedGroup(group3, false);
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+ assertEquals(group2, ids.uniqueResult(qb.createQuery()));
+
+
ctx.commit();
}
}
Modified: idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/RoleQueryTest.java
===================================================================
---
idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/RoleQueryTest.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/RoleQueryTest.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -22,14 +22,27 @@
package org.jboss.identity.idm.impl.api;
+import org.jboss.identity.idm.api.IdentitySession;
+import org.jboss.identity.idm.api.User;
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.RoleType;
+import org.jboss.identity.idm.api.Role;
+import org.jboss.identity.idm.api.query.RoleQueryBuilder;
+import org.jboss.identity.idm.api.query.RoleQuery;
+import junit.framework.Assert;
+
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
* @version : 0.1 $
*/
-public class RoleQueryTest
+public class RoleQueryTest extends Assert
{
private APITestContext ctx;
+ private String ORGANIZATION = "ORGANIZATION";
+ private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
+ private String DEPARTMENT = "DEPARTMENT";
+
public RoleQueryTest(APITestContext testContext)
{
this.ctx = testContext;
@@ -39,8 +52,65 @@
{
ctx.begin();
+ IdentitySession ids =
ctx.getIdentitySessionFactory().getCurrentIdentitySession(realmName);
+ // Create some stuff...
+ User user1 = ids.getPersistenceManager().createUser("user1");
+ User user2 = ids.getPersistenceManager().createUser("user2");
+ User user3 = ids.getPersistenceManager().createUser("user3");
+ User user4 = ids.getPersistenceManager().createUser("user4");
+
+ Group group1 = ids.getPersistenceManager().createGroup("group1",
ORGANIZATION);
+ Group group2 = ids.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
+ Group group3 = ids.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
+ Group group4 = ids.getPersistenceManager().createGroup("group4",
DEPARTMENT);
+ Group group5 = ids.getPersistenceManager().createGroup("group5",
DEPARTMENT);
+
+ RoleType rt1 = ids.getRoleManager().createRoleType("rt1");
+ RoleType rt2 = ids.getRoleManager().createRoleType("rt2");
+ RoleType rt3 = ids.getRoleManager().createRoleType("rt3");
+ RoleType rt4 = ids.getRoleManager().createRoleType("rt4");
+
+ Role role1 = ids.getRoleManager().createRole(rt1, user1, group1);
+ Role role2 = ids.getRoleManager().createRole(rt1, user1, group2);
+ Role role3 = ids.getRoleManager().createRole("rt2", user1.getId(),
group1.getId());
+
+ // Test Query
+
+ //
+ RoleQueryBuilder rqb = ids.createRoleQueryBuilder();
+
+ rqb.setUser("user1");
+
+ RoleQuery rq = rqb.createQuery();
+
+ assertEquals(3, ids.execute(rq).size());
+
+ //
+ rqb.setGroup(group1);
+ rq = rqb.createQuery();
+
+ assertEquals(2, ids.execute(rq).size());
+
+ //
+ rqb.setRoleType(rt2);
+ rq = rqb.createQuery();
+
+ assertEquals(1, ids.execute(rq).size());
+
+
+ //
+ rqb.reset();
+
+ rqb.setGroup(group2);
+ rqb.setRoleType(rt1);
+
+ rq = rqb.createQuery();
+
+ assertEquals(1, ids.execute(rq).size());
+ assertEquals(role2, ids.uniqueResult(rq));
+
ctx.commit();
}
}
Modified: idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/UserQueryTest.java
===================================================================
---
idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/UserQueryTest.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm/src/test/java/org/jboss/identity/idm/impl/api/UserQueryTest.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -23,7 +23,12 @@
package org.jboss.identity.idm.impl.api;
import org.jboss.identity.idm.api.IdentitySession;
+import org.jboss.identity.idm.api.User;
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.RoleType;
+import org.jboss.identity.idm.api.Role;
import org.jboss.identity.idm.api.query.UserQuery;
+import org.jboss.identity.idm.api.query.UserQueryBuilder;
import junit.framework.Assert;
/**
@@ -34,6 +39,12 @@
{
private APITestContext ctx;
+ private String ORGANIZATION = "ORGANIZATION";
+
+ private String ORGANIZATION_UNIT = "ORGANIZATION_UNIT";
+
+ private String DEPARTMENT = "DEPARTMENT";
+
public UserQueryTest(APITestContext testContext)
{
this.ctx = testContext;
@@ -45,18 +56,104 @@
IdentitySession ids =
ctx.getIdentitySessionFactory().getCurrentIdentitySession(realmName);
- ids.getPersistenceManager().createUser("testUser");
- ids.getPersistenceManager().createUser("testUser2");
- ids.getPersistenceManager().createUser("testUser3");
+ // Create stuff
- UserQuery q = ids.createUserQuery();
+ User user1 = ids.getPersistenceManager().createUser("user1");
+ User user2 = ids.getPersistenceManager().createUser("user2");
+ User user3 = ids.getPersistenceManager().createUser("user3");
+ User user4 = ids.getPersistenceManager().createUser("user4");
- q.withUserId("testUser");
+ Group group1 = ids.getPersistenceManager().createGroup("group1",
ORGANIZATION);
+ Group group2 = ids.getPersistenceManager().createGroup("group2",
ORGANIZATION_UNIT);
+ Group group3 = ids.getPersistenceManager().createGroup("group3",
ORGANIZATION_UNIT);
+ Group group4 = ids.getPersistenceManager().createGroup("group4",
DEPARTMENT);
+ Group group5 = ids.getPersistenceManager().createGroup("group5",
DEPARTMENT);
- assertEquals(1, q.execute().size());
- assertEquals(1, q.list().size());
- assertEquals("testUser", q.uniqueResult().getId());
+ ids.getRelationshipManager().associateUser(group1, user1);
+ ids.getRelationshipManager().associateUser(group1, user2);
+ RoleType rt1 = ids.getRoleManager().createRoleType("rt1");
+ RoleType rt2 = ids.getRoleManager().createRoleType("rt2");
+ RoleType rt3 = ids.getRoleManager().createRoleType("rt3");
+ RoleType rt4 = ids.getRoleManager().createRoleType("rt4");
+
+ Role role1 = ids.getRoleManager().createRole(rt1, user1, group1);
+ Role role2 = ids.getRoleManager().createRole(rt1, user1, group2);
+ Role role3 = ids.getRoleManager().createRole("rt2", user1.getId(),
group1.getId());
+
+ // Asserts
+
+ //
+ UserQueryBuilder qb = ids.createUserQueryBuilder();
+
+ qb.withUserId("user1");
+ UserQuery q = qb.createQuery();
+
+ assertEquals(1, ids.execute(q).size());
+ assertEquals(1, ids.list(q).size());
+ assertEquals("user1", ids.uniqueResult(q).getId());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedGroup(group2);
+
+ assertEquals(0, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedGroup(group1);
+
+ assertEquals(2, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedGroup(group1);
+ qb.withUserId(user1.getId());
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedGroup(group2);
+ qb.withUserId(user1.getId());
+
+ assertEquals(0, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addAssociatedGroup(group1);
+ qb.addGroupConnectedWithRole(group2);
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+ assertEquals(user1, ids.uniqueResult(qb.createQuery()));
+
+ //
+ qb.reset();
+
+ qb.addRelatedGroup(group1);
+
+ assertEquals(2, ids.execute(qb.createQuery()).size());
+
+ //
+ qb.reset();
+
+ qb.addRelatedGroup(group2);
+ qb.addAssociatedGroup(group1);
+
+ assertEquals(1, ids.execute(qb.createQuery()).size());
+ assertEquals(user1, ids.uniqueResult(qb.createQuery()));
+
+ //
+ qb.reset();
+
+ assertEquals(4, ids.execute(qb.createQuery()).size());
+
+
ctx.commit();
}
Modified: idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/IdentitySession.java
===================================================================
---
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/IdentitySession.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/IdentitySession.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -27,7 +27,14 @@
import org.jboss.identity.idm.api.query.RoleQuery;
import org.jboss.identity.idm.api.query.GroupQuery;
import org.jboss.identity.idm.api.query.UserQuery;
+import org.jboss.identity.idm.api.query.GroupQueryBuilder;
+import org.jboss.identity.idm.api.query.UserQueryBuilder;
+import org.jboss.identity.idm.api.query.RoleQueryBuilder;
+import org.jboss.identity.idm.api.query.QueryException;
+import java.util.Collection;
+import java.util.List;
+
/**
* Expose all identity management operations within a given realm
*
@@ -111,19 +118,92 @@
*
* @return
*/
- UserQuery createUserQuery();
+ UserQueryBuilder createUserQueryBuilder();
/**
*
* @return
*/
- GroupQuery createGroupQuery();
+ GroupQueryBuilder createGroupQueryBuilder();
/**
*
* @return
*/
- RoleQuery createRoleQuery() throws FeatureNotSupportedException;
+ RoleQueryBuilder createRoleQueryBuilder() throws FeatureNotSupportedException;
+ /**
+ *
+ * @param userQuery
+ * @return
+ * @throws QueryException
+ */
+ Collection<User> execute(UserQuery userQuery) throws QueryException;
+ /**
+ *
+ * @param userQuery
+ * @return
+ * @throws QueryException
+ */
+ User uniqueResult(UserQuery userQuery) throws QueryException;
+
+ /**
+ *
+ * @param userQuery
+ * @return
+ * @throws QueryException
+ */
+ List<User> list(UserQuery userQuery) throws QueryException;
+
+ /**
+ *
+ * @param groupQuery
+ * @return
+ * @throws QueryException
+ */
+ Collection<Group> execute(GroupQuery groupQuery) throws QueryException;
+
+ /**
+ *
+ * @param groupQuery
+ * @return
+ * @throws QueryException
+ */
+ Group uniqueResult(GroupQuery groupQuery) throws QueryException;
+
+ /**
+ *
+ * @param groupQuery
+ * @return
+ * @throws QueryException
+ */
+ List<Group> list(GroupQuery groupQuery) throws QueryException;
+
+ /**
+ *
+ * @param roleQuery
+ * @return
+ * @throws QueryException
+ */
+ Collection<Role> execute(RoleQuery roleQuery) throws QueryException;
+
+ /**
+ *
+ * @param roleQuery
+ * @return
+ * @throws QueryException
+ */
+ Role uniqueResult(RoleQuery roleQuery) throws QueryException;
+
+ /**
+ *
+ * @param roleQuery
+ * @return
+ * @throws QueryException
+ */
+ List<Role> list(RoleQuery roleQuery) throws QueryException;
+
+
+
}
\ No newline at end of file
Modified:
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/RelationshipManager.java
===================================================================
---
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/RelationshipManager.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/RelationshipManager.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -278,13 +278,13 @@
/**
* Find groups that are associated with given group.
* If 'parent' parameter is set to false, all parent group will be returned.
If parent parameter is
- * set to true and 'inherited' is set to true all nested subgroubs will be
returned.
+ * set to true and 'cascade' is set to true all nested subgroubs will be
returned.
*
* @param group parent group
* @param groupType can be null
* @param parent defines if given identity is parent or child side in the
* relationship - default is true (parent)
- * @param inherited if true also identities from subgroubs will be retreived. Matters
only when parent is set to true.
+ * @param cascade if true also identities from subgroubs will be retreived. Matters
only when parent is set to true.
* Default is false
* @return
* @throws org.jboss.identity.idm.exception.IdentityException
@@ -292,18 +292,18 @@
Collection<Group> findAssociatedGroups(Group group,
String groupType,
boolean parent,
- boolean inherited) throws IdentityException;
+ boolean cascade) throws IdentityException;
/**
* Find groups that are associated with given group.
* If 'parent' parameter is set to false, all parent group will be returned.
If parent parameter is
- * set to true and 'inherited' is set to true all nested subgroubs will be
returned.
+ * set to true and 'cascade' is set to true all nested subgroubs will be
returned.
*
* @param group parent group
* @param groupType can be null
* @param parent defines if given identity is parent or child side in the
* relationship - default is true (parent)
- * @param inherited if true also identities from subgroubs will be retreived. Matters
only when parent is set to true.
+ * @param cascade if true also identities from subgroubs will be retreived. Matters
only when parent is set to true.
* Default is false
* @return
* @throws org.jboss.identity.idm.exception.IdentityException
@@ -311,19 +311,19 @@
Collection<Group> findAssociatedGroups(Group group,
String groupType,
boolean parent,
- boolean inherited,
+ boolean cascade,
IdentitySearchCriteria controls) throws
IdentityException;
/**
* Find groups that are associated with given group.
* If 'parent' parameter is set to false, all parent group will be returned.
If parent parameter is
- * set to true and 'inherited' is set to true all nested subgroubs will be
returned.
+ * set to true and 'cascade' is set to true all nested subgroubs will be
returned.
*
* @param groupId Id of parent group
* @param groupType can be null
* @param parent defines if given identity is parent or child side in the
* relationship - default is true (parent)
- * @param inherited if true also identities from subgroubs will be retreived. Matters
only when parent is set to true.
+ * @param cascade if true also identities from subgroubs will be retreived. Matters
only when parent is set to true.
* Default is false
* @return
* @throws org.jboss.identity.idm.exception.IdentityException
@@ -331,7 +331,7 @@
Collection<Group> findAssociatedGroups(String groupId,
String groupType,
boolean parent,
- boolean inherited,
+ boolean cascade,
IdentitySearchCriteria controls) throws
IdentityException;
/**
@@ -401,35 +401,35 @@
* Find identities that have relationship with given parent group.
*
* @param group parent group
- * @param inherited if true also identities from subgroubs will be retrieved. Default
is false
+ * @param cascade if true also identities from subgroubs will be retrieved. Default is
false
* @return
* @throws org.jboss.identity.idm.exception.IdentityException
*/
Collection<User> findAssociatedUsers(Group group,
- boolean inherited) throws IdentityException;
+ boolean cascade) throws IdentityException;
/**
* Find identities that have relationship with given parent group.
*
* @param group parent group
- * @param inherited if true also identities from subgroubs will be retrieved. Default
is false
+ * @param cascade if true also identities from subgroubs will be retrieved. Default is
false
* @return
* @throws org.jboss.identity.idm.exception.IdentityException
*/
Collection<User> findAssociatedUsers(Group group,
- boolean inherited,
+ boolean cascade,
IdentitySearchCriteria controls) throws
IdentityException;
/**
* Find identities that have relationship with given parent group.
*
* @param groupId parent group id
- * @param inherited if true also identities from subgroubs will be retrieved. Default
is false
+ * @param cascade if true also identities from subgroubs will be retrieved. Default is
false
* @return
* @throws org.jboss.identity.idm.exception.IdentityException
*/
Collection<User> findAssociatedUsers(String groupId,
- boolean inherited,
+ boolean cascade,
IdentitySearchCriteria controls) throws
IdentityException;
Modified: idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/RoleType.java
===================================================================
--- idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/RoleType.java 2009-05-07
19:45:12 UTC (rev 479)
+++ idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/RoleType.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -37,4 +37,5 @@
*/
String getName();
+
}
\ No newline at end of file
Modified:
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/GroupQuery.java
===================================================================
---
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/GroupQuery.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/GroupQuery.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -36,56 +36,6 @@
public interface GroupQuery extends Query
{
- Collection<Group> execute() throws QueryException;
+
- Group uniqueResult() throws QueryException;
-
- List<Group> list() throws QueryException;
-
- GroupQuery setId(String id);
-
- GroupQuery setNameAndType(String name, String type);
-
- GroupQuery setName(String name);
-
- GroupQuery setType(String type);
-
- GroupQuery addAssociatedGroup(Group group, boolean parent);
-
- GroupQuery addAssociatedGroup(String id, boolean parent);
-
- GroupQuery addAssociatedGroups(Collection<Group> groups, boolean parent);
-
- GroupQuery addAssociatedGroupsIds(Collection<String> ids, boolean parent);
-
- GroupQuery addAssociatedUser(User user);
-
- GroupQuery addAssociatedUser(String id);
-
- GroupQuery addAssociatedUsers(Collection<User> users);
-
- GroupQuery addAssociatedUsersIds(Collection<String> ids);
-
- GroupQuery addUserConnectedByRole(User user);
-
- GroupQuery addUserConnectedByRole(String id);
-
- GroupQuery addUsersConnectedByRole(Collection<User> users);
-
- GroupQuery addUsersIdsConnectedByRole(Collection<String> ids);
-
- GroupQuery addRelatedUser(User user);
-
- GroupQuery addRelatedUser(String id);
-
- GroupQuery sort(SortOrder order) throws UnsupportedQueryCriterium;
-
- GroupQuery sortAttributeName(String name) throws UnsupportedQueryCriterium;
-
- GroupQuery page(int firstResult, int maxResults) throws UnsupportedQueryCriterium;
-
- GroupQuery attributeValuesFilter(String attributeName, String[] attributeValue) throws
UnsupportedQueryCriterium;
-
-
-
}
Added:
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/GroupQueryBuilder.java
===================================================================
---
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/GroupQueryBuilder.java
(rev 0)
+++
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/GroupQueryBuilder.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -0,0 +1,85 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.idm.api.query;
+
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.User;
+import org.jboss.identity.idm.api.SortOrder;
+
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface GroupQueryBuilder extends QueryBuilder
+{
+ GroupQuery createQuery();
+
+ GroupQueryBuilder reset();
+
+ GroupQueryBuilder setId(String id);
+
+ GroupQueryBuilder setNameAndType(String name, String type);
+
+ GroupQueryBuilder setName(String name);
+
+ GroupQueryBuilder setType(String type);
+
+ GroupQueryBuilder addAssociatedGroup(Group group, boolean parent);
+
+ GroupQueryBuilder addAssociatedGroup(String id, boolean parent);
+
+ GroupQueryBuilder addAssociatedGroups(Collection<Group> groups, boolean
parent);
+
+ GroupQueryBuilder addAssociatedGroupsIds(Collection<String> ids, boolean
parent);
+
+ GroupQueryBuilder addAssociatedUser(User user);
+
+ GroupQueryBuilder addAssociatedUser(String id);
+
+ GroupQueryBuilder addAssociatedUsers(Collection<User> users);
+
+ GroupQueryBuilder addAssociatedUsersIds(Collection<String> ids);
+
+ GroupQueryBuilder addUserConnectedByRole(User user);
+
+ GroupQueryBuilder addUserConnectedByRole(String id);
+
+ GroupQueryBuilder addUsersConnectedByRole(Collection<User> users);
+
+ GroupQueryBuilder addUsersIdsConnectedByRole(Collection<String> ids);
+
+ GroupQueryBuilder addRelatedUser(User user);
+
+ GroupQueryBuilder addRelatedUser(String id);
+
+ GroupQueryBuilder sort(SortOrder order) throws UnsupportedQueryCriterium;
+
+ GroupQueryBuilder sortAttributeName(String name) throws UnsupportedQueryCriterium;
+
+ GroupQueryBuilder page(int firstResult, int maxResults) throws
UnsupportedQueryCriterium;
+
+ GroupQueryBuilder attributeValuesFilter(String attributeName, String[] attributeValue)
throws UnsupportedQueryCriterium;
+
+}
Added: idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/QueryBuilder.java
===================================================================
--- idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/QueryBuilder.java
(rev 0)
+++
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/QueryBuilder.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -0,0 +1,31 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.idm.api.query;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface QueryBuilder
+{
+}
Modified: idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/RoleQuery.java
===================================================================
---
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/RoleQuery.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/RoleQuery.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -38,26 +38,8 @@
public interface RoleQuery extends Query
{
- Collection<Role> execute() throws QueryException;
+
- Role uniqueResult() throws QueryException;
+
- List<Role> list() throws QueryException;
-
- RoleQuery setUser(User user);
-
- RoleQuery setUser(String id);
-
- RoleQuery setGroup(Group group);
-
- RoleQuery setGroup(String id);
-
- RoleQuery setRoleType(RoleType roleType);
-
- RoleQuery setRoleType(String string);
-
- RoleQuery setIdentityType(IdentityType identityType);
-
- RoleQuery setIdentityTypeId(String id);
-
}
Added:
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/RoleQueryBuilder.java
===================================================================
---
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/RoleQueryBuilder.java
(rev 0)
+++
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/RoleQueryBuilder.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -0,0 +1,56 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.idm.api.query;
+
+import org.jboss.identity.idm.api.User;
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.RoleType;
+import org.jboss.identity.idm.api.IdentityType;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface RoleQueryBuilder extends QueryBuilder
+{
+ RoleQuery createQuery();
+
+ RoleQueryBuilder reset();
+
+ RoleQueryBuilder setUser(User user);
+
+ RoleQueryBuilder setUser(String id);
+
+ RoleQueryBuilder setGroup(Group group);
+
+ RoleQueryBuilder setGroup(String id);
+
+ RoleQueryBuilder setRoleType(RoleType roleType);
+
+ RoleQueryBuilder setRoleType(String string);
+
+ RoleQueryBuilder setIdentityType(IdentityType identityType);
+
+ RoleQueryBuilder setIdentityTypeId(String id);
+
+}
Modified: idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/UserQuery.java
===================================================================
---
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/UserQuery.java 2009-05-07
19:45:12 UTC (rev 479)
+++
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/UserQuery.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -35,44 +35,8 @@
*/
public interface UserQuery extends Query
{
- Collection<User> execute() throws QueryException;
+
- User uniqueResult() throws QueryException;
+
- List<User> list() throws QueryException;
-
- UserQuery withUserId(String id);
-
- UserQuery addAssociatedGroup(Group group);
-
- UserQuery addAssociatedGroup(String id);
-
- UserQuery addAssociatedGroups(Collection<Group> groups);
-
- UserQuery addAssociatedGroupsIds(Collection<String> groups);
-
- UserQuery addGroupConnectedWithRole(Group group);
-
- UserQuery addGroupConnectedWithRole(String id);
-
- UserQuery addGroupsConnectedWithRole(Collection<Group> groups);
-
- UserQuery addGroupsIdsConnectedWithRole(Collection<String> groups);
-
- UserQuery addRelatedGroup(Group group);
-
- UserQuery addRelatedGroup(String id);
-
- UserQuery addRelatedGroups(Collection<Group> group);
-
- UserQuery addRelatedGroupsIds(Collection<String> ids);
-
- UserQuery sort(SortOrder order) throws UnsupportedQueryCriterium;
-
- UserQuery sortAttributeName(String name) throws UnsupportedQueryCriterium;
-
- UserQuery page(int firstResult, int maxResults) throws UnsupportedQueryCriterium;
-
- UserQuery attributeValuesFilter(String attributeName, String[] attributeValue) throws
UnsupportedQueryCriterium;
-
}
Added:
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/UserQueryBuilder.java
===================================================================
---
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/UserQueryBuilder.java
(rev 0)
+++
idm/trunk/idm-api/src/main/java/org/jboss/identity/idm/api/query/UserQueryBuilder.java 2009-05-08
20:46:17 UTC (rev 480)
@@ -0,0 +1,75 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.identity.idm.api.query;
+
+import org.jboss.identity.idm.api.Group;
+import org.jboss.identity.idm.api.SortOrder;
+
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ * @version : 0.1 $
+ */
+public interface UserQueryBuilder extends QueryBuilder
+{
+
+ UserQuery createQuery();
+
+ UserQueryBuilder reset();
+
+ UserQueryBuilder withUserId(String id);
+
+ UserQueryBuilder addAssociatedGroup(Group group);
+
+ UserQueryBuilder addAssociatedGroup(String id);
+
+ UserQueryBuilder addAssociatedGroups(Collection<Group> groups);
+
+ UserQueryBuilder addAssociatedGroupsIds(Collection<String> groups);
+
+ UserQueryBuilder addGroupConnectedWithRole(Group group);
+
+ UserQueryBuilder addGroupConnectedWithRole(String id);
+
+ UserQueryBuilder addGroupsConnectedWithRole(Collection<Group> groups);
+
+ UserQueryBuilder addGroupsIdsConnectedWithRole(Collection<String> groups);
+
+ UserQueryBuilder addRelatedGroup(Group group);
+
+ UserQueryBuilder addRelatedGroup(String id);
+
+ UserQueryBuilder addRelatedGroups(Collection<Group> group);
+
+ UserQueryBuilder addRelatedGroupsIds(Collection<String> ids);
+
+ UserQueryBuilder sort(SortOrder order) throws UnsupportedQueryCriterium;
+
+ UserQueryBuilder sortAttributeName(String name) throws UnsupportedQueryCriterium;
+
+ UserQueryBuilder page(int firstResult, int maxResults) throws
UnsupportedQueryCriterium;
+
+ UserQueryBuilder attributeValuesFilter(String attributeName, String[] attributeValue)
throws UnsupportedQueryCriterium;
+
+}