Search in sources :

Example 1 with AddAccountingLineEvent

use of org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent in project cu-kfs by CU-CommunityApps.

the class AccountingLineAccessibleValidation method validate.

/**
 * Validates that the given accounting line is accessible for editing by the current user.
 * <strong>This method expects a document as the first parameter and an accounting line as the second</strong>
 *
 * @see org.kuali.kfs.sys.document.validation.Validation#validate(java.lang.Object[])
 */
@Override
public boolean validate(AttributedDocumentEvent event) {
    final Person currentUser = GlobalVariables.getUserSession().getPerson();
    if (accountingDocumentForValidation instanceof Correctable) {
        final String errorDocumentNumber = ((FinancialSystemDocumentHeader) accountingDocumentForValidation.getDocumentHeader()).getFinancialDocumentInErrorNumber();
        if (StringUtils.isNotBlank(errorDocumentNumber)) {
            return true;
        }
    }
    final AccountingLineAuthorizer accountingLineAuthorizer = lookupAccountingLineAuthorizer();
    final Set<String> currentNodes = accountingDocumentForValidation.getDocumentHeader().getWorkflowDocument().getCurrentNodeNames();
    final boolean lineIsAccessible = accountingLineAuthorizer.hasEditPermissionOnAccountingLine(accountingDocumentForValidation, accountingLineForValidation, getAccountingLineCollectionProperty(), currentUser, true, currentNodes);
    final boolean isAccessible = accountingLineAuthorizer.hasEditPermissionOnField(accountingDocumentForValidation, accountingLineForValidation, getAccountingLineCollectionProperty(), KFSPropertyConstants.ACCOUNT_NUMBER, lineIsAccessible, true, currentUser, currentNodes);
    boolean valid = true;
    boolean isExceptionNode = isExceptionNode(event.getDocument());
    if (!isAccessible) {
        // if only object code changed and the user has edit permissions on object code, that's ok
        if (event instanceof UpdateAccountingLineEvent) {
            final boolean isObjectCodeAccessible = accountingLineAuthorizer.hasEditPermissionOnField(accountingDocumentForValidation, accountingLineForValidation, getAccountingLineCollectionProperty(), KFSPropertyConstants.FINANCIAL_OBJECT_CODE, lineIsAccessible, true, currentUser, currentNodes);
            final boolean onlyObjectCodeChanged = onlyObjectCodeChanged(((UpdateAccountingLineEvent) event).getAccountingLine(), ((UpdateAccountingLineEvent) event).getUpdatedAccountingLine());
            if (isObjectCodeAccessible && onlyObjectCodeChanged) {
                return true;
            }
        }
        if (isPreqDiscountRecreate(event)) {
            return true;
        }
        // KFSPTS-2253
        if (!isExceptionNode) {
            final String principalName = currentUser.getPrincipalName();
            final String[] chartErrorParams = new String[] { getDataDictionaryService().getAttributeLabel(accountingLineForValidation.getClass(), KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE), accountingLineForValidation.getChartOfAccountsCode(), principalName };
            // KFSPTS-1273 : fixing an exisiting issue.  Limit to REQ and POA.  Broader solution need more work.
            if (event instanceof UpdateAccountingLineEvent) {
                // if (CollectionUtils.isEmpty(GlobalVariables.getMessageMap().getErrorPath()) && event instanceof UpdateAccountingLineEvent) {
                GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(event.getErrorPathPrefix() + "." + KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, convertEventToMessage(event), chartErrorParams);
            } else {
                GlobalVariables.getMessageMap().putError(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, convertEventToMessage(event), chartErrorParams);
            }
            final String[] accountErrorParams = new String[] { getDataDictionaryService().getAttributeLabel(accountingLineForValidation.getClass(), KFSPropertyConstants.ACCOUNT_NUMBER), accountingLineForValidation.getAccountNumber(), principalName };
            // KFSPTS-1273 : fixing an exisiting issue.  Limit to REQ and POA.  Broader solution need more work.
            if (event instanceof UpdateAccountingLineEvent) {
                GlobalVariables.getMessageMap().putErrorWithoutFullErrorPath(event.getErrorPathPrefix() + "." + KFSPropertyConstants.ACCOUNT_NUMBER, convertEventToMessage(event), accountErrorParams);
            } else {
                GlobalVariables.getMessageMap().putError(KFSPropertyConstants.ACCOUNT_NUMBER, convertEventToMessage(event), accountErrorParams);
            }
        }
    // end KFSPTS-2253
    } else if (event instanceof AddAccountingLineEvent && isAccountNode(event.getDocument()) && !isAccountingLineFo(event.getDocument()) && !isDiscountTradeInAccount()) {
        final String principalName = currentUser.getPrincipalName();
        final String[] chartErrorParams = new String[] { getDataDictionaryService().getAttributeLabel(accountingLineForValidation.getClass(), KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE), accountingLineForValidation.getChartOfAccountsCode(), principalName };
        GlobalVariables.getMessageMap().putError(KFSPropertyConstants.CHART_OF_ACCOUNTS_CODE, convertEventToMessage(event), chartErrorParams);
        final String[] accountErrorParams = new String[] { getDataDictionaryService().getAttributeLabel(accountingLineForValidation.getClass(), KFSPropertyConstants.ACCOUNT_NUMBER), accountingLineForValidation.getAccountNumber(), principalName };
        GlobalVariables.getMessageMap().putError(KFSPropertyConstants.ACCOUNT_NUMBER, convertEventToMessage(event), accountErrorParams);
        valid = false;
    }
    return (isAccessible || isExceptionNode) && valid;
}
Also used : AddAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent) Correctable(org.kuali.kfs.sys.document.Correctable) FinancialSystemDocumentHeader(org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader) UpdateAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.UpdateAccountingLineEvent) AccountingLineAuthorizer(org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizer) Person(org.kuali.rice.kim.api.identity.Person)

Example 2 with AddAccountingLineEvent

use of org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent in project cu-kfs by CU-CommunityApps.

the class KualiAccountingDocumentActionBase method insertSourceLine.

/**
 * This action executes an insert of a SourceAccountingLine into a document only after validating the accounting line and
 * checking any appropriate business rules.
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws Exception
 */
public ActionForward insertSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    KualiAccountingDocumentFormBase financialDocumentForm = (KualiAccountingDocumentFormBase) form;
    SourceAccountingLine line = financialDocumentForm.getNewSourceLine();
    // populate chartOfAccountsCode from account number if accounts cant cross chart and Javascript is turned off
    // SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line);
    boolean rulePassed = true;
    // DV acct line amount got error during form populate; should not insert this line.  KFSUPGRADE-847
    MessageMap msgMap = GlobalVariables.getMessageMap();
    if (msgMap.hasErrors() && msgMap.getErrorMessages().keySet().contains("newSourceLine.amount") && financialDocumentForm.getDocument() instanceof DisbursementVoucherDocument) {
        rulePassed = false;
    }
    // before we check the regular rules we need to check the sales tax rules
    // TODO: Refactor rules so we no longer have to call this before a copy of the
    // accountingLine
    rulePassed &= checkSalesTax((AccountingDocument) financialDocumentForm.getDocument(), line, true, true, 0);
    // check any business rules
    rulePassed &= SpringContext.getBean(KualiRuleService.class).applyRules(new AddAccountingLineEvent(KFSConstants.NEW_SOURCE_ACCT_LINE_PROPERTY_NAME, financialDocumentForm.getDocument(), line));
    if (rulePassed) {
        // add accountingLine
        SpringContext.getBean(PersistenceService.class).refreshAllNonUpdatingReferences(line);
        insertAccountingLine(true, financialDocumentForm, line);
        // clear the used newTargetLine
        financialDocumentForm.setNewSourceLine(null);
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : PersistenceService(org.kuali.kfs.krad.service.PersistenceService) AddAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) MessageMap(org.kuali.kfs.krad.util.MessageMap) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument)

Example 3 with AddAccountingLineEvent

use of org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent in project cu-kfs by CU-CommunityApps.

the class KualiAccountingDocumentActionBase method insertTargetLine.

/**
 * This method will add a TargetAccountingLine to a FinancialDocument. This assumes that the user presses the add button for a
 * specific accounting line on the document and that the document is represented by a FinancialDocumentFormBase. It first
 * validates the line for data integrity and then checks appropriate business rules.
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws Exception
 */
public ActionForward insertTargetLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    KualiAccountingDocumentFormBase financialDocumentForm = (KualiAccountingDocumentFormBase) form;
    TargetAccountingLine line = financialDocumentForm.getNewTargetLine();
    // populate chartOfAccountsCode from account number if accounts cant cross chart and Javascript is turned off
    // SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line);
    boolean rulePassed = true;
    // before we check the regular rules we need to check the sales tax rules
    // TODO: Refactor rules so we no longer have to call this before a copy of the
    // accountingLine
    rulePassed &= checkSalesTax((AccountingDocument) financialDocumentForm.getDocument(), line, false, true, 0);
    // check any business rules
    rulePassed &= SpringContext.getBean(KualiRuleService.class).applyRules(new AddAccountingLineEvent(KFSConstants.NEW_TARGET_ACCT_LINE_PROPERTY_NAME, financialDocumentForm.getDocument(), line));
    // if the rule evaluation passed, let's add it
    if (rulePassed) {
        // add accountingLine
        SpringContext.getBean(PersistenceService.class).refreshAllNonUpdatingReferences(line);
        insertAccountingLine(false, financialDocumentForm, line);
        // clear the used newTargetLine
        financialDocumentForm.setNewTargetLine(null);
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : PersistenceService(org.kuali.kfs.krad.service.PersistenceService) AddAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent) TargetAccountingLine(org.kuali.kfs.sys.businessobject.TargetAccountingLine) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument)

Example 4 with AddAccountingLineEvent

use of org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent in project cu-kfs by CU-CommunityApps.

the class PurchasingAccountsPayableDocumentBase method generateEvents.

// KFSUPGRADE-503 copied from AccountingDocumentBase and change
protected List generateEvents(List persistedLines, List currentLines, String errorPathPrefix, TransactionalDocument document) {
    List addEvents = new ArrayList();
    List updateEvents = new ArrayList();
    List reviewEvents = new ArrayList();
    List deleteEvents = new ArrayList();
    errorPathPrefix = KFSConstants.DOCUMENT_PROPERTY_NAME + ".item[";
    // 
    // generate events
    Map persistedLineMap = buildAccountingLineMap(persistedLines);
    // (iterate through current lines to detect additions and updates, removing affected lines from persistedLineMap as we go
    // so deletions can be detected by looking at whatever remains in persistedLineMap)
    int index = 0;
    for (Iterator i = currentLines.iterator(); i.hasNext(); index++) {
        // String indexedErrorPathPrefix = errorPathPrefix + "[" + index + "]";
        AccountingLine currentLine = (AccountingLine) i.next();
        Integer key = currentLine.getSequenceNumber();
        String indexedErrorPathPrefix = getIndexedErrorPathPrefix(errorPathPrefix, currentLine);
        AccountingLine persistedLine = (AccountingLine) persistedLineMap.get(key);
        // if line is both current and persisted...
        if (persistedLine != null) {
            // ...check for updates
            if (!currentLine.isLike(persistedLine)) {
                UpdateAccountingLineEvent updateEvent = new UpdateAccountingLineEvent(indexedErrorPathPrefix, document, persistedLine, currentLine);
                updateEvents.add(updateEvent);
            } else {
                ReviewAccountingLineEvent reviewEvent = new ReviewAccountingLineEvent(indexedErrorPathPrefix, document, currentLine);
                reviewEvents.add(reviewEvent);
            }
            persistedLineMap.remove(key);
        } else {
            // it must be a new addition
            AddAccountingLineEvent addEvent = new AddAccountingLineEvent(indexedErrorPathPrefix, document, currentLine);
            addEvents.add(addEvent);
        }
    }
    // detect deletions
    for (Iterator i = persistedLineMap.entrySet().iterator(); i.hasNext(); ) {
        // the deleted line is not displayed on the page, so associate the error with the whole group
        String groupErrorPathPrefix = errorPathPrefix + KFSConstants.ACCOUNTING_LINE_GROUP_SUFFIX;
        Map.Entry e = (Map.Entry) i.next();
        AccountingLine persistedLine = (AccountingLine) e.getValue();
        DeleteAccountingLineEvent deleteEvent = new DeleteAccountingLineEvent(groupErrorPathPrefix, document, persistedLine, true);
        deleteEvents.add(deleteEvent);
    }
    // 
    // merge the lists
    List lineEvents = new ArrayList();
    lineEvents.addAll(reviewEvents);
    lineEvents.addAll(updateEvents);
    lineEvents.addAll(addEvents);
    lineEvents.addAll(deleteEvents);
    return lineEvents;
}
Also used : SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) AccountingLine(org.kuali.kfs.sys.businessobject.AccountingLine) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) ArrayList(java.util.ArrayList) UpdateAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.UpdateAccountingLineEvent) ReviewAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.ReviewAccountingLineEvent) AddAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent) GeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) Iterator(java.util.Iterator) DeleteAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.DeleteAccountingLineEvent) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with AddAccountingLineEvent

use of org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent in project cu-kfs by CU-CommunityApps.

the class PurchasingActionBase method validateDistributeAccounts.

/**
 * Validates that the accounting lines while a distribute accounts action is being taken.
 *
 * @param document
 * @param distributionsourceAccountingLines
 * @return
 */
protected boolean validateDistributeAccounts(Document document, List<PurApAccountingLine> distributionsourceAccountingLines) {
    boolean rulePassed = true;
    String errorPrefix = null;
    int i = 0;
    for (PurApAccountingLine accountingLine : distributionsourceAccountingLines) {
        errorPrefix = "accountDistributionsourceAccountingLine" + "[" + Integer.toString(i) + "]";
        rulePassed &= SpringContext.getBean(KualiRuleService.class).applyRules(new AddAccountingLineEvent(errorPrefix, document, accountingLine));
        i++;
    }
    return rulePassed;
}
Also used : AddAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)

Aggregations

AddAccountingLineEvent (org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent)5 PersistenceService (org.kuali.kfs.krad.service.PersistenceService)2 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)2 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)2 AccountingDocument (org.kuali.kfs.sys.document.AccountingDocument)2 UpdateAccountingLineEvent (org.kuali.kfs.sys.document.validation.event.UpdateAccountingLineEvent)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)1 MessageMap (org.kuali.kfs.krad.util.MessageMap)1 AccountingLine (org.kuali.kfs.sys.businessobject.AccountingLine)1 FinancialSystemDocumentHeader (org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader)1 GeneralLedgerPendingEntry (org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry)1 TargetAccountingLine (org.kuali.kfs.sys.businessobject.TargetAccountingLine)1 Correctable (org.kuali.kfs.sys.document.Correctable)1 AccountingLineAuthorizer (org.kuali.kfs.sys.document.authorization.AccountingLineAuthorizer)1 DeleteAccountingLineEvent (org.kuali.kfs.sys.document.validation.event.DeleteAccountingLineEvent)1