1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.web.struts;
17
18 import static org.kuali.ole.fp.document.validation.impl.ProcurementCardDocumentRuleConstants.DISPUTE_URL_PARM_NM;
19
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Map;
24
25 import javax.servlet.http.HttpServletRequest;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.kuali.ole.fp.businessobject.CapitalAssetInformation;
29 import org.kuali.ole.fp.businessobject.ProcurementCardTargetAccountingLine;
30 import org.kuali.ole.fp.businessobject.ProcurementCardTransactionDetail;
31 import org.kuali.ole.fp.document.CapitalAssetEditable;
32 import org.kuali.ole.fp.document.ProcurementCardDocument;
33 import org.kuali.ole.sys.OLEConstants;
34 import org.kuali.ole.sys.OLEPropertyConstants;
35 import org.kuali.ole.sys.businessobject.TargetAccountingLine;
36 import org.kuali.ole.sys.context.SpringContext;
37 import org.kuali.ole.sys.document.authorization.AccountingLineAuthorizer;
38 import org.kuali.ole.sys.document.datadictionary.AccountingLineGroupDefinition;
39 import org.kuali.ole.sys.document.datadictionary.FinancialSystemTransactionalDocumentEntry;
40 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
41 import org.kuali.rice.kim.api.identity.Person;
42 import org.kuali.rice.kns.service.DataDictionaryService;
43 import org.kuali.rice.krad.datadictionary.DataDictionary;
44 import org.kuali.rice.krad.util.GlobalVariables;
45 import org.kuali.rice.krad.util.KRADConstants;
46
47
48
49
50
51 public class ProcurementCardForm extends CapitalAccountingLinesFormBase implements CapitalAssetEditable{
52 protected static final long serialVersionUID = 1L;
53 protected List<ProcurementCardTargetAccountingLine> newTargetLines;
54 protected List<Boolean> transactionCreditCardNumbersViewStatus;
55 protected final static String TARGET_ACCOUNTING_LINE_GROUP_NAME = "target";
56
57 protected List<CapitalAssetInformation> capitalAssetInformation;
58
59
60
61
62
63
64 @Override
65 public void populate(HttpServletRequest request) {
66 super.populate(request);
67
68
69
70
71
72 final String methodToCall = this.getMethodToCall();
73 final Map parameterMap = request.getParameterMap();
74 if (StringUtils.isNotBlank(methodToCall)) {
75 if (methodToCall.equals(OLEConstants.INSERT_SOURCE_LINE_METHOD)) {
76 populateSourceAccountingLine(getNewSourceLine(), OLEPropertyConstants.NEW_SOURCE_LINE, parameterMap);
77 }
78
79 if (methodToCall.equals(OLEConstants.INSERT_TARGET_LINE_METHOD)) {
80
81 for (Iterator newTargetLinesIter = getNewTargetLines().iterator(); newTargetLinesIter.hasNext();) {
82 TargetAccountingLine targetAccountingLine = (TargetAccountingLine) newTargetLinesIter.next();
83 populateTargetAccountingLine(targetAccountingLine, OLEPropertyConstants.NEW_TARGET_LINE, parameterMap);
84 }
85 }
86 }
87
88
89
90 if (!StringUtils.equals(methodToCall, OLEConstants.COPY_METHOD) && !StringUtils.equals(methodToCall, OLEConstants.ERRORCORRECT_METHOD)) {
91 populateAccountingLines(parameterMap);
92 }
93
94 setDocTypeName(discoverDocumentTypeName());
95 }
96
97
98
99
100
101 public ProcurementCardForm() {
102 super();
103
104 this.newTargetLines = new ArrayList<ProcurementCardTargetAccountingLine>();
105
106 capitalAssetInformation = new ArrayList<CapitalAssetInformation>();
107 }
108
109 public void buildNewTargetAccountingLines(int transactionsCount) {
110 for (int i=0; i < transactionsCount; i++) {
111 ProcurementCardTargetAccountingLine newLine = new ProcurementCardTargetAccountingLine();
112 newLine.setTransactionContainerIndex(i);
113 this.newTargetLines.add(i, newLine);
114 }
115 }
116
117 @Override
118 protected String getDefaultDocumentTypeName() {
119 return "OLE_PCDO";
120 }
121
122
123
124
125 public String getDisputeURL() {
126 return SpringContext.getBean(ParameterService.class).getParameterValueAsString(ProcurementCardDocument.class, DISPUTE_URL_PARM_NM);
127 }
128
129
130
131
132
133 public List getNewTargetLines() {
134 return newTargetLines;
135 }
136
137
138
139
140 public void setNewTargetLines(List newTargetLines) {
141 this.newTargetLines = newTargetLines;
142 }
143
144
145
146
147 public List<CapitalAssetInformation> getCapitalAssetInformation() {
148 return this.capitalAssetInformation;
149 }
150
151
152
153
154 public void setCapitalAssetInformation(List<CapitalAssetInformation> capitalAssetInformation) {
155 this.capitalAssetInformation = capitalAssetInformation;
156 }
157
158
159
160
161
162 public List<Boolean> getTransactionCreditCardNumbersViewStatus() {
163 if (this.transactionCreditCardNumbersViewStatus == null) {
164 populateTransactionCreditCardNumbersViewStatuses();
165 }
166 return transactionCreditCardNumbersViewStatus;
167 }
168
169
170
171
172
173
174 protected void populateTransactionCreditCardNumbersViewStatuses() {
175 final AccountingLineAuthorizer accountingLineAuthorizer = getAccountingLineAuthorizerForDocument();
176 final Person currentUser = GlobalVariables.getUserSession().getPerson();
177 transactionCreditCardNumbersViewStatus = new ArrayList<Boolean>();
178
179 for (Object transactionEntryAsObject : ((ProcurementCardDocument)getDocument()).getTransactionEntries()) {
180 final ProcurementCardTransactionDetail transactionDetail = (ProcurementCardTransactionDetail)transactionEntryAsObject;
181 Boolean canEditAnyAccountingLine = Boolean.FALSE;
182
183 int count = 0;
184 while (!canEditAnyAccountingLine.booleanValue() && count < transactionDetail.getTargetAccountingLines().size()) {
185 final TargetAccountingLine accountingLine = (TargetAccountingLine)transactionDetail.getTargetAccountingLines().get(count);
186 if (accountingLineAuthorizer.hasEditPermissionOnAccountingLine(((ProcurementCardDocument)getDocument()), accountingLine, getAccountingLineCollectionName(), currentUser, getDocumentActions().containsKey(KRADConstants.KUALI_ACTION_CAN_EDIT))) {
187 canEditAnyAccountingLine = Boolean.TRUE;
188 }
189 count += 1;
190 }
191 transactionCreditCardNumbersViewStatus.add(canEditAnyAccountingLine);
192 }
193 }
194
195
196
197
198 protected AccountingLineAuthorizer getAccountingLineAuthorizerForDocument() {
199 final DataDictionaryService dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
200 final DataDictionary dataDictionary = dataDictionaryService.getDataDictionary();
201 final String documentTypeCode = dataDictionaryService.getDocumentTypeNameByClass(this.getDocument().getClass());
202 final FinancialSystemTransactionalDocumentEntry documentEntry = (FinancialSystemTransactionalDocumentEntry)dataDictionary.getDocumentEntry(documentTypeCode);
203 final AccountingLineGroupDefinition targetAccountingLineGroupDefinition = documentEntry.getAccountingLineGroups().get(ProcurementCardForm.TARGET_ACCOUNTING_LINE_GROUP_NAME);
204 return targetAccountingLineGroupDefinition.getAccountingLineAuthorizer();
205 }
206
207
208
209
210 protected String getAccountingLineCollectionName() {
211
212 return "targetAccountingLines";
213 }
214 }