1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.validation.impl;
17
18 import java.util.Iterator;
19 import java.util.List;
20
21 import org.kuali.ole.fp.businessobject.ProcurementCardTargetAccountingLine;
22 import org.kuali.ole.fp.businessobject.ProcurementCardTransactionDetail;
23 import org.kuali.ole.fp.document.ProcurementCardDocument;
24 import org.kuali.ole.sys.OLEPropertyConstants;
25 import org.kuali.ole.sys.businessobject.AccountingLine;
26 import org.kuali.ole.sys.document.AccountingDocument;
27 import org.kuali.rice.krad.util.GlobalVariables;
28 import org.kuali.rice.krad.util.MessageMap;
29
30
31
32
33 public class ProcurementCardErrorPathUtil {
34 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ProcurementCardErrorPathUtil.class);
35
36
37
38
39
40
41
42
43
44
45 public static void fixErrorPath(AccountingDocument financialDocument, AccountingLine accountingLine) {
46 List transactionEntries = ((ProcurementCardDocument) financialDocument).getTransactionEntries();
47 if (accountingLine.isTargetAccountingLine()) {
48 ProcurementCardTargetAccountingLine targetAccountingLineToBeFound = (ProcurementCardTargetAccountingLine) accountingLine;
49
50 String errorPath = OLEPropertyConstants.DOCUMENT;
51
52
53
54 boolean done = false;
55 int transactionLineIndex = 0;
56 for (Iterator iterTransactionEntries = transactionEntries.iterator(); !done && iterTransactionEntries.hasNext(); transactionLineIndex++) {
57 ProcurementCardTransactionDetail transactionEntry = (ProcurementCardTransactionDetail) iterTransactionEntries.next();
58
59
60 int accountingLineCounter = 0;
61 for (Iterator iterTargetAccountingLines = transactionEntry.getTargetAccountingLines().iterator(); !done && iterTargetAccountingLines.hasNext(); accountingLineCounter++) {
62 ProcurementCardTargetAccountingLine targetAccountingLine = (ProcurementCardTargetAccountingLine) iterTargetAccountingLines.next();
63
64 if (targetAccountingLine.getSequenceNumber().equals(targetAccountingLineToBeFound.getSequenceNumber())) {
65
66 errorPath = errorPath + "." + OLEPropertyConstants.TRANSACTION_ENTRIES + "[" + transactionLineIndex + "]." + OLEPropertyConstants.TARGET_ACCOUNTING_LINES + "[" + accountingLineCounter + "]";
67 done = true;
68 }
69 }
70 }
71
72 if (!done) {
73 LOG.warn("fixErrorPath failed to locate item accountingLine=" + accountingLine.toString());
74 }
75
76
77
78
79 MessageMap messageMap = GlobalVariables.getMessageMap();
80 messageMap.clearErrorPath();
81 messageMap.addToErrorPath(errorPath);
82 }
83 }
84 }