Author: bdaw
Date: 2008-10-22 07:47:54 -0400 (Wed, 22 Oct 2008)
New Revision: 113
Modified:
trunk/identity-api/src/main/java/org/jboss/identity/api/AttributesManager.java
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipManager.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AttributesManagerImpl.java
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RelationshipManagerImpl.java
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/OrganizationTest.java
Log:
some more stuff for portal sample testcase
Modified: trunk/identity-api/src/main/java/org/jboss/identity/api/AttributesManager.java
===================================================================
---
trunk/identity-api/src/main/java/org/jboss/identity/api/AttributesManager.java 2008-10-22
10:19:16 UTC (rev 112)
+++
trunk/identity-api/src/main/java/org/jboss/identity/api/AttributesManager.java 2008-10-22
11:47:54 UTC (rev 113)
@@ -76,6 +76,16 @@
Map<String, String[]> getAttributes(IdentityType identity) throws
IdentityException;
/**
+ * Get attribute values for the given IdentityType
+ *
+ * @param identity
+ * @param attributeName
+ * @return
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ String[] getAttributeValues(IdentityType identity, String attributeName) throws
IdentityException;
+
+ /**
* Update attributes with new values - previous values will be overwritten. All the
other attributes are not changed -
* method doesn't overwrite whole attribute set connected with a given
IdentityType object.
* @param identity
@@ -97,6 +107,30 @@
throws IdentityException;
/**
+ * Add new attribute - if attribute with given name already exists the values
+ * will be appended
+ *
+ * @param identity
+ * @param attributeName
+ * @param values
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ void addAttribute(IdentityType identity, String attributeName, String[] values)
+ throws IdentityException;
+
+ /**
+ * Add new attribute - if attribute with given name already exists the values
+ * will be appended
+ *
+ * @param identity
+ * @param attributeName
+ * @param values
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ void addAttribute(IdentityType identity, String attributeName, String value)
+ throws IdentityException;
+
+ /**
* Remove attributes
*
* @param identity
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-22
10:19:16 UTC (rev 112)
+++
trunk/identity-api/src/main/java/org/jboss/identity/api/RelationshipManager.java 2008-10-22
11:47:54 UTC (rev 113)
@@ -111,6 +111,16 @@
<G extends IdentityType, I extends IdentityType> boolean
isAssociated(Collection<G> parents, Collection<I> members)
throws IdentityException;
+ /**
+ * <p>Check if association is present </p>
+ * @param parent
+ * @param member
+ * @return
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ <G extends IdentityType, I extends IdentityType> boolean isAssociated(G parent,
I member)
+ throws IdentityException;
+
// Resolve relationships
/**
@@ -163,6 +173,25 @@
boolean ascending) throws IdentityException;
/**
+ * Find all groups that given identity is associated with.
+ * If the paginatedSearch or orderedSearch operations
+ * are not supported, dedicated parameters will
+ * take no effect
+ *
+ * @param identity child identity
+ * @param offset
+ * @param limit 0 means unlimited page size
+ * @param orderedByName
+ * @param ascending
+ * @return
+ * @throws org.jboss.identity.exception.IdentityException
+ */
+ Collection<Group> findAssociatedGroups(Identity identity,
+ int offset, int limit,
+ boolean orderedByName,
+ boolean ascending) throws IdentityException;
+
+ /**
* Find identities that have relationship with given parent group.
* If the paginatedSearch or orderedSearch operations
* are not supported in this store implementation, dedicated parameters will
Modified:
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AttributesManagerImpl.java
===================================================================
---
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AttributesManagerImpl.java 2008-10-22
10:19:16 UTC (rev 112)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/AttributesManagerImpl.java 2008-10-22
11:47:54 UTC (rev 113)
@@ -96,6 +96,29 @@
}
+ public String[] getAttributeValues(IdentityType identity, String attributeName) throws
IdentityException
+ {
+ return getAttributes(identity).get(attributeName);
+ }
+
+ public void addAttribute(IdentityType identity, String attributeName, String[] values)
throws IdentityException
+ {
+ Map<String, String[]> attrs = new HashMap<String, String[]>();
+ attrs.put(attributeName, values);
+
+ addAttributes(identity, attrs);
+
+ }
+
+ public void addAttribute(IdentityType identity, String attributeName, String value)
throws IdentityException
+ {
+ Map<String, String[]> attrs = new HashMap<String, String[]>();
+ attrs.put(attributeName, new String[]{value});
+
+ addAttributes(identity, attrs);
+
+ }
+
public void addAttributes(IdentityType identity, Map<String, String[]>
attributes) throws IdentityException
{
Map<String, Set<String>> attrs = new HashMap<String,
Set<String>>();
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-22
10:19:16 UTC (rev 112)
+++
trunk/identity-impl/src/main/java/org/jboss/identity/impl/api/RelationshipManagerImpl.java 2008-10-22
11:47:54 UTC (rev 113)
@@ -40,6 +40,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
+import java.util.Set;
+import java.util.HashSet;
/**
* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
@@ -169,9 +171,19 @@
}
}
- return false;
+ return true;
}
+ public <G extends IdentityType, I extends IdentityType> boolean isAssociated(G
parent, I member) throws IdentityException
+ {
+ Set<G> parents = new HashSet<G>();
+ parents.add(parent);
+ Set<I> members = new HashSet<I>();
+ members.add(member);
+
+ return isAssociated(parents, members);
+ }
+
public Collection<Group> findAssociatedGroups(Group group, GroupType groupType,
boolean parent, boolean inherited, int offset, int limit, boolean orderedByName, boolean
ascending) throws IdentityException
{
@@ -212,6 +224,22 @@
return identities;
}
+ public Collection<Group> findAssociatedGroups(Identity identity, int offset, int
limit, boolean orderedByName, boolean ascending) throws IdentityException
+ {
+ List<Group> identities = new LinkedList<Group>();
+
+ Collection<IdentityObject> ios =
getRepository().findIdentityObject(getInvocationContext(), createIdentityObject(identity),
MEMBER, false, offset, limit, false, false);
+
+ for (IdentityObject io : ios)
+ {
+ identities.add(createGroup(io));
+ }
+
+ return identities;
+ }
+
+
+
public Collection<Identity> findAssociatedIdentities(Group group, boolean
inherited, int offset, int limit, boolean orderedByName, boolean ascending) throws
IdentityException
{
List<Identity> identities = new LinkedList<Identity>();
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-22
10:19:16 UTC (rev 112)
+++
trunk/identity-impl/src/test/java/org/jboss/identity/impl/api/OrganizationTest.java 2008-10-22
11:47:54 UTC (rev 113)
@@ -348,6 +348,8 @@
Group acmeOrg = session.getPersistenceManager().createGroup("ACME",
ORGANIZATION);
+ session.getRelationshipManager().associateGroups(organizationRootGroup, acmeOrg);
+
Group departmentsOU =
session.getPersistenceManager().createGroup("Departments", ORGANIZATION_UNIT);
Group officesOU = session.getPersistenceManager().createGroup("Offices",
ORGANIZATION_UNIT);
Group employeesOU =
session.getPersistenceManager().createGroup("Employees", ORGANIZATION_UNIT);
@@ -390,9 +392,109 @@
Identity billUser =
session.getPersistenceManager().createIdentity("bill");
Identity jackUser =
session.getPersistenceManager().createIdentity("jack");
- // Roles assignment
+ // All users are under people root
+ session.getRelationshipManager().associateIdentities(usersROOTGroup, anneUser);
+ session.getRelationshipManager().associateIdentities(usersROOTGroup, marieUser);
+ session.getRelationshipManager().associateIdentities(usersROOTGroup, eveUser);
+ session.getRelationshipManager().associateIdentities(usersROOTGroup,
angelinaUser);
+ session.getRelationshipManager().associateIdentities(usersROOTGroup, joannaUser);
+ session.getRelationshipManager().associateIdentities(usersROOTGroup, merilUser);
+ session.getRelationshipManager().associateIdentities(usersROOTGroup, johnUser);
+ session.getRelationshipManager().associateIdentities(usersROOTGroup, stanUser);
+ session.getRelationshipManager().associateIdentities(usersROOTGroup, chrisUser);
+ session.getRelationshipManager().associateIdentities(usersROOTGroup, billUser);
+ session.getRelationshipManager().associateIdentities(usersROOTGroup, jackUser);
+
+ //
+
+
+ // Anna is...
+
+ // Anna Smith...
+
+
+ session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_NAME_GIVEN, "Anne");
+ session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_NAME_FAMILY, "Smith");
+ session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_JOB_TITLE, "Senior Software Developer");
+ session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, "anne.smith(a)acme.com");
+ session.getAttributesManager().addAttribute(anneUser,
P3PConstants.INFO_USER_BUSINESS_INFO_TELECOM_MOBILE_NUMBER, "777 777 777 7
77");
+
+ // Anna works in Paris office and participates in BASE jumping community as a forum
moderator and CMS admin
+
+ session.getRelationshipManager().associateIdentities(parisOffice, anneUser);
+
+ // Anne could be just associated with BASE jumping community group using
RelationshipManager but insted Role mechanism
+ // is used to have more fine grained control of access rights inside of a
community
+
+ session.getRoleManager().createRole(communityMemberRT, anneUser,
baseJumpingCommunity);
+ session.getRoleManager().createRole(communityForumModeratorRT, anneUser,
baseJumpingCommunity);
+ session.getRoleManager().createRole(communityCMSAdminRT, anneUser,
baseJumpingCommunity);
+
+ // Anne belongs to CMS portal admins security group
+
+ session.getRelationshipManager().associateIdentities(cmsAdminGroup, anneUser);
+
+ // Ann is also an owner of geeks community
+
+ session.getRoleManager().createRole(communityOwnerRT, anneUser, geeksCommunity);
+
+
+ //
+
+
+ // Angelina ...
+
+ session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_NAME_GIVEN, "Angelina");
+ session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_NAME_FAMILY, "Blond");
+ session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_JOB_TITLE, "Very important looking job title");
+ session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, "angelina1979(a)acme.com");
+ session.getAttributesManager().addAttribute(angelinaUser,
P3PConstants.INFO_USER_BUSINESS_INFO_TELECOM_MOBILE_NUMBER, "888 88 88 8888");
+
+ // She works in London and is office manager there - se both RelationshipManager
and RoleManager used against
+ // the same pair of identity objects
+
+ session.getRelationshipManager().associateIdentities(londonOffice, angelinaUser);
+
+ session.getRoleManager().createRole(officeManagerRT, angelinaUser, londonOffice);
+
+ // Angelina is member of geeks community and manages cms content there
+
+ session.getRoleManager().createRole(communityMemberRT, angelinaUser,
geeksCommunity);
+ session.getRoleManager().createRole(communityCMSAdminRT, angelinaUser,
geeksCommunity);
+
+ // As office manager she also edits portal cms content
+
+ session.getRelationshipManager().associateIdentities(cmsEditorGroup,
angelinaUser);
+
+
+ //
+
+
+ // Some assertions
+
+ // How many users do we have in whole acme org and how many people in paris and
london offices
+ assertEquals(11,
session.getRelationshipManager().findAssociatedIdentities(usersROOTGroup, false, 0, 0,
false, false).size());
+ assertEquals(1,
session.getRelationshipManager().findAssociatedIdentities(parisOffice, false, 0, 0, false,
false).size());
+ assertEquals(1,
session.getRelationshipManager().findAssociatedIdentities(londonOffice, false, 0, 0,
false, false).size());
+
+
+ // Is anne geeks community owner?
+ assertTrue(session.getRoleManager().hasRole(anneUser, geeksCommunity,
communityOwnerRT));
+
+ // Does she belong to cms admins
+ assertTrue(session.getRelationshipManager().isAssociated(cmsAdminGroup,
anneUser));
+
+ // Check all groups that anna belongs to
+ Collection<Group> groups =
session.getRelationshipManager().findAssociatedGroups(anneUser, 0, 0, false, false );
+ assertEquals(3, groups.size());
+ assertTrue(groups.contains(usersROOTGroup));
+ assertTrue(groups.contains(parisOffice));
+ assertTrue(groups.contains(cmsAdminGroup));
+
+
+
session.getTransaction().commit();
}