View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.document.web.struts;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.sys.OLEConstants;
23  import org.kuali.ole.sys.businessobject.FinancialSystemDocumentHeader;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.rice.core.api.config.property.ConfigurationService;
26  import org.kuali.rice.kew.api.WorkflowDocument;
27  import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
28  import org.kuali.rice.kns.web.ui.ExtraButton;
29  import org.kuali.rice.kns.web.ui.HeaderField;
30  
31  /**
32   * This class is a Financial System specific transactional document form base
33   */
34  public class FinancialSystemTransactionalDocumentFormBase extends KualiTransactionalDocumentFormBase {
35  
36      /**
37       * Constructs a FinancialSystemTransactionalDocumentFormBase.java.
38       */
39      public FinancialSystemTransactionalDocumentFormBase() {
40          super();
41      }
42  
43      /**
44       * @see org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase#populateHeaderFields(org.kuali.rice.kew.api.WorkflowDocument)
45  
46       * KRAD Conversion: Customizing the header fields - Uses data dictionary
47       */
48      @Override
49      public void populateHeaderFields(WorkflowDocument workflowDocument) {
50          super.populateHeaderFields(workflowDocument);
51          if (getDocument().getDocumentHeader() instanceof FinancialSystemDocumentHeader) {
52              FinancialSystemDocumentHeader documentHeader = (FinancialSystemDocumentHeader)getDocument().getDocumentHeader();
53              if (StringUtils.isNotBlank(documentHeader.getFinancialDocumentInErrorNumber())) {
54                  extendDocInfoToThreeColumns();
55                  int insertIndex = 2;
56                  getDocInfo().remove(insertIndex);
57                  getDocInfo().add(insertIndex, new HeaderField("DataDictionary.FinancialSystemDocumentHeader.attributes.financialDocumentInErrorNumber", 
58                          documentHeader.getFinancialDocumentInErrorNumber(), buildHtmlLink(getDocumentHandlerUrl(documentHeader.getFinancialDocumentInErrorNumber()), documentHeader.getFinancialDocumentInErrorNumber())));
59              }
60              if (StringUtils.isNotBlank(documentHeader.getCorrectedByDocumentId())) {
61                  extendDocInfoToThreeColumns();
62                  int insertIndex = getNumColumns() + 2;
63                  getDocInfo().remove(insertIndex);
64                  getDocInfo().add(insertIndex, new HeaderField("DataDictionary.FinancialSystemDocumentHeader.attributes.correctedByDocumentId", 
65                          documentHeader.getCorrectedByDocumentId(), buildHtmlLink(getDocumentHandlerUrl(documentHeader.getCorrectedByDocumentId()), documentHeader.getCorrectedByDocumentId())));
66            
67              
68              }
69          }
70      }
71      
72      /**
73       * Extends the DocInfo on the form to 3 columns if it currently has less than 3 columns.
74       * If it has exactly 3 or more columns, no action will be taken.
75       */
76      protected void extendDocInfoToThreeColumns() {
77          List<HeaderField> newDocInfo = new ArrayList<HeaderField>();
78          int currentColumns = getNumColumns();
79          int targetColumns = 3;
80          if (getNumColumns() < targetColumns) {
81              int column = 0;
82              for (HeaderField headerField : getDocInfo()) {
83                  if (column + 1 > currentColumns) {
84                      newDocInfo.add(HeaderField.EMPTY_FIELD);
85                      column = (column + 1) % targetColumns;
86                  }
87                  newDocInfo.add(headerField);
88                  column = (column + 1) % targetColumns;
89              }
90              // fill out the final row with empty columns
91              while (newDocInfo.size() % targetColumns != 0) {
92                  newDocInfo.add(HeaderField.EMPTY_FIELD);
93              }
94              setDocInfo(newDocInfo);
95              setNumColumns(3);
96          }
97      }
98  
99      /**
100      * @see org.kuali.rice.kns.web.struts.form.KualiForm#getExtraButtons()
101      * 
102      * KRAD Conversion: Customizing the addition of extra buttons
103      */
104     @Override
105     public List<ExtraButton> getExtraButtons() {
106         List<ExtraButton> buttons = super.getExtraButtons();
107         if (getDocumentActions().containsKey(OLEConstants.KFS_ACTION_CAN_ERROR_CORRECT)) {
108             buttons.add(generateErrorCorrectionButton());
109         }
110         return buttons;
111     }
112     
113     private ExtraButton errorCorrectionButton;
114     
115     /**
116      * Generates an ExtraButton which represents the error correction button
117      * 
118      * @return an ExtraButton representing an ErrorCorrection button
119      * 
120      *  KRAD Conversion: Customizing the error correction button
121      */
122     protected ExtraButton generateErrorCorrectionButton() {
123         if ( errorCorrectionButton == null ) {
124             ExtraButton button = new ExtraButton();
125             button.setExtraButtonAltText("Create error correction document from current document");
126             button.setExtraButtonProperty("methodToCall.correct");
127             button.setExtraButtonSource(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString("kr.externalizable.images.url")+"buttonsmall_errcorr.gif");
128             errorCorrectionButton = button;
129         }
130         return errorCorrectionButton;
131     }
132 }