001 /** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kim.lookup; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.rice.kew.api.KewApiConstants; 020 import org.kuali.rice.kim.api.KimConstants; 021 import org.kuali.rice.kim.api.permission.PermissionService; 022 import org.kuali.rice.kim.api.services.KimApiServiceLocator; 023 import org.kuali.rice.kim.util.KimCommonUtilsInternal; 024 import org.kuali.rice.kns.lookup.KualiLookupableImpl; 025 import org.kuali.rice.krad.util.GlobalVariables; 026 import org.kuali.rice.krad.util.KRADConstants; 027 import org.kuali.rice.krad.util.UrlFactory; 028 029 import java.util.Collections; 030 import java.util.Properties; 031 032 /** 033 * This is a description of what this class does - shyu don't forget to fill this in. 034 * 035 * @author Kuali Rice Team (rice.collab@kuali.org) 036 * 037 */ 038 public class PersonLookupableImpl extends KualiLookupableImpl { 039 040 private static final long serialVersionUID = 1707861010746829601L; 041 042 @Override 043 public String getCreateNewUrl() { 044 String url = ""; 045 if((getLookupableHelperService()).allowsNewOrCopyAction(KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_TYPE_NAME) 046 && canModifyEntity(GlobalVariables.getUserSession().getPrincipalId(), null)){ 047 Properties parameters = new Properties(); 048 parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.DOC_HANDLER_METHOD); 049 parameters.put(KRADConstants.PARAMETER_COMMAND, KewApiConstants.INITIATE_COMMAND); 050 parameters.put(KRADConstants.DOCUMENT_TYPE_NAME, KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_TYPE_NAME); 051 if (StringUtils.isNotBlank(getReturnLocation())) { 052 parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, getReturnLocation()); 053 } 054 url = getCreateNewUrl(UrlFactory.parameterizeUrl( 055 KimCommonUtilsInternal.getKimBasePath()+ KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_ACTION, parameters)); 056 //String url = "lookup.do?businessObjectClassName=org.kuali.rice.kim.bo.types.impl.KimTypeImpl&returnLocation=portal.do&docFormKey="+KimApiConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY; 057 //url = "../kim/identityManagementPersonDocument.do?methodToCall=docHandler&command=initiate&docTypeName=IdentityManagementPersonDocument"; 058 //url = "<a title=\"Create a new record\" href=\"" + url + "\"><img src=\"images/tinybutton-createnew.gif\" alt=\"create new\" width=\"70\" height=\"15\"/></a>"; 059 } 060 return url; 061 } 062 063 064 // TODO: this is a copy from the UIDocumentService. They should be combined outside of UIDocumentService at some point 065 // as to not have duplicate code 066 // we can't have the UIDocumentService here, because that is not available when in Kim embedded mode 067 private boolean canModifyEntity( String currentUserPrincipalId, String toModifyPrincipalId ){ 068 return (StringUtils.isNotBlank(currentUserPrincipalId) && StringUtils.isNotBlank(toModifyPrincipalId) && 069 currentUserPrincipalId.equals(toModifyPrincipalId)) || 070 KimApiServiceLocator.getPermissionService().isAuthorized( 071 currentUserPrincipalId, 072 KimConstants.NAMESPACE_CODE, 073 KimConstants.PermissionNames.MODIFY_ENTITY, 074 Collections.singletonMap(KimConstants.AttributeConstants.PRINCIPAL_ID, currentUserPrincipalId)); 075 } 076 077 }