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