Update of /var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms In directory james.mmbase.org:/tmp/cvs-serv31990/community/src/java/com/finalist/cmsc/community/forms
Modified Files: SearchConditionalUserAction.java Added Files: ParameterMapper.java Removed Files: PersonForShow.java Log Message: CMSC-996 code improve. See also: http://cvs.mmbase.org/viewcvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms See also: http://www.mmbase.org/jira/browse/CMSC-996 ParameterMapper.java is new Index: SearchConditionalUserAction.java =================================================================== RCS file: /var/cvs/contributions/CMSContainer_Modules/community/src/java/com/finalist/cmsc/community/forms/SearchConditionalUserAction.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -b -r1.7 -r1.8 --- SearchConditionalUserAction.java 30 Jul 2008 09:52:38 -0000 1.7 +++ SearchConditionalUserAction.java 31 Jul 2008 02:27:47 -0000 1.8 @@ -1,94 +1,62 @@ package com.finalist.cmsc.community.forms; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import com.finalist.cmsc.paging.PagingUtils; +import com.finalist.cmsc.services.community.domain.PersonVO; +import com.finalist.cmsc.services.community.person.Person; import net.sf.mmapps.commons.util.StringUtil; - -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.collections.IteratorUtils; -import org.apache.commons.lang.StringUtils; - import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; -import com.finalist.cmsc.mmbase.PropertiesUtil; -import com.finalist.cmsc.paging.PagingStatusHolder; -import com.finalist.cmsc.paging.PagingUtils; -import com.finalist.cmsc.services.community.person.Person; -import com.finalist.cmsc.services.community.security.Authority; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.*; public class SearchConditionalUserAction extends AbstractCommunityAction { public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { + PagingUtils.initStatusHolder(request); - PagingStatusHolder holder = PagingUtils.getStatusHolder(); + + Map<String, String> map = ParameterMapper.wrap(actionForm). + map("fullname", "fullName"). + map("username", "userName"). + map("email", "emailAddr"). + map("group", "groups"). + getMap(); String groupName = request.getParameter("groupName"); - SearchForm searchform = (SearchForm) actionForm; - HashMap map = new HashMap(); - if (!StringUtil.isEmptyOrWhitespace(searchform.getFullName())) { - map.put("fullname", searchform.getFullName()); - } - if (!StringUtil.isEmptyOrWhitespace(searchform.getUserName())) { - map.put("username", searchform.getUserName()); - } - if (!StringUtil.isEmptyOrWhitespace(searchform.getemailAddr())) { - map.put("email", searchform.getemailAddr()); - } - if (!StringUtil.isEmptyOrWhitespace(searchform.getGroups())) { - map.put("group", searchform.getGroups()); - } - if (!StringUtil.isEmptyOrWhitespace(groupName)) { - map.put("group", groupName); - } if (!StringUtil.isEmptyOrWhitespace(groupName)) { map.put("group", groupName); map.put("strict", "strict"); } - - List<Person> persons; - int totalCount = 0; - if (map.size() > 0) { - persons = getPersonService().getAssociatedPersons(map); - totalCount = getPersonService().getAssociatedPersonsNum(map, holder); - } - else { - persons = getPersonService().getAllPeople(holder); - totalCount = getPersonService().countAllPersons(); - } - + List<Person> persons = getPersonService().getAssociatedPersons(map); + int totalCount = getPersonService().getAssociatedPersonsNum(map); request.setAttribute("personForShow", convertToVO(persons)); request.setAttribute("totalCount", totalCount); request.setAttribute("newsletterId", request.getParameter("newsletterId")); request.setAttribute("method", request.getParameter("method")); + if (!StringUtil.isEmptyOrWhitespace(groupName)) { request.setAttribute("groupName", groupName); return actionMapping.findForward("group"); } - removeFromSession(request, searchform); - ActionForward ret = actionMapping.findForward("success"); - return ret; + else { + return actionMapping.findForward("success"); + } } - private List<PersonForShow> convertToVO(List<Person> persons) { - List<PersonForShow> perShow; - perShow = new ArrayList<PersonForShow>(); + private List<PersonVO> convertToVO(List<Person> persons) { + List<PersonVO> perShow; + perShow = new ArrayList<PersonVO>(); for (Person p : persons) { String username = getAuthenticationService().getAuthenticationById(p.getAuthenticationId()).getUserId(); - PersonForShow per = new PersonForShow(); + PersonVO per = new PersonVO(); per.setFullname(p.getFullName()); per.setEmail(p.getEmail()); per.setUsername(username); @@ -96,7 +64,7 @@ String groupsName = ""; Set<String> authorityNames = getAuthorityService().getAuthorityNamesForUser(username); if (authorityNames.size() >= 1) { - Iterator iter = authorityNames.iterator(); + Iterator<String> iter = authorityNames.iterator(); while (iter.hasNext()) { groupsName += iter.next() + ", "; } _______________________________________________ Cvs mailing list Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs