Coverage Report - org.kuali.rice.kim.web.struts.action.IdentityManagementDocumentActionBase
 
Classes in this File Line Coverage Branch Coverage Complexity
IdentityManagementDocumentActionBase
0%
0/60
0%
0/20
2.308
 
 1  
 /*
 2  
  * Copyright 2007-2009 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.kim.web.struts.action;
 17  
 
 18  
 import javax.servlet.http.HttpServletRequest;
 19  
 import javax.servlet.http.HttpServletResponse;
 20  
 
 21  
 import org.apache.commons.lang.StringUtils;
 22  
 import org.apache.struts.action.ActionForm;
 23  
 import org.apache.struts.action.ActionForward;
 24  
 import org.apache.struts.action.ActionMapping;
 25  
 import org.kuali.rice.core.util.RiceConstants;
 26  
 import org.kuali.rice.kim.bo.Role;
 27  
 import org.kuali.rice.kim.bo.types.dto.KimTypeInfo;
 28  
 import org.kuali.rice.kim.lookup.KimTypeLookupableHelperServiceImpl;
 29  
 import org.kuali.rice.kim.service.IdentityService;
 30  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 31  
 import org.kuali.rice.kim.service.ResponsibilityService;
 32  
 import org.kuali.rice.kim.service.UiDocumentService;
 33  
 import org.kuali.rice.kim.service.support.KimRoleTypeService;
 34  
 import org.kuali.rice.kim.service.support.KimTypeService;
 35  
 import org.kuali.rice.kim.util.KimCommonUtils;
 36  
 import org.kuali.rice.kim.web.struts.form.IdentityManagementDocumentFormBase;
 37  
 import org.kuali.rice.kns.question.ConfirmationQuestion;
 38  
 import org.kuali.rice.kns.util.GlobalVariables;
 39  
 import org.kuali.rice.kns.util.KNSConstants;
 40  
 import org.kuali.rice.kns.util.RiceKeyConstants;
 41  
 import org.kuali.rice.kns.web.struts.action.KualiTransactionalDocumentActionBase;
 42  
 import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
 43  
 import org.kuali.rice.kns.web.struts.form.KualiTableRenderFormMetadata;
 44  
 
 45  
 /**
 46  
  * 
 47  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 48  
  *
 49  
  */
 50  0
 abstract public class IdentityManagementDocumentActionBase extends KualiTransactionalDocumentActionBase {
 51  
 
 52  
         protected static final String CHANGE_MEMBER_TYPE_CODE_METHOD_TO_CALL = "changeMemberTypeCode";
 53  
         protected static final String CHANGE_NAMESPACE_METHOD_TO_CALL = "changeNamespace";
 54  
 
 55  
         protected IdentityService identityService;
 56  
         protected ResponsibilityService responsibilityService;
 57  
         protected UiDocumentService uiDocumentService;
 58  
                 
 59  
     /**
 60  
      * 
 61  
      * This overridden method is to add 'kim/" to the return path
 62  
      * 
 63  
      * @see org.kuali.rice.kns.web.struts.action.KualiAction#performLookup(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 64  
      */
 65  
         @Override
 66  
         public ActionForward performLookup(ActionMapping mapping, ActionForm form,
 67  
                         HttpServletRequest request, HttpServletResponse response)
 68  
                         throws Exception {
 69  0
                 ActionForward forward =  super.performLookup(mapping, form, request, response);
 70  0
                 String path = forward.getPath();
 71  
                 //Making the hack look cleaner!
 72  0
                 forward.setPath(KimCommonUtils.getPathWithKimContext(path, getActionName()));
 73  0
                 return forward;
 74  
         }
 75  
 
 76  
         protected abstract String getActionName();
 77  
         
 78  
     protected IdentityService getIdentityService() {
 79  0
             if ( identityService == null ) {
 80  0
                     identityService = KIMServiceLocator.getIdentityService();
 81  
             }
 82  0
                 return identityService;
 83  
         }
 84  
 
 85  
     protected ResponsibilityService getResponsibilityService() {
 86  0
             if ( responsibilityService == null ) {
 87  0
                     responsibilityService = KIMServiceLocator.getResponsibilityService();
 88  
             }
 89  0
                 return responsibilityService;
 90  
         }
 91  
 
 92  
     protected UiDocumentService getUiDocumentService() {
 93  0
                 if ( uiDocumentService == null ) {
 94  0
                         uiDocumentService = KIMServiceLocator.getUiDocumentService();
 95  
                 }
 96  0
                 return uiDocumentService;
 97  
         }
 98  
 
 99  
         @Override
 100  
     protected String getReturnLocation(HttpServletRequest request, ActionMapping mapping){
 101  0
             String returnLocation = super.getReturnLocation(request, mapping);
 102  0
             return KimCommonUtils.getPathWithKimContext(returnLocation, getActionName());
 103  
     }
 104  
 
 105  
         @Override
 106  
     protected ActionForward returnToSender(HttpServletRequest request, ActionMapping mapping, KualiDocumentFormBase form) {
 107  0
         ActionForward dest = null;
 108  0
         if (form.isReturnToActionList()) {
 109  0
             String workflowBase = getKualiConfigurationService().getPropertyString(KNSConstants.WORKFLOW_URL_KEY);
 110  0
             String actionListUrl = workflowBase + "/ActionList.do";
 111  
 
 112  0
             dest = new ActionForward(actionListUrl, true);
 113  0
         } else if (StringUtils.isNotBlank(form.getBackLocation())){
 114  0
                 dest = new ActionForward(form.getBackLocation(), true);
 115  
         } else {
 116  0
                 dest = mapping.findForward(KNSConstants.MAPPING_PORTAL);
 117  0
             ActionForward newDest = new ActionForward();
 118  
             //why is this being done?
 119  0
             KimCommonUtils.copyProperties(newDest, dest);
 120  0
             newDest.setPath(getApplicationBaseUrl());
 121  0
             return newDest;
 122  
         }
 123  
 
 124  0
         setupDocumentExit();
 125  0
         return dest;
 126  
     }    
 127  
 
 128  
         protected ActionForward getBasePathForward(HttpServletRequest request, ActionForward forward){
 129  0
                 ActionForward newDest = new ActionForward();
 130  0
         KimCommonUtils.copyProperties(newDest, forward);
 131  0
         newDest.setPath(getApplicationBaseUrl());
 132  0
         return newDest;
 133  
     }
 134  
 
 135  
     /**
 136  
      * @see org.kuali.rice.kns.web.struts.action.KualiTableAction#switchToPage(org.apache.struts.action.ActionMapping,
 137  
      *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 138  
      */
 139  
     public ActionForward switchToPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 140  0
         IdentityManagementDocumentFormBase idmForm = (IdentityManagementDocumentFormBase) form;
 141  
         
 142  0
         KualiTableRenderFormMetadata memberTableMetadata = idmForm.getMemberTableMetadata();
 143  0
         memberTableMetadata.jumpToPage(memberTableMetadata.getSwitchToPageNumber(), idmForm.getMemberRows().size(), idmForm.getRecordsPerPage());
 144  0
         memberTableMetadata.setColumnToSortIndex(memberTableMetadata.getPreviouslySortedColumnIndex());
 145  0
         return mapping.findForward(RiceConstants.MAPPING_BASIC);
 146  
     }
 147  
 
 148  
     protected void applyPagingAndSortingFromPreviousPageView(IdentityManagementDocumentFormBase idmForm) {
 149  0
         KualiTableRenderFormMetadata memberTableMetadata = idmForm.getMemberTableMetadata();
 150  
 
 151  0
         memberTableMetadata.jumpToPage(memberTableMetadata.getViewedPageNumber(), idmForm.getMemberRows().size(), idmForm.getRecordsPerPage());
 152  0
     }
 153  
 
 154  
     protected boolean validateRole( String roleId, Role role, String propertyName, String message){
 155  0
             if ( role == null ) {
 156  0
                 GlobalVariables.getMessageMap().putError(propertyName, RiceKeyConstants.ERROR_INVALID_ROLE, roleId );
 157  0
                     return false;
 158  
             }
 159  0
             KimTypeInfo typeInfo = KIMServiceLocator.getTypeInfoService().getKimType(role.getKimTypeId());
 160  
             
 161  0
             if(KimTypeLookupableHelperServiceImpl.hasDerivedRoleTypeService(typeInfo)){
 162  0
                 GlobalVariables.getMessageMap().putError(propertyName, RiceKeyConstants.ERROR_CANT_ADD_DERIVED_ROLE, message);
 163  0
                 return false;
 164  
         }
 165  0
             return true;
 166  
     }
 167  
  
 168  
     public ActionForward changeNamespace(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
 169  0
         return refresh(mapping, form, request, response);
 170  
     }
 171  
 
 172  
     protected KimTypeService getKimTypeService( KimTypeInfo typeInfo ) {
 173  0
                 String serviceName = typeInfo.getKimTypeServiceName();
 174  0
                 if ( StringUtils.isNotBlank(serviceName) ) {
 175  
                         try {
 176  0
                                 KimTypeService service = (KimTypeService)KIMServiceLocator.getService( serviceName );
 177  0
                                 if ( service != null && service instanceof KimRoleTypeService ) {
 178  0
                                         return (KimRoleTypeService)service;
 179  
                                 } else {
 180  0
                                         return (KimRoleTypeService)KIMServiceLocator.getService( "kimNoMembersRoleTypeService" );
 181  
                                 }
 182  0
                         } catch ( Exception ex ) {
 183  
 //                                LOG.error( "Unable to find role type service with name: " + serviceName, ex );
 184  0
                                 return (KimRoleTypeService)KIMServiceLocator.getService( "kimNoMembersRoleTypeService" );
 185  
                         }
 186  
                 }
 187  0
                 return null;
 188  
     }
 189  
 
 190  
 }