<commit_before>/*
 * Copyright 2006-2008 The Kuali Foundation
 * 
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.osedu.org/licenses/ECL-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.kuali.kra.web.struts.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.Globals;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.kuali.core.bo.user.UniversalUser;
import org.kuali.core.document.Document;
import org.kuali.core.document.authorization.PessimisticLock;
import org.kuali.core.service.BusinessObjectService;
import org.kuali.core.service.PessimisticLockService;
import org.kuali.core.util.GlobalVariables;
import org.kuali.core.util.ObjectUtils;
import org.kuali.kra.authorization.KraAuthorizationConstants;
import org.kuali.kra.infrastructure.Constants;
import org.kuali.kra.infrastructure.KeyConstants;
import org.kuali.rice.KNSServiceLocator;
import org.kuali.rice.kns.util.KNSConstants;


/**
 * Retrieves and populates error messages during exception-handling
 */
public class KraExceptionAction extends Action {
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        ActionForward returnForward = mapping.findForward(Constants.MAPPING_BASIC);

        Exception e = (Exception) request.getAttribute(Globals.EXCEPTION_KEY);
        ActionMessage errorInfo = new ActionMessage(KeyConstants.ERROR_GLOBAL_MESSAGE);
        
        ActionMessages errors = new ActionMessages();
        errors.add(ActionMessages.GLOBAL_MESSAGE, errorInfo);
        
        saveErrors(request, errors);
        
        UniversalUser loggedInUser = GlobalVariables.getUserSession().getUniversalUser();
        String documentNumber = (String) request.getSession().getAttribute(KNSConstants.DOCUMENT_HTTP_SESSION_KEY);
        PessimisticLockService lockService = KNSServiceLocator.getPessimisticLockService();
        
        if(StringUtils.isNotEmpty(documentNumber)) {
            Document document = KNSServiceLocator.getDocumentService().getByDocumentHeaderId(documentNumber);

            if (ObjectUtils.isNotNull(document)) {
                String budgetLockDescriptor = null;
                for(PessimisticLock lock: document.getPessimisticLocks()) {
                    if(StringUtils.isNotEmpty(lock.getLockDescriptor()) && lock.getLockDescriptor().contains(KraAuthorizationConstants.LOCK_DESCRIPTOR_BUDGET)) {<commit_msg>The execute method does a document lookup using the documentNumber. However, if no document is found, an uncaught exception was thrown. This causes Struts to forward to the /exception.do handler - which is this same class. This causes a infinite recursion-like loop and ultimately a StackOverflowError.<commit_after>/*
 * Copyright 2006-2008 The Kuali Foundation
 * 
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.osedu.org/licenses/ECL-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.kuali.kra.web.struts.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.struts.Globals;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.kuali.core.bo.user.UniversalUser;
import org.kuali.core.document.Document;
import org.kuali.core.document.authorization.PessimisticLock;
import org.kuali.core.service.BusinessObjectService;
import org.kuali.core.service.PessimisticLockService;
import org.kuali.core.util.GlobalVariables;
import org.kuali.core.util.ObjectUtils;
import org.kuali.kra.authorization.KraAuthorizationConstants;
import org.kuali.kra.infrastructure.Constants;
import org.kuali.kra.infrastructure.KeyConstants;
import org.kuali.rice.KNSServiceLocator;
import org.kuali.rice.kns.util.KNSConstants;


/**
 * Retrieves and populates error messages during exception-handling
 */
public class KraExceptionAction extends Action {
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        ActionForward returnForward = mapping.findForward(Constants.MAPPING_BASIC);

        Exception e = (Exception) request.getAttribute(Globals.EXCEPTION_KEY);
        ActionMessage errorInfo = new ActionMessage(KeyConstants.ERROR_GLOBAL_MESSAGE);
        
        ActionMessages errors = new ActionMessages();
        errors.add(ActionMessages.GLOBAL_MESSAGE, errorInfo);
        
        saveErrors(request, errors);
        
        UniversalUser loggedInUser = GlobalVariables.getUserSession().getUniversalUser();
        String documentNumber = (String) request.getSession().getAttribute(KNSConstants.DOCUMENT_HTTP_SESSION_KEY);
        PessimisticLockService lockService = KNSServiceLocator.getPessimisticLockService();
        
        if(StringUtils.isNotEmpty(documentNumber)) {
            Document document;
            try {
                document = KNSServiceLocator.getDocumentService().getByDocumentHeaderId(documentNumber);
            } catch (Exception exc) {
                document = null;
            }

            if (ObjectUtils.isNotNull(document)) {
                String budgetLockDescriptor = null;
                for(PessimisticLock lock: document.getPessimisticLocks()) {
                    if(StringUtils.isNotEmpty(lock.getLockDescriptor()) && lock.getLockDescriptor().contains(KraAuthorizationConstants.LOCK_DESCRIPTOR_BUDGET)) {
{'fraction_non_alphanumeric': 0.08428084138715179, 'fraction_numerical': 0.0034110289937464467, 'mean_word_length': 4.290977443609022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6961989', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1896, 'n_words': 459}