Author: julien_viet
Date: 2011-08-24 08:11:40 -0400 (Wed, 24 Aug 2011)
New Revision: 7207
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/PortalNamesCache.java
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/SearchTask.java
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
Log:
GTNPORTAL-2047 : Provide retrieval of all group site names
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java 2011-08-24
06:21:32 UTC (rev 7206)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorage.java 2011-08-24
12:11:40 UTC (rev 7207)
@@ -227,6 +227,8 @@
*/
public List<String> getAllPortalNames() throws Exception;
+ public List<String> getAllGroupNames() throws Exception;
+
/*************************************************************
Public API to access/modify MOP mixin, temporarily put here
**************************************************************/
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java 2011-08-24
06:21:32 UTC (rev 7206)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java 2011-08-24
12:11:40 UTC (rev 7207)
@@ -227,6 +227,18 @@
return list;
}
+ public List<String> getAllGroupNames() throws Exception {
+
+ Query<PortalKey> q = new Query<PortalKey>("group",
null,PortalKey.class);
+ List<PortalKey> keys = delegate.find(q).getAll();
+ LinkedList<String> list = new LinkedList<String>();
+ for (PortalKey key : keys)
+ {
+ list.add(key.getId());
+ }
+ return list;
+ }
+
public <T> ListAccess<T> find2(Query<T> q) throws Exception
{
return find2(q, null);
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java 2011-08-24
06:21:32 UTC (rev 7206)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/UserPortalConfigService.java 2011-08-24
12:11:40 UTC (rev 7207)
@@ -30,6 +30,7 @@
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.config.model.TransientApplicationState;
import org.exoplatform.portal.mop.SiteKey;
+import org.exoplatform.portal.mop.SiteType;
import org.exoplatform.portal.mop.description.DescriptionService;
import org.exoplatform.portal.mop.navigation.NavigationContext;
import org.exoplatform.portal.mop.navigation.NavigationService;
@@ -510,18 +511,45 @@
}
/**
- * Returns the list of all portal names.
+ * Returns the list of all portal site names.
*
- * @return the list of all portal names
+ * @return the list of all portal site names
* @throws Exception any exception
*/
public List<String> getAllPortalNames() throws Exception
{
- List<String> list = storage_.getAllPortalNames();
+ return getAllSiteNames(SiteType.PORTAL);
+ }
+
+ /**
+ * Returns the list of all group site names.
+ *
+ * @return the list of all group site names
+ * @throws Exception any exception
+ */
+ public List<String> getAllGroupNames() throws Exception
+ {
+ return getAllSiteNames(SiteType.GROUP);
+ }
+
+ private List<String> getAllSiteNames(SiteType siteType) throws Exception
+ {
+ List<String> list;
+ switch (siteType)
+ {
+ case PORTAL:
+ list = storage_.getAllPortalNames();
+ break;
+ case GROUP:
+ list = storage_.getAllGroupNames();
+ break;
+ default:
+ throw new AssertionError();
+ }
for (Iterator<String> i = list.iterator();i.hasNext();)
{
String name = i.next();
- PortalConfig config = storage_.getPortalConfig(name);
+ PortalConfig config = storage_.getPortalConfig(siteType.getName(), name);
if (config == null || !userACL_.hasPermission(config))
{
i.remove();
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java 2011-08-24
06:21:32 UTC (rev 7206)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/POMDataStorage.java 2011-08-24
12:11:40 UTC (rev 7207)
@@ -253,6 +253,10 @@
{
return (LazyPageList<T>)pomMgr.execute(new
SearchTask.FindSiteKey((Query<PortalKey>)q));
}
+ else if (PortalKey.class.equals(type) &&
"group".equals(q.getOwnerType()))
+ {
+ return (LazyPageList<T>)pomMgr.execute(new
SearchTask.FindSiteKey((Query<PortalKey>)q));
+ }
else
{
throw new UnsupportedOperationException("Could not perform search on query
" + q);
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/PortalNamesCache.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/PortalNamesCache.java 2011-08-24
06:21:32 UTC (rev 7206)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/cache/PortalNamesCache.java 2011-08-24
12:11:40 UTC (rev 7207)
@@ -52,12 +52,13 @@
{
if (task instanceof SearchTask.FindSiteKey)
{
- List<PortalKey> data =
(List<PortalKey>)session.getFromCache(SearchTask.FindSiteKey.class);
+ SearchTask.FindSiteKey find = (SearchTask.FindSiteKey)task;
+ List<PortalKey> data =
(List<PortalKey>)session.getFromCache(find.getKey());
if (data == null)
{
V result = super.execute(session, task);
LazyPageList<PortalKey> list =
(LazyPageList<PortalKey>)result;
- session.putInCache(SearchTask.FindSiteKey.class,
Collections.unmodifiableList(new ArrayList<PortalKey>(list.getAll())));
+ session.putInCache(find.getKey(), Collections.unmodifiableList(new
ArrayList<PortalKey>(list.getAll())));
return result;
}
else
@@ -68,7 +69,8 @@
else if (task instanceof PortalConfigTask.Save || task instanceof
PortalConfigTask.Remove)
{
V result = super.execute(session, task);
- session.scheduleForEviction(SearchTask.FindSiteKey.class);
+ session.scheduleForEviction(SearchTask.FindSiteKey.PORTAL_KEY);
+ session.scheduleForEviction(SearchTask.FindSiteKey.GROUP_KEY);
return result;
}
}
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/SearchTask.java
===================================================================
---
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/SearchTask.java 2011-08-24
06:21:32 UTC (rev 7206)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/SearchTask.java 2011-08-24
12:11:40 UTC (rev 7207)
@@ -32,6 +32,7 @@
import org.gatein.mop.api.workspace.Site;
import org.gatein.mop.api.workspace.Workspace;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -119,19 +120,63 @@
public static class FindSiteKey extends SearchTask<PortalKey>
{
+ /** . */
+ public static Serializable PORTAL_KEY = "FindPortalSiteKey";
+
+ /** . */
+ public static Serializable GROUP_KEY = "FindGroupSiteKey";
+
+ /** . */
+ private final ObjectType<Site> type;
+
+ /** . */
+ private final Serializable key;
+
public FindSiteKey(Query<PortalKey> siteQuery)
{
super(siteQuery);
+
+ //
+ ObjectType<Site> type;
+ Serializable key;
+ if ("portal".equals(siteQuery.getOwnerType()))
+ {
+ type = ObjectType.PORTAL_SITE;
+ key = PORTAL_KEY;
+ }
+ else if ("group".equals(siteQuery.getOwnerType()))
+ {
+ type = ObjectType.GROUP_SITE;
+ key = GROUP_KEY;
+ }
+ else
+ {
+ throw new IllegalArgumentException("Invalid site type " +
siteQuery.getOwnerType());
+ }
+
+ //
+ this.type = type;
+ this.key = key;
}
+ public ObjectType<Site> getType()
+ {
+ return type;
+ }
+
+ public Serializable getKey()
+ {
+ return key;
+ }
+
public LazyPageList<PortalKey> run(final POMSession session) throws
Exception
{
Workspace workspace = session.getWorkspace();
- Collection<Site> sites = workspace.getSites(ObjectType.PORTAL_SITE);
+ Collection<Site> sites = workspace.getSites(type);
final ArrayList<PortalKey> keys = new
ArrayList<PortalKey>(sites.size());
for (Site site : sites)
{
- keys.add(new PortalKey("portal", site.getName()));
+ keys.add(new PortalKey(q.getOwnerType(), site.getName()));
}
ListAccess<PortalKey> la = new ListAccess<PortalKey>()
{
Modified:
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
===================================================================
---
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java 2011-08-24
06:21:32 UTC (rev 7206)
+++
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java 2011-08-24
12:11:40 UTC (rev 7207)
@@ -785,16 +785,26 @@
public void testGetAllPortalNames() throws Exception
{
- final List<String> names = storage_.getAllPortalNames();
+ testGetAllSiteNames("portal", "getAllPortalNames");
+ }
+ public void testGetAllGroupNames() throws Exception
+ {
+ testGetAllSiteNames("group", "getAllGroupNames");
+ }
+
+ private void testGetAllSiteNames(String siteType, final String methodName) throws
Exception
+ {
+ final List<String> names =
(List<String>)storage_.getClass().getMethod(methodName).invoke(storage_);
+
// Create new portal
- storage_.create(new PortalConfig("portal",
"testGetAllPortalNames"));
+ storage_.create(new PortalConfig(siteType, "testGetAllSiteNames"));
// Test during tx we see the good names
- List<String> transientNames = storage_.getAllPortalNames();
- assertTrue(transientNames.containsAll(names));
+ List<String> transientNames =
(List<String>)storage_.getClass().getMethod(methodName).invoke(storage_);
+ assertTrue("Was expecting " + transientNames + " to contain " +
names, transientNames.containsAll(names));
transientNames.removeAll(names);
- assertEquals(Collections.singletonList("testGetAllPortalNames"),
transientNames);
+ assertEquals(Collections.singletonList("testGetAllSiteNames"),
transientNames);
// Test we have not seen anything yet outside of tx
final CountDownLatch addSync = new CountDownLatch(1);
@@ -807,7 +817,7 @@
begin();
try
{
- List<String> isolatedNames = storage_.getAllPortalNames();
+ List<String> isolatedNames =
(List<String>)storage_.getClass().getMethod(methodName).invoke(storage_);
assertEquals(new HashSet<String>(names), new
HashSet<String>(isolatedNames));
}
catch (Throwable t)
@@ -836,17 +846,17 @@
// We test we observe the change
begin();
- List<String> afterNames = storage_.getAllPortalNames();
+ List<String> afterNames =
(List<String>)storage_.getClass().getMethod(methodName).invoke(storage_);
assertTrue(afterNames.containsAll(names));
afterNames.removeAll(names);
- assertEquals(Collections.singletonList("testGetAllPortalNames"),
afterNames);
+ assertEquals(Collections.singletonList("testGetAllSiteNames"),
afterNames);
// Then we remove the newly created portal
- storage_.remove(new PortalConfig("portal",
"testGetAllPortalNames"));
+ storage_.remove(new PortalConfig(siteType, "testGetAllSiteNames"));
// Test we are syeing the transient change
transientNames.clear();
- transientNames = storage_.getAllPortalNames();
+ transientNames =
(List<String>)storage_.getClass().getMethod(methodName).invoke(storage_);
assertEquals(names, transientNames);
// Test we have not seen anything yet outside of tx
@@ -859,10 +869,10 @@
begin();
try
{
- List<String> isolatedNames = storage_.getAllPortalNames();
- assertTrue(isolatedNames.containsAll(names));
+ List<String> isolatedNames =
(List<String>)storage_.getClass().getMethod(methodName).invoke(storage_);
+ assertTrue("Was expecting " + isolatedNames + " to contain
" + names, isolatedNames.containsAll(names));
isolatedNames.removeAll(names);
- assertEquals(Collections.singletonList("testGetAllPortalNames"),
isolatedNames);
+ assertEquals(Collections.singletonList("testGetAllSiteNames"),
isolatedNames);
}
catch (Throwable t)
{
@@ -890,7 +900,7 @@
// Now test it is still removed
begin();
- afterNames = storage_.getAllPortalNames();
+ afterNames =
(List<String>)storage_.getClass().getMethod(methodName).invoke(storage_);
assertEquals(new HashSet<String>(names), new
HashSet<String>(afterNames));
}