Source Code Cross Referenced for KualiAccountingDocumentFormBase.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » kfs » web » struts » form » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » org.kuali.kfs.web.struts.form 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.kfs.web.struts.form;
017:
018:        import java.util.ArrayList;
019:        import java.util.HashMap;
020:        import java.util.Iterator;
021:        import java.util.List;
022:        import java.util.Map;
023:
024:        import javax.servlet.http.HttpServletRequest;
025:
026:        import org.apache.commons.lang.StringUtils;
027:        import org.apache.struts.upload.FormFile;
028:        import org.kuali.core.bo.user.UniversalUser;
029:        import org.kuali.core.document.authorization.DocumentAuthorizer;
030:        import org.kuali.core.exceptions.InfrastructureException;
031:        import org.kuali.core.service.BusinessObjectDictionaryService;
032:        import org.kuali.core.service.DocumentAuthorizationService;
033:        import org.kuali.core.service.KualiConfigurationService;
034:        import org.kuali.core.util.GlobalVariables;
035:        import org.kuali.core.util.ObjectUtils;
036:        import org.kuali.core.web.format.CurrencyFormatter;
037:        import org.kuali.core.web.format.SimpleBooleanFormatter;
038:        import org.kuali.core.web.struts.form.KualiTransactionalDocumentFormBase;
039:        import org.kuali.kfs.KFSConstants;
040:        import org.kuali.kfs.bo.AccountingLine;
041:        import org.kuali.kfs.bo.AccountingLineBase;
042:        import org.kuali.kfs.bo.AccountingLineOverride;
043:        import org.kuali.kfs.bo.SourceAccountingLine;
044:        import org.kuali.kfs.bo.TargetAccountingLine;
045:        import org.kuali.kfs.context.SpringContext;
046:        import org.kuali.kfs.document.AccountingDocument;
047:        import org.kuali.kfs.document.authorization.AccountingDocumentAuthorizer;
048:        import org.kuali.kfs.service.ParameterService;
049:        import org.kuali.kfs.service.impl.ParameterConstants;
050:        import org.kuali.kfs.web.ui.AccountingLineDecorator;
051:        import org.kuali.module.chart.bo.Account;
052:        import org.kuali.module.chart.bo.ChartUser;
053:        import org.kuali.module.chart.bo.ObjectCode;
054:        import org.kuali.module.chart.bo.SubAccount;
055:        import org.kuali.module.chart.bo.SubObjCd;
056:
057:        /**
058:         * This class is the base action form for all financial documents.
059:         */
060:        public class KualiAccountingDocumentFormBase extends
061:                KualiTransactionalDocumentFormBase {
062:            private SourceAccountingLine newSourceLine;
063:            private TargetAccountingLine newTargetLine;
064:
065:            private Map editableAccounts;
066:            private Map accountingLineEditableFields;
067:            private Map forcedLookupOptionalFields;
068:
069:            // TODO: FormFile isn't Serializable, so mark these fields need as transient or create a Serializable subclass of FormFile
070:            protected FormFile sourceFile;
071:            protected FormFile targetFile;
072:            private boolean hideDetails = false;
073:
074:            private List<AccountingLineDecorator> sourceLineDecorators;
075:            private List<AccountingLineDecorator> targetLineDecorators;
076:
077:            private List baselineSourceAccountingLines;
078:            private List baselineTargetAccountingLines;
079:
080:            /**
081:             * This constructor sets up empty instances for the dependent objects...
082:             */
083:            public KualiAccountingDocumentFormBase() {
084:                super ();
085:                setFormatterType("sourceLineDecorator.revertible",
086:                        SimpleBooleanFormatter.class);
087:                setFormatterType("targetLineDecorator.revertible",
088:                        SimpleBooleanFormatter.class);
089:
090:                // create an empty editableAccounts map, for safety's sake
091:                editableAccounts = new HashMap();
092:                accountingLineEditableFields = new HashMap();
093:                forcedReadOnlyFields = new HashMap();
094:                forcedLookupOptionalFields = new HashMap();
095:
096:                // initialize accountingLine lists
097:                baselineSourceAccountingLines = new ArrayList();
098:                baselineTargetAccountingLines = new ArrayList();
099:
100:                // initialize accountingLine decoration lists
101:                sourceLineDecorators = new ArrayList<AccountingLineDecorator>();
102:                targetLineDecorators = new ArrayList<AccountingLineDecorator>();
103:            }
104:
105:            /**
106:             * Overrides the parent to call super.populate and then to call the accounting lines populate method that is specific to loading
107:             * the two select lists on the page.
108:             * 
109:             * @see org.kuali.core.web.struts.pojo.PojoForm#populate(javax.servlet.http.HttpServletRequest)
110:             */
111:            @Override
112:            public void populate(HttpServletRequest request) {
113:                super .populate(request);
114:
115:                //
116:                // now run through all of the accounting lines and make sure they've been uppercased and populated appropriately
117:
118:                // handle new accountingLine, if one is being added
119:                String methodToCall = this .getMethodToCall();
120:                if (StringUtils.isNotBlank(methodToCall)) {
121:                    if (methodToCall
122:                            .equals(KFSConstants.INSERT_SOURCE_LINE_METHOD)) {
123:                        populateSourceAccountingLine(getNewSourceLine());
124:                    }
125:
126:                    if (methodToCall
127:                            .equals(KFSConstants.INSERT_TARGET_LINE_METHOD)) {
128:                        populateTargetAccountingLine(getNewTargetLine());
129:                    }
130:                }
131:
132:                // don't call populateAccountingLines if you are copying or errorCorrecting a document,
133:                // since you want the accountingLines in the copy to be "identical" to those in the original
134:                if (!StringUtils.equals(methodToCall, KFSConstants.COPY_METHOD)
135:                        && !StringUtils.equals(methodToCall,
136:                                KFSConstants.ERRORCORRECT_METHOD)) {
137:                    populateAccountingLines();
138:                }
139:
140:                setDocTypeName(discoverDocumentTypeName());
141:            }
142:
143:            /**
144:             * Refactored out actually calling the documentAuthorizer methods, since FinancialDocuments call a differently-parameterized
145:             * version of getEditMode
146:             * 
147:             * @param documentAuthorizer
148:             */
149:            @Override
150:            protected void useDocumentAuthorizer(
151:                    DocumentAuthorizer documentAuthorizer) {
152:                UniversalUser kualiUser = GlobalVariables.getUserSession()
153:                        .getUniversalUser();
154:
155:                AccountingDocument financialDocument = (AccountingDocument) getDocument();
156:                AccountingDocumentAuthorizer financialDocumentAuthorizer = (AccountingDocumentAuthorizer) documentAuthorizer;
157:
158:                setEditingMode(financialDocumentAuthorizer.getEditMode(
159:                        financialDocument, kualiUser,
160:                        getBaselineSourceAccountingLines(),
161:                        getBaselineTargetAccountingLines()));
162:
163:                setAccountingLineEditableFields(financialDocumentAuthorizer
164:                        .getAccountingLineEditableFields(financialDocument,
165:                                kualiUser));
166:                setDocumentActionFlags(financialDocumentAuthorizer
167:                        .getDocumentActionFlags(financialDocument, kualiUser));
168:
169:                setEditableAccounts(financialDocumentAuthorizer
170:                        .getEditableAccounts(glomBaselineAccountingLines(),
171:                                (ChartUser) kualiUser
172:                                        .getModuleUser(ChartUser.MODULE_ID)));
173:            }
174:
175:            /**
176:             * This method iterates over all of the source lines and all of the target lines in a transactional document, and calls
177:             * prepareAccountingLineForValidationAndPersistence on each one. This is called because a user could have updated already
178:             * existing accounting lines that had blank values in composite key fields.
179:             */
180:            protected void populateAccountingLines() {
181:                Iterator sourceLines = getFinancialDocument()
182:                        .getSourceAccountingLines().iterator();
183:                while (sourceLines.hasNext()) {
184:                    SourceAccountingLine sourceLine = (SourceAccountingLine) sourceLines
185:                            .next();
186:                    populateSourceAccountingLine(sourceLine);
187:                }
188:
189:                Iterator targetLines = getFinancialDocument()
190:                        .getTargetAccountingLines().iterator();
191:                while (targetLines.hasNext()) {
192:                    TargetAccountingLine targetLine = (TargetAccountingLine) targetLines
193:                            .next();
194:                    populateTargetAccountingLine(targetLine);
195:                }
196:            }
197:
198:            /**
199:             * Populates a source accounting line bo using values from the struts form. This is in place to make sure that all of the
200:             * composite key objects have the correct values in them. This should be overridden by children forms in the situation where
201:             * document level attributes need to be pushed down into the accounting lines.
202:             * 
203:             * @param sourceLine
204:             */
205:            public void populateSourceAccountingLine(
206:                    SourceAccountingLine sourceLine) {
207:                populateAccountingLine(sourceLine);
208:            }
209:
210:            /**
211:             * Populates a target accounting line bo using values from the struts form. This is in place to make sure that all of the
212:             * composite key objects have the correct values in them. This should be overridden by children forms in the situation where
213:             * document level attributes need to be pushed down into the accounting lines.
214:             * 
215:             * @param targetLine
216:             */
217:            public void populateTargetAccountingLine(
218:                    TargetAccountingLine targetLine) {
219:                populateAccountingLine(targetLine);
220:            }
221:
222:            /**
223:             * Populates the dependent fields of objects contained within the given accountingLine
224:             * 
225:             * @param line
226:             */
227:            @SuppressWarnings("deprecation")
228:            private void populateAccountingLine(AccountingLineBase line) {
229:                SpringContext.getBean(BusinessObjectDictionaryService.class)
230:                        .performForceUppercase(line);
231:
232:                line.setDocumentNumber(getDocument().getDocumentNumber());
233:
234:                if (ObjectUtils.isNull(line.getAccount())) {
235:                    line.setAccount(new Account());
236:                }
237:                line.getAccount().setChartOfAccountsCode(
238:                        line.getChartOfAccountsCode());
239:
240:                if (ObjectUtils.isNull(line.getObjectCode())) {
241:                    line.setObjectCode(new ObjectCode());
242:                }
243:                line.getObjectCode().setUniversityFiscalYear(
244:                        getFinancialDocument().getPostingYear());
245:                line.getObjectCode().setChartOfAccountsCode(
246:                        line.getChartOfAccountsCode());
247:
248:                if (ObjectUtils.isNull(line.getSubAccount())) {
249:                    line.setSubAccount(new SubAccount());
250:                }
251:                line.getSubAccount().setChartOfAccountsCode(
252:                        line.getChartOfAccountsCode());
253:                line.getSubAccount().setAccountNumber(line.getAccountNumber());
254:
255:                if (ObjectUtils.isNull(line.getSubObjectCode())) {
256:                    line.setSubObjectCode(new SubObjCd());
257:                }
258:                line.getSubObjectCode().setChartOfAccountsCode(
259:                        line.getChartOfAccountsCode());
260:                line.getSubObjectCode().setAccountNumber(
261:                        line.getAccountNumber());
262:                line.getSubObjectCode().setFinancialObjectCode(
263:                        line.getFinancialObjectCode());
264:                line.getSubObjectCode().setUniversityFiscalYear(
265:                        getFinancialDocument().getPostingYear());
266:
267:                AccountingLineOverride.populateFromInput(line);
268:            }
269:
270:            /**
271:             * This method retrieves an instance of the form.
272:             * 
273:             * @return
274:             */
275:            public AccountingDocument getFinancialDocument() {
276:                return (AccountingDocument) getDocument();
277:            }
278:
279:            /**
280:             * @return Returns the newTargetLine.
281:             */
282:            public TargetAccountingLine getNewTargetLine() {
283:                if (newTargetLine == null) {
284:                    newTargetLine = createNewTargetAccountingLine(getFinancialDocument());
285:                }
286:                return newTargetLine;
287:            }
288:
289:            /**
290:             * @param newExpenseLine The newTargetLine to set.
291:             */
292:            public void setNewTargetLine(TargetAccountingLine newExpenseLine) {
293:                this .newTargetLine = newExpenseLine;
294:            }
295:
296:            /**
297:             * @return Returns the newSourceLine.
298:             */
299:            public SourceAccountingLine getNewSourceLine() {
300:                if (newSourceLine == null) {
301:                    newSourceLine = createNewSourceAccountingLine(getFinancialDocument());
302:                }
303:                return newSourceLine;
304:            }
305:
306:            /**
307:             * @param newIncomeLine The newSourceLine to set.
308:             */
309:            public void setNewSourceLine(SourceAccountingLine newIncomeLine) {
310:                this .newSourceLine = newIncomeLine;
311:            }
312:
313:            /**
314:             * @return Returns the sourceFile.
315:             */
316:            public FormFile getSourceFile() {
317:                return sourceFile;
318:            }
319:
320:            /**
321:             * @param sourceFile The sourceFile to set.
322:             */
323:            public void setSourceFile(FormFile sourceFile) {
324:                this .sourceFile = sourceFile;
325:            }
326:
327:            /**
328:             * @return Returns the targetFile.
329:             */
330:            public FormFile getTargetFile() {
331:                return targetFile;
332:            }
333:
334:            /**
335:             * @param targetFile The targetFile to set.
336:             */
337:            public void setTargetFile(FormFile targetFile) {
338:                this .targetFile = targetFile;
339:            }
340:
341:            /**
342:             * @return current Map of editableAccounts
343:             */
344:            public Map getEditableAccounts() {
345:                return editableAccounts;
346:            }
347:
348:            /**
349:             * @param editableAccounts the account Map to set
350:             */
351:            public void setEditableAccounts(Map editableAccounts) {
352:                this .editableAccounts = editableAccounts;
353:            }
354:
355:            /**
356:             * @return Returns the editableFields.
357:             */
358:            public Map getAccountingLineEditableFields() {
359:                return accountingLineEditableFields;
360:            }
361:
362:            /**
363:             * @param editableFields The editableFields to set.
364:             */
365:            public void setAccountingLineEditableFields(Map editableFields) {
366:                this .accountingLineEditableFields = editableFields;
367:            }
368:
369:            /**
370:             * @return hideDetails attribute
371:             */
372:            public boolean isHideDetails() {
373:                return hideDetails;
374:            }
375:
376:            /**
377:             * @return hideDetails attribute
378:             * @see #isHideDetails()
379:             */
380:            public boolean getHideDetails() {
381:                return isHideDetails();
382:            }
383:
384:            /**
385:             * @param hideDetails
386:             */
387:            public void setHideDetails(boolean hideDetails) {
388:                this .hideDetails = hideDetails;
389:            }
390:
391:            /**
392:             * @return current List of baseline SourceAccountingLines for use in update-event generation
393:             */
394:            public List getBaselineSourceAccountingLines() {
395:                return baselineSourceAccountingLines;
396:            }
397:
398:            /**
399:             * Sets the current List of baseline SourceAccountingLines to the given List
400:             * 
401:             * @param baselineSourceAccountingLines
402:             */
403:            public void setBaselineSourceAccountingLines(
404:                    List baselineSourceAccountingLines) {
405:                this .baselineSourceAccountingLines = baselineSourceAccountingLines;
406:            }
407:
408:            /**
409:             * @param index
410:             * @return true if a baselineSourceAccountingLine with the given index exists
411:             */
412:            public boolean hasBaselineSourceAccountingLine(int index) {
413:                boolean has = false;
414:
415:                if ((index >= 0)
416:                        && (index <= baselineSourceAccountingLines.size())) {
417:                    has = true;
418:                }
419:
420:                return has;
421:            }
422:
423:            /**
424:             * Implementation creates empty SourceAccountingLines as a side-effect, so that Struts' efforts to set fields of lines which
425:             * haven't been created will succeed rather than causing a NullPointerException.
426:             * 
427:             * @param index
428:             * @return baseline SourceAccountingLine at the given index
429:             */
430:            public SourceAccountingLine getBaselineSourceAccountingLine(
431:                    int index) {
432:                try {
433:                    while (baselineSourceAccountingLines.size() <= index) {
434:                        baselineSourceAccountingLines
435:                                .add(getFinancialDocument()
436:                                        .getSourceAccountingLineClass()
437:                                        .newInstance());
438:                    }
439:                } catch (InstantiationException e) {
440:                    throw new RuntimeException(
441:                            "Unable to get new source line instance for document"
442:                                    + e.getMessage());
443:                } catch (IllegalAccessException e) {
444:                    throw new RuntimeException(
445:                            "Unable to get new source line instance for document"
446:                                    + e.getMessage());
447:                }
448:
449:                return (SourceAccountingLine) baselineSourceAccountingLines
450:                        .get(index);
451:            }
452:
453:            /**
454:             * @return current List of baseline TargetAccountingLines for use in update-event generation
455:             */
456:            public List getBaselineTargetAccountingLines() {
457:                return baselineTargetAccountingLines;
458:            }
459:
460:            /**
461:             * Sets the current List of baseline TargetAccountingLines to the given List
462:             * 
463:             * @param baselineTargetAccountingLines
464:             */
465:            public void setBaselineTargetAccountingLines(
466:                    List baselineTargetAccountingLines) {
467:                this .baselineTargetAccountingLines = baselineTargetAccountingLines;
468:            }
469:
470:            /**
471:             * @param index
472:             * @return true if a baselineTargetAccountingLine with the given index exists
473:             */
474:            public boolean hasBaselineTargetAccountingLine(int index) {
475:                boolean has = false;
476:
477:                if ((index >= 0)
478:                        && (index <= baselineTargetAccountingLines.size())) {
479:                    has = true;
480:                }
481:
482:                return has;
483:            }
484:
485:            /**
486:             * Implementation creates empty TargetAccountingLines as a side-effect, so that Struts' efforts to set fields of lines which
487:             * haven't been created will succeed rather than causing a NullPointerException.
488:             * 
489:             * @param index
490:             * @return baseline TargetAccountingLine at the given index
491:             */
492:            public TargetAccountingLine getBaselineTargetAccountingLine(
493:                    int index) {
494:                try {
495:                    while (baselineTargetAccountingLines.size() <= index) {
496:                        baselineTargetAccountingLines
497:                                .add(getFinancialDocument()
498:                                        .getTargetAccountingLineClass()
499:                                        .newInstance());
500:                    }
501:                } catch (InstantiationException e) {
502:                    throw new RuntimeException(
503:                            "Unable to get new target line instance for document"
504:                                    + e.getMessage());
505:                } catch (IllegalAccessException e) {
506:                    throw new RuntimeException(
507:                            "Unable to get new target line instance for document"
508:                                    + e.getMessage());
509:                }
510:
511:                return (TargetAccountingLine) baselineTargetAccountingLines
512:                        .get(index);
513:            }
514:
515:            /**
516:             * @return current List of SourceAccountingLine decorations
517:             */
518:            public List<AccountingLineDecorator> getSourceLineDecorators() {
519:                return sourceLineDecorators;
520:            }
521:
522:            /**
523:             * @param minSize
524:             * @return current List of SourceAccountingLine decorations, expanded to have at least minSize elements
525:             */
526:            public List<AccountingLineDecorator> getSourceLineDecorators(
527:                    int minSize) {
528:                extendSourceLineDecorators(minSize);
529:
530:                return sourceLineDecorators;
531:            }
532:
533:            /**
534:             * Adds default AccountingLineDecorators to sourceAccountingLineDecorators until it contains at least minSize elements
535:             * 
536:             * @param minSize
537:             */
538:            private void extendSourceLineDecorators(int minSize) {
539:                while (sourceLineDecorators.size() < minSize) {
540:                    sourceLineDecorators.add(new AccountingLineDecorator());
541:                }
542:            }
543:
544:            /**
545:             * Sets the current List of SourceAccountingLine decorators
546:             * 
547:             * @param sourceLineDecorators
548:             */
549:            public void setSourceLineDecorators(
550:                    List<AccountingLineDecorator> sourceLineDecorators) {
551:                this .sourceLineDecorators = sourceLineDecorators;
552:            }
553:
554:            /**
555:             * Implementation creates empty AccountingLineDecorators as a side-effect, so that Struts' efforts to set fields of lines which
556:             * haven't been created will succeed rather than causing a NullPointerException.
557:             * 
558:             * @param index
559:             * @return AccountingLineDecorators for sourceLine at the given index
560:             */
561:            public AccountingLineDecorator getSourceLineDecorator(int index) {
562:                extendSourceLineDecorators(index + 1);
563:
564:                return sourceLineDecorators.get(index);
565:            }
566:
567:            /**
568:             * @return current List of TargetAccountingLine decorators
569:             */
570:            public List<AccountingLineDecorator> getTargetLineDecorators() {
571:                return targetLineDecorators;
572:            }
573:
574:            /**
575:             * @param minSize
576:             * @return current List of TargetAccountingLine decorators, expanded to have at least minSize elements
577:             */
578:            public List<AccountingLineDecorator> getTargetLineDecorators(
579:                    int minSize) {
580:                extendTargetLineDecorators(minSize);
581:
582:                return targetLineDecorators;
583:            }
584:
585:            /**
586:             * Adds default AccountingLineDecorators to targetAccountingLineDecorators until it contains at least minSize elements
587:             * 
588:             * @param minSize
589:             */
590:            private void extendTargetLineDecorators(int minSize) {
591:                while (targetLineDecorators.size() < minSize) {
592:                    targetLineDecorators.add(new AccountingLineDecorator());
593:                }
594:            }
595:
596:            /**
597:             * Sets the current List of TargetAccountingLine decorators
598:             * 
599:             * @param targetLineDecorators
600:             */
601:            public void setTargetLineDecorators(
602:                    List<AccountingLineDecorator> targetLineDecorators) {
603:                this .targetLineDecorators = targetLineDecorators;
604:            }
605:
606:            /**
607:             * Implementation creates empty AccountingLineDecorators as a side-effect, so that Struts' efforts to set fields of lines which
608:             * haven't been created will succeed rather than causing a NullPointerException.
609:             * 
610:             * @param index
611:             * @return AccountingLineDecorator for targetLine at the given index
612:             */
613:            public AccountingLineDecorator getTargetLineDecorator(int index) {
614:                extendTargetLineDecorators(index + 1);
615:
616:                return targetLineDecorators.get(index);
617:            }
618:
619:            /**
620:             * Resets the source accounting line decorators to new and ensures that there are the given number. These decorators take very
621:             * little memory, there are few of them on the page, and they are rarely reset, so this method does it the simple way.
622:             * 
623:             * @param size
624:             */
625:            public void resetSourceLineDecorators(int size) {
626:                sourceLineDecorators.clear();
627:                extendSourceLineDecorators(size);
628:            }
629:
630:            /**
631:             * Resets the target accounting line decorators to new and ensures that there are the given number. These decorators take very
632:             * little memory, there are few of them on the page, and they are rarely reset, so this method does it the simple way.
633:             * 
634:             * @param size
635:             */
636:            public void resetTargetLineDecorators(int size) {
637:                targetLineDecorators.clear();
638:                extendTargetLineDecorators(size);
639:            }
640:
641:            /**
642:             * Retrieves the source accounting lines total in a currency format with commas.
643:             * 
644:             * @return String
645:             */
646:            public String getCurrencyFormattedSourceTotal() {
647:                return (String) new CurrencyFormatter()
648:                        .format(getFinancialDocument().getSourceTotal());
649:            }
650:
651:            /**
652:             * Retrieves the source accounting lines total in a currency format with commas.
653:             * 
654:             * @return String
655:             */
656:            public String getCurrencyFormattedTargetTotal() {
657:                return (String) new CurrencyFormatter()
658:                        .format(getFinancialDocument().getTargetTotal());
659:            }
660:
661:            /**
662:             * @return String
663:             */
664:            public String getAccountingLineImportInstructionsUrl() {
665:                return SpringContext.getBean(KualiConfigurationService.class)
666:                        .getPropertyString(
667:                                KFSConstants.EXTERNALIZABLE_HELP_URL_KEY)
668:                        + SpringContext
669:                                .getBean(ParameterService.class)
670:                                .getParameterValue(
671:                                        ParameterConstants.FINANCIAL_SYSTEM_DOCUMENT.class,
672:                                        KFSConstants.FinancialApcParms.ACCOUNTING_LINE_IMPORT_HELP);
673:            }
674:
675:            /**
676:             * @param financialDocument
677:             * @return a new source accounting line for the document
678:             */
679:            protected SourceAccountingLine createNewSourceAccountingLine(
680:                    AccountingDocument financialDocument) {
681:                if (financialDocument == null) {
682:                    throw new IllegalArgumentException(
683:                            "invalid (null) document");
684:                }
685:                try {
686:                    return (SourceAccountingLine) financialDocument
687:                            .getSourceAccountingLineClass().newInstance();
688:                } catch (Exception e) {
689:                    throw new InfrastructureException(
690:                            "unable to create a new source accounting line", e);
691:                }
692:            }
693:
694:            /**
695:             * @param financialDocument
696:             * @return a new target accounting line for the documet
697:             */
698:            protected TargetAccountingLine createNewTargetAccountingLine(
699:                    AccountingDocument financialDocument) {
700:                if (financialDocument == null) {
701:                    throw new IllegalArgumentException(
702:                            "invalid (null) document");
703:                }
704:                try {
705:                    return (TargetAccountingLine) financialDocument
706:                            .getTargetAccountingLineClass().newInstance();
707:                } catch (Exception e) {
708:                    throw new InfrastructureException(
709:                            "unable to create a new target accounting line", e);
710:                }
711:            }
712:
713:            /**
714:             * This method finds its appropriate document authorizer and uses that to reset the map of editable accounts, based on the
715:             * current accounting lines.
716:             */
717:            public void refreshEditableAccounts() {
718:                AccountingDocumentAuthorizer authorizer = (AccountingDocumentAuthorizer) SpringContext
719:                        .getBean(DocumentAuthorizationService.class)
720:                        .getDocumentAuthorizer(this .getDocument());
721:                this .setEditableAccounts(authorizer.getEditableAccounts(
722:                        glomBaselineAccountingLines(),
723:                        (ChartUser) GlobalVariables.getUserSession()
724:                                .getUniversalUser().getModuleUser(
725:                                        ChartUser.MODULE_ID)));
726:            }
727:
728:            /**
729:             * This method returns a list made up of accounting line from all baseline accounting line sources.
730:             * 
731:             * @return a list of accounting lines, made up of all baseline source and baseline target lines.
732:             */
733:            private List<AccountingLine> glomBaselineAccountingLines() {
734:                List<AccountingLine> lines = new ArrayList<AccountingLine>();
735:                lines.addAll(harvestAccountingLines(this 
736:                        .getBaselineSourceAccountingLines()));
737:                lines.addAll(harvestAccountingLines(this 
738:                        .getBaselineTargetAccountingLines()));
739:                return lines;
740:            }
741:
742:            /**
743:             * This method takes a generic list, hopefully with some AccountingLine objects in it, and returns a list of AccountingLine
744:             * objects, because Java generics are just so wonderful.
745:             * 
746:             * @param lines a list of objects
747:             * @return a list of the accounting lines that were in the lines parameter
748:             */
749:            private List<AccountingLine> harvestAccountingLines(List lines) {
750:                List<AccountingLine> accountingLines = new ArrayList<AccountingLine>();
751:                for (Object o : lines) {
752:                    if (o instanceof  AccountingLine) {
753:                        accountingLines.add((AccountingLine) o);
754:                    }
755:                }
756:                return accountingLines;
757:            }
758:
759:            /**
760:             * A <code>{@link Map}</code> of names of optional accounting line fields that require a quickfinder.
761:             * 
762:             * @return a Map of fields
763:             */
764:            public void setForcedLookupOptionalFields(Map fieldMap) {
765:                forcedLookupOptionalFields = fieldMap;
766:            }
767:
768:            /**
769:             * A <code>{@link Map}</code> of names of optional accounting line fields that require a quickfinder.
770:             * 
771:             * @return a Map of fields
772:             */
773:            public Map getForcedLookupOptionalFields() {
774:                return forcedLookupOptionalFields;
775:            }
776:
777:            /**
778:             * Adds the accounting line file size to the list of max file sizes.
779:             * 
780:             * @see org.kuali.core.web.struts.pojo.PojoFormBase#customInitMaxUploadSizes()
781:             */
782:            @Override
783:            protected void customInitMaxUploadSizes() {
784:                super .customInitMaxUploadSizes();
785:                addMaxUploadSize(SpringContext
786:                        .getBean(ParameterService.class)
787:                        .getParameterValue(
788:                                ParameterConstants.FINANCIAL_SYSTEM_DOCUMENT.class,
789:                                KFSConstants.ACCOUNTING_LINE_IMPORT_MAX_FILE_SIZE_PARM_NM));
790:            }
791:
792:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.