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.labor.web.struts.action;
017:
018: import static org.kuali.kfs.KFSKeyConstants.ERROR_ZERO_AMOUNT;
019:
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Collections;
023: import java.util.HashMap;
024: import java.util.HashSet;
025: import java.util.Iterator;
026: import java.util.List;
027: import java.util.Map;
028: import java.util.Properties;
029: import java.util.Set;
030:
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: import org.apache.commons.lang.StringUtils;
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionForward;
037: import org.apache.struts.action.ActionMapping;
038: import org.kuali.core.bo.PersistableBusinessObject;
039: import org.kuali.core.document.TransactionalDocument;
040: import org.kuali.core.rule.event.KualiDocumentEventBase;
041: import org.kuali.core.service.KualiRuleService;
042: import org.kuali.core.service.PersistenceService;
043: import org.kuali.core.util.GlobalVariables;
044: import org.kuali.core.util.KualiDecimal;
045: import org.kuali.core.util.UrlFactory;
046: import org.kuali.core.web.struts.form.KualiDocumentFormBase;
047: import org.kuali.core.web.struts.form.KualiForm;
048: import org.kuali.kfs.KFSConstants;
049: import org.kuali.kfs.KFSKeyConstants;
050: import org.kuali.kfs.KFSPropertyConstants;
051: import org.kuali.kfs.bo.AccountingLine;
052: import org.kuali.kfs.bo.AccountingLineOverride;
053: import org.kuali.kfs.context.SpringContext;
054: import org.kuali.kfs.document.AccountingDocument;
055: import org.kuali.kfs.rule.event.AddAccountingLineEvent;
056: import org.kuali.kfs.web.struts.action.KualiAccountingDocumentActionBase;
057: import org.kuali.module.gl.GLConstants;
058: import org.kuali.module.labor.LaborConstants;
059: import org.kuali.module.labor.bo.ExpenseTransferAccountingLine;
060: import org.kuali.module.labor.bo.ExpenseTransferSourceAccountingLine;
061: import org.kuali.module.labor.bo.ExpenseTransferTargetAccountingLine;
062: import org.kuali.module.labor.bo.LaborAccountingLineOverride;
063: import org.kuali.module.labor.bo.LedgerBalance;
064: import org.kuali.module.labor.document.LaborExpenseTransferDocumentBase;
065: import org.kuali.module.labor.service.SegmentedLookupResultsService;
066: import org.kuali.module.labor.web.struts.form.ExpenseTransferDocumentFormBase;
067:
068: import edu.iu.uis.eden.exception.WorkflowException;
069:
070: /**
071: * Base Struts Action class for Benefit Expense Transfer Document.
072: */
073: public class ExpenseTransferDocumentActionBase extends
074: KualiAccountingDocumentActionBase {
075: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
076: .getLogger(ExpenseTransferDocumentActionBase.class);
077:
078: /**
079: * Takes care of storing the action form in the user session and forwarding to the balance inquiry lookup action.
080: *
081: * @param mapping
082: * @param form
083: * @param request
084: * @param response
085: * @return ActionForward
086: * @throws Exception
087: */
088: public ActionForward performBalanceInquiryLookup(
089: ActionMapping mapping, ActionForm form,
090: HttpServletRequest request, HttpServletResponse response)
091: throws Exception {
092: ExpenseTransferDocumentFormBase financialDocumentForm = (ExpenseTransferDocumentFormBase) form;
093: TransactionalDocument document = financialDocumentForm
094: .getTransactionalDocument();
095:
096: String basePath = request.getScheme() + "://"
097: + request.getServerName() + ":"
098: + request.getServerPort() + request.getContextPath();
099:
100: // parse out the important strings from our methodToCall parameter
101: String fullParameter = (String) request
102: .getAttribute(KFSConstants.METHOD_TO_CALL_ATTRIBUTE);
103:
104: // parse out business object class name for lookup
105: String boClassName = StringUtils.substringBetween(
106: fullParameter,
107: KFSConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL,
108: KFSConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL);
109: if (StringUtils.isBlank(boClassName)) {
110: throw new RuntimeException(
111: "Illegal call to perform lookup, no business object class name specified.");
112: }
113:
114: // build the parameters for the lookup url
115: Properties parameters = new Properties();
116: String conversionFields = StringUtils.substringBetween(
117: fullParameter,
118: KFSConstants.METHOD_TO_CALL_PARM1_LEFT_DEL,
119: KFSConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL);
120: if (StringUtils.isNotBlank(conversionFields)) {
121: parameters.put(KFSConstants.CONVERSION_FIELDS_PARAMETER,
122: conversionFields);
123: }
124:
125: // pass values from form that should be pre-populated on lookup search
126: String parameterFields = StringUtils.substringBetween(
127: fullParameter,
128: KFSConstants.METHOD_TO_CALL_PARM2_LEFT_DEL,
129: KFSConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL);
130: if (StringUtils.isNotBlank(parameterFields)) {
131: String[] lookupParams = parameterFields
132: .split(KFSConstants.FIELD_CONVERSIONS_SEPERATOR);
133:
134: for (int i = 0; i < lookupParams.length; i++) {
135: String[] keyValue = lookupParams[i]
136: .split(KFSConstants.FIELD_CONVERSION_PAIR_SEPERATOR);
137:
138: // hard-coded passed value
139: if (StringUtils.contains(keyValue[0], "'")) {
140: parameters.put(keyValue[1], StringUtils.replace(
141: keyValue[0], "'", ""));
142: }
143: // passed value should come from property
144: else if (StringUtils.isNotBlank(request
145: .getParameter(keyValue[0]))) {
146: parameters.put(keyValue[1], request
147: .getParameter(keyValue[0]));
148: }
149: }
150: }
151:
152: // grab whether or not the "return value" link should be hidden or not
153: String hideReturnLink = StringUtils.substringBetween(
154: fullParameter,
155: KFSConstants.METHOD_TO_CALL_PARM3_LEFT_DEL,
156: KFSConstants.METHOD_TO_CALL_PARM3_RIGHT_DEL);
157: if (StringUtils.isNotBlank(hideReturnLink)) {
158: parameters.put(KFSConstants.HIDE_LOOKUP_RETURN_LINK,
159: hideReturnLink);
160: }
161:
162: // anchor, if it exists
163: if (form instanceof KualiForm
164: && StringUtils.isNotEmpty(((KualiForm) form)
165: .getAnchor())) {
166: parameters.put(KFSConstants.LOOKUP_ANCHOR,
167: ((KualiForm) form).getAnchor());
168: }
169:
170: // determine what the action path is
171: String actionPath = StringUtils.substringBetween(fullParameter,
172: KFSConstants.METHOD_TO_CALL_PARM4_LEFT_DEL,
173: KFSConstants.METHOD_TO_CALL_PARM4_RIGHT_DEL);
174: if (StringUtils.isBlank(actionPath)) {
175: throw new IllegalStateException(
176: "The \"actionPath\" attribute is an expected parameter for the <kul:balanceInquiryLookup> tag - it "
177: + "should never be blank.");
178: }
179:
180: // now add required parameters
181: parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER,
182: "search");
183: parameters.put(KFSConstants.DOC_FORM_KEY, GlobalVariables
184: .getUserSession().addObject(form));
185: parameters.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE,
186: boClassName);
187: parameters.put(KFSConstants.RETURN_LOCATION_PARAMETER, basePath
188: + mapping.getPath() + ".do");
189: parameters
190: .put(
191: GLConstants.LookupableBeanKeys.SEGMENTED_LOOKUP_FLAG_NAME,
192: Boolean.TRUE.toString());
193:
194: String lookupUrl = UrlFactory.parameterizeUrl(basePath + "/"
195: + actionPath, parameters);
196:
197: return new ActionForward(lookupUrl, true);
198: }
199:
200: /**
201: * Populates the lines of the ST or BT document from a balance lookup. First, the data must be retrieved based on the selected
202: * ids persisted from the framework. The basic steps are: 1) Retrieve selected (row) ids that were persisted 2) Each id has
203: * form: {db object id}.{period name}.{line amount} 3) Retrieve the balance records associated with the object ids 4)Build an
204: * accounting line from the retrieved balance record, using parsed period name as the pay period, and parsed amount as the new
205: * line amount. 5) Call insertAccountingLine
206: *
207: * @see org.kuali.core.web.struts.action.KualiDocumentActionBase#refresh(ActionMapping, ActionForm, HttpServletRequest,
208: * HttpServletResponse)
209: */
210: @Override
211: public ActionForward refresh(ActionMapping mapping,
212: ActionForm form, HttpServletRequest request,
213: HttpServletResponse response) throws Exception {
214: super .refresh(mapping, form, request, response);
215:
216: ExpenseTransferDocumentFormBase expenseTransferDocumentForm = (ExpenseTransferDocumentFormBase) form;
217:
218: Collection<PersistableBusinessObject> rawValues = null;
219: Map<String, Set<String>> segmentedSelection = new HashMap<String, Set<String>>();
220:
221: if (StringUtils.equals(KFSConstants.MULTIPLE_VALUE,
222: expenseTransferDocumentForm.getRefreshCaller())) {
223: String lookupResultsSequenceNumber = expenseTransferDocumentForm
224: .getLookupResultsSequenceNumber();
225:
226: if (StringUtils.isNotBlank(lookupResultsSequenceNumber)) {
227: // actually returning from a multiple value lookup
228: Set<String> selectedIds = getSegmentedLookupResultsService()
229: .retrieveSetOfSelectedObjectIds(
230: lookupResultsSequenceNumber,
231: GlobalVariables.getUserSession()
232: .getUniversalUser()
233: .getPersonUniversalIdentifier());
234: for (String selectedId : selectedIds) {
235: String selectedObjId = StringUtils.substringBefore(
236: selectedId, ".");
237: String selectedMonthData = StringUtils
238: .substringAfter(selectedId, ".");
239:
240: if (!segmentedSelection.containsKey(selectedObjId)) {
241: segmentedSelection.put(selectedObjId,
242: new HashSet<String>());
243: }
244: segmentedSelection.get(selectedObjId).add(
245: selectedMonthData);
246: }
247:
248: LOG.debug("Asking segmentation service for object ids "
249: + segmentedSelection.keySet());
250: rawValues = getSegmentedLookupResultsService()
251: .retrieveSelectedResultBOs(
252: lookupResultsSequenceNumber,
253: segmentedSelection.keySet(),
254: LedgerBalance.class,
255: GlobalVariables.getUserSession()
256: .getUniversalUser()
257: .getPersonUniversalIdentifier());
258: }
259:
260: if (rawValues != null) {
261: boolean isFirstBalance = true;
262: for (PersistableBusinessObject bo : rawValues) {
263:
264: // reset the form with the first leadge balance
265: if (isFirstBalance) {
266: resetLookupFields(expenseTransferDocumentForm,
267: (LedgerBalance) bo);
268: isFirstBalance = false;
269: }
270:
271: for (String selectedMonthData : segmentedSelection
272: .get(bo.getObjectId())) {
273: String selectedPeriodName = StringUtils
274: .substringBefore(selectedMonthData, ".");
275: String selectedPeriodAmount = StringUtils
276: .substringAfter(selectedMonthData, ".");
277:
278: if (LaborConstants.periodCodeMapping
279: .containsKey(selectedPeriodName)) {
280: String periodCode = LaborConstants.periodCodeMapping
281: .get(selectedPeriodName);
282: ExpenseTransferAccountingLine line = (ExpenseTransferAccountingLine) expenseTransferDocumentForm
283: .getFinancialDocument()
284: .getSourceAccountingLineClass()
285: .newInstance();
286: LaborExpenseTransferDocumentBase financialDocument = (LaborExpenseTransferDocumentBase) expenseTransferDocumentForm
287: .getDocument();
288:
289: try {
290: KualiDecimal lineAmount = (new KualiDecimal(
291: selectedPeriodAmount))
292: .divide(new KualiDecimal(100));
293:
294: // Notice that user tried to import an accounting line which has Zero amount
295: if (KFSConstants.ZERO
296: .compareTo(lineAmount) == 0) {
297: GlobalVariables
298: .getErrorMap()
299: .putError(
300: KFSPropertyConstants.SOURCE_ACCOUNTING_LINES,
301: ERROR_ZERO_AMOUNT,
302: "an accounting line");
303: } else {
304: buildAccountingLineFromLedgerBalance(
305: (LedgerBalance) bo, line,
306: lineAmount, periodCode);
307:
308: // SpringContext.getBean(KualiRuleService.class).applyRules(new
309: // AddAccountingLineEvent(KFSConstants.NEW_SOURCE_ACCT_LINE_PROPERTY_NAME, financialDocument,
310: // line));
311: SpringContext.getBean(
312: PersistenceService.class)
313: .retrieveNonKeyFields(line);
314:
315: insertAccountingLine(
316: true,
317: expenseTransferDocumentForm,
318: line);
319: updateAccountOverrideCode(line);
320: processAccountingLineOverrides(line);
321: }
322: } catch (Exception e) {
323: // No way to recover gracefully, so throw it back as a RuntimeException
324: throw new RuntimeException(e);
325: }
326: }
327: }
328: }
329:
330: Collections
331: .sort((List<Comparable>) expenseTransferDocumentForm
332: .getFinancialDocument()
333: .getSourceAccountingLines());
334: }
335: }
336:
337: return mapping.findForward(KFSConstants.MAPPING_BASIC);
338: }
339:
340: /**
341: * Overload the method in order to have balance importing section be populated with the last search criteria
342: *
343: * @see org.kuali.kfs.web.struts.action.KualiAccountingDocumentActionBase#loadDocument(org.kuali.core.web.struts.form.KualiDocumentFormBase)
344: */
345: @Override
346: protected void loadDocument(
347: KualiDocumentFormBase kualiDocumentFormBase)
348: throws WorkflowException {
349: super .loadDocument(kualiDocumentFormBase);
350: ExpenseTransferDocumentFormBase expenseTransferDocumentForm = (ExpenseTransferDocumentFormBase) kualiDocumentFormBase;
351: expenseTransferDocumentForm.populateSearchFields();
352: }
353:
354: /**
355: * This method copies all accounting lines from financial document form if they pass validation rules
356: *
357: * @param mapping
358: * @param form
359: * @param request
360: * @param response
361: * @return
362: * @throws Exception
363: */
364: public ActionForward copyAllAccountingLines(ActionMapping mapping,
365: ActionForm form, HttpServletRequest request,
366: HttpServletResponse response) throws Exception {
367: ExpenseTransferDocumentFormBase financialDocumentForm = (ExpenseTransferDocumentFormBase) form;
368: for (Object line : financialDocumentForm.getFinancialDocument()
369: .getSourceAccountingLines()) {
370: ExpenseTransferAccountingLine to = (ExpenseTransferAccountingLine) financialDocumentForm
371: .getFinancialDocument()
372: .getTargetAccountingLineClass().newInstance();
373: copyAccountingLine((ExpenseTransferAccountingLine) line, to);
374:
375: boolean rulePassed = runRule(new AddAccountingLineEvent(
376: KFSConstants.NEW_TARGET_ACCT_LINE_PROPERTY_NAME,
377: financialDocumentForm.getDocument(), to));
378:
379: // if the rule evaluation passed, let's add it
380: if (rulePassed) {
381: // add accountingLine
382: SpringContext.getBean(PersistenceService.class)
383: .retrieveNonKeyFields(line);
384: insertAccountingLine(false, financialDocumentForm, to);
385: }
386: processAccountingLineOverrides(to);
387: }
388: return mapping.findForward(KFSConstants.MAPPING_BASIC);
389: }
390:
391: /**
392: * Delete all source accounting lines
393: *
394: * @param mapping
395: * @param form
396: * @param request
397: * @param response
398: * @return ActionMapping
399: * @throws Exception
400: */
401: public ActionForward deleteAllSourceAccountingLines(
402: ActionMapping mapping, ActionForm form,
403: HttpServletRequest request, HttpServletResponse response)
404: throws Exception {
405: ExpenseTransferDocumentFormBase financialDocumentForm = (ExpenseTransferDocumentFormBase) form;
406: financialDocumentForm.getFinancialDocument()
407: .setSourceAccountingLines(new ArrayList());
408:
409: return mapping.findForward(KFSConstants.MAPPING_BASIC);
410: }
411:
412: /**
413: * Delete all target accounting lines
414: *
415: * @param mapping
416: * @param form
417: * @param request
418: * @param response
419: * @return ActionMapping
420: * @throws Exception
421: */
422: public ActionForward deleteAllTargetAccountingLines(
423: ActionMapping mapping, ActionForm form,
424: HttpServletRequest request, HttpServletResponse response)
425: throws Exception {
426: ExpenseTransferDocumentFormBase financialDocumentForm = (ExpenseTransferDocumentFormBase) form;
427: financialDocumentForm.getFinancialDocument()
428: .setTargetAccountingLines(new ArrayList());
429:
430: return mapping.findForward(KFSConstants.MAPPING_BASIC);
431: }
432:
433: /**
434: * Copy a single accounting line
435: *
436: * @see org.kuali.core.web.struts.action.KualiDocumentActionBase#copyAccountingLine(ActionMapping, ActionForm,
437: * HttpServletRequest, HttpServletResponse)
438: */
439: public ActionForward copyAccountingLine(ActionMapping mapping,
440: ActionForm form, HttpServletRequest request,
441: HttpServletResponse response) throws Exception {
442: ExpenseTransferDocumentFormBase financialDocumentForm = (ExpenseTransferDocumentFormBase) form;
443: LaborExpenseTransferDocumentBase financialDocument = (LaborExpenseTransferDocumentBase) financialDocumentForm
444: .getDocument();
445:
446: int index = getSelectedLine(request);
447:
448: ExpenseTransferAccountingLine line = (ExpenseTransferAccountingLine) financialDocumentForm
449: .getFinancialDocument().getTargetAccountingLineClass()
450: .newInstance();
451: copyAccountingLine(
452: (ExpenseTransferAccountingLine) financialDocument
453: .getSourceAccountingLine(index), line);
454:
455: boolean rulePassed = runRule(new AddAccountingLineEvent(
456: KFSConstants.NEW_TARGET_ACCT_LINE_PROPERTY_NAME,
457: financialDocumentForm.getDocument(), line));
458:
459: // if the rule evaluation passed, let's add it
460: if (rulePassed) {
461: // add accountingLine
462: SpringContext.getBean(PersistenceService.class)
463: .retrieveNonKeyFields(line);
464: insertAccountingLine(false, financialDocumentForm, line);
465: }
466: processAccountingLineOverrides(line);
467:
468: return mapping.findForward(KFSConstants.MAPPING_BASIC);
469: }
470:
471: /**
472: * Reset the lookup fields in the given expense transfer form with the given ledger balance
473: *
474: * @param expenseTransferDocumentForm the given expense transfer form
475: * @param the given ledger balance
476: */
477: protected void resetLookupFields(
478: ExpenseTransferDocumentFormBase expenseTransferDocumentForm,
479: LedgerBalance balance) {
480: expenseTransferDocumentForm.setUniversityFiscalYear(balance
481: .getUniversityFiscalYear());
482: }
483:
484: /**
485: * Copies content from one accounting line to the other. Ignores Source or Target information.
486: *
487: * @param source line to copy from
488: * @param target new line to copy data to
489: */
490: private void copyAccountingLine(
491: ExpenseTransferAccountingLine source,
492: ExpenseTransferAccountingLine target) {
493: target.setChartOfAccountsCode(source.getChartOfAccountsCode());
494: target.setAccountNumber(source.getAccountNumber());
495: target.setSubAccountNumber(source.getSubAccountNumber());
496: target.setPostingYear(source.getPostingYear());
497: target.setPayrollEndDateFiscalYear(source
498: .getPayrollEndDateFiscalYear());
499: target.setFinancialObjectCode(source.getFinancialObjectCode());
500: target.setFinancialSubObjectCode(source
501: .getFinancialSubObjectCode());
502: target.setBalanceTypeCode(source.getBalanceTypeCode());
503: target.setPositionNumber(source.getPositionNumber());
504: target.setAmount(source.getAmount());
505: target.setEmplid(source.getEmplid());
506: target.setPayrollEndDateFiscalPeriodCode(source
507: .getPayrollEndDateFiscalPeriodCode());
508: target.setObjectTypeCode(source.getObjectTypeCode());
509: target.setOverrideCode(source.getOverrideCode());
510: target.setPayrollTotalHours(source.getPayrollTotalHours());
511: }
512:
513: /**
514: * Translates <code>{@link LedgerBalance}</code> data into an <code>{@link ExpenseTransferAccountingLine}</code>
515: *
516: * @param bo <code>{@link LedgerBalance}</code> instance
517: * @param line <code>{@link ExpenseTransferAccountingLine}</code> to copy data to
518: */
519: private void buildAccountingLineFromLedgerBalance(LedgerBalance bo,
520: ExpenseTransferAccountingLine line, KualiDecimal amount,
521: String periodCode) {
522: line.setChartOfAccountsCode(bo.getChartOfAccountsCode());
523: line.setAccountNumber(bo.getAccountNumber());
524:
525: if (!KFSConstants.getDashSubAccountNumber().equals(
526: bo.getSubAccountNumber())) {
527: line.setSubAccountNumber(bo.getSubAccountNumber());
528: }
529:
530: line.setPostingYear(bo.getUniversityFiscalYear());
531: line.setPayrollEndDateFiscalYear(bo.getUniversityFiscalYear());
532: line.setFinancialObjectCode(bo.getFinancialObjectCode());
533: line.setObjectTypeCode(bo.getFinancialObjectTypeCode());
534:
535: if (!KFSConstants.getDashFinancialSubObjectCode().equals(
536: bo.getFinancialSubObjectCode())) {
537: line.setFinancialSubObjectCode(bo
538: .getFinancialSubObjectCode());
539: }
540:
541: line.setBalanceTypeCode(bo.getFinancialBalanceTypeCode());
542: line.setPositionNumber(bo.getPositionNumber());
543: line.setAmount(amount);
544: line.setEmplid(bo.getEmplid());
545: line.setPayrollEndDateFiscalPeriodCode(periodCode);
546: }
547:
548: /**
549: * Processes accounting line overrides for output to JSP
550: *
551: * @see org.kuali.kfs.web.struts.action.KualiAccountingDocumentActionBase#processAccountingLineOverrides(java.util.List)
552: */
553: @Override
554: protected void processAccountingLineOverrides(List accountingLines) {
555: if (!accountingLines.isEmpty()) {
556: SpringContext.getBean(PersistenceService.class)
557: .retrieveReferenceObjects(accountingLines,
558: AccountingLineOverride.REFRESH_FIELDS);
559:
560: for (Iterator i = accountingLines.iterator(); i.hasNext();) {
561: AccountingLine line = (AccountingLine) i.next();
562: LaborAccountingLineOverride.processForOutput(line);
563: }
564: }
565: }
566:
567: /**
568: * Clear all overrides that are not needed.
569: *
570: * @see org.kuali.kfs.web.struts.action.KualiAccountingDocumentActionBase#clearOverridesThatBecameUnneeded(org.kuali.kfs.bo.AccountingLine)
571: */
572: @Override
573: protected void clearOverridesThatBecameUnneeded(
574: AccountingLine formLine) {
575: AccountingLineOverride currentlyNeeded = LaborAccountingLineOverride
576: .determineNeededOverrides(formLine);
577: AccountingLineOverride currentOverride = AccountingLineOverride
578: .valueOf(formLine.getOverrideCode());
579: if (!currentOverride.isValidMask(currentlyNeeded)) {
580: // todo: handle unsupported combinations of overrides (not a problem until we allow certain multiple overrides)
581: }
582: formLine.setOverrideCode(currentOverride.mask(currentlyNeeded)
583: .getCode());
584: }
585:
586: /**
587: * For given accounting line, set the corresponding override code
588: *
589: * @param line accounting line
590: */
591: private void updateAccountOverrideCode(
592: ExpenseTransferAccountingLine line) {
593: AccountingLineOverride override = LaborAccountingLineOverride
594: .determineNeededOverrides(line);
595: line.setOverrideCode(override.getCode());
596: }
597:
598: /**
599: * Executes for the given event. This is more of a convenience method.
600: *
601: * @param event to run the rules for
602: * @return true if rule passes
603: */
604: private boolean runRule(KualiDocumentEventBase event) {
605: // check any business rules
606:
607: boolean rulePassed = SpringContext.getBean(
608: KualiRuleService.class).applyRules(event);
609: return rulePassed;
610: }
611:
612: /**
613: * Get the BO class name of the set of lookup results
614: *
615: * @param expenseTransferDocumentForm the Struts form for expense transfer document
616: * @return the BO class name of the set of lookup results
617: */
618: protected String getLookupResultsBOClassName(
619: ExpenseTransferDocumentFormBase expenseTransferDocumentForm) {
620: return expenseTransferDocumentForm
621: .getLookupResultsBOClassName();
622: }
623:
624: /**
625: * @return SegmentedLookupResultsService
626: */
627: private SegmentedLookupResultsService getSegmentedLookupResultsService() {
628: return SpringContext
629: .getBean(SegmentedLookupResultsService.class);
630: }
631:
632: /**
633: * This method will revert a TargetAccountingLine by overwriting its current values with the values in the corresponding
634: * baseline accountingLine. This assumes that the user presses the revert button for a specific accounting line on the document
635: * and that the document is represented by a FinancialDocumentFormBase.
636: *
637: * @param mapping
638: * @param form
639: * @param request
640: * @param response
641: * @return ActionForward
642: * @throws Exception
643: */
644: @Override
645: public ActionForward revertTargetLine(ActionMapping mapping,
646: ActionForm form, HttpServletRequest request,
647: HttpServletResponse response) throws Exception {
648: ExpenseTransferDocumentFormBase financialDocumentForm = (ExpenseTransferDocumentFormBase) form;
649: LaborExpenseTransferDocumentBase financialDocument = (LaborExpenseTransferDocumentBase) financialDocumentForm
650: .getDocument();
651:
652: int revertIndex = getSelectedLine(request);
653:
654: ExpenseTransferTargetAccountingLine originalLine = (ExpenseTransferTargetAccountingLine) financialDocumentForm
655: .getBaselineTargetAccountingLine(revertIndex);
656: ExpenseTransferTargetAccountingLine brokenLine = (ExpenseTransferTargetAccountingLine) financialDocument
657: .getTargetAccountingLine(revertIndex);
658:
659: SpringContext.getBean(PersistenceService.class)
660: .refreshAllNonUpdatingReferences(originalLine);
661:
662: // *always* revert (so that if someone manually changes the line to its original values, then hits revert, they won't get an
663: // error message saying "couldn't revert")
664: brokenLine.copyFrom(originalLine);
665: if (super .isSalesTaxRequired(
666: (AccountingDocument) financialDocumentForm
667: .getDocument(), brokenLine)) {
668: brokenLine.setSalesTaxRequired(true);
669: }
670: financialDocumentForm.getTargetLineDecorator(revertIndex)
671: .setRevertible(false);
672: GlobalVariables.getMessageList().add(
673: KFSKeyConstants.MESSAGE_REVERT_SUCCESSFUL);
674:
675: // no business rules to check, no events to create
676: return mapping.findForward(KFSConstants.MAPPING_BASIC);
677: }
678:
679: /**
680: * This method will revert a SourceAccountingLine by overwriting its current values with the values in the corresponding
681: * baseline accountingLine. This assumes that the user presses the revert button for a specific accounting line on the document
682: * and that the document is represented by a FinancialDocumentFormBase.
683: *
684: * @param mapping
685: * @param form
686: * @param request
687: * @param response
688: * @return ActionForward
689: * @throws Exception
690: */
691: @Override
692: public ActionForward revertSourceLine(ActionMapping mapping,
693: ActionForm form, HttpServletRequest request,
694: HttpServletResponse response) throws Exception {
695: ExpenseTransferDocumentFormBase financialDocumentForm = (ExpenseTransferDocumentFormBase) form;
696: LaborExpenseTransferDocumentBase financialDocument = (LaborExpenseTransferDocumentBase) financialDocumentForm
697: .getDocument();
698: int revertIndex = getSelectedLine(request);
699:
700: ExpenseTransferSourceAccountingLine originalLine = (ExpenseTransferSourceAccountingLine) financialDocumentForm
701: .getBaselineSourceAccountingLine(revertIndex);
702: ExpenseTransferSourceAccountingLine brokenLine = (ExpenseTransferSourceAccountingLine) financialDocument
703: .getSourceAccountingLine(revertIndex);
704:
705: SpringContext.getBean(PersistenceService.class)
706: .refreshAllNonUpdatingReferences(originalLine);
707:
708: // *always* revert (so that if someone manually changes the line to its original values, then hits revert, they won't get an
709: // error message saying "couldn't revert")
710: brokenLine.copyFrom(originalLine);
711: if (super .isSalesTaxRequired(
712: (AccountingDocument) financialDocumentForm
713: .getDocument(), brokenLine)) {
714: brokenLine.setSalesTaxRequired(true);
715: }
716: financialDocumentForm.getSourceLineDecorator(revertIndex)
717: .setRevertible(false);
718: GlobalVariables.getMessageList().add(
719: KFSKeyConstants.MESSAGE_REVERT_SUCCESSFUL);
720:
721: // no business rules to check, no events to create
722: return mapping.findForward(KFSConstants.MAPPING_BASIC);
723: }
724: }
|