Author: liem_nguyen
Date: 2010-02-24 05:25:27 -0500 (Wed, 24 Feb 2010)
New Revision: 1835
Modified:
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestPortalConfig.java
Log:
GTNPORTAL-717 Navigation Groups should be ordered alphabetically
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 2010-02-24
10:08:10 UTC (rev 1834)
+++
portal/trunk/component/portal/src/main/java/org/exoplatform/portal/config/DataStorageImpl.java 2010-02-24
10:25:27 UTC (rev 1835)
@@ -42,7 +42,10 @@
import org.exoplatform.services.listener.ListenerService;
import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.List;
/**
@@ -175,12 +178,22 @@
final Query<O> q;
final Class<D> dataType;
+
+ final Comparator<O> cp;
Bilto(Query<O> q, Class<D> dataType)
{
this.q = q;
this.dataType = dataType;
+ this.cp = null;
}
+
+ Bilto(Query<O> q, Class<D> dataType, Comparator<O> cp)
+ {
+ this.q = q;
+ this.dataType = dataType;
+ this.cp = cp;
+ }
protected abstract O create(D d);
@@ -188,7 +201,9 @@
{
Query<D> delegateQ = new Query<D>(q, dataType);
LazyPageList<D> r = delegate.find(delegateQ, null);
- final List<D> list = r.getAll();
+ List<D> tmp = r.getAll();
+ tmp = sort(tmp, this.cp);
+ final List<D> list = tmp;
return new ListAccess<O>()
{
public int getSize() throws Exception
@@ -206,8 +221,30 @@
return pages;
}
};
+ }
+
+
+ private List<D> sort(List<D> list, final Comparator<O>
comparator) {
+ List<D> tmpList = new ArrayList<D>();
+ for (int i=0; i<list.size();i++) {
+ tmpList.add(list.get(i));
+ }
+ Collections.sort(tmpList, new Comparator<D>() {
+
+ @Override
+ public int compare(D d1, D d2)
+ {
+ if (comparator == null) {
+ return d1.getStorageId().compareTo(d2.getStorageId());
+ }
+ O o1 = create(d1);
+ O o2 = create(d2);
+ return comparator.compare(o1, o2);
+ }
+
+ });
+ return tmpList;
}
-
}
public <T> ListAccess<T> find2(Query<T> q) throws Exception
@@ -225,7 +262,7 @@
Class<T> type = q.getClassType();
if (type == Page.class)
{
- Bilto<Page, PageData> bilto = new Bilto<Page,
PageData>((Query<Page>)q, PageData.class)
+ Bilto<Page, PageData> bilto = new Bilto<Page,
PageData>((Query<Page>)q, PageData.class,
(Comparator<Page>)sortComparator)
{
@Override
protected Page create(PageData pageData)
@@ -237,7 +274,7 @@
}
else if (type == PageNavigation.class)
{
- Bilto<PageNavigation, NavigationData> bilto = new Bilto<PageNavigation,
NavigationData>((Query<PageNavigation>)q, NavigationData.class)
+ Bilto<PageNavigation, NavigationData> bilto = new Bilto<PageNavigation,
NavigationData>((Query<PageNavigation>)q, NavigationData.class,
(Comparator<PageNavigation>)sortComparator)
{
@Override
protected PageNavigation create(NavigationData page)
@@ -249,7 +286,7 @@
}
else if (type == PortalConfig.class)
{
- Bilto<PortalConfig, PortalData> bilto = new Bilto<PortalConfig,
PortalData>((Query<PortalConfig>)q, PortalData.class)
+ Bilto<PortalConfig, PortalData> bilto = new Bilto<PortalConfig,
PortalData>((Query<PortalConfig>)q, PortalData.class,
(Comparator<PortalConfig>)sortComparator)
{
@Override
protected PortalConfig create(PortalData portalData)
Modified:
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestPortalConfig.java
===================================================================
---
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestPortalConfig.java 2010-02-24
10:08:10 UTC (rev 1834)
+++
portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestPortalConfig.java 2010-02-24
10:25:27 UTC (rev 1835)
@@ -20,8 +20,7 @@
package org.exoplatform.portal.config;
import org.exoplatform.container.PortalContainer;
-import org.exoplatform.container.component.ComponentRequestLifecycle;
-import org.exoplatform.container.component.RequestLifeCycle;
+import org.exoplatform.portal.config.model.PageNavigation;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.pom.config.POMSession;
import org.exoplatform.portal.pom.config.POMSessionManager;
@@ -31,6 +30,9 @@
import org.exoplatform.services.organization.User;
import org.exoplatform.services.organization.UserHandler;
+import java.util.Comparator;
+import java.util.List;
+
/**
* Author : TrongTT
*/
@@ -136,4 +138,27 @@
PortalConfig pConfig = storage.getPortalConfig(PortalConfig.USER_TYPE,
"testing");
assertNotNull("the User's PortalConfig is not null", pConfig);
}
+
+ public void testGetAllOrder() throws Exception
+ {
+ // Query with comparator to make sure returned list is ordered
+ Query<PageNavigation> query = new
Query<PageNavigation>(PortalConfig.GROUP_TYPE, null, PageNavigation.class);
+ Comparator<PageNavigation> sortComparator = new
Comparator<PageNavigation>()
+ {
+ public int compare(PageNavigation pconfig1, PageNavigation pconfig2)
+ {
+ return pconfig1.getOwnerId().compareTo(pconfig2.getOwnerId());
+ }
+ };
+
+ // First query
+ List<PageNavigation> navis = storage.find(query, sortComparator).getAll();
+ storage.save(navis.get(0)); // Modify
+ // Second query
+ List<PageNavigation> navis2 = storage.find(query, sortComparator).getAll();
+ for (int i = 0; i < navis.size(); i++)
+ {
+ assertEquals(true,
navis.get(i).getOwnerId().equals(navis2.get(i).getOwnerId()));
+ }
+ }
}