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