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.rules;
017:
018: import org.kuali.core.bo.user.UniversalUser;
019: import org.kuali.core.document.Document;
020: import org.kuali.core.exceptions.UserNotFoundException;
021: import org.kuali.core.exceptions.ValidationException;
022: import org.kuali.core.rule.event.ApproveDocumentEvent;
023: import org.kuali.core.rules.TransactionalDocumentRuleBase;
024: import org.kuali.core.service.UniversalUserService;
025: import org.kuali.core.util.ObjectUtils;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.kfs.service.ParameterService;
028: import org.kuali.kfs.service.impl.ParameterConstants;
029: import org.kuali.module.purap.PurapParameterConstants;
030: import org.kuali.module.purap.document.PurchaseOrderDocument;
031:
032: /**
033: * Rules for Purchase Order Retransmit document creation. Should not extend <code>PurchaseOrderDocumentRule</code>, since it does
034: * not allow the purchase order to be edited, nor should it create GL entries.
035: */
036: public class PurchaseOrderRetransmitDocumentRule extends
037: TransactionalDocumentRuleBase {
038:
039: /**
040: * @see org.kuali.module.financial.rules.TransactionalDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.core.document.Document)
041: */
042: @Override
043: protected boolean processCustomRouteDocumentBusinessRules(
044: Document document) {
045: boolean isValid = true;
046: PurchaseOrderDocument porDocument = (PurchaseOrderDocument) document;
047: return isValid &= processValidation(porDocument);
048: }
049:
050: /**
051: * @see org.kuali.core.rules.DocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.core.document.Document)
052: */
053: @Override
054: protected boolean processCustomSaveDocumentBusinessRules(
055: Document document) {
056: boolean isValid = true;
057: PurchaseOrderDocument porDocument = (PurchaseOrderDocument) document;
058: return isValid &= processValidation(porDocument);
059: }
060:
061: /**
062: * @see org.kuali.core.rules.DocumentRuleBase#processCustomApproveDocumentBusinessRules(org.kuali.core.rule.event.ApproveDocumentEvent)
063: */
064: @Override
065: protected boolean processCustomApproveDocumentBusinessRules(
066: ApproveDocumentEvent approveEvent) {
067: boolean isValid = true;
068: PurchaseOrderDocument porDocument = (PurchaseOrderDocument) approveEvent
069: .getDocument();
070: return isValid;
071: }
072:
073: /**
074: * Central method to control the processing of rule checks. Checks that the purchase order document is not null, and that the
075: * user is in the purchasing workgroup.
076: *
077: * @param document A PurchaseOrderDocument.
078: * @return True if the document passes all the validations.
079: */
080: private boolean processValidation(PurchaseOrderDocument document) {
081: boolean valid = true;
082:
083: // Check that the PO is not null.
084: if (ObjectUtils.isNull(document)) {
085: throw new ValidationException(
086: "Purchase Order Retransmit document was null on validation.");
087: } else {
088: if (!document.getPurchaseOrderAutomaticIndicator()) {
089: // Check that the user is in purchasing workgroup.
090: String initiatorNetworkId = document
091: .getDocumentHeader().getWorkflowDocument()
092: .getInitiatorNetworkId();
093: UniversalUserService uus = SpringContext
094: .getBean(UniversalUserService.class);
095: UniversalUser user = null;
096: try {
097: user = uus
098: .getUniversalUserByAuthenticationUserId(initiatorNetworkId);
099: String purchasingGroup = SpringContext
100: .getBean(ParameterService.class)
101: .getParameterValue(
102: ParameterConstants.PURCHASING_DOCUMENT.class,
103: PurapParameterConstants.Workgroups.WORKGROUP_PURCHASING);
104: if (!uus.isMember(user, purchasingGroup)) {
105: valid = false;
106: }
107: } catch (UserNotFoundException ue) {
108: valid = false;
109: }
110: }
111: }
112:
113: return valid;
114: }
115: }
|