View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.sys.document.web.struts;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.kuali.kfs.sys.KFSConstants;
26  import org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader;
27  import org.kuali.kfs.sys.context.SpringContext;
28  import org.kuali.rice.core.api.config.property.ConfigurationService;
29  import org.kuali.rice.kew.api.WorkflowDocument;
30  import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
31  import org.kuali.rice.kns.web.ui.ExtraButton;
32  import org.kuali.rice.kns.web.ui.HeaderField;
33  
34  /**
35   * This class is a Financial System specific transactional document form base
36   */
37  public class FinancialSystemTransactionalDocumentFormBase extends KualiTransactionalDocumentFormBase {
38  
39      /**
40       * Constructs a FinancialSystemTransactionalDocumentFormBase.java.
41       */
42      public FinancialSystemTransactionalDocumentFormBase() {
43          super();
44      }
45  
46      /**
47       * @see org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase#populateHeaderFields(org.kuali.rice.kew.api.WorkflowDocument)
48  
49       * KRAD Conversion: Customizing the header fields - Uses data dictionary
50       */
51      @Override
52      public void populateHeaderFields(WorkflowDocument workflowDocument) {
53          super.populateHeaderFields(workflowDocument);
54          if (getDocument().getDocumentHeader() instanceof FinancialSystemDocumentHeader) {
55              FinancialSystemDocumentHeader documentHeader = (FinancialSystemDocumentHeader)getDocument().getDocumentHeader();
56              if (StringUtils.isNotBlank(documentHeader.getFinancialDocumentInErrorNumber())) {
57                  extendDocInfoToThreeColumns();
58                  int insertIndex = 2;
59                  getDocInfo().remove(insertIndex);
60                  getDocInfo().add(insertIndex, new HeaderField("DataDictionary.FinancialSystemDocumentHeader.attributes.financialDocumentInErrorNumber",
61                          documentHeader.getFinancialDocumentInErrorNumber(), buildHtmlLink(getDocumentHandlerUrl(documentHeader.getFinancialDocumentInErrorNumber()), documentHeader.getFinancialDocumentInErrorNumber())));
62              }
63              if (StringUtils.isNotBlank(documentHeader.getCorrectedByDocumentId())) {
64                  extendDocInfoToThreeColumns();
65                  int insertIndex = getNumColumns() + 2;
66                  getDocInfo().remove(insertIndex);
67                  getDocInfo().add(insertIndex, new HeaderField("DataDictionary.FinancialSystemDocumentHeader.attributes.correctedByDocumentId",
68                          documentHeader.getCorrectedByDocumentId(), buildHtmlLink(getDocumentHandlerUrl(documentHeader.getCorrectedByDocumentId()), documentHeader.getCorrectedByDocumentId())));
69  
70  
71              }
72          }
73      }
74  
75      /**
76       * Extends the DocInfo on the form to 3 columns if it currently has less than 3 columns.
77       * If it has exactly 3 or more columns, no action will be taken.
78       */
79      protected void extendDocInfoToThreeColumns() {
80          List<HeaderField> newDocInfo = new ArrayList<HeaderField>();
81          int currentColumns = getNumColumns();
82          int targetColumns = 3;
83          if (getNumColumns() < targetColumns) {
84              int column = 0;
85              for (HeaderField headerField : getDocInfo()) {
86                  if (column + 1 > currentColumns) {
87                      newDocInfo.add(HeaderField.EMPTY_FIELD);
88                      column = (column + 1) % targetColumns;
89                  }
90                  newDocInfo.add(headerField);
91                  column = (column + 1) % targetColumns;
92              }
93              // fill out the final row with empty columns
94              while (newDocInfo.size() % targetColumns != 0) {
95                  newDocInfo.add(HeaderField.EMPTY_FIELD);
96              }
97              setDocInfo(newDocInfo);
98              setNumColumns(3);
99          }
100     }
101 
102     /**
103      * @see org.kuali.rice.kns.web.struts.form.KualiForm#getExtraButtons()
104      *
105      * KRAD Conversion: Customizing the addition of extra buttons
106      */
107     @Override
108     public List<ExtraButton> getExtraButtons() {
109         List<ExtraButton> buttons = super.getExtraButtons();
110         if (getDocumentActions().containsKey(KFSConstants.KFS_ACTION_CAN_ERROR_CORRECT)) {
111             buttons.add(generateErrorCorrectionButton());
112         }
113         return buttons;
114     }
115 
116     private ExtraButton errorCorrectionButton;
117 
118     /**
119      * Generates an ExtraButton which represents the error correction button
120      *
121      * @return an ExtraButton representing an ErrorCorrection button
122      *
123      *  KRAD Conversion: Customizing the error correction button
124      */
125     protected ExtraButton generateErrorCorrectionButton() {
126         if ( errorCorrectionButton == null ) {
127             ExtraButton button = new ExtraButton();
128             button.setExtraButtonAltText("Create error correction document from current document");
129             button.setExtraButtonProperty("methodToCall.correct");
130             button.setExtraButtonSource(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString("kr.externalizable.images.url")+"buttonsmall_errcorr.gif");
131             errorCorrectionButton = button;
132         }
133         return errorCorrectionButton;
134     }
135 
136 
137 }