001    /**
002     * Copyright 2004-2013 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.Collections;
019    import java.util.Set;
020    
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.kew.api.document.DocumentStatus;
025    import org.kuali.rice.kim.api.identity.Person;
026    import org.kuali.rice.kns.document.authorization.TransactionalDocumentAuthorizerBase;
027    import org.kuali.rice.krad.document.Document;
028    import org.kuali.rice.krad.util.KRADConstants;
029    
030    public class MissedPunchAuthorizer extends TransactionalDocumentAuthorizerBase {
031    
032            private static final Logger LOG = Logger.getLogger(MissedPunchAuthorizer.class);
033            
034            @Override
035            public boolean canEditDocumentOverview(Document document, Person user) {
036                    return true;
037            }
038    
039            @Override
040            public Set<String> getDocumentActions(Document document, Person user,
041                            Set<String> documentActions) {
042                    Set<String> author =  super.getDocumentActions(document, user, documentActions);
043                    MissedPunchDocument mpDoc = (MissedPunchDocument)document;
044            if (mpDoc == null || mpDoc.getDocumentHeader() == null) {
045                return author;
046            }
047            if (document.getDocumentHeader().hasWorkflowDocument()) {
048                DocumentStatus documentStatus = document.getDocumentHeader().getWorkflowDocument().getStatus();
049    
050                if(DocumentStatus.ENROUTE.equals(documentStatus) ){
051                    if(KewApiServiceLocator.getWorkflowDocumentActionsService().isFinalApprover(mpDoc.getDocumentNumber(), TKContext.getPrincipalId())){
052                        author.add(KRADConstants.KUALI_ACTION_CAN_EDIT);
053                        author.add(KRADConstants.KUALI_ACTION_CAN_APPROVE);
054                    }
055                } else if(DocumentStatus.INITIATED.equals(documentStatus)
056                            || DocumentStatus.SAVED.equals(documentStatus)){
057                    author.add(KRADConstants.KUALI_ACTION_CAN_EDIT);
058                    author.add(KRADConstants.KUALI_ACTION_CAN_ROUTE);
059                } else {
060                    author.remove(KRADConstants.KUALI_ACTION_CAN_APPROVE);
061                }
062            }
063                    author.remove(KRADConstants.KUALI_ACTION_CAN_ADD_ADHOC_REQUESTS);
064                    author.remove(KRADConstants.KUALI_ACTION_CAN_SEND_ADHOC_REQUESTS);
065    
066            //can never disapprove
067            author.remove(KRADConstants.KUALI_ACTION_CAN_DISAPPROVE);
068                    return author;
069            }
070            
071            
072            
073    }