View Javadoc

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.lookup;
17  
18  import org.kuali.rice.kim.api.identity.Person;
19  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
20  import org.kuali.rice.kim.api.type.KimTypeInfoService;
21  import org.kuali.rice.kns.lookup.KualiLookupableHelperServiceImpl;
22  import org.kuali.rice.krad.document.authorization.DocumentAuthorizer;
23  import org.kuali.rice.krad.document.authorization.DocumentPresentationController;
24  import org.kuali.rice.krad.service.DocumentHelperService;
25  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
26  import org.kuali.rice.krad.util.GlobalVariables;
27  
28  /**
29   * This is a description of what this class does - shyu don't forget to fill this in.
30   *
31   * @author Kuali Rice Team (rice.collab@kuali.org)
32   *
33   */
34  public class KimLookupableHelperServiceImpl extends KualiLookupableHelperServiceImpl {
35  
36  	private static final long serialVersionUID = 1L;
37  	
38  	private static DocumentHelperService documentHelperService;
39  	private static KimTypeInfoService typeInfoService;
40  	
41      @Override
42  	public boolean allowsNewOrCopyAction(String documentTypeName) {
43  		// TODO : to let it rendering 'create new' and 'edit'/'copy' button
44          DocumentAuthorizer documentAuthorizer = getDocumentHelperService().getDocumentAuthorizer(documentTypeName);
45          DocumentPresentationController documentPresentationController = getDocumentHelperService().getDocumentPresentationController(documentTypeName);
46          // make sure this person is authorized to initiate
47          Person currentUser = GlobalVariables.getUserSession().getPerson();
48          return documentPresentationController.canInitiate(documentTypeName) && documentAuthorizer.canInitiate(documentTypeName, currentUser);
49  
50  	}
51  
52  	protected DocumentHelperService getDocumentHelperService() {
53  	    if ( documentHelperService == null ) {
54  	        documentHelperService = KRADServiceLocatorWeb.getDocumentHelperService();
55  		}
56  	    return documentHelperService;
57  	}
58  
59  	protected KimTypeInfoService getTypeInfoService() {
60  	    if ( typeInfoService == null ) {
61  	    	typeInfoService = KimApiServiceLocator.getKimTypeInfoService();
62  		}
63  	    return typeInfoService;
64  	}
65  }