001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.purap.document.authorization;
017:
018: import java.util.HashMap;
019: import java.util.List;
020: import java.util.Map;
021:
022: import org.kuali.core.authorization.AuthorizationConstants;
023: import org.kuali.core.bo.user.UniversalUser;
024: import org.kuali.core.document.Document;
025: import org.kuali.core.document.authorization.DocumentActionFlags;
026: import org.kuali.core.exceptions.GroupNotFoundException;
027: import org.kuali.core.service.KualiGroupService;
028: import org.kuali.core.workflow.service.KualiWorkflowDocument;
029: import org.kuali.kfs.context.SpringContext;
030: import org.kuali.kfs.service.ParameterService;
031: import org.kuali.module.purap.PurapAuthorizationConstants;
032: import org.kuali.module.purap.PurapParameterConstants;
033: import org.kuali.module.purap.document.PurchaseOrderDocument;
034:
035: /**
036: * Document Authorizer for the PO Retransmit document.
037: */
038: public class PurchaseOrderRetransmitDocumentAuthorizer extends
039: PurchaseOrderDocumentAuthorizer {
040:
041: /**
042: * @see org.kuali.core.document.authorization.DocumentAuthorizerBase#hasInitiateAuthorization(org.kuali.core.document.Document,
043: * org.kuali.core.bo.user.UniversalUser)
044: */
045: @Override
046: public boolean hasInitiateAuthorization(Document document,
047: UniversalUser user) {
048: PurchaseOrderDocument po = (PurchaseOrderDocument) document;
049: if (po.getPurchaseOrderAutomaticIndicator()) {
050: return true;
051: } else {
052: String authorizedWorkgroup = SpringContext
053: .getBean(ParameterService.class)
054: .getParameterValue(
055: PurchaseOrderDocument.class,
056: PurapParameterConstants.Workgroups.PURAP_DOCUMENT_PO_INITIATE_ACTION);
057: try {
058: return SpringContext.getBean(KualiGroupService.class)
059: .getByGroupName(authorizedWorkgroup).hasMember(
060: user);
061: } catch (GroupNotFoundException e) {
062: throw new RuntimeException("Workgroup "
063: + authorizedWorkgroup + " not found", e);
064: }
065: }
066: }
067:
068: /**
069: * @see org.kuali.core.document.authorization.DocumentAuthorizer#getDocumentActionFlags(org.kuali.core.document.Document,
070: * org.kuali.core.bo.user.UniversalUser)
071: */
072: @Override
073: public DocumentActionFlags getDocumentActionFlags(
074: Document document, UniversalUser user) {
075: DocumentActionFlags flags = super .getDocumentActionFlags(
076: document, user);
077: KualiWorkflowDocument workflowDocument = document
078: .getDocumentHeader().getWorkflowDocument();
079:
080: if (workflowDocument.stateIsInitiated()
081: || workflowDocument.stateIsSaved()) {
082: // do not allow this document to be saved; once initiated, it must be routed or canceled
083: flags.setCanSave(false);
084: }
085:
086: // NEED TO REDO ANNOTATE CHECK SINCE CHANGED THE VALUE OF FLAGS
087: this .setAnnotateFlag(flags);
088:
089: return flags;
090: }
091:
092: /**
093: * @see org.kuali.kfs.document.authorization.AccountingDocumentAuthorizer#getEditMode(org.kuali.core.document.Document,
094: * org.kuali.core.bo.user.UniversalUser, java.util.List, java.util.List)
095: */
096: @Override
097: public Map getEditMode(Document d, UniversalUser u,
098: List sourceAccountingLines, List targetAccountingLines) {
099: Map editModeMap = new HashMap();
100: String editMode = PurapAuthorizationConstants.PurchaseOrderEditMode.DISPLAY_RETRANSMIT_TAB;
101: editModeMap.put(editMode, "TRUE");
102: String viewOnlyEditMode = AuthorizationConstants.EditMode.VIEW_ONLY;
103: editModeMap.put(viewOnlyEditMode, "TRUE");
104:
105: return editModeMap;
106: }
107:
108: }
|