Author: bdaw
Date: 2011-10-06 11:07:16 -0400 (Thu, 06 Oct 2011)
New Revision: 7682
Added:
epp/portal/branches/EPP_5_2_Branch/component/identity/src/main/java/org/exoplatform/services/organization/idm/IDMMembershipListAccess.java
Modified:
epp/portal/branches/EPP_5_2_Branch/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipDAOImpl.java
epp/portal/branches/EPP_5_2_Branch/pom.xml
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/FindMembershipByGroupPageList.java
Log:
JBEPP-909 All memberships needs to be obtained when change group in UIGroupExplorer
Added:
epp/portal/branches/EPP_5_2_Branch/component/identity/src/main/java/org/exoplatform/services/organization/idm/IDMMembershipListAccess.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/identity/src/main/java/org/exoplatform/services/organization/idm/IDMMembershipListAccess.java
(rev 0)
+++
epp/portal/branches/EPP_5_2_Branch/component/identity/src/main/java/org/exoplatform/services/organization/idm/IDMMembershipListAccess.java 2011-10-06
15:07:16 UTC (rev 7682)
@@ -0,0 +1,186 @@
+/**
+* Copyright (C) 2009 eXo Platform SAS.
+*
+* 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.exoplatform.services.organization.idm;
+
+import org.exoplatform.commons.utils.ListAccess;
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.services.organization.Membership;
+import org.exoplatform.services.organization.OrganizationService;
+import org.exoplatform.services.organization.User;
+import org.exoplatform.services.organization.impl.GroupImpl;
+import org.exoplatform.services.organization.impl.UserImpl;
+import org.gatein.common.logging.LogLevel;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+import org.picketlink.idm.api.Group;
+import org.picketlink.idm.api.IdentitySearchCriteria;
+import org.picketlink.idm.api.Role;
+import org.picketlink.idm.api.SortOrder;
+import org.picketlink.idm.api.query.UserQuery;
+import org.picketlink.idm.impl.api.IdentitySearchCriteriaImpl;
+
+import java.io.Serializable;
+import java.util.LinkedList;
+import java.util.List;
+
+/*
+* @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+*/
+public class IDMMembershipListAccess implements ListAccess<Membership>,
Serializable
+{
+ private static Logger log = LoggerFactory.getLogger(IDMMembershipListAccess.class);
+
+ private final Group group;
+
+ private final org.picketlink.idm.api.User user;
+
+ private int size = -1;
+
+ public IDMMembershipListAccess(Group group)
+ {
+ this.group = group;
+ this.user = null;
+ }
+
+ public IDMMembershipListAccess(org.picketlink.idm.api.User user)
+ {
+ this.group = null;
+ this.user = user;
+ }
+
+ public Membership[] load(int index, int length) throws Exception,
IllegalArgumentException
+ {
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "load",
+ new Object[]{
+ "index", index,
+ "length", length
+ }
+ );
+ }
+
+ IdentitySearchCriteria crit = new IdentitySearchCriteriaImpl().page(index,
length);
+ crit.sort(SortOrder.ASCENDING);
+
+
+ List<Role> roles = null;
+
+ if (group != null)
+ {
+ roles = new
LinkedList<Role>(getIDMService().getIdentitySession().getRoleManager().findRoles(group,
null, crit));
+ }
+ else if (user != null)
+ {
+ roles = new
LinkedList<Role>(getIDMService().getIdentitySession().getRoleManager().findRoles(user,
null, crit));
+ }
+
+ Membership[] memberships = new Membership[roles.size()];
+
+ for (int i = 0; i < roles.size(); i++)
+ {
+
+ Role role = roles.get(i);
+
+ org.exoplatform.services.organization.Group exoGroup =
+
((GroupDAOImpl)getOrganizationService().getGroupHandler()).convertGroup(role.getGroup());
+
+ MembershipImpl memb = new MembershipImpl();
+ memb.setGroupId(exoGroup.getId());
+ memb.setUserName(role.getUser().getId());
+ memb.setMembershipType(role.getRoleType().getName());
+
+ memberships[i] = memb;
+ }
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "load",
+ memberships
+ );
+ }
+
+ return memberships;
+ }
+
+ public int getSize() throws Exception
+ {
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodIn(
+ log,
+ LogLevel.TRACE,
+ "getSize",
+ null
+ );
+ }
+
+ int result = 0;
+
+ if (size < 0)
+ {
+ if (group != null && user == null)
+ {
+ result =
getIDMService().getIdentitySession().getRoleManager().getRolesCount(group, null, null);
+ }
+ else if (group == null && user != null)
+ {
+ result =
getIDMService().getIdentitySession().getRoleManager().getRolesCount(user, null, null);
+ }
+
+ size = result;
+ }
+ else
+ {
+ result = size;
+ }
+
+ if (log.isTraceEnabled())
+ {
+ Tools.logMethodOut(
+ log,
+ LogLevel.TRACE,
+ "getSize",
+ result
+ );
+ }
+
+ return result;
+
+ }
+
+ PicketLinkIDMService getIDMService()
+ {
+ return (PicketLinkIDMService)
+
PortalContainer.getInstance().getComponentInstanceOfType(PicketLinkIDMService.class);
+ }
+
+ PicketLinkIDMOrganizationServiceImpl getOrganizationService()
+ {
+ return (PicketLinkIDMOrganizationServiceImpl)
+
PortalContainer.getInstance().getComponentInstanceOfType(OrganizationService.class);
+ }
+}
Modified:
epp/portal/branches/EPP_5_2_Branch/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipDAOImpl.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipDAOImpl.java 2011-10-06
13:51:56 UTC (rev 7681)
+++
epp/portal/branches/EPP_5_2_Branch/component/identity/src/main/java/org/exoplatform/services/organization/idm/MembershipDAOImpl.java 2011-10-06
15:07:16 UTC (rev 7682)
@@ -763,8 +763,19 @@
return result;
}
+
+ public ListAccess<Membership> findAllMembershipsByUser(User user) throws
Exception
+ {
+ org.picketlink.idm.api.User gtnUser =
service_.getIdentitySession().getPersistenceManager().findUser(user.getUserName());
+
+ if (gtnUser == null)
+ {
+ log.log(LogLevel.ERROR, "Internal ERROR. Cannot obtain user: " +
user.getUserName());
+ return new ListAccessImpl(Membership.class, Collections.emptyList());
+ }
+ return new IDMMembershipListAccess(gtnUser);
+ }
-
public Collection findMembershipsByGroup(Group group) throws Exception
{
return findMembershipsByGroupId(group.getId());
@@ -772,7 +783,20 @@
public ListAccess<Membership> findAllMembershipsByGroup(Group group) throws
Exception
{
- return new ListAccessImpl(Membership.class, (List)findMembershipsByGroup(group));
+ String plGroupName = getPLIDMGroupName(getGroupNameFromId(group.getId()));
+
+ String gid =
+ getIdentitySession().getPersistenceManager().
+ createGroupKey(plGroupName, getGroupTypeFromId(group.getId()));
+
+ org.picketlink.idm.api.Group gtnGroup =
service_.getIdentitySession().getPersistenceManager().findGroupByKey(gid);
+
+ if (gtnGroup == null)
+ {
+ log.log(LogLevel.ERROR, "Internal ERROR. Cannot obtain group: " +
group.getId());
+ return new ListAccessImpl(Membership.class, Collections.emptyList());
+ }
+ return new IDMMembershipListAccess(gtnGroup);
}
public Collection findMembershipsByGroupId(String groupId) throws Exception
Modified: epp/portal/branches/EPP_5_2_Branch/pom.xml
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/pom.xml 2011-10-06 13:51:56 UTC (rev 7681)
+++ epp/portal/branches/EPP_5_2_Branch/pom.xml 2011-10-06 15:07:16 UTC (rev 7682)
@@ -52,7 +52,7 @@
<org.gatein.dep.version>1.1.0-GA</org.gatein.dep.version>
<org.gatein.wci.version>2.1.0-Beta06</org.gatein.wci.version>
<org.gatein.pc.version>2.3.0-Beta06</org.gatein.pc.version>
- <org.picketlink.idm>1.3.0.Alpha06</org.picketlink.idm>
+ <org.picketlink.idm>1.3.0.Alpha08</org.picketlink.idm>
<org.gatein.wsrp.version>2.1.0-Beta07-EPP520</org.gatein.wsrp.version>
<org.gatein.mop.version>1.1.0-Beta06</org.gatein.mop.version>
<org.gatein.mgmt.version>1.0.0-Beta04</org.gatein.mgmt.version>
Modified:
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/FindMembershipByGroupPageList.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/FindMembershipByGroupPageList.java 2011-10-06
13:51:56 UTC (rev 7681)
+++
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/FindMembershipByGroupPageList.java 2011-10-06
15:07:16 UTC (rev 7682)
@@ -50,7 +50,6 @@
OrganizationService service =
(OrganizationService)container.getComponentInstance(OrganizationService.class);
MembershipHandler handler = service.getMembershipHandler();
Group group = service.getGroupHandler().findGroupById(state);
- List<Membership> memberships =
(List<Membership>)handler.findMembershipsByGroup(group);
- return new ListAccessImpl<Membership>(Membership.class, memberships);
+ return handler.findAllMembershipsByGroup(group);
}
}