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.apache.commons.lang.StringUtils;
023: import org.kuali.core.authorization.AuthorizationConstants;
024: import org.kuali.core.bo.user.UniversalUser;
025: import org.kuali.core.document.Document;
026: import org.kuali.core.document.authorization.DocumentActionFlags;
027: import org.kuali.core.exceptions.GroupNotFoundException;
028: import org.kuali.core.service.KualiGroupService;
029: import org.kuali.core.util.GlobalVariables;
030: import org.kuali.core.util.ObjectUtils;
031: import org.kuali.core.workflow.service.KualiWorkflowDocument;
032: import org.kuali.kfs.context.SpringContext;
033: import org.kuali.kfs.document.authorization.AccountingDocumentAuthorizerBase;
034: import org.kuali.kfs.service.ParameterService;
035: import org.kuali.module.purap.PurapAuthorizationConstants;
036: import org.kuali.module.purap.PurapParameterConstants;
037: import org.kuali.module.purap.PurapWorkflowConstants;
038: import org.kuali.module.purap.PurapConstants.PurchaseOrderStatuses;
039: import org.kuali.module.purap.PurapWorkflowConstants.PurchaseOrderDocument.NodeDetailEnum;
040: import org.kuali.module.purap.document.PurchaseOrderDocument;
041: import org.kuali.module.purap.service.PurApWorkflowIntegrationService;
042:
043: /**
044: * Document Authorizer for the PO document.
045: */
046: public class PurchaseOrderDocumentAuthorizer extends
047: AccountingDocumentAuthorizerBase {
048:
049: /**
050: * @see org.kuali.core.document.authorization.DocumentAuthorizerBase#hasInitiateAuthorization(org.kuali.core.document.Document,
051: * org.kuali.core.bo.user.UniversalUser)
052: */
053: @Override
054: public boolean hasInitiateAuthorization(Document document,
055: UniversalUser user) {
056: String authorizedWorkgroup = SpringContext
057: .getBean(ParameterService.class)
058: .getParameterValue(
059: PurchaseOrderDocument.class,
060: PurapParameterConstants.Workgroups.PURAP_DOCUMENT_PO_INITIATE_ACTION);
061: try {
062: return SpringContext.getBean(KualiGroupService.class)
063: .getByGroupName(authorizedWorkgroup)
064: .hasMember(user);
065: } catch (GroupNotFoundException e) {
066: throw new RuntimeException("Workgroup "
067: + authorizedWorkgroup + " not found", e);
068: }
069: }
070:
071: /**
072: * This is essentially the same getEditMode as in DocumentAuthorizerBase.java. In AccountingDocumentAuthorizerBase.java, which
073: * is currently the superclass of this class, this method is being overriden. Unfortunately it will return view only edit mode
074: * if the initiator of the document is different than the current user. Currently the initiators of Purchase Order Document are
075: * all "Kuali System User" which is different than the users that we use to log in. Therefore here we have to re-override the
076: * getEditMode to prevent the problem where the fields appear as read-only. There has been an addition to this method, which at
077: * this point I'm not sure whether there would be any cases where the Purchase Order Document would have status "RETR". If so,
078: * then when the status code is "RETR" (retransmit), the edit mode should be set to displayRetransmitTab because we want to hide
079: * the other tabs and display the retransmit tab when the user clicks on the Retransmit button (is that what we want ?)
080: *
081: * @see org.kuali.core.document.authorization.DocumentAuthorizer#getEditMode(org.kuali.core.document.Document,
082: * org.kuali.core.bo.user.UniversalUser)
083: */
084: @Override
085: public Map getEditMode(Document d, UniversalUser user,
086: List sourceAccountingLines, List targetAccountingLines) {
087: Map editModeMap = new HashMap();
088: String editMode = AuthorizationConstants.EditMode.VIEW_ONLY;
089:
090: KualiWorkflowDocument workflowDocument = d.getDocumentHeader()
091: .getWorkflowDocument();
092:
093: PurchaseOrderDocument poDocument = (PurchaseOrderDocument) d;
094: if (workflowDocument.stateIsInitiated()
095: || workflowDocument.stateIsSaved()
096: || workflowDocument.stateIsEnroute()) {
097: if (ObjectUtils.isNotNull(poDocument
098: .getVendorHeaderGeneratedIdentifier())) {
099: editModeMap
100: .put(
101: PurapAuthorizationConstants.PurchaseOrderEditMode.LOCK_VENDOR_ENTRY,
102: "TRUE");
103: }
104: }
105:
106: if (workflowDocument.stateIsInitiated()
107: || workflowDocument.stateIsSaved()) {
108: if (hasInitiateAuthorization(d, user)) {
109: editMode = AuthorizationConstants.EditMode.FULL_ENTRY;
110:
111: // PRE_ROUTE_CHANGEABLE mode is used for fields that are editable only before PO is routed
112: // for ex, contract manager, manual status change, and quote etc
113: editModeMap
114: .put(
115: PurapAuthorizationConstants.PurchaseOrderEditMode.PRE_ROUTE_CHANGEABLE,
116: "TRUE");
117: }
118: } else if (workflowDocument.stateIsEnroute()
119: && workflowDocument.isApprovalRequested()) {
120: List currentRouteLevels = getCurrentRouteLevels(workflowDocument);
121:
122: /**
123: * INTERNAL PURCHASING ROUTE LEVEL - Approvers can edit full detail on Purchase Order except they cannot change the
124: * CHART/ORG.
125: */
126: if (((PurchaseOrderDocument) d)
127: .isDocumentStoppedInRouteNode(PurapWorkflowConstants.PurchaseOrderDocument.NodeDetailEnum.INTERNAL_PURCHASING_REVIEW)) {
128: // FULL_ENTRY allowed; also set internal purchasing lock
129: editMode = AuthorizationConstants.EditMode.FULL_ENTRY;
130: editModeMap
131: .put(
132: PurapAuthorizationConstants.PurchaseOrderEditMode.LOCK_INTERNAL_PURCHASING_ENTRY,
133: "TRUE");
134: }
135:
136: /**
137: * CONTRACTS & GRANTS ROUTE LEVEL - Approvers cannot edit any detail on PO. BUDGET OFFICE ROUTE LEVEL - Approvers cannot
138: * edit any detail on PO. VENDOR TAX ROUTE LEVEL - Approvers cannot edit any detail on PO. DOCUMENT TRANSMISSION ROUTE
139: * LEVEL - Approvers cannot edit any detail on PO.
140: */
141: else {
142: // VIEW_ENTRY that is already being set is sufficient.
143: }
144: }
145: editModeMap.put(editMode, "TRUE");
146:
147: return editModeMap;
148: }
149:
150: @Override
151: public DocumentActionFlags getDocumentActionFlags(
152: Document document, UniversalUser user) {
153: DocumentActionFlags flags = super .getDocumentActionFlags(
154: document, user);
155: PurchaseOrderDocument po = (PurchaseOrderDocument) document;
156: String statusCode = po.getStatusCode();
157:
158: if ((StringUtils.equals(statusCode,
159: PurchaseOrderStatuses.WAITING_FOR_DEPARTMENT))
160: || (StringUtils.equals(statusCode,
161: PurchaseOrderStatuses.WAITING_FOR_VENDOR))) {
162: flags.setCanRoute(false);
163: } else if (PurchaseOrderStatuses.STATUSES_BY_TRANSMISSION_TYPE
164: .values().contains(statusCode)) {
165: if (SpringContext.getBean(
166: PurApWorkflowIntegrationService.class)
167: .isActionRequestedOfUserAtNodeName(
168: po.getDocumentNumber(),
169: NodeDetailEnum.DOCUMENT_TRANSMISSION
170: .getName(),
171: GlobalVariables.getUserSession()
172: .getUniversalUser())) {
173: /*
174: * code below for overriding workflow buttons has to do with hiding the workflow buttons but still allowing the
175: * actions... this is needed because document service calls this method (getDocumentActionFlags) before it will
176: * allow a workflow action to be performed
177: */
178: if (ObjectUtils.isNotNull(po
179: .getOverrideWorkflowButtons())
180: && (po.getOverrideWorkflowButtons())) {
181: /*
182: * if document is in pending transmission status and current user has document transmission action request then
183: * assume that the transmit button/action whatever it might be will take associated workflow action for user
184: * automatically
185: */
186: flags.setCanApprove(false);
187: flags.setCanDisapprove(false);
188: flags.setCanAcknowledge(false);
189: flags.setCanFYI(false);
190: }
191: }
192: }
193: if (po
194: .isDocumentStoppedInRouteNode(NodeDetailEnum.INTERNAL_PURCHASING_REVIEW)) {
195: flags.setCanSave(true);
196: // NEED TO REDO ANNOTATE CHECK SINCE CHANGED THE VALUE OF FLAGS
197: this.setAnnotateFlag(flags);
198: }
199:
200: return flags;
201: }
202: }
|