Coverage Report - org.kuali.rice.kew.docsearch.web.DocumentSearchAction
 
Classes in this File Line Coverage Branch Coverage Complexity
DocumentSearchAction
0%
0/1
N/A
0
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.kew.docsearch.web;
 18  
 
 19  
 
 20  
 /**
 21  
  * Document search struts action
 22  
  *
 23  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 24  
  */
 25  0
 public class DocumentSearchAction {
 26  
 //FIXME: delete this when doc search is fully moved over
 27  
 //extends WorkflowAction {
 28  
 //
 29  
 //    private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentSearchAction.class);
 30  
 //
 31  
 //    public static final Map<String,String> SEARCH_RESULT_LABEL_KEYS_BY_COLUMN_KEY = new HashMap<String,String>();
 32  
 //    static {
 33  
 //        SEARCH_RESULT_LABEL_KEYS_BY_COLUMN_KEY.put(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_HEADER_ID,"docSearch.DocumentSearch.results.label.documentId");
 34  
 //        SEARCH_RESULT_LABEL_KEYS_BY_COLUMN_KEY.put(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOC_TYPE_LABEL,"docSearch.DocumentSearch.results.label.type");
 35  
 //        SEARCH_RESULT_LABEL_KEYS_BY_COLUMN_KEY.put(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOCUMENT_TITLE,"docSearch.DocumentSearch.results.label.title");
 36  
 //        SEARCH_RESULT_LABEL_KEYS_BY_COLUMN_KEY.put(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_STATUS_DESC,"docSearch.DocumentSearch.results.label.routeStatus");
 37  
 //        SEARCH_RESULT_LABEL_KEYS_BY_COLUMN_KEY.put(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_INITIATOR,"docSearch.DocumentSearch.results.label.initiator");
 38  
 //        SEARCH_RESULT_LABEL_KEYS_BY_COLUMN_KEY.put(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DATE_CREATED,"docSearch.DocumentSearch.results.label.dateCreated");
 39  
 //        SEARCH_RESULT_LABEL_KEYS_BY_COLUMN_KEY.put(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_ROUTE_LOG,"docSearch.DocumentSearch.results.label.routeLog");
 40  
 //    }
 41  
 //
 42  
 //    public static final List<KeyValue> DOCUMENT_SEARCH_SEARCHABLE_DOCUMENT_STATUSES = Arrays.asList(new KeyValue[] { new KeyValue("I", "Initiated"),
 43  
 //            new KeyValue("R", "Enroute"),
 44  
 //            new KeyValue("S", "Saved"),
 45  
 //            new KeyValue("F", "Final"),
 46  
 //            new KeyValue("A", "Approved"),
 47  
 //            new KeyValue("X", "Canceled"),
 48  
 //            new KeyValue("E", "Exception"),
 49  
 //            new KeyValue("P", "Processed"),
 50  
 //            new KeyValue("D", "Disapproved") });
 51  
 //
 52  
 //    public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 53  
 //        DocumentSearchForm docSearchForm = (DocumentSearchForm) form;
 54  
 //        docSearchForm.setupPropertyFieldsUsingCriteria();
 55  
 //        adjustStateAndForm(getCurrentState(request), docSearchForm, getUserSession(request));
 56  
 //        // if there's no search criteria, just execute the search
 57  
 //        if (!docSearchForm.isShowSearchCriteria()) {
 58  
 //            return doDocSearch(mapping, form, request, response);
 59  
 //        }
 60  
 //        return mapping.findForward("success");
 61  
 //    }
 62  
 //
 63  
 //    public ActionForward performLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 64  
 //        DocumentSearchForm docSearchForm = (DocumentSearchForm) form;
 65  
 //        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + mapping.getModuleConfig().getPrefix();
 66  
 //        StringBuffer lookupUrl = new StringBuffer(basePath);
 67  
 //
 68  
 //        String lookupType = docSearchForm.getLookupType();
 69  
 //        docSearchForm.setLookupType(null);
 70  
 //
 71  
 //        String docFormKey = getUserSession(request).addObject(form);
 72  
 //        lookupUrl.append("/Lookup.do?methodToCall=start&docFormKey=").append(docFormKey).append("&lookupableImplServiceName=").append(request.getParameter("lookupableImplServiceName"));
 73  
 //
 74  
 //        StringBuffer conversionFields = new StringBuffer();
 75  
 //
 76  
 //        if (lookupType != null && !lookupType.equals("")) {
 77  
 //            lookupUrl.append("&conversionFields=");
 78  
 //
 79  
 //            //WorkflowLookupable workflowLookupable = (WorkflowLookupable) GlobalResourceLoader.getService(request.getParameter("lookupableImplServiceName"));
 80  
 //            //for (Iterator iterator = workflowLookupable.getDefaultReturnType().iterator(); iterator.hasNext();) {
 81  
 //            //    String returnType = (String) iterator.next();
 82  
 //            //    conversionFields.append(returnType).append(":").append(lookupType);
 83  
 //            //}
 84  
 //            lookupUrl.append(conversionFields);
 85  
 //        } else if (!Utilities.isEmpty(docSearchForm.getConversionFields())) {
 86  
 //            lookupUrl.append("&conversionFields=");
 87  
 //            lookupUrl.append(docSearchForm.getConversionFields());
 88  
 //            conversionFields.append(docSearchForm.getConversionFields());
 89  
 //        }
 90  
 //
 91  
 //        lookupUrl.append("&returnLocation=").append(basePath).append(mapping.getPath()).append(".do");
 92  
 //
 93  
 //        /*
 94  
 //        * Code below added by Jeremy and Eric - 12-10-2008
 95  
 //        *
 96  
 //        * Temporarily,  until Document Search is converted to a proper lookup, let's have our outgoing lookup links
 97  
 //        * for the Document Type lookup
 98  
 //        * generated in here, instead of using the KNS tags to generate our lookup links
 99  
 //        */
 100  
 //       String lookupableImplServiceName = request.getParameter("lookupableImplServiceName");
 101  
 //       if (lookupableImplServiceName.equals(DocumentSearchCriteriaProcessor.DOC_TYP_LOOKUPABLE)) {
 102  
 //           lookupUrl = new StringBuffer();
 103  
 //           lookupUrl.append("../kr/lookup.do?businessObjectClassName=org.kuali.rice.kew.doctype.bo.DocumentType&docFormKey=" +
 104  
 //               docFormKey +
 105  
 //               "&returnLocation=" +
 106  
 //               basePath +
 107  
 //               mapping.getPath() +
 108  
 //               ".do" +
 109  
 //               "&conversionFields=" +
 110  
 //               conversionFields.toString());
 111  
 //       }
 112  
 //
 113  
 //        return new ActionForward(lookupUrl.toString(), true);
 114  
 //    }
 115  
 //
 116  
 //    public ActionForward basic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 117  
 //        DocumentSearchForm docSearchForm = (DocumentSearchForm) form;
 118  
 //        docSearchForm.setIsAdvancedSearch("NO");
 119  
 //        return mapping.findForward("success");
 120  
 //    }
 121  
 //
 122  
 //    public ActionForward resetNamedSearches(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, RuntimeException {
 123  
 //        getDocumentSearchService().clearNamedSearches(getUserSession(request).getPrincipalId());
 124  
 //        return mapping.findForward("success");
 125  
 //    }
 126  
 //
 127  
 //    public ActionForward advanced(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 128  
 //        DocumentSearchForm docSearchForm = (DocumentSearchForm) form;
 129  
 //        docSearchForm.setIsAdvancedSearch(DocSearchCriteriaDTO.ADVANCED_SEARCH_INDICATOR_STRING);
 130  
 //        return mapping.findForward("success");
 131  
 //    }
 132  
 //
 133  
 //    public ActionForward superUserSearch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 134  
 //        DocumentSearchForm docSearchForm = (DocumentSearchForm) form;
 135  
 //        docSearchForm.setSuperUserSearch(DocSearchCriteriaDTO.SUPER_USER_SEARCH_INDICATOR_STRING);
 136  
 //        return mapping.findForward("success");
 137  
 //    }
 138  
 //
 139  
 //    public ActionForward clearSuperUserSearch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 140  
 //        DocumentSearchForm docSearchForm = (DocumentSearchForm) form;
 141  
 //        docSearchForm.setSuperUserSearch("NO");
 142  
 //        return mapping.findForward("success");
 143  
 //    }
 144  
 //
 145  
 //    public ActionForward clear(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 146  
 //        DocumentSearchForm docSearchForm = (DocumentSearchForm) form;
 147  
 //        String currentDocTypeName = docSearchForm.getCriteria().getDocTypeFullName();
 148  
 //        String advancedSearchValue = docSearchForm.getIsAdvancedSearch();
 149  
 //        String superUserSearchValue = docSearchForm.getSuperUserSearch();
 150  
 //        // set up new criteria object using generator class if possible
 151  
 //        DocSearchCriteriaDTO newCriteria = null;
 152  
 //        if (StringUtils.isNotBlank(currentDocTypeName)) {
 153  
 //            newCriteria = getValidDocumentType(currentDocTypeName).getDocumentSearchGenerator().clearSearch(docSearchForm.getCriteria());
 154  
 //        }
 155  
 //        if (newCriteria == null) {
 156  
 //            newCriteria = new DocSearchCriteriaDTO();
 157  
 //        }
 158  
 //        newCriteria.setIsAdvancedSearch(advancedSearchValue);
 159  
 //        newCriteria.setSuperUserSearch(superUserSearchValue);
 160  
 //        // adjust the processor class and state if necessary
 161  
 //        State state = getCurrentState(request);
 162  
 //        DocumentSearchCriteriaProcessor currentProcessor = state.getCriteriaProcessor();
 163  
 //        if (StringUtils.equals(currentProcessor.getDocSearchCriteriaDTO().getDocTypeFullName(),newCriteria.getDocTypeFullName())) {
 164  
 //            // since doc type names are equal do not reset the state or processor only the criteria object
 165  
 //            state.getCriteriaProcessor().setDocSearchCriteriaDTO(newCriteria);
 166  
 //        } else {
 167  
 //            // document types are not equal so reset the state and processor using the new criteria
 168  
 //            state = adjustStateAndForm(null, docSearchForm, newCriteria, getUserSession(request));
 169  
 //        }
 170  
 //        setAdjustedState(request, state);
 171  
 ////        DocumentSearchCriteriaProcessor processor = buildCriteriaProcessor((state != null) ? state.getCriteriaProcessor() : null, docSearchForm, getUserSession(request));
 172  
 ////        if (StringUtils.isNotBlank(docSearchForm.getCriteria().getDocTypeFullName())) {
 173  
 ////            DocumentSearchGenerator generator = getValidDocumentType(docSearchForm.getCriteria().getDocTypeFullName()).getDocumentSearchGenerator();
 174  
 ////            DocSearchCriteriaDTO newCriteria = generator.clearSearch(processor.getDocSearchCriteriaDTO());
 175  
 ////            if (newCriteria == null) {
 176  
 ////                newCriteria = new DocSearchCriteriaDTO();
 177  
 ////            }
 178  
 ////            newCriteria.setIsAdvancedSearch(processor.getDocSearchCriteriaDTO().getIsAdvancedSearch());
 179  
 ////            newCriteria.setSuperUserSearch(processor.getDocSearchCriteriaDTO().getSuperUserSearch());
 180  
 ////            processor = buildCriteriaProcessor(processor, docSearchForm, newCriteria, getUserSession(request));
 181  
 ////            setAdjustedState(request, state);
 182  
 ////        }
 183  
 //       docSearchForm.clearSearchableAttributeProperties();
 184  
 //       return mapping.findForward("success");
 185  
 //    }
 186  
 //
 187  
 //    public ActionForward doDocSearch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 188  
 //        LOG.info("started doDocSearch");
 189  
 //        DocumentSearchForm docSearchForm = (DocumentSearchForm) form;
 190  
 //        DocumentSearchResultComponents results = null;
 191  
 //        SavedSearchResult result = null;
 192  
 //        State currentState = getCurrentState(request);
 193  
 //        if (docSearchForm.getNamedSearch() != null && !"".equals(docSearchForm.getNamedSearch()) && !"ignore".equals(docSearchForm.getNamedSearch())) {
 194  
 //            result = getDocumentSearchService().getSavedSearchResults(getUserSession(request).getPerson().getPrincipalId(), docSearchForm.getNamedSearch());
 195  
 //            if (result != null) {
 196  
 //                // if using a saved search assume new state needs created by discarding old state
 197  
 //                currentState = null;
 198  
 //                docSearchForm.setCriteriaProcessor(buildCriteriaProcessor(null, docSearchForm, getUserSession(request)));
 199  
 //                docSearchForm.getCriteriaProcessor().setDocSearchCriteriaDTO(result.getDocSearchCriteriaDTO());
 200  
 //                docSearchForm.clearSearchableAttributeProperties();
 201  
 //                docSearchForm.checkForAdditionalFields();
 202  
 //                docSearchForm.setupPropertyFieldsUsingCriteria();
 203  
 //                docSearchForm.setNamedSearch("");
 204  
 //                setDropdowns(docSearchForm, request);
 205  
 //                results = result.getSearchResult();
 206  
 //            } else {
 207  
 //                LOG.warn("Could not find saved search with name '" + docSearchForm.getNamedSearch() + "' for user " + getUserSession(request).getPrincipalName());
 208  
 //                ActionErrors errors = new ActionErrors();
 209  
 //                errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage("docsearch.DocumentSearchService.savedSearches.notFound", docSearchForm.getNamedSearch()));
 210  
 //                saveErrors(request, errors);
 211  
 //                return mapping.findForward("success");
 212  
 //            }
 213  
 //        } else {
 214  
 //            docSearchForm.addSearchableAttributesToCriteria();
 215  
 //            DocSearchCriteriaDTO criteria = docSearchForm.getCriteria();
 216  
 //            if (docSearchForm.isInitiatorUser()) {
 217  
 //                criteria.setInitiator(getUserSession(request).getPrincipalName());
 218  
 //            }
 219  
 //            results = getDocumentSearchService().getList(getUserSession(request).getPerson().getPrincipalId(), criteria);
 220  
 //            result = new SavedSearchResult(criteria, results);
 221  
 //        }
 222  
 //
 223  
 //        List columns = results.getColumns();
 224  
 //        MessageResources mr = getResources(request);
 225  
 //        mr.setReturnNull(true);
 226  
 //        Locale locale = (Locale) request.getAttribute(Globals.LOCALE_KEY);
 227  
 //        for (Iterator iter = columns.iterator(); iter.hasNext();) {
 228  
 //            DocumentSearchColumn column = (DocumentSearchColumn) iter.next();
 229  
 //            if ((column.getColumnTitle() == null) || (column.getColumnTitle().trim().length() == 0)) {
 230  
 //                String title = mr.getMessage(locale, SEARCH_RESULT_LABEL_KEYS_BY_COLUMN_KEY.get(column.getKey()));
 231  
 //                if (StringUtils.isBlank(title)) {
 232  
 //                    title = "** No Title Available **";
 233  
 //                }
 234  
 //                column.setColumnTitle(title);
 235  
 //            }
 236  
 //        }
 237  
 //
 238  
 //        // adjust results and result objects
 239  
 //        result = new SavedSearchResult(docSearchForm.getCriteria(), new DocumentSearchResultComponents(columns, results.getSearchResults()));
 240  
 //        request.setAttribute("reqSearchResultColumns", result.getSearchResult().getColumns());
 241  
 //        request.setAttribute("reqSearchResults", result.getSearchResult().getSearchResults());
 242  
 //        State state = adjustStateAndForm(currentState, docSearchForm, getUserSession(request));
 243  
 //        state.setResult(result);
 244  
 //        setAdjustedState(request, state);
 245  
 //        if (docSearchForm.getCriteria().isOverThreshold() && docSearchForm.getCriteria().getSecurityFilteredRows() > 0) {
 246  
 //            ActionErrors errors = new ActionErrors();
 247  
 //            errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage("docsearch.DocumentSearchService.exceededThresholdAndSecurityFiltered", String.valueOf(results.getSearchResults().size()), docSearchForm.getCriteria().getSecurityFilteredRows()));
 248  
 //            saveErrors(request, errors);
 249  
 //        } else if (docSearchForm.getCriteria().getSecurityFilteredRows() > 0) {
 250  
 //            ActionErrors errors = new ActionErrors();
 251  
 //            errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage("docsearch.DocumentSearchService.securityFiltered", docSearchForm.getCriteria().getSecurityFilteredRows()));
 252  
 //            saveErrors(request, errors);
 253  
 //        } else if (docSearchForm.getCriteria().isOverThreshold()) {
 254  
 //            ActionErrors errors = new ActionErrors();
 255  
 //            errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionMessage("docsearch.DocumentSearchService.exceededThreshold", String.valueOf(results.getSearchResults().size())));
 256  
 //            saveErrors(request, errors);
 257  
 //        }
 258  
 //
 259  
 //        LOG.info("end doDocSearch");
 260  
 //        return mapping.findForward("success");
 261  
 //    }
 262  
 //
 263  
 //    private static DocumentType getValidDocumentType(String docTypeName) {
 264  
 //        DocumentType documentType = KEWServiceLocator.getDocumentTypeService().findByName(docTypeName);
 265  
 //        if (documentType == null) {
 266  
 //            throw new RuntimeException("Document Type invalid : " + docTypeName);
 267  
 //        }
 268  
 //        return documentType;
 269  
 //    }
 270  
 //
 271  
 //    private State getCurrentState(HttpServletRequest request) {
 272  
 //        return (State)request.getAttribute("currentSearchState");
 273  
 //    }
 274  
 //
 275  
 //    private void setAdjustedState(HttpServletRequest request, State state) {
 276  
 //        request.removeAttribute("currentSearchState");
 277  
 //        request.setAttribute("currentSearchState", state);
 278  
 //    }
 279  
 //
 280  
 //    private State adjustStateAndForm(State currentState, DocumentSearchForm docSearchForm, UserSession userSession) {
 281  
 //        State state = new State(docSearchForm);
 282  
 //        if (currentState != null) {
 283  
 //            state = new State(currentState);
 284  
 //        }
 285  
 //        state.setCriteriaProcessor(buildCriteriaProcessor(state.getCriteriaProcessor(), docSearchForm, userSession));
 286  
 //        state.updateForm(docSearchForm);
 287  
 //        return state;
 288  
 //    }
 289  
 //
 290  
 //    private State adjustStateAndForm(State currentState, DocumentSearchForm docSearchForm, DocSearchCriteriaDTO criteria, UserSession userSession) {
 291  
 //        State state = new State(docSearchForm);
 292  
 //        if (currentState != null) {
 293  
 //            state = new State(currentState);
 294  
 //        }
 295  
 //        state.setCriteriaProcessor(buildCriteriaProcessor(state.getCriteriaProcessor(), docSearchForm, criteria, userSession));
 296  
 //        state.updateForm(docSearchForm);
 297  
 //        return state;
 298  
 //    }
 299  
 //
 300  
 //    private DocumentSearchCriteriaProcessor buildCriteriaProcessor(DocumentSearchCriteriaProcessor processor, DocumentSearchForm docSearchForm, UserSession userSession) {
 301  
 //        return buildCriteriaProcessor(processor, docSearchForm, docSearchForm.getCriteria(), userSession);
 302  
 //    }
 303  
 //
 304  
 //    private DocumentSearchCriteriaProcessor buildCriteriaProcessor(DocumentSearchCriteriaProcessor processor, DocumentSearchForm docSearchForm, DocSearchCriteriaDTO criteria, UserSession userSession) {
 305  
 //        if (processor == null) {
 306  
 //            // no criteria processor... set one up
 307  
 //            if ( (criteria != null) && (StringUtils.isNotBlank(criteria.getDocTypeFullName())) ) {
 308  
 //                processor = getValidDocumentType(criteria.getDocTypeFullName()).getDocumentSearchCriteriaProcessor();
 309  
 //            } else {
 310  
 //                processor = new StandardDocumentSearchCriteriaProcessor();
 311  
 //            }
 312  
 //        } else {
 313  
 //            // criteria processor exists in state... check for match against form criteria doc type name
 314  
 //            if (Utilities.isEmpty(criteria.getDocTypeFullName())) {
 315  
 //                // document type name was cleared out... clear the criteria processor
 316  
 //                processor = new StandardDocumentSearchCriteriaProcessor();
 317  
 //            } else if (!StringUtils.equals(criteria.getDocTypeFullName(), processor.getDocSearchCriteriaDTO().getDocTypeFullName())) {
 318  
 //                // document type name is not the same as previous state's criteria... update criteria processor
 319  
 //                processor = getValidDocumentType(criteria.getDocTypeFullName()).getDocumentSearchCriteriaProcessor();
 320  
 //            }
 321  
 //        }
 322  
 //        docSearchForm.addSearchableAttributesToCriteria();
 323  
 //        DocSearchCriteriaDTO newCriteria = criteria;
 324  
 //        if (docSearchForm.isInitiatorUser()) {
 325  
 //            newCriteria.setInitiator(userSession.getPrincipalName());
 326  
 //        }
 327  
 //        if (newCriteria != null) {
 328  
 //            processor.setDocSearchCriteriaDTO(newCriteria);
 329  
 //        }
 330  
 ////        processor.getDocSearchCriteriaDTO().setSuperUserSearch(formCriteria.getSuperUserSearch());
 331  
 ////        processor.getDocSearchCriteriaDTO().setIsAdvancedSearch(docSearchForm.getIsAdvancedSearch());
 332  
 //        processor.setSearchingUser(userSession.getPrincipalId());
 333  
 //        return processor;
 334  
 //    }
 335  
 //
 336  
 //    public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm form) throws Exception {
 337  
 //        DocumentSearchForm docSearchForm = (DocumentSearchForm) form;
 338  
 //        Preferences preferences = getUserSession(request).getPreferences();
 339  
 ////        setupState(request, docSearchForm);
 340  
 //        State currentState = getOriginalState(request);
 341  
 //        State newState = adjustStateAndForm(currentState, docSearchForm, getUserSession(request));
 342  
 ////        if (currentState == null) {
 343  
 //            newState.updateForm(docSearchForm);
 344  
 ////        }
 345  
 //        setAdjustedState(request, newState);
 346  
 //        request.setAttribute("preferences", preferences);
 347  
 //        // request.setAttribute("namedSearches", getSavedSearches(getUserSession(request).getWorkflowUser()));
 348  
 //        setDropdowns(docSearchForm, request);
 349  
 //        docSearchForm.checkForAdditionalFields();
 350  
 //        return null;
 351  
 //    }
 352  
 //
 353  
 //    private State getOriginalState(HttpServletRequest request) {
 354  
 //        String searchStateKeyValue = request.getParameter("searchStateKey");
 355  
 //        if (Utilities.isEmpty(searchStateKeyValue)) {
 356  
 //            searchStateKeyValue = (String) request.getAttribute("searchStateKey");
 357  
 //        }
 358  
 //        return (State) getUserSession(request).retrieveObject(searchStateKeyValue);
 359  
 //    }
 360  
 //
 361  
 //    @Override
 362  
 //    public ActionMessages establishFinalState(HttpServletRequest request, ActionForm form) throws Exception {
 363  
 ////        request.setAttribute("namedSearches", getSavedSearches(getUserSession(request).getWorkflowUser()));
 364  
 //        DocumentSearchForm docSearchForm = (DocumentSearchForm) form;
 365  
 //        State currentState = getCurrentState(request);
 366  
 //        if (currentState == null) {
 367  
 //            throw new RuntimeException("Search state is empty and search cannot proceed");
 368  
 //        }
 369  
 //        currentState.updateForm(docSearchForm);
 370  
 //        request.setAttribute("searchStateKey", getUserSession(request).addObject(currentState));
 371  
 //        request.removeAttribute("currentSearchState");
 372  
 ////        setupState(request, docSearchForm);
 373  
 ////        docSearchForm.checkForAdditionalFields();
 374  
 //        updateNamedSearches(request, docSearchForm);
 375  
 //        return null;
 376  
 //    }
 377  
 //
 378  
 //    private void updateNamedSearches(HttpServletRequest request, DocumentSearchForm docSearchForm) {
 379  
 //        request.setAttribute("namedSearches", getSavedSearches(getUserSession(request).getPrincipalId()));
 380  
 //        docSearchForm.checkForAdditionalFields();
 381  
 //        docSearchForm.setupPropertyFieldsUsingCriteria();
 382  
 //    }
 383  
 //
 384  
 //    @Override
 385  
 //    public void establishExceptionFinalState(HttpServletRequest request, ActionForm form) throws Exception {
 386  
 //        try {
 387  
 //            updateNamedSearches(request, (DocumentSearchForm)form);
 388  
 //        } catch (Exception e) {
 389  
 //            LOG.warn("Swallowing exception thrown by establishFinalState since we already had a source exception: " + e.getLocalizedMessage());
 390  
 //        }
 391  
 //    }
 392  
 //
 393  
 //    private List getSavedSearches(String principalId) {
 394  
 //        List savedSearches = new ArrayList();
 395  
 //        savedSearches.add(new KeyValue("", "Searches"));
 396  
 //        savedSearches.add(new KeyValue("ignore", "-----"));
 397  
 //        savedSearches.add(new KeyValue("ignore", "&nbsp;&nbsp;Named Searches"));
 398  
 //        List namedSearches = getDocumentSearchService().getNamedSearches(principalId);
 399  
 //        for (Iterator iter = namedSearches.iterator(); iter.hasNext();) {
 400  
 //            KeyValue namedSearch = (KeyValue) iter.next();
 401  
 //            savedSearches.add(new KeyValue(namedSearch.getKey(), "&nbsp;&nbsp;&nbsp;&nbsp;" + namedSearch.getValue()));
 402  
 //        }
 403  
 //        savedSearches.add(new KeyValue("ignore", "-----"));
 404  
 //        savedSearches.add(new KeyValue("ignore", "&nbsp;&nbsp;Recent Searches"));
 405  
 //        List mostRecentSearches = getDocumentSearchService().getMostRecentSearches(principalId);
 406  
 //        for (Iterator iter = mostRecentSearches.iterator(); iter.hasNext();) {
 407  
 //            KeyValue recentSearch = (KeyValue) iter.next();
 408  
 //            savedSearches.add(new KeyValue(recentSearch.getKey(), "&nbsp;&nbsp;&nbsp;&nbsp;" + (recentSearch.getValue().length() > 100 ? recentSearch.getValue().substring(0, 100) + "..." : recentSearch.getValue())));
 409  
 //        }
 410  
 //        return savedSearches;
 411  
 //    }
 412  
 //
 413  
 //    private DocumentSearchService getDocumentSearchService() {
 414  
 //        return ((DocumentSearchService) KEWServiceLocator.getService(KEWServiceLocator.DOCUMENT_SEARCH_SERVICE));
 415  
 //    }
 416  
 //
 417  
 //    public ActionForward refresh(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 418  
 //        DocumentSearchForm documentSearchForm = (DocumentSearchForm) form;
 419  
 //
 420  
 //        String docTypeFullName = request.getParameter("docTypeFullName");
 421  
 //        if (docTypeFullName != null) {
 422  
 //            documentSearchForm.setNamedSearch("");
 423  
 //            documentSearchForm.getCriteria().setNamedSearch("");
 424  
 //            documentSearchForm.clearSearchableAttributeProperties();
 425  
 //        }
 426  
 //        if (request.getParameter("workgroupId") != null) {
 427  
 //            String groupId = request.getParameter("workgroupId");
 428  
 //            KimGroup group = KIMServiceLocator.getIdentityManagementService().getGroup(groupId);
 429  
 //            documentSearchForm.getCriteria().setWorkgroupViewerName(group.getGroupName());
 430  
 //            documentSearchForm.getCriteria().setWorkgroupViewerNamespace(group.getNamespaceCode());
 431  
 //        }
 432  
 //        String documentTypeId = request.getParameter("documentTypeId");
 433  
 //        if (documentTypeId != null) {
 434  
 //            documentSearchForm.setNamedSearch("");
 435  
 //            documentSearchForm.getCriteria().setNamedSearch("");
 436  
 //            documentSearchForm.clearSearchableAttributeProperties();
 437  
 //            DocumentType docType = KEWServiceLocator.getDocumentTypeService().findById(new Long(documentTypeId));
 438  
 //            documentSearchForm.setDocTypeFullName(docType.getName());
 439  
 //        }
 440  
 //        return mapping.findForward("success");
 441  
 //    }
 442  
 //
 443  
 //    private static void setDropdowns(DocumentSearchForm dsForm, HttpServletRequest request) {
 444  
 //        LOG.debug("Entered setDropDowns");
 445  
 //
 446  
 //        List documentRouteStatus = new ArrayList();
 447  
 //        documentRouteStatus.add(new KeyValue("", "All"));
 448  
 //        documentRouteStatus.addAll(DOCUMENT_SEARCH_SEARCHABLE_DOCUMENT_STATUSES);
 449  
 //        request.setAttribute("documentRouteStatus", documentRouteStatus);
 450  
 //
 451  
 //        if (!Utilities.isEmpty(dsForm.getCriteria().getDocTypeFullName())) {
 452  
 //            List qualifierLogic = new ArrayList();
 453  
 //            for (String key : KEWConstants.DOC_SEARCH_ROUTE_STATUS_QUALIFIERS.keySet()) {
 454  
 //                qualifierLogic.add(new KeyValue(key, KEWConstants.DOC_SEARCH_ROUTE_STATUS_QUALIFIERS.get(key)));
 455  
 //            }
 456  
 //            request.setAttribute("qualifierLogic", qualifierLogic);
 457  
 //
 458  
 //            // people are going to be feeding us doctype names by url for inline doc search so check for a null doctype to
 459  
 //            // give
 460  
 //            // a sensible error
 461  
 //            List routeNodes = KEWServiceLocator.getRouteNodeService().getFlattenedNodes(getValidDocumentType(dsForm.getCriteria().getDocTypeFullName()), true);
 462  
 //            RouteNode blankNode = new RouteNode();// for a default no choice option
 463  
 //            blankNode.setRouteNodeId(new Long(-1));
 464  
 //            blankNode.setRouteNodeName("");
 465  
 //            routeNodes.add(0, blankNode);
 466  
 //            request.setAttribute("routeNodes", routeNodes);
 467  
 //        }
 468  
 //        LOG.debug("Leaving setDropDowns");
 469  
 //    }
 470  
 //
 471  
 //    public ActionForward viewResults(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 472  
 //        DocumentSearchForm docSearchForm = (DocumentSearchForm) form;
 473  
 //
 474  
 //        State state = getCurrentState(request);
 475  
 //        state.updateForm(docSearchForm);
 476  
 //        State originalState = getOriginalState(request);
 477  
 //        docSearchForm.getCriteriaProcessor().setDocSearchCriteriaDTO(originalState.getCriteriaProcessor().getDocSearchCriteriaDTO());
 478  
 //        DocumentSearchResultComponents searchComponents = state.getResult().getSearchResult();
 479  
 //        List<DocumentSearchColumn> columns = searchComponents.getColumns();
 480  
 //        List<DocumentSearchResult> displayResults = searchComponents.getSearchResults();
 481  
 //
 482  
 ////        docSearchForm.setCriteriaProcessor(state.getCriteriaProcessor());
 483  
 ////        docSearchForm.setCriteria(state.getResult().getDocSearchCriteriaDTO());
 484  
 //        setDropdowns(docSearchForm, request);
 485  
 //        docSearchForm.setNamedSearch("");
 486  
 //
 487  
 //        boolean ascending = true;
 488  
 //        String sortOrderParameter = new ParamEncoder("result").encodeParameterName(TableTagParameters.PARAMETER_ORDER);
 489  
 //        String sortOrder = request.getParameter(sortOrderParameter);
 490  
 //        if (sortOrder == null) {
 491  
 //            sortOrder = "1";
 492  
 //        }
 493  
 //        if (sortOrder.equals("2")) {
 494  
 //            ascending = false;
 495  
 //        }
 496  
 //        String sortNameParameter = new ParamEncoder("result").encodeParameterName(TableTagParameters.PARAMETER_SORT);
 497  
 //        String sortName = request.getParameter(sortNameParameter);
 498  
 //        DocumentSearchColumn sortColumn = getSortColumn(columns, sortName);
 499  
 //        sortDisplayList(sortColumn, displayResults, ascending);
 500  
 //        state.getResult().setSearchResult(new DocumentSearchResultComponents(columns, displayResults));
 501  
 //        setAdjustedState(request, state);
 502  
 ////        setStateForUse(request, state);
 503  
 //        request.setAttribute("reqSearchResultColumns", state.getResult().getSearchResult().getColumns());
 504  
 //        request.setAttribute("reqSearchResults", state.getResult().getSearchResult().getSearchResults());
 505  
 //        return mapping.findForward("success");
 506  
 //    }
 507  
 //
 508  
 //    private DocumentSearchColumn getSortColumn(List<DocumentSearchColumn> columns, String sortName) {
 509  
 //        if (StringUtils.isEmpty(sortName)) {
 510  
 //            return (DocumentSearchColumn) columns.get(0);
 511  
 //        }
 512  
 //        for (Iterator iterator = columns.iterator(); iterator.hasNext();) {
 513  
 //            DocumentSearchColumn column = (DocumentSearchColumn) iterator.next();
 514  
 //            if (column.getSortName().equals(sortName)) {
 515  
 //                return column;
 516  
 //            }
 517  
 //        }
 518  
 //        throw new WorkflowRuntimeException("Could not sort based on the given sort name of " + sortName);
 519  
 //    }
 520  
 //
 521  
 //    private void sortDisplayList(DocumentSearchColumn sortColumn, List<DocumentSearchResult> displayList, boolean ascending) {
 522  
 //        Collections.sort(displayList, new ColumnComparator(sortColumn, ascending));
 523  
 //    }
 524  
 //
 525  
 //    private class ColumnComparator implements Comparator<Object> {
 526  
 //
 527  
 //        private DocumentSearchColumn column;
 528  
 //        private boolean ascending;
 529  
 //
 530  
 //        public ColumnComparator(DocumentSearchColumn column, boolean ascending) {
 531  
 //            this.column = column;
 532  
 //            this.ascending = ascending;
 533  
 //        }
 534  
 //
 535  
 //        public int compare(Object row1, Object row2) {
 536  
 //            try {
 537  
 //                Object property1 = PropertyUtils.getProperty(row1, column.getSortName());
 538  
 //                Object property2 = PropertyUtils.getProperty(row2, column.getSortName());
 539  
 //                int compare = 0;
 540  
 //                if ((property1 != null) || (property2 != null)) {
 541  
 //                    if ((property1 != null) && (property2 != null) && (!(property1.getClass().equals(property2.getClass())))) {
 542  
 //                        // two classes are unequal... throw exception
 543  
 //                        String errorMessage = "Found classes in this comparator that are unequal (property class '" + property1.getClass().getName() + "' is not equal to property class '" + property2.getClass().getName() + "')";
 544  
 //                        LOG.error("compare() " + errorMessage);
 545  
 //                        throw new RuntimeException(errorMessage);
 546  
 //                    }
 547  
 //                    if ((property1 instanceof Integer) || (property2 instanceof Integer)) {
 548  
 //                        Integer value1 = (property1 != null) ? (Integer) property1 : Integer.MIN_VALUE;
 549  
 //                        Integer value2 = (property2 != null) ? (Integer) property2 : Integer.MIN_VALUE;
 550  
 //                        compare = value1.compareTo(value2);
 551  
 //                    } else if ((property1 instanceof Long) || (property2 instanceof Long)) {
 552  
 //                        Long value1 = (property1 != null) ? (Long) property1 : Long.MIN_VALUE;
 553  
 //                        Long value2 = (property2 != null) ? (Long) property2 : Long.MIN_VALUE;
 554  
 //                        compare = value1.compareTo(value2);
 555  
 //                    } else if ((property1 instanceof BigDecimal) || (property2 instanceof BigDecimal)) {
 556  
 //                        BigDecimal value1 = (property1 != null) ? (BigDecimal) property1 : BigDecimal.ZERO;
 557  
 //                        BigDecimal value2 = (property2 != null) ? (BigDecimal) property2 : BigDecimal.ZERO;
 558  
 //                        compare = value1.compareTo(value2);
 559  
 //                    } else if ((property1 instanceof Timestamp) || (property2 instanceof Timestamp)) {
 560  
 //                        Timestamp value1 = (Timestamp) property1;
 561  
 //                        Timestamp value2 = (Timestamp) property2;
 562  
 //                        if ((value1 != null) && (value2 != null)) {
 563  
 //                            compare = value1.compareTo(value2);
 564  
 //                        } else if ((value1 == null) && (value2 != null)) {
 565  
 //                            compare = -1;
 566  
 //                        } else if ((value1 != null) && (value2 == null)) {
 567  
 //                            compare = 1;
 568  
 //                        }
 569  
 //                    } else {
 570  
 //                        // at this point... assume String
 571  
 //                        String value1 = (property1 != null) ? (String) property1 : "";
 572  
 //                        String value2 = (property2 != null) ? (String) property2 : "";
 573  
 //                        compare = String.CASE_INSENSITIVE_ORDER.compare(value1, value2);
 574  
 //                    }
 575  
 //                }
 576  
 //
 577  
 //                // String property1Value = (property1 != null) ? property1.toString() : "";
 578  
 //                // String property2Value = (property2 != null) ? property2.toString() : "";
 579  
 //                // if (Column.INTEGER.equals(column.getType())) {
 580  
 //                // Integer i1 = Integer.valueOf(property1Value);
 581  
 //                // Integer i2 = Integer.valueOf(property2Value);
 582  
 //                // compare = i1.compareTo(i2);
 583  
 //                // } else if (Column.LONG.equals(column.getType())) {
 584  
 //                // Long l1 = Long.valueOf(property1Value);
 585  
 //                // Long l2 = Long.valueOf(property2Value);
 586  
 //                // compare = l1.compareTo(l2);
 587  
 //                // } else if (Column.FLOAT.equals(column.getType())) {
 588  
 //                // Float f1 = Float.valueOf(property1Value);
 589  
 //                // Float f2 = Float.valueOf(property2Value);
 590  
 //                // compare = f1.compareTo(f2);
 591  
 //                // } else if (Column.DATETIME.equals(column.getType())) {
 592  
 //                // Timestamp t1 = Timestamp.valueOf(property1Value);
 593  
 //                // Timestamp t2 = Timestamp.valueOf(property2Value);
 594  
 //                // compare = t1.compareTo(t2);
 595  
 //                // } else {
 596  
 //                // compare = property1Value.compareTo(property2Value);
 597  
 //                // }
 598  
 //                if (!ascending) {
 599  
 //                    compare *= -1;
 600  
 //                }
 601  
 //                return compare;
 602  
 //            } catch (Exception e) {
 603  
 //                throw new WorkflowRuntimeException(e);
 604  
 //            }
 605  
 //        }
 606  
 //
 607  
 //    }
 608  
 //
 609  
 //    private class State {
 610  
 //        private boolean headerBarEnabled = true;
 611  
 //        private boolean searchCriteriaEnabled = true;
 612  
 //        private DocumentSearchCriteriaProcessor criteriaProcessor = null;
 613  
 //        private SavedSearchResult result = null;
 614  
 //
 615  
 //        public State(DocumentSearchForm form) {
 616  
 //            this.headerBarEnabled = form.isHeaderBarEnabled();
 617  
 //            this.searchCriteriaEnabled = form.isSearchCriteriaEnabled();
 618  
 //        }
 619  
 //
 620  
 //        public State(State state) {
 621  
 //            this.headerBarEnabled = state.isHeaderBarEnabled();
 622  
 //            this.searchCriteriaEnabled = state.isSearchCriteriaEnabled();
 623  
 //            this.criteriaProcessor = state.getCriteriaProcessor();
 624  
 //            this.result = state.getResult();
 625  
 //        }
 626  
 //
 627  
 //        public void updateForm(DocumentSearchForm form) {
 628  
 //            updateForm(form, null);
 629  
 //        }
 630  
 //
 631  
 //        public void updateForm(DocumentSearchForm form, DocSearchCriteriaDTO criteria) {
 632  
 //            form.setCriteriaProcessor(getCriteriaProcessor());
 633  
 //            if (criteria != null) {
 634  
 //                form.getCriteriaProcessor().setDocSearchCriteriaDTO(criteria);
 635  
 //            }
 636  
 //            form.setHeaderBarEnabled(isHeaderBarEnabled());
 637  
 //            form.setSearchCriteriaEnabled(isSearchCriteriaEnabled());
 638  
 //        }
 639  
 //
 640  
 //        public void setResult(SavedSearchResult result) {
 641  
 //            this.result = result;
 642  
 //        }
 643  
 //
 644  
 //        public SavedSearchResult getResult() {
 645  
 //            return result;
 646  
 //        }
 647  
 //
 648  
 //        public DocumentSearchCriteriaProcessor getCriteriaProcessor() {
 649  
 //            return criteriaProcessor;
 650  
 //        }
 651  
 //
 652  
 //        public void setCriteriaProcessor(DocumentSearchCriteriaProcessor processor) {
 653  
 //            this.criteriaProcessor = processor;
 654  
 //        }
 655  
 //
 656  
 //        public boolean isHeaderBarEnabled() {
 657  
 //            return headerBarEnabled;
 658  
 //        }
 659  
 //
 660  
 //        public boolean isSearchCriteriaEnabled() {
 661  
 //            return searchCriteriaEnabled;
 662  
 //        }
 663  
 //
 664  
 //    }
 665  
 
 666  
 }