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.businessobject;
20  
21  import java.sql.Date;
22  import java.sql.Timestamp;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.kuali.kfs.sys.KFSConstants;
26  import org.kuali.kfs.sys.context.SpringContext;
27  import org.kuali.rice.core.api.util.type.KualiDecimal;
28  import org.kuali.rice.kew.api.WorkflowDocument;
29  import org.kuali.rice.kew.api.exception.WorkflowException;
30  import org.kuali.rice.krad.bo.DocumentHeader;
31  import org.kuali.rice.krad.service.BusinessObjectService;
32  import org.kuali.rice.krad.util.GlobalVariables;
33  import org.kuali.rice.krad.workflow.service.WorkflowDocumentService;
34  
35  /**
36   * This class is a custom {@link DocumentHeader} class used by KFS to facilitate custom data fields and a few UI fields
37   */
38  public class FinancialSystemDocumentHeader extends DocumentHeader {
39  
40      protected KualiDecimal financialDocumentTotalAmount;
41      protected String correctedByDocumentId;
42      protected String financialDocumentInErrorNumber;
43      protected String financialDocumentStatusCode;
44      protected String workflowDocumentStatusCode;
45      protected String applicationDocumentStatus;
46      protected String initiatorPrincipalId;
47      protected String workflowDocumentTypeName;
48      protected Timestamp workflowCreateDate;
49  
50      /**
51       * Constructor - creates empty instances of dependent objects
52       *
53       */
54      public FinancialSystemDocumentHeader() {
55          super();
56          financialDocumentStatusCode = KFSConstants.DocumentStatusCodes.INITIATED;
57      }
58  
59      /**
60       * Gets the financialDocumentTotalAmount attribute.
61       * @return Returns the financialDocumentTotalAmount.
62       */
63      public KualiDecimal getFinancialDocumentTotalAmount() {
64          return financialDocumentTotalAmount;
65      }
66  
67      /**
68       * Sets the financialDocumentTotalAmount attribute value.
69       * @param financialDocumentTotalAmount The financialDocumentTotalAmount to set.
70       */
71      public void setFinancialDocumentTotalAmount(KualiDecimal financialDocumentTotalAmount) {
72          this.financialDocumentTotalAmount = financialDocumentTotalAmount;
73      }
74  
75      /**
76       * Gets the correctedByDocumentId attribute.
77       * @return Returns the correctedByDocumentId.
78       */
79      public String getCorrectedByDocumentId() {
80          return correctedByDocumentId;
81      }
82  
83      /**
84       * Sets the correctedByDocumentId attribute value.
85       * @param correctedByDocumentId The correctedByDocumentId to set.
86       */
87      public void setCorrectedByDocumentId(String correctedByDocumentId) {
88          this.correctedByDocumentId = correctedByDocumentId;
89      }
90  
91      /**
92       * Gets the financialDocumentInErrorNumber attribute.
93       * @return Returns the financialDocumentInErrorNumber.
94       */
95      public String getFinancialDocumentInErrorNumber() {
96          return financialDocumentInErrorNumber;
97      }
98  
99      /**
100      * Sets the financialDocumentInErrorNumber attribute value.
101      * @param financialDocumentInErrorNumber The financialDocumentInErrorNumber to set.
102      */
103     public void setFinancialDocumentInErrorNumber(String financialDocumentInErrorNumber) {
104         this.financialDocumentInErrorNumber = financialDocumentInErrorNumber;
105     }
106 
107     /**
108      * Gets the financialDocumentStatusCode attribute.
109      * @return Returns the financialDocumentStatusCode.
110      */
111     public String getFinancialDocumentStatusCode() {
112         return financialDocumentStatusCode;
113     }
114 
115     /**
116      * Sets the financialDocumentStatusCode attribute value.
117      * @param financialDocumentStatusCode The financialDocumentStatusCode to set.
118      */
119     public void setFinancialDocumentStatusCode(String financialDocumentStatusCode) {
120         this.financialDocumentStatusCode = financialDocumentStatusCode;
121     }
122 
123     public String getWorkflowDocumentStatusCode() {
124         return workflowDocumentStatusCode;
125     }
126 
127     public void setWorkflowDocumentStatusCode(String workflowDocumentStatusCode) {
128         this.workflowDocumentStatusCode = workflowDocumentStatusCode;
129     }
130 
131     public String getInitiatorPrincipalId() {
132         return initiatorPrincipalId;
133     }
134 
135     public void setInitiatorPrincipalId(String initiatorPrincipalId) {
136         this.initiatorPrincipalId = initiatorPrincipalId;
137     }
138 
139     public String getWorkflowDocumentTypeName() {
140         return workflowDocumentTypeName;
141     }
142 
143     public void setWorkflowDocumentTypeName(String workflowDocumentTypeName) {
144         this.workflowDocumentTypeName = workflowDocumentTypeName;
145     }
146 
147     /**
148      * Gets the documentFinalDate attribute.
149      * @return Returns the documentFinalDate.
150      */
151     public Date getDocumentFinalDate() {
152         WorkflowDocument workflowDoc = this.getWorkflowDocument();
153         if (workflowDoc == null || (workflowDoc.getDateFinalized() == null)) {
154             return null;
155         }
156         return  new java.sql.Date(workflowDoc.getDateFinalized().getMillis());
157     }
158 
159     /**
160      * Gets the applicationDocumentStatus attribute.
161      *
162      * @return Returns the applicationDocumentStatus
163      */
164 
165     public String getApplicationDocumentStatus() {
166         return applicationDocumentStatus;
167     }
168 
169     /**
170      * Sets the applicationDocumentStatus attribute.
171      *
172      * @param applicationDocumentStatus The applicationDocumentStatus to set.
173      */
174     public void setApplicationDocumentStatus(String applicationDocumentStatus) {
175         WorkflowDocument document = getWorkflowDocument();
176 
177         document.setApplicationDocumentStatus(applicationDocumentStatus);
178         this.applicationDocumentStatus = applicationDocumentStatus;
179     }
180 
181     /**
182      * method to retrieve the workflow document for the given documentHeader.
183      *
184      * @return workflowDocument
185      */
186     @Override
187     public WorkflowDocument getWorkflowDocument() {
188 
189         WorkflowDocument workflowDocument = null;
190 
191         if (hasWorkflowDocument()) {
192             workflowDocument = super.getWorkflowDocument();
193         }
194 
195         try {
196             if (workflowDocument != null) {
197                 return workflowDocument;
198             }
199             if ( StringUtils.isNotBlank(getDocumentNumber()) ) {
200                 workflowDocument = SpringContext.getBean(WorkflowDocumentService.class).loadWorkflowDocument(getDocumentNumber(), GlobalVariables.getUserSession().getPerson());
201             } else {
202                 throw new RuntimeException("Document number is blank/null.  Unable to load a WorkflowDocument" );
203             }
204         }
205         catch (WorkflowException we) {
206             throw new RuntimeException("Unable to load a WorkflowDocument object for " + getDocumentNumber(), we);
207         }
208 
209         return workflowDocument;
210     }
211 
212     /**
213      * Updates status of this document and saves the workflow data
214      *
215      * @param applicationDocumentStatus is the app doc status to save
216      * @throws WorkflowException
217      */
218     public void updateAndSaveAppDocStatus(String applicationDocumentStatus) throws WorkflowException {
219        setApplicationDocumentStatus(applicationDocumentStatus);
220        SpringContext.getBean(WorkflowDocumentService.class).saveRoutingData(getWorkflowDocument());
221        SpringContext.getBean(BusinessObjectService.class).save(this);
222     }
223 
224     public Timestamp getWorkflowCreateDate() {
225         return workflowCreateDate;
226     }
227 
228     public void setWorkflowCreateDate(Timestamp workflowCreateDate) {
229         this.workflowCreateDate = workflowCreateDate;
230     }
231 }