001/*
002 * Copyright 2008-2009 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 */
016package org.kuali.ole.module.purap.document.authorization;
017
018import org.kuali.ole.module.purap.PurapAuthorizationConstants;
019import org.kuali.ole.module.purap.document.BulkReceivingDocument;
020import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
021import org.kuali.rice.krad.document.Document;
022import org.kuali.rice.krad.util.ObjectUtils;
023
024import java.util.Set;
025
026
027public class BulkReceivingDocumentPresentationController extends PurchasingAccountsPayableDocumentPresentationController {
028
029    @Override
030    public boolean canSave(Document document) {
031        if (((PurchasingAccountsPayableDocument) document).getFinancialSystemDocumentHeader().getWorkflowDocument().isInitiated()) {
032            return false;
033        }
034        return super.canSave(document);
035    }
036
037    @Override
038    public boolean canCancel(Document document) {
039        if (((PurchasingAccountsPayableDocument) document).getFinancialSystemDocumentHeader().getWorkflowDocument().isInitiated()) {
040            return false;
041        }
042        return super.canCancel(document);
043    }
044
045    @Override
046    public boolean canClose(Document document) {
047        if (((PurchasingAccountsPayableDocument) document).getFinancialSystemDocumentHeader().getWorkflowDocument().isInitiated()) {
048            return false;
049        }
050        return super.canClose(document);
051    }
052
053    @Override
054    public Set<String> getEditModes(Document document) {
055        Set<String> editModes = super.getEditModes(document);
056        BulkReceivingDocument bulkReceivingDocument = (BulkReceivingDocument) document;
057
058        // if vendor has been selected from DB, certain vendor fields are not allowed to be edited
059        if (ObjectUtils.isNotNull(bulkReceivingDocument.getVendorHeaderGeneratedIdentifier())) {
060            editModes.add(PurapAuthorizationConstants.BulkReceivingEditMode.LOCK_VENDOR_ENTRY);
061        }
062
063        if (((PurchasingAccountsPayableDocument) document).getFinancialSystemDocumentHeader().getWorkflowDocument().isInitiated()) {
064            editModes.add(PurapAuthorizationConstants.BulkReceivingEditMode.DISPLAY_INIT_TAB);
065        }
066
067        return editModes;
068    }
069}