View Javadoc

1   /**
2    * Copyright 2005-2014 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.lookup;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.kew.api.KewApiConstants;
20  import org.kuali.rice.kim.api.KimConstants;
21  import org.kuali.rice.kim.api.permission.PermissionService;
22  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
23  import org.kuali.rice.kim.util.KimCommonUtilsInternal;
24  import org.kuali.rice.kns.lookup.KualiLookupableImpl;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  import org.kuali.rice.krad.util.KRADConstants;
27  import org.kuali.rice.krad.util.UrlFactory;
28  
29  import java.util.Collections;
30  import java.util.Properties;
31  
32  /**
33   * This is a description of what this class does - shyu don't forget to fill this in. 
34   * 
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   *
37   */
38  public class PersonLookupableImpl extends KualiLookupableImpl {
39  
40  	private static final long serialVersionUID = 1707861010746829601L;
41  
42  	@Override
43  	public String getCreateNewUrl() {
44  		String url = "";
45  		if((getLookupableHelperService()).allowsNewOrCopyAction(KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_TYPE_NAME)
46  				&& canModifyEntity(GlobalVariables.getUserSession().getPrincipalId(), null)){
47  	        Properties parameters = new Properties();
48  	        parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.DOC_HANDLER_METHOD);
49  	        parameters.put(KRADConstants.PARAMETER_COMMAND, KewApiConstants.INITIATE_COMMAND);
50  	        parameters.put(KRADConstants.DOCUMENT_TYPE_NAME, KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_TYPE_NAME);
51  	        if (StringUtils.isNotBlank(getReturnLocation())) {
52  	        	parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, getReturnLocation());
53  	        	}
54  	        url = getCreateNewUrl(UrlFactory.parameterizeUrl(
55  	        		KimCommonUtilsInternal.getKimBasePath()+ KimConstants.KimUIConstants.KIM_PERSON_DOCUMENT_ACTION, parameters));
56  	        //String url = "lookup.do?businessObjectClassName=org.kuali.rice.kim.bo.types.impl.KimTypeImpl&returnLocation=portal.do&docFormKey="+KimApiConstants.KimUIConstants.KIM_ROLE_DOCUMENT_SHORT_KEY;
57  	        //url = "../kim/identityManagementPersonDocument.do?methodToCall=docHandler&command=initiate&docTypeName=IdentityManagementPersonDocument";
58  	        //url = "<a title=\"Create a new record\" href=\"" + url + "\"><img src=\"images/tinybutton-createnew.gif\" alt=\"create new\" width=\"70\" height=\"15\"/></a>";
59  		}
60  		return url;
61  	}
62  
63  
64      // TODO: this is a copy from the UIDocumentService.  They should be combined outside of UIDocumentService at some point
65      // as to not have duplicate code
66      // we can't have the UIDocumentService here, because that is not available when in Kim embedded mode
67      private boolean canModifyEntity( String currentUserPrincipalId, String toModifyPrincipalId ){
68          return (StringUtils.isNotBlank(currentUserPrincipalId) && StringUtils.isNotBlank(toModifyPrincipalId) &&
69                  currentUserPrincipalId.equals(toModifyPrincipalId)) ||
70                  KimApiServiceLocator.getPermissionService().isAuthorized(
71                          currentUserPrincipalId,
72                          KimConstants.NAMESPACE_CODE,
73                          KimConstants.PermissionNames.MODIFY_ENTITY,
74                          Collections.singletonMap(KimConstants.AttributeConstants.PRINCIPAL_ID, currentUserPrincipalId));
75      }
76  
77  }