Author: bdaw
Date: 2008-10-21 17:33:37 -0400 (Tue, 21 Oct 2008)
New Revision: 111
Modified:
trunk/identity-api/src/main/java/org/jboss/identity/api/Group.java
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipManager.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RelationshipManagerImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupType.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleIdentityImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationship.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreImpl.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/OrganizationTest.java
Log:
more in OrganizationTest plus some fixes
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/Group.java
===================================================================
--- trunk/identity-api/src/main/java/org/jboss/identity/api/Group.java 2008-10-21 14:30:03
UTC (rev 110)
+++ trunk/identity-api/src/main/java/org/jboss/identity/api/Group.java 2008-10-21 21:33:37
UTC (rev 111)
@@ -33,16 +33,9 @@
*/
public interface Group extends IdentityType
{
-
/**
- * <p>Return the name of the identity</p>
* @return
*/
- String getName();
-
- /**
- * @return
- */
GroupType getGroupType();
Modified:
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipManager.java
===================================================================
---
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipManager.java 2008-10-21
14:30:03 UTC (rev 110)
+++
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipManager.java 2008-10-21
21:33:37 UTC (rev 111)
@@ -128,7 +128,7 @@
* Default is false
* @param offset
* @param limit 0 means unlimited page size
- * @param orderedByAttributeName can be null
+ * @param orderedByName
* @param ascending
* @return
* @throws org.jboss.identity.exception.IdentityException
@@ -138,7 +138,7 @@
boolean parent,
boolean inherited,
int offset, int limit,
- String orderedByAttributeName,
+ boolean orderedByName,
boolean ascending) throws IdentityException;
/**
@@ -151,7 +151,7 @@
* @param groupType can be null
* @param offset
* @param limit 0 means unlimited page size
- * @param orderedByAttributeName can be null
+ * @param orderedByName
* @param ascending
* @return
* @throws org.jboss.identity.exception.IdentityException
@@ -159,7 +159,7 @@
Collection<Group> findAssociatedGroups(Identity identity,
GroupType groupType,
int offset, int limit,
- String orderedByAttributeName,
+ boolean orderedByName,
boolean ascending) throws IdentityException;
/**
@@ -172,7 +172,7 @@
* @param inherited if true also identities from subgroubs will be retrieved. Default
is false
* @param offset
* @param limit 0 means unlimited page size
- * @param orderedByAttributeName can be null
+ * @param orderedByName
* @param ascending
* @return
* @throws org.jboss.identity.exception.IdentityException
@@ -180,7 +180,7 @@
Collection<Identity> findAssociatedIdentities(Group group,
boolean inherited,
int offset, int limit,
- String orderedByAttributeName,
+ boolean orderedByName,
boolean ascending) throws IdentityException;
}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RelationshipManagerImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RelationshipManagerImpl.java 2008-10-21
14:30:03 UTC (rev 110)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RelationshipManagerImpl.java 2008-10-21
21:33:37 UTC (rev 111)
@@ -32,10 +32,14 @@
import org.jboss.identity.exception.IdentityException;
import org.jboss.identity.spi.model.IdentityObjectRelationshipType;
import org.jboss.identity.spi.model.IdentityObjectRelationship;
+import org.jboss.identity.spi.model.IdentityObject;
+import org.jboss.identity.spi.model.IdentityObjectType;
import org.jboss.identity.impl.NotYetImplementedException;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
+import java.util.LinkedList;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
@@ -168,18 +172,57 @@
return false;
}
- public Collection<Group> findAssociatedGroups(Group group, GroupType groupType,
boolean parent, boolean inherited, int offset, int limit, String orderedByAttributeName,
boolean ascending) throws IdentityException
+ public Collection<Group> findAssociatedGroups(Group group, GroupType groupType,
boolean parent, boolean inherited, int offset, int limit, boolean orderedByName, boolean
ascending) throws IdentityException
{
- throw new NotYetImplementedException();
+
+ List<Group> identities = new LinkedList<Group>();
+
+ IdentityObjectType iot = getIdentityObjectType(groupType);
+
+ Collection<IdentityObject> ios =
getRepository().findIdentityObject(getInvocationContext(), createIdentityObject(group),
MEMBER, true, offset, limit, false, false);
+
+ for (IdentityObject io : ios)
+ {
+ if (io.getIdentityType().getName().equals(iot.getName()))
+ {
+ identities.add(createGroup(io));
+ }
+ }
+
+ return identities;
+
}
- public Collection<Group> findAssociatedGroups(Identity identity, GroupType
groupType, int offset, int limit, String orderedByAttributeName, boolean ascending) throws
IdentityException
+ public Collection<Group> findAssociatedGroups(Identity identity, GroupType
groupType, int offset, int limit, boolean orderedByName, boolean ascending) throws
IdentityException
{
- throw new NotYetImplementedException();
+ List<Group> identities = new LinkedList<Group>();
+
+ IdentityObjectType iot = getIdentityObjectType(groupType);
+
+ Collection<IdentityObject> ios =
getRepository().findIdentityObject(getInvocationContext(), createIdentityObject(identity),
MEMBER, false, offset, limit, false, false);
+
+ for (IdentityObject io : ios)
+ {
+ if (io.getIdentityType().getName().equals(iot.getName()))
+ {
+ identities.add(createGroup(io));
+ }
+ }
+
+ return identities;
}
- public Collection<Identity> findAssociatedIdentities(Group group, boolean
inherited, int offset, int limit, String orderedByAttributeName, boolean ascending) throws
IdentityException
+ public Collection<Identity> findAssociatedIdentities(Group group, boolean
inherited, int offset, int limit, boolean orderedByName, boolean ascending) throws
IdentityException
{
- throw new NotYetImplementedException();
+ List<Identity> identities = new LinkedList<Identity>();
+
+ Collection<IdentityObject> ios =
getRepository().findIdentityObject(getInvocationContext(), createIdentityObject(group),
MEMBER, true, offset, limit, false, false);
+
+ for (IdentityObject io : ios)
+ {
+ identities.add(createIdentity(io));
+ }
+
+ return identities;
}
}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupImpl.java 2008-10-21
14:30:03 UTC (rev 110)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupImpl.java 2008-10-21
21:33:37 UTC (rev 111)
@@ -64,4 +64,38 @@
{
return null;
}
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ SimpleGroupImpl that = (SimpleGroupImpl)o;
+
+ if (groupType != null ? !groupType.equals(that.groupType) : that.groupType !=
null)
+ {
+ return false;
+ }
+ if (name != null ? !name.equals(that.name) : that.name != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (name != null ? name.hashCode() : 0);
+ result = 31 * result + (id != null ? id.hashCode() : 0);
+ result = 31 * result + (groupType != null ? groupType.hashCode() : 0);
+ return result;
+ }
}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupType.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupType.java 2008-10-21
14:30:03 UTC (rev 110)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleGroupType.java 2008-10-21
21:33:37 UTC (rev 111)
@@ -43,5 +43,29 @@
return name;
}
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+ SimpleGroupType that = (SimpleGroupType)o;
+
+ if (name != null ? !name.equals(that.name) : that.name != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ return (name != null ? name.hashCode() : 0);
+ }
}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleIdentityImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleIdentityImpl.java 2008-10-21
14:30:03 UTC (rev 110)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/SimpleIdentityImpl.java 2008-10-21
21:33:37 UTC (rev 111)
@@ -60,4 +60,33 @@
{
return null;
}
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ SimpleIdentityImpl that = (SimpleIdentityImpl)o;
+
+ if (name != null ? !name.equals(that.name) : that.name != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (name != null ? name.hashCode() : 0);
+ result = 31 * result + (id != null ? id.hashCode() : 0);
+ return result;
+ }
}
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationship.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationship.java 2008-10-21
14:30:03 UTC (rev 110)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/model/hibernate/HibernateIdentityObjectRelationship.java 2008-10-21
21:33:37 UTC (rev 111)
@@ -32,11 +32,13 @@
import javax.persistence.JoinColumn;
import javax.persistence.UniqueConstraint;
import javax.persistence.Column;
+import javax.persistence.FetchType;
import org.jboss.identity.spi.model.IdentityObjectRelationship;
import org.jboss.identity.spi.model.IdentityObjectRelationshipType;
import org.jboss.identity.impl.model.hibernate.HibernateIdentityObject;
import org.jboss.identity.impl.model.hibernate.HibernateIdentityObjectRelationshipType;
+import org.hibernate.annotations.Fetch;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
@@ -69,11 +71,11 @@
@JoinColumn(nullable = false, name="TYPE")
private HibernateIdentityObjectRelationshipType type;
- @ManyToOne
+ @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(nullable = false, name="FROM_IDENTITY")
private HibernateIdentityObject fromIdentityObject;
- @ManyToOne
+ @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(nullable = false, name="TO_IDENTITY")
private HibernateIdentityObject toIdentityObject;
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java 2008-10-21
14:30:03 UTC (rev 110)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/repository/FallbackIdentityStoreRepository.java 2008-10-21
21:33:37 UTC (rev 111)
@@ -146,11 +146,15 @@
return resolveIdentityStore(identityType).findIdentityObject(invocationCtx,
identityType, attributes, offset, limit, orderByName, ascending);
}
- public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext invocationCxt, IdentityObject identity,
IdentityObjectRelationshipType relationshipType, boolean parent, int offset, int limit,
boolean orderByName, boolean ascending) throws IdentityException
+ public Collection<IdentityObject>
findIdentityObject(IdentityStoreInvocationContext invocationCxt,
+ IdentityObject identity,
+ IdentityObjectRelationshipType
relationshipType,
+ boolean parent,
+ int offset, int limit, boolean
orderByName, boolean ascending) throws IdentityException
{
- //TODO:!!!!!!
- //return defaultIdentityStore.findIdentityObject(invocationCxt, identity,
relationshipType, parent, offset, limit, orderByName, ascending);
- throw new NotYetImplementedException();
+ //TODO:
+ return defaultIdentityStore.findIdentityObject(invocationCxt, identity,
relationshipType, parent, offset, limit, orderByName, ascending);
+
}
public IdentityObjectRelationship createRelationship(IdentityStoreInvocationContext
invocationCxt, IdentityObject fromIdentity, IdentityObject toIdentity,
IdentityObjectRelationshipType relationshipType, String relationshipName, boolean
createNames) throws IdentityException
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreImpl.java 2008-10-21
14:30:03 UTC (rev 110)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/store/hibernate/HibernateIdentityStoreImpl.java 2008-10-21
21:33:37 UTC (rev 111)
@@ -343,7 +343,7 @@
}
q =
getHibernateEntityManager(ctx).getSession().createQuery(hqlString.toString())
- .setParameter("relType", relationshipType)
+ .setParameter("relType", relationshipType.getName())
.setParameter("identity",hibernateObject)
.setFirstResult(offset);
@@ -352,8 +352,9 @@
q.setMaxResults(limit);
}
- results = (List<IdentityObject>)q.list();
+ results = q.list();
+
}
catch (Exception e)
{
Modified: trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java 2008-10-21
14:30:03 UTC (rev 110)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/APITestCase.java 2008-10-21
21:33:37 UTC (rev 111)
@@ -159,8 +159,8 @@
final LDAPIdentityStoreConfiguration ldapConfig =
createLDAPConfig("IDENTITY", null, null);
-
+
IdentityStore ldapStore = new LDAPIdentityStore("LDAPStore");
Map<String, IdentityStore> isMap = new HashMap<String,
IdentityStore>();
Modified:
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/OrganizationTest.java
===================================================================
---
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/OrganizationTest.java 2008-10-21
14:30:03 UTC (rev 110)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/OrganizationTest.java 2008-10-21
21:33:37 UTC (rev 111)
@@ -65,9 +65,6 @@
public void testRedHatOrganization() throws Exception
{
-
-
-
GroupType ORGANIZATION = new SimpleGroupType("ORGANIZATION");
GroupType ORGANIZATION_UNIT = new SimpleGroupType("ORGANIZATION_UNIT");
GroupType DIVISION = new SimpleGroupType("DIVISION");
@@ -97,10 +94,17 @@
session.getRelationshipManager().associateGroups(jbossDivision, itDepartment);
session.getRelationshipManager().associateGroups(jbossDivision, hrDepartment);
- Group projectsDepartment =
session.getPersistenceManager().createGroup("Projects", DEPARTMENT);
+ Group rndDepartment = session.getPersistenceManager().createGroup("RnD",
DEPARTMENT);
- session.getRelationshipManager().associateGroups(itDepartment,
projectsDepartment);
+ session.getRelationshipManager().associateGroups(itDepartment, rndDepartment);
+ Group projectsOU =
session.getPersistenceManager().createGroup("Projects", ORGANIZATION_UNIT);
+ Group commonFrameworksOU = session.getPersistenceManager().createGroup("Common
Frameworks", ORGANIZATION_UNIT);
+
+ session.getRelationshipManager().associateGroups(rndDepartment, projectsOU);
+
+ // Projects
+
Group portalProject =
session.getPersistenceManager().createGroup("Portal", PROJECT);
Group soaProject = session.getPersistenceManager().createGroup("SOA",
PROJECT);
Group jbpmProject = session.getPersistenceManager().createGroup("jBPM",
PROJECT);
@@ -108,12 +112,16 @@
Group asProject = session.getPersistenceManager().createGroup("AS",
PROJECT);
Group securityProject =
session.getPersistenceManager().createGroup("Security", PROJECT);
- session.getRelationshipManager().associateGroups(projectsDepartment,
portalProject);
- session.getRelationshipManager().associateGroups(projectsDepartment, soaProject);
- session.getRelationshipManager().associateGroups(projectsDepartment, jbpmProject);
- session.getRelationshipManager().associateGroups(projectsDepartment, asProject);
- session.getRelationshipManager().associateGroups(projectsDepartment, seamProject);
+ session.getRelationshipManager().associateGroups(projectsOU, portalProject);
+ session.getRelationshipManager().associateGroups(projectsOU, soaProject);
+ session.getRelationshipManager().associateGroups(projectsOU, jbpmProject);
+ session.getRelationshipManager().associateGroups(projectsOU, asProject);
+ session.getRelationshipManager().associateGroups(projectsOU, seamProject);
+ // Portal is part of common frameworks
+ session.getRelationshipManager().associateGroups(commonFrameworksOU,
portalProject);
+
+
//TODO: common frameworks for bgeorges - whats the type of group?
// People
@@ -147,7 +155,7 @@
session.getRelationshipManager().associateIdentities(employeesGroup, sshahUser);
session.getRelationshipManager().associateIdentities(employeesGroup, mwringeUser);
- // Portal team for management
+ // Portal team for management purposes
Group portalTeamGroup = session.getPersistenceManager().createGroup("Portal
Team", PEOPLE);
session.getRelationshipManager().associateIdentities(portalTeamGroup,
bdawidowUser);
@@ -156,6 +164,10 @@
session.getRelationshipManager().associateIdentities(portalTeamGroup, sshahUser);
session.getRelationshipManager().associateIdentities(portalTeamGroup,
mwringeUser);
+ // Portal team is under common frameworks
+
+ session.getRelationshipManager().associateGroups(commonFrameworksOU,
portalTeamGroup);
+
// Role Types
RoleType developerRT =
session.getRoleManager().createRoleType("Developer");
@@ -165,6 +177,10 @@
// Assign roles
+ // Common frameworks manager
+
+ session.getRoleManager().createRole(managerRT, bgeorgesUser, commonFrameworksOU);
+
// Portal developers
session.getRoleManager().createRole(developerRT, theuteUser, portalProject);
@@ -191,11 +207,9 @@
session.getRoleManager().createRole(leadDeveloperRT, asaldhanaUser,
securityProject);
- //TODO: Asserts for this structure
-
-
// Check what RoleTypes has user theute
Collection<RoleType> roleTypes =
session.getRoleManager().findIdentityRoleTypes(theuteUser, 0, 0, false, false);
+ assertEquals(3, roleTypes.size());
assertTrue(roleTypes.contains(developerRT));
assertTrue(roleTypes.contains(leadDeveloperRT));
assertTrue(roleTypes.contains(managerRT));
@@ -205,9 +219,51 @@
assertTrue(session.getRoleManager().hasRole(theuteUser, portalProject,
leadDeveloperRT));
assertTrue(session.getRoleManager().hasRole(theuteUser, portalTeamGroup,
managerRT));
- //TODO: Something about profile
+ // Check where anil is Lead Developer and where Developer
+ roleTypes = session.getRoleManager().findIdentityRoleTypes(asaldhanaUser, 0, 0,
false, false);
+ assertEquals(2, roleTypes.size());
+ assertTrue(roleTypes.contains(developerRT));
+ assertTrue(roleTypes.contains(leadDeveloperRT));
+ roleTypes = session.getRoleManager().findRoleTypes(asaldhanaUser, securityProject,
0, 0, false, false);
+ assertEquals(2, roleTypes.size());
+ assertTrue(roleTypes.contains(leadDeveloperRT));
+
+ roleTypes = session.getRoleManager().findRoleTypes(asaldhanaUser, asProject, 0, 0,
false, false);
+ assertEquals(1, roleTypes.size());
+ assertTrue(roleTypes.contains(developerRT));
+
+ // and simpler...
+ assertTrue(session.getRoleManager().hasRole(asaldhanaUser, asProject,
developerRT));
+
+ // Assert relationships
+
+ Collection<Identity> identities =
session.getRelationshipManager().findAssociatedIdentities(portalTeamGroup, false, 0, 0,
false, false);
+ assertEquals(5, identities.size());
+ assertTrue(identities.contains(claprunUser));
+ assertTrue(identities.contains(mwringeUser));
+ assertTrue(identities.contains(sshahUser));
+ assertTrue(identities.contains(whalesUser));
+ assertTrue(identities.contains(bdawidowUser));
+
+ Collection<Group> groups =
session.getRelationshipManager().findAssociatedGroups(rndDepartment, PROJECT, true, false,
0, 0, false, false);
+ assertEquals(0, groups.size());
+
+ // Check to which group Anil belongs
+ groups = session.getRelationshipManager().findAssociatedGroups(asaldhanaUser,
PEOPLE, 0, 0, false, false);
+ assertEquals(1, groups.size());
+ assertTrue(groups.contains(employeesGroup));
+
+ // Now check sshah
+ groups = session.getRelationshipManager().findAssociatedGroups(sshahUser, PEOPLE,
0, 0, false, false);
+ assertEquals(2, groups.size());
+ assertTrue(groups.contains(employeesGroup));
+ assertTrue(groups.contains(portalTeamGroup));
+
+
+ //TODO: Attributes
+
session.getTransaction().commit();
}