Java tutorial
/******************************************************************************* * Copyright (c) 2009 David Harrison. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl-3.0.html * * Contributors: * David Harrison - initial API and implementation ******************************************************************************/ package com.sfs.whichdoctor.search.http; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import com.sfs.DataFilter; import com.sfs.beans.UserBean; import com.sfs.whichdoctor.beans.GroupBean; import com.sfs.whichdoctor.beans.SearchBean; import com.sfs.whichdoctor.search.sql.GroupSqlHandler; /** * The Class GroupInputHandler. * * @author David Harrison */ public class GroupInputHandler extends InputHandlerBase { /** The data logger. */ private static Logger dataLogger = Logger.getLogger(GroupInputHandler.class); /** The group sql handler. */ @Resource private GroupSqlHandler groupSqlHandler; /** * Process the incoming HttpRequest for search parameters. * * @param request the request * @param user the user * * @return the search bean */ public final SearchBean process(final HttpServletRequest request, final UserBean user) { SearchBean search = groupSqlHandler.initiate(user); GroupBean searchCriteria = (GroupBean) search.getSearchCriteria(); GroupBean searchConstraints = (GroupBean) search.getSearchConstraints(); String name = DataFilter.getHtml(request.getParameter("name")); String groupClass = DataFilter.getHtml(request.getParameter("groupClass")); String groupType = DataFilter.getHtml(request.getParameter("groupType")); String description = DataFilter.getHtml(request.getParameter("description")); String strGUIDList = DataFilter.getHtml(request.getParameter("guidList")); String strIncludeGUIDList = DataFilter.getHtml(request.getParameter("includeGUIDList")); String strCreatedA = DataFilter.getHtml(request.getParameter("createdA")); String strCreatedB = DataFilter.getHtml(request.getParameter("createdB")); String strUpdatedA = DataFilter.getHtml(request.getParameter("updatedA")); String strUpdatedB = DataFilter.getHtml(request.getParameter("updatedB")); try { searchCriteria.setName(DataFilter.getHtml(name.trim())); } catch (Exception e) { dataLogger.debug("Error parsing Name: " + e.getMessage()); } /* Tag searches */ searchCriteria.setTags(setTagArray(request, user)); if (StringUtils.isNotBlank(groupClass) && !StringUtils.equals(groupClass, "Null")) { searchCriteria.setObjectType(groupClass); } if (StringUtils.isNotBlank(groupType) && !StringUtils.equals(groupType, "Null")) { searchCriteria.setType(groupType); } searchCriteria.setDescription(description); if (StringUtils.isNotBlank(strGUIDList)) { // Parse the GUID list string into a collection of strings searchCriteria.setGUIDList(DataFilter.parseTextDataToCollection(strGUIDList)); } if (StringUtils.isNotBlank(strIncludeGUIDList)) { // Parse the GUID list string into a collection of strings searchCriteria.setIncludeGUIDList(DataFilter.parseTextDataToCollection(strIncludeGUIDList)); } if (StringUtils.isNotBlank(strCreatedA)) { searchCriteria.setCreatedDate(DataFilter.parseDate(strCreatedA, false)); } if (StringUtils.isNotBlank(strCreatedB)) { searchConstraints.setCreatedDate(DataFilter.parseDate(strCreatedB, false)); if (strCreatedB.compareTo("+") == 0) { /* All dates above Date A requested */ searchConstraints.setCreatedDate(getMaximumDate()); } if (strCreatedB.compareTo("-") == 0) { /* Add dates below Date A requested */ searchConstraints.setCreatedDate(getMinimumDate()); } } if (StringUtils.isNotBlank(strUpdatedA)) { searchCriteria.setModifiedDate(DataFilter.parseDate(strUpdatedA, false)); } if (StringUtils.isNotBlank(strUpdatedB)) { searchConstraints.setModifiedDate(DataFilter.parseDate(strUpdatedB, false)); if (strUpdatedB.compareTo("+") == 0) { /* All dates above Date A requested */ searchConstraints.setModifiedDate(getMaximumDate()); } if (strUpdatedB.compareTo("-") == 0) { /* Add dates below Date A requested */ searchConstraints.setModifiedDate(getMinimumDate()); } } search.setSearchCriteria(searchCriteria); search.setSearchConstraints(searchConstraints); return search; } /** * Return a standard search bean. * * @param user the user * * @return the search bean */ public final SearchBean process(final UserBean user) { SearchBean search = groupSqlHandler.initiate(user); GroupBean searchCriteria = (GroupBean) search.getSearchCriteria(); search.setSearchCriteria(searchCriteria); return search; } }