001    /**
002     * Copyright 2004-2012 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.hr.time.missedpunch;
017    
018    import java.util.Set;
019    
020    import org.apache.commons.lang.StringUtils;
021    import org.apache.log4j.Logger;
022    import org.kuali.hr.time.util.TKContext;
023    import org.kuali.rice.kew.api.KewApiServiceLocator;
024    import org.kuali.rice.kim.api.identity.Person;
025    import org.kuali.rice.kns.document.authorization.TransactionalDocumentAuthorizerBase;
026    import org.kuali.rice.krad.document.Document;
027    import org.kuali.rice.krad.util.KRADConstants;
028    
029    public class MissedPunchAuthorizer extends TransactionalDocumentAuthorizerBase {
030    
031            private Logger LOG = Logger.getLogger(MissedPunchAuthorizer.class);
032            
033            @Override
034            public boolean canEditDocumentOverview(Document document, Person user) {
035                    return true;
036            }
037    
038            @Override
039            public Set<String> getDocumentActions(Document document, Person user,
040                            Set<String> documentActions) {
041                    Set<String> author =  super.getDocumentActions(document, user, documentActions);
042                    MissedPunchDocument mpDoc = (MissedPunchDocument)document;
043                    if(StringUtils.equals(mpDoc.getDocumentStatus(),"R") ){
044                            if(KewApiServiceLocator.getWorkflowDocumentActionsService().isFinalApprover(mpDoc.getDocumentNumber(), TKContext.getPrincipalId())){
045                                    author.add(KRADConstants.KUALI_ACTION_CAN_EDIT);
046                                    author.add(KRADConstants.KUALI_ACTION_CAN_APPROVE);
047                                    
048                                    author.remove(KRADConstants.KUALI_ACTION_CAN_DISAPPROVE);
049                            }
050                    } else if(!StringUtils.equals(mpDoc.getDocumentStatus(), "A")){
051                            author.add(KRADConstants.KUALI_ACTION_CAN_EDIT);
052                            author.add(KRADConstants.KUALI_ACTION_CAN_ROUTE);
053                    }
054                    author.remove(KRADConstants.KUALI_ACTION_CAN_ADD_ADHOC_REQUESTS);
055                    author.remove(KRADConstants.KUALI_ACTION_CAN_SEND_ADHOC_REQUESTS);
056                    return author;
057            }
058            
059            
060            
061    }