Coverage Report - org.kuali.rice.kew.preferences.web.PreferencesAction
 
Classes in this File Line Coverage Branch Coverage Complexity
PreferencesAction
0%
0/36
0%
0/4
1.429
 
 1  
 /**
 2  
  * Copyright 2005-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  
 package org.kuali.rice.kew.preferences.web;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.apache.struts.action.ActionForm;
 20  
 import org.apache.struts.action.ActionForward;
 21  
 import org.apache.struts.action.ActionMapping;
 22  
 import org.apache.struts.action.ActionMessages;
 23  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 24  
 import org.kuali.rice.core.api.util.ConcreteKeyValue;
 25  
 import org.kuali.rice.core.api.util.KeyValue;
 26  
 import org.kuali.rice.kew.api.KewApiServiceLocator;
 27  
 import org.kuali.rice.kew.api.preferences.PreferencesService;
 28  
 import org.kuali.rice.kew.api.preferences.Preferences;
 29  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 30  
 import org.kuali.rice.kew.api.KewApiConstants;
 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("KewApiConstants"));
 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(KewApiServiceLocator.PREFERENCES_SERVICE);
 61  0
         PreferencesForm preferencesForm = (PreferencesForm) form;
 62  0
         org.kuali.rice.kew.api.preferences.Preferences preferences = preferencesService.getPreferences(
 63  
                 getUserSession().getPrincipalId());
 64  0
         preferencesForm.setPreferences(org.kuali.rice.kew.api.preferences.Preferences.Builder.create(preferences));
 65  0
         return mapping.findForward("basic");
 66  
     }
 67  
 
 68  
     public ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 69  0
         PreferencesService prefSrv = (PreferencesService) KEWServiceLocator.getService(KewApiServiceLocator.PREFERENCES_SERVICE);
 70  0
         PreferencesForm prefForm = (PreferencesForm) form;
 71  
 
 72  0
         prefForm.validatePreferences();
 73  0
         if (GlobalVariables.getMessageMap().hasNoErrors()) {
 74  0
             prefSrv.savePreferences(getUserSession().getPrincipalId(), prefForm.getPreferences().build());
 75  
         }
 76  
         
 77  0
         GlobalVariables.getUserSession().addObject(KewApiConstants.UPDATE_ACTION_LIST_ATTR_NAME, Boolean.TRUE);
 78  0
         GlobalVariables.getUserSession().removeObject(KewApiConstants.PREFERENCES);
 79  
         
 80  0
         if (! StringUtils.isEmpty(prefForm.getReturnMapping())) {
 81  0
             return mapping.findForward(prefForm.getReturnMapping());
 82  
         }
 83  0
         return mapping.findForward("basic");
 84  
     }
 85  
 
 86  
     public ActionMessages initForm(HttpServletRequest request, ActionForm form) throws Exception {
 87  0
         request.setAttribute("actionListContent", KewApiConstants.ACTION_LIST_CONTENT);
 88  0
         getDelegatorFilterChoices(request);
 89  0
         getPrimaryDelegateFilterChoices(request);
 90  0
         PreferencesForm prefForm = (PreferencesForm)form;
 91  0
         prefForm.setShowOutbox(ConfigContext.getCurrentContextConfig().getOutBoxOn());
 92  0
         return null;
 93  
     }
 94  
 
 95  
     public void getDelegatorFilterChoices(HttpServletRequest request) {
 96  0
         List<KeyValue> delegatorFilterChoices = new ArrayList<KeyValue>();
 97  0
         delegatorFilterChoices.add(new ConcreteKeyValue(KewApiConstants.DELEGATORS_ON_FILTER_PAGE, KewApiConstants.DELEGATORS_ON_FILTER_PAGE));
 98  0
         delegatorFilterChoices.add(new ConcreteKeyValue(KewApiConstants.DELEGATORS_ON_ACTION_LIST_PAGE, KewApiConstants.DELEGATORS_ON_ACTION_LIST_PAGE));
 99  0
         request.setAttribute("delegatorFilter", delegatorFilterChoices);
 100  0
     }
 101  
     
 102  
     public void getPrimaryDelegateFilterChoices(HttpServletRequest request) {
 103  0
             List<KeyValue> primaryDelegateFilterChoices = new ArrayList<KeyValue>();
 104  0
             primaryDelegateFilterChoices.add(new ConcreteKeyValue(KewApiConstants.PRIMARY_DELEGATES_ON_FILTER_PAGE, KewApiConstants.PRIMARY_DELEGATES_ON_FILTER_PAGE));
 105  0
         primaryDelegateFilterChoices.add(new ConcreteKeyValue(KewApiConstants.PRIMARY_DELEGATES_ON_ACTION_LIST_PAGE, KewApiConstants.PRIMARY_DELEGATES_ON_ACTION_LIST_PAGE));
 106  0
         request.setAttribute("primaryDelegateFilter", primaryDelegateFilterChoices);
 107  0
     }
 108  
 
 109  
     private static UserSession getUserSession() {
 110  0
         return GlobalVariables.getUserSession();
 111  
     }
 112  
 }