Coverage Report - org.kuali.rice.kew.preferences.web.PreferencesAction
 
Classes in this File Line Coverage Branch Coverage Complexity
PreferencesAction
0%
0/35
0%
0/4
1.429
 
 1  
 /*
 2  
  * Copyright 2006-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.kuali.rice.kew.preferences.web;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.apache.struts.action.ActionForm;
 21  
 import org.apache.struts.action.ActionForward;
 22  
 import org.apache.struts.action.ActionMapping;
 23  
 import org.apache.struts.action.ActionMessages;
 24  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 25  
 import org.kuali.rice.core.util.ConcreteKeyValue;
 26  
 import org.kuali.rice.core.util.KeyValue;
 27  
 import org.kuali.rice.kew.preferences.Preferences;
 28  
 import org.kuali.rice.kew.preferences.service.PreferencesService;
 29  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 30  
 import org.kuali.rice.kew.util.KEWConstants;
 31  
 import org.kuali.rice.kew.web.KewKualiAction;
 32  
 import org.kuali.rice.krad.UserSession;
 33  
 import org.kuali.rice.krad.util.GlobalVariables;
 34  
 
 35  
 import javax.servlet.http.HttpServletRequest;
 36  
 import javax.servlet.http.HttpServletResponse;
 37  
 import java.util.ArrayList;
 38  
 import java.util.List;
 39  
 
 40  
 
 41  
 /**
 42  
  * A Struts Action for interfaces with {@link Preferences}.
 43  
  *
 44  
  * @see PreferencesService
 45  
  * @see Preferences
 46  
  *
 47  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 48  
  */
 49  0
 public class PreferencesAction extends KewKualiAction {
 50  
 
 51  
     @Override
 52  
         public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 53  0
         initForm(request, form);
 54  0
         request.setAttribute("Constants", getServlet().getServletContext().getAttribute("KEWConstants"));
 55  0
         return super.execute(mapping, form, request, response);
 56  
     }
 57  
 
 58  
     @Override
 59  
         public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 60  0
         PreferencesService preferencesService = (PreferencesService) KEWServiceLocator.getService(KEWServiceLocator.PREFERENCES_SERVICE);
 61  0
         PreferencesForm preferencesForm = (PreferencesForm) form;
 62  0
         preferencesForm.setPreferences(preferencesService.getPreferences(getUserSession().getPrincipalId()));
 63  0
         return mapping.findForward("basic");
 64  
     }
 65  
 
 66  
     public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 67  0
         PreferencesService prefSrv = (PreferencesService) KEWServiceLocator.getService(KEWServiceLocator.PREFERENCES_SERVICE);
 68  0
         PreferencesForm prefForm = (PreferencesForm) form;
 69  
 
 70  0
         prefForm.validatePreferences();
 71  0
         if (GlobalVariables.getMessageMap().hasNoErrors()) {
 72  0
             prefSrv.savePreferences(getUserSession().getPrincipalId(), prefForm.getPreferences());
 73  
         }
 74  
         
 75  0
         GlobalVariables.getUserSession().addObject(KEWConstants.UPDATE_ACTION_LIST_ATTR_NAME, Boolean.TRUE);
 76  0
         GlobalVariables.getUserSession().removeObject(KEWConstants.PREFERENCES);
 77  
         
 78  0
         if (! StringUtils.isEmpty(prefForm.getReturnMapping())) {
 79  0
             return mapping.findForward(prefForm.getReturnMapping());
 80  
         }
 81  0
         return mapping.findForward("basic");
 82  
     }
 83  
 
 84  
     public ActionMessages initForm(HttpServletRequest request, ActionForm form) throws Exception {
 85  0
         request.setAttribute("actionListContent", KEWConstants.ACTION_LIST_CONTENT);
 86  0
         getDelegatorFilterChoices(request);
 87  0
         getPrimaryDelegateFilterChoices(request);
 88  0
         PreferencesForm prefForm = (PreferencesForm)form;
 89  0
         prefForm.setShowOutbox(ConfigContext.getCurrentContextConfig().getOutBoxOn());
 90  0
         return null;
 91  
     }
 92  
 
 93  
     public void getDelegatorFilterChoices(HttpServletRequest request) {
 94  0
         List<KeyValue> delegatorFilterChoices = new ArrayList<KeyValue>();
 95  0
         delegatorFilterChoices.add(new ConcreteKeyValue(KEWConstants.DELEGATORS_ON_FILTER_PAGE, KEWConstants.DELEGATORS_ON_FILTER_PAGE));
 96  0
         delegatorFilterChoices.add(new ConcreteKeyValue(KEWConstants.DELEGATORS_ON_ACTION_LIST_PAGE, KEWConstants.DELEGATORS_ON_ACTION_LIST_PAGE));
 97  0
         request.setAttribute("delegatorFilter", delegatorFilterChoices);
 98  0
     }
 99  
     
 100  
     public void getPrimaryDelegateFilterChoices(HttpServletRequest request) {
 101  0
             List<KeyValue> primaryDelegateFilterChoices = new ArrayList<KeyValue>();
 102  0
             primaryDelegateFilterChoices.add(new ConcreteKeyValue(KEWConstants.PRIMARY_DELEGATES_ON_FILTER_PAGE, KEWConstants.PRIMARY_DELEGATES_ON_FILTER_PAGE));
 103  0
         primaryDelegateFilterChoices.add(new ConcreteKeyValue(KEWConstants.PRIMARY_DELEGATES_ON_ACTION_LIST_PAGE, KEWConstants.PRIMARY_DELEGATES_ON_ACTION_LIST_PAGE));
 104  0
         request.setAttribute("primaryDelegateFilter", primaryDelegateFilterChoices);
 105  0
     }
 106  
 
 107  
     private static UserSession getUserSession() {
 108  0
         return GlobalVariables.getUserSession();
 109  
     }
 110  
 }