Author: chris.laprun(a)jboss.com
Date: 2011-08-02 16:29:19 -0400 (Tue, 02 Aug 2011)
New Revision: 6981
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java
Log:
- Implemented getGroupSites and getPortalSites for a user.
- Added calls to begin and end where needed.
- Replaced OrganizationService and NavigationService by UserPortalConfigService since we
can get theses services from it and we also get access to DescriptionService.
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-08-02
20:09:09 UTC (rev 6980)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-08-02
20:29:19 UTC (rev 6981)
@@ -30,7 +30,11 @@
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.portal.config.Query;
+import org.exoplatform.portal.config.UserACL;
+import org.exoplatform.portal.config.UserPortalConfigService;
+import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.mop.SiteType;
+import org.exoplatform.portal.mop.description.DescriptionService;
import org.exoplatform.portal.mop.navigation.NavigationService;
import org.exoplatform.portal.pom.data.DashboardData;
import org.exoplatform.portal.pom.data.ModelDataStorage;
@@ -40,9 +44,12 @@
import org.exoplatform.portal.pom.data.PortalKey;
import org.exoplatform.services.organization.Group;
import org.exoplatform.services.organization.GroupHandler;
+import org.exoplatform.services.organization.Membership;
import org.exoplatform.services.organization.OrganizationService;
import org.exoplatform.services.organization.User;
import org.exoplatform.services.organization.UserHandler;
+import org.exoplatform.services.security.Identity;
+import org.exoplatform.services.security.MembershipEntry;
import org.gatein.api.GateIn;
import org.gatein.api.content.Category;
import org.gatein.api.content.Content;
@@ -57,6 +64,7 @@
import org.gatein.api.portal.Page;
import org.gatein.api.portal.Portal;
import org.gatein.api.portal.Site;
+import org.gatein.api.util.Filter;
import org.gatein.api.util.IterableIdentifiableCollection;
import org.gatein.api.util.Type;
import org.gatein.common.util.ParameterValidation;
@@ -69,6 +77,7 @@
import org.picocontainer.Startable;
import java.net.URI;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -105,11 +114,10 @@
private ExoContainer container;
private ModelDataStorage dataStorage;
- private NavigationService navigationService;
- private OrganizationService organizationService;
private ApplicationRegistryService registryService;
private GadgetRegistryService gadgetService;
private SourceStorage sourceStorage;
+ private UserPortalConfigService configService;
private Map<Type, Object> properties = new HashMap<Type, Object>(7);
private LifecycleManager lcManager = GateIn.NO_OP_MANAGER;
@@ -201,7 +209,8 @@
{
try
{
- final UserHandler userHandler = organizationService.getUserHandler();
+ begin();
+ final UserHandler userHandler = getOrganizationService().getUserHandler();
// todo: optimize
List<User> users = userHandler.getUserPageList(1000).getAll();
@@ -232,13 +241,19 @@
{
throw new RuntimeException(e);
}
+ finally
+ {
+ end();
+ }
}
public IterableIdentifiableCollection<Site> getGroupSites()
{
try
{
- final GroupHandler groupHandler = organizationService.getGroupHandler();
+ begin();
+
+ final GroupHandler groupHandler = getOrganizationService().getGroupHandler();
Collection groups = groupHandler.getAllGroups();
return new AdaptedIterableIdentifiableCollection<Object,
Site>(groups.size(), groups.iterator())
@@ -266,6 +281,10 @@
{
throw new RuntimeException(e);
}
+ finally
+ {
+ end();
+ }
}
public Site getGroupSite(Id groupId)
@@ -278,12 +297,103 @@
public IterableIdentifiableCollection<Site> getGroupSites(Id userId)
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ final GroupHandler groupHandler = getOrganizationService().getGroupHandler();
+ try
+ {
+ begin();
+ final String id = userId.toString();
+ Collection groups = groupHandler.findGroupsOfUser(id);
+
+ return new AdaptedIterableIdentifiableCollection<Object,
Site>(groups.size(), groups.iterator())
+ {
+ public boolean contains(Id<Site> siteId)
+ {
+ try
+ {
+ Group group = groupHandler.findGroupById(siteId.toString());
+ return group != null && !groupHandler.findGroupByMembership(id,
null).isEmpty();
+ }
+ catch (Exception e)
+ {
+ return false;
+ }
+ }
+
+ public Site adapt(Object old)
+ {
+ Group group = (Group)old;
+ return getGroupSite(GROUP_CONTEXT.parse(group.getId()));
+ }
+ };
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ end();
+ }
}
public IterableIdentifiableCollection<Portal> getPortalSites(Id userId)
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ try
+ {
+ begin();
+ final List<PortalData> portalDatas = dataStorage.find(PORTALS).getAll();
+
+ // first build Identity based on user id so that we can check its permissions
using UserACL... ugh! :(
+ final String user = userId.toString();
+ final Collection membershipsByUser =
getOrganizationService().getMembershipHandler().findMembershipsByUser(user);
+ Collection<MembershipEntry> membershipEntries = new
ArrayList<MembershipEntry>(membershipsByUser.size());
+ for (Object o : membershipsByUser)
+ {
+ Membership membership = (Membership)o;
+ membershipEntries.add(new MembershipEntry(membership.getGroupId(),
membership.getMembershipType()));
+ }
+ final Identity identity = new Identity(user, membershipEntries);
+
+ final List<Portal> portals = new
ArrayList<Portal>(portalDatas.size());
+ final Filter<PortalData> filter = new Filter<PortalData>()
+ {
+ @Override
+ public boolean accept(PortalData item)
+ {
+ return getUserACL().hasPermission(identity, new PortalConfig(item));
+ }
+ };
+
+ for (PortalData portalData : portalDatas)
+ {
+ if(filter.accept(portalData))
+ {
+ portals.add(new PortalImpl(portalData, this));
+ }
+ }
+
+ return new AdaptedIterableIdentifiableCollection<Portal,
Portal>(portals.size(), portals.iterator())
+ {
+ public Portal adapt(Portal old)
+ {
+ return old;
+ }
+
+ public boolean contains(Id<Portal> id)
+ {
+ final PortalData portalData = getPortalDataFor(id);
+ return portalData != null && filter.accept(portalData);
+ }
+ };
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ end();
+ }
}
public Site getDashboard(Id userId)
@@ -400,11 +510,10 @@
public void start()
{
dataStorage =
(ModelDataStorage)container.getComponentInstanceOfType(ModelDataStorage.class);
- navigationService =
(NavigationService)container.getComponentInstanceOfType(NavigationService.class);
- organizationService =
(OrganizationService)container.getComponentInstanceOfType(OrganizationService.class);
registryService =
(ApplicationRegistryService)container.getComponentInstanceOfType(ApplicationRegistryService.class);
gadgetService =
(GadgetRegistryService)container.getComponentInstanceOfType(GadgetRegistryService.class);
sourceStorage =
(SourceStorage)container.getComponentInstanceOfType(SourceStorage.class);
+ configService =
(UserPortalConfigService)container.getComponentInstanceOfType(UserPortalConfigService.class);
}
public void stop()
@@ -419,7 +528,7 @@
public NavigationService getNavigationService()
{
- return navigationService;
+ return configService.getNavigationService();
}
public ApplicationRegistryService getRegistryService()
@@ -465,4 +574,19 @@
{
return gadgetService;
}
+
+ public OrganizationService getOrganizationService()
+ {
+ return configService.getOrganizationService();
+ }
+
+ public UserACL getUserACL()
+ {
+ return configService.getUserACL();
+ }
+
+ public DescriptionService getDescriptionService()
+ {
+ return configService.getDescriptionService();
+ }
}
Show replies by date