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.List;
019: import java.util.Map;
020:
021: import org.apache.commons.lang.StringUtils;
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.util.GlobalVariables;
029: import org.kuali.core.workflow.service.KualiWorkflowDocument;
030: import org.kuali.kfs.context.SpringContext;
031: import org.kuali.kfs.document.authorization.AccountingDocumentAuthorizerBase;
032: import org.kuali.kfs.service.ParameterService;
033: import org.kuali.kfs.service.impl.ParameterConstants;
034: import org.kuali.module.purap.PurapAuthorizationConstants;
035: import org.kuali.module.purap.PurapConstants;
036: import org.kuali.module.purap.PurapParameterConstants;
037: import org.kuali.module.purap.document.CreditMemoDocument;
038: import org.kuali.module.purap.service.CreditMemoService;
039: import org.kuali.module.purap.service.PurapService;
040:
041: /**
042: * Document Authorizer for the Credit Memo document.
043: */
044: public class CreditMemoDocumentAuthorizer extends
045: AccountingDocumentAuthorizerBase {
046:
047: /**
048: * @see org.kuali.core.document.authorization.DocumentAuthorizerBase#hasInitiateAuthorization(org.kuali.core.document.Document,
049: * org.kuali.core.bo.user.UniversalUser)
050: */
051: @Override
052: public boolean hasInitiateAuthorization(Document document,
053: UniversalUser user) {
054: String authorizedWorkgroup = SpringContext
055: .getBean(ParameterService.class)
056: .getParameterValue(
057: ParameterConstants.PURCHASING_DOCUMENT.class,
058: PurapParameterConstants.Workgroups.WORKGROUP_ACCOUNTS_PAYABLE);
059: try {
060: return SpringContext.getBean(KualiGroupService.class)
061: .getByGroupName(authorizedWorkgroup)
062: .hasMember(user);
063: } catch (GroupNotFoundException e) {
064: throw new RuntimeException("Workgroup "
065: + authorizedWorkgroup + " not found", e);
066: }
067: }
068:
069: /**
070: * @see org.kuali.core.document.authorization.DocumentAuthorizerBase#getEditMode(org.kuali.core.document.Document,
071: * org.kuali.core.bo.user.UniversalUser)
072: */
073: @Override
074: public Map getEditMode(Document document, UniversalUser user,
075: List sourceAccountingLines, List targetAccountingLines) {
076: Map<String, String> editModeMap = super .getEditMode(document,
077: user, sourceAccountingLines, targetAccountingLines);
078: String editMode = AuthorizationConstants.EditMode.VIEW_ONLY;
079:
080: KualiWorkflowDocument workflowDocument = document
081: .getDocumentHeader().getWorkflowDocument();
082: if (workflowDocument.stateIsInitiated()
083: || workflowDocument.stateIsSaved()) {
084: if (hasInitiateAuthorization(document, user)) {
085: editMode = AuthorizationConstants.EditMode.FULL_ENTRY;
086: }
087: } else if (workflowDocument.stateIsEnroute()
088: && workflowDocument.isApprovalRequested()) {
089: if (!SpringContext.getBean(PurapService.class)
090: .isFullDocumentEntryCompleted(
091: (CreditMemoDocument) document)) {
092: editMode = AuthorizationConstants.EditMode.FULL_ENTRY;
093: }
094: }
095: editModeMap.put(editMode, "TRUE");
096:
097: CreditMemoDocument creditMemoDocument = (CreditMemoDocument) document;
098: if (StringUtils.equals(creditMemoDocument.getStatusCode(),
099: PurapConstants.CreditMemoStatuses.INITIATE)) {
100: editModeMap
101: .put(
102: PurapAuthorizationConstants.CreditMemoEditMode.DISPLAY_INIT_TAB,
103: "TRUE");
104: } else {
105: editModeMap
106: .put(
107: PurapAuthorizationConstants.CreditMemoEditMode.DISPLAY_INIT_TAB,
108: "FALSE");
109: }
110:
111: if (!creditMemoDocument.isSourceDocumentPaymentRequest()) {
112: editModeMap
113: .put(
114: PurapAuthorizationConstants.CreditMemoEditMode.LOCK_VENDOR_ENTRY,
115: "TRUE");
116: }
117:
118: String apGroup = SpringContext
119: .getBean(ParameterService.class)
120: .getParameterValue(
121: ParameterConstants.PURCHASING_DOCUMENT.class,
122: PurapParameterConstants.Workgroups.WORKGROUP_ACCOUNTS_PAYABLE);
123: if (user.isMember(apGroup)
124: && (creditMemoDocument.getExtractedDate() == null)) {
125: editModeMap
126: .put(
127: PurapAuthorizationConstants.PaymentRequestEditMode.EDIT_PRE_EXTRACT,
128: "TRUE");
129: }
130:
131: return editModeMap;
132: }
133:
134: /**
135: * @see org.kuali.core.document.authorization.TransactionalDocumentAuthorizerBase#getDocumentActionFlags(org.kuali.core.document.Document,
136: * org.kuali.core.bo.user.UniversalUser)
137: */
138: @Override
139: public DocumentActionFlags getDocumentActionFlags(
140: Document document, UniversalUser user) {
141: DocumentActionFlags flags = super .getDocumentActionFlags(
142: document, user);
143:
144: CreditMemoDocument creditMemoDocument = (CreditMemoDocument) document;
145: if (StringUtils.equals(creditMemoDocument.getStatusCode(),
146: PurapConstants.CreditMemoStatuses.INITIATE)) {
147: flags.setCanSave(false);
148: flags.setCanClose(true);
149: flags.setCanCancel(false);
150: } else {
151: flags.setCanSave(true);
152:
153: if (SpringContext.getBean(CreditMemoService.class)
154: .canCancelCreditMemo(
155: creditMemoDocument,
156: GlobalVariables.getUserSession()
157: .getUniversalUser())) {
158: flags.setCanCancel(true);
159: } else {
160: flags.setCanCancel(false);
161: }
162: }
163:
164: // NEED TO REDO ANNOTATE CHECK SINCE CHANGED THE VALUE OF FLAGS
165: this.setAnnotateFlag(flags);
166:
167: return flags;
168: }
169:
170: }
|