001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.kim.lookup; 017 018import org.kuali.rice.kim.api.identity.Person; 019import org.kuali.rice.kim.api.services.KimApiServiceLocator; 020import org.kuali.rice.kim.api.type.KimTypeInfoService; 021import org.kuali.rice.kns.document.authorization.DocumentAuthorizer; 022import org.kuali.rice.kns.document.authorization.DocumentPresentationController; 023import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl; 024import org.kuali.rice.kns.service.DocumentHelperService; 025import org.kuali.rice.kns.service.KNSServiceLocator; 026import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 027import org.kuali.rice.krad.util.GlobalVariables; 028 029/** 030 * This is a description of what this class does - shyu don't forget to fill this in. 031 * 032 * @author Kuali Rice Team (rice.collab@kuali.org) 033 */ 034public class KimLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl { 035 036 private static final long serialVersionUID = 1L; 037 038 private static DocumentHelperService documentHelperService; 039 private static KimTypeInfoService typeInfoService; 040 041 @Override 042 public boolean allowsNewOrCopyAction(String documentTypeName) { 043 // TODO : to let it rendering 'create new' and 'edit'/'copy' button 044 DocumentAuthorizer documentAuthorizer = getDocumentHelperService().getDocumentAuthorizer(documentTypeName); 045 DocumentPresentationController documentPresentationController = getDocumentHelperService().getDocumentPresentationController(documentTypeName); 046 // make sure this person is authorized to initiate 047 Person currentUser = GlobalVariables.getUserSession().getPerson(); 048 return documentPresentationController.canInitiate(documentTypeName) && documentAuthorizer.canInitiate(documentTypeName, currentUser); 049 050 } 051 052 protected DocumentHelperService getDocumentHelperService() { 053 if ( documentHelperService == null ) { 054 documentHelperService = KNSServiceLocator.getDocumentHelperService(); 055 } 056 return documentHelperService; 057 } 058 059 protected KimTypeInfoService getTypeInfoService() { 060 if ( typeInfoService == null ) { 061 typeInfoService = KimApiServiceLocator.getKimTypeInfoService(); 062 } 063 return typeInfoService; 064 } 065}