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.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.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 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 DocumentStatus documentStatus = document.getDocumentHeader().getWorkflowDocument().getStatus();
045
046 if(DocumentStatus.ENROUTE.equals(documentStatus) ){
047 if(KewApiServiceLocator.getWorkflowDocumentActionsService().isFinalApprover(mpDoc.getDocumentNumber(), TKContext.getPrincipalId())){
048 author.add(KRADConstants.KUALI_ACTION_CAN_EDIT);
049 author.add(KRADConstants.KUALI_ACTION_CAN_APPROVE);
050 }
051 } else if(DocumentStatus.INITIATED.equals(documentStatus)
052 || DocumentStatus.SAVED.equals(documentStatus)){
053 author.add(KRADConstants.KUALI_ACTION_CAN_EDIT);
054 author.add(KRADConstants.KUALI_ACTION_CAN_ROUTE);
055 } else {
056 author.remove(KRADConstants.KUALI_ACTION_CAN_APPROVE);
057 }
058 author.remove(KRADConstants.KUALI_ACTION_CAN_ADD_ADHOC_REQUESTS);
059 author.remove(KRADConstants.KUALI_ACTION_CAN_SEND_ADHOC_REQUESTS);
060
061 //can never disapprove
062 author.remove(KRADConstants.KUALI_ACTION_CAN_DISAPPROVE);
063 return author;
064 }
065
066
067
068 }