Java tutorial
/* * ShowMessagesByCategoryController.java * * Developed by Medici Archive Project (2010-2012). * * This file is part of DocSources. * * DocSources is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * DocSources is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * As a special exception, if you link this library with other files to * produce an executable, this library does not by itself cause the * resulting executable to be covered by the GNU General Public License. * This exception does not however invalidate any other reasons why the * executable file might be covered by the GNU General Public License. */ package org.medici.bia.controller.community; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import org.apache.commons.lang.ObjectUtils; import org.medici.bia.command.community.ShowMessagesByCategoryCommand; import org.medici.bia.domain.UserMessage.UserMessageCategory; import org.medici.bia.service.community.CommunityService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.servlet.ModelAndView; /** * Controller to view user messages. * It manages View and request's elaboration process. * * @author Lorenzo Pasquinelli (<a href=mailto:l.pasquinelli@gmail.com>l.pasquinelli@gmail.com</a>) */ @Controller @RequestMapping("/community/ShowMessagesByCategory") public class ShowMessagesByCategoryController { @Autowired private CommunityService communityService; /** * * @param request * @param model * @return */ @RequestMapping(method = RequestMethod.GET) public ModelAndView setupForm(@ModelAttribute("command") ShowMessagesByCategoryCommand command) { Map<String, Object> model = new HashMap<String, Object>(0); // This number is used to generate an unique id for new search UUID uuid = UUID.randomUUID(); command.setSearchUUID(uuid.toString()); model.put("searchUUID", uuid.toString()); // Add outputFields; List<String> outputFields = getOutputFields(command.getUserMessageCategory()); model.put("outputFields", outputFields); if (ObjectUtils.toString(command.getCompleteDOM()).equals(Boolean.TRUE.toString())) { return new ModelAndView("community/ShowMessagesByCategoryCompleteDOM", model); } else { return new ModelAndView("community/ShowMessagesByCategory", model); } } /** * This method return a list of output fields by UserMessageCategory. * * @param userMessageCategory * @return */ private List<String> getOutputFields(UserMessageCategory userMessageCategory) { List<String> outputFields = null; if (userMessageCategory.equals(UserMessageCategory.OUTBOX)) { outputFields = new ArrayList<String>(3); outputFields.add("To"); outputFields.add("Subject"); outputFields.add("Date"); } else if (userMessageCategory.equals(UserMessageCategory.INBOX)) { outputFields = new ArrayList<String>(3); outputFields.add("From"); outputFields.add("Subject"); outputFields.add("Date"); } else if (userMessageCategory.equals(UserMessageCategory.DRAFT)) { outputFields = new ArrayList<String>(3); outputFields.add("To"); outputFields.add("Subject"); outputFields.add("Date"); } else { outputFields = new ArrayList<String>(3); outputFields.add("To"); outputFields.add("Subject"); outputFields.add("Date"); } return outputFields; } /** * @param communityService the communityService to set */ public void setCommunityService(CommunityService communityService) { this.communityService = communityService; } /** * @return the communityService */ public CommunityService getCommunityService() { return communityService; } }