001    /*
002     * Copyright 2011 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.kfs.module.purap.document.validation.impl;
017    
018    import java.util.Arrays;
019    import java.util.List;
020    
021    import org.kuali.kfs.coa.service.AccountService;
022    import org.kuali.kfs.module.purap.PurapWorkflowConstants.RequisitionDocument.NodeDetailEnum;
023    import org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument;
024    import org.kuali.kfs.module.purap.document.RequisitionDocument;
025    import org.kuali.kfs.module.purap.document.service.PurapService;
026    import org.kuali.kfs.sys.KFSKeyConstants;
027    import org.kuali.kfs.sys.KFSPropertyConstants;
028    import org.kuali.kfs.sys.businessobject.AccountingLine;
029    import org.kuali.kfs.sys.context.SpringContext;
030    import org.kuali.kfs.sys.document.AccountingDocument;
031    import org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent;
032    import org.kuali.kfs.sys.document.validation.event.DeleteAccountingLineEvent;
033    import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
034    import org.kuali.kfs.sys.document.validation.event.UpdateAccountingLineEvent;
035    import org.kuali.kfs.sys.document.validation.impl.AccountingLineAccessibleValidation;
036    import org.kuali.rice.kew.exception.WorkflowException;
037    import org.kuali.rice.kns.rule.event.KualiDocumentEvent;
038    import org.kuali.rice.kns.util.GlobalVariables;
039    import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument;
040    
041    /**
042     * A validation that checks whether the given accounting line is accessible to the given user or not
043     */
044    public class PurchaseOrderAmendmentAccountingLineAccessibleValidation extends PurchasingAccountsPayableAccountingLineAccessibleValidation {
045    
046        private PurapService purapService;
047        
048        /**
049         * Validates that the given accounting line is accessible for editing by the current user.
050         * <strong>This method expects a document as the first parameter and an accounting line as the second</strong>
051         * @see org.kuali.kfs.sys.document.validation.Validation#validate(java.lang.Object[])
052         */
053        public boolean validate(AttributedDocumentEvent event) {
054    
055            if( purapService.isDocumentStoppedInRouteNode((PurchasingAccountsPayableDocument)event.getDocument(), "New Unordered Items") ){
056                //DO NOTHING: do not check that user owns acct lines; at this level, they can edit all accounts on PO amendment
057                return true;
058            } else if (event.getDocument().getDocumentHeader().getWorkflowDocument().isAdHocRequested()) {
059                return true;
060            } else {
061                return super.validate(event);
062            }
063        }
064    
065        public PurapService getPurapService() {
066            return purapService;
067        }
068    
069        public void setPurapService(PurapService purapService) {
070            this.purapService = purapService;
071        }
072     
073    }
074