Update of /var/cvs/contributions/CMSContainer_Portlets/portlets-newsletter/src/java/com/finalist/newsletter/forms In directory james.mmbase.org:/tmp/cvs-serv4342
Modified Files: SubscriptioManagementAction.java Log Message: CMSC-1094, All newsletters with their subscriptions list should be ordered,add convertToOderedMap and pseudoRanking See also: http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Portlets/portlets-newsletter/src/java/com/finalist/newsletter/forms See also: http://www.mmbase.org/jira/browse/CMSC-1094 Index: SubscriptioManagementAction.java =================================================================== RCS file: /var/cvs/contributions/CMSContainer_Portlets/portlets-newsletter/src/java/com/finalist/newsletter/forms/SubscriptioManagementAction.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -b -r1.14 -r1.15 --- SubscriptioManagementAction.java 14 Oct 2008 11:22:43 -0000 1.14 +++ SubscriptioManagementAction.java 22 Oct 2008 05:19:44 -0000 1.15 @@ -1,6 +1,8 @@ package com.finalist.newsletter.forms; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -19,6 +21,7 @@ import org.apache.struts.action.ActionMapping; import org.springframework.web.struts.DispatchActionSupport; +import com.finalist.cmsc.paging.PagingStatusHolder; import com.finalist.cmsc.paging.PagingUtils; import com.finalist.cmsc.services.community.person.PersonService; import com.finalist.newsletter.domain.Newsletter; @@ -26,6 +29,7 @@ import com.finalist.newsletter.services.NewsletterService; import com.finalist.newsletter.services.NewsletterSubscriptionServices; import com.finalist.newsletter.services.SubscriptionHibernateService; +import com.finalist.newsletter.util.ComparisonUtil; /** * @author Lisa @@ -66,7 +70,8 @@ protected void onInit() { super.onInit(); newsletterService = (NewsletterService) getWebApplicationContext().getBean("newsletterServices"); - subscriptionServices = (NewsletterSubscriptionServices) getWebApplicationContext().getBean("subscriptionServices"); + subscriptionServices = (NewsletterSubscriptionServices) getWebApplicationContext() + .getBean("subscriptionServices"); personServices = (PersonService) getWebApplicationContext().getBean("personService"); publicationService = (NewsletterPublicationService) getWebApplicationContext().getBean("publicationService"); subscriptionHService = (SubscriptionHibernateService) getWebApplicationContext().getBean("subscriptionHService"); @@ -106,11 +111,11 @@ PagingUtils.initStatusHolder(request); String title = request.getParameter(PARAM_TITLE); String subscriber = request.getParameter(PARAM_SUBSCRIBER); - int resultCount = newsletterService.getNewsletters(subscriber, title, false).size(); - List<Newsletter> newsletters = newsletterService.getNewsletters(subscriber, title, true); - List<Map<Object, Object>> results = convertToMap(newsletters); - + List<Newsletter> newsletters; + List<Map<Object, Object>> results; + newsletters = newsletterService.getNewsletters(subscriber, title, true); + results = convertToOderedMap(newsletters); request.setAttribute(RESULTS, results); request.setAttribute(RESULTCOUNT, resultCount); return mapping.findForward(FORWARD_OVERVIEW); @@ -149,9 +154,12 @@ /** * get newsletter related newsletter subscription information List * - * @param newsletterId subscribed newsletter's Id - * @param name subscriber's name - * @param email subscriber's email address + * @param newsletterId + * subscribed newsletter's Id + * @param name + * subscriber's name + * @param email + * subscriber's email address * @return newsletter subscription list with information subscriber's user name, email address, authenticationId,user * name, */ @@ -175,7 +183,8 @@ /** * convert related information to Map * - * @param results result list with information of newsletter subscription + * @param results + * result list with information of newsletter subscription * @param fullName * @param userName * @param email @@ -296,4 +305,33 @@ } return results; } + + private List<Map<Object, Object>> convertToOderedMap(List<Newsletter> newsletters) { + List<Map<Object, Object>> results = convertToMap(newsletters); + PagingStatusHolder pagingHolder = PagingUtils.getStatusHolder(); + String order = pagingHolder.getSort(); + if (!"title".equals(order) && null != order) { + results = pseudoRanking(results, pagingHolder, order); + } + return results; + } + + private List<Map<Object, Object>> pseudoRanking(List<Map<Object, Object>> results, PagingStatusHolder pagingHolder, + String order) { + String oderby = pagingHolder.getDir(); + int offset = pagingHolder.getOffset(); + int size = pagingHolder.getPageSize(); + ComparisonUtil comparator = new ComparisonUtil(); + comparator.setFields_user(new String[] { order }); + Collections.sort(results, comparator); + if ("desc".equals(oderby)) { + Collections.reverse(results); + } + if (size + offset < results.size()) { + results = results.subList(offset, size + offset); + } else { + results = results.subList(offset, results.size()); + } + return results; + } } _______________________________________________ Cvs mailing list Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs