View Javadoc
1   /*
2    * Copyright 2007 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.module.purap.businessobject;
17  
18  import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
19  import org.kuali.ole.sys.OLEConstants;
20  import org.kuali.ole.sys.context.SpringContext;
21  import org.kuali.rice.krad.bo.Note;
22  import org.kuali.rice.krad.document.Document;
23  import org.kuali.rice.krad.util.ObjectUtils;
24  
25  import java.sql.Timestamp;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  /**
30   * Purchase Order View Business Object.
31   */
32  public class PurchaseOrderView extends AbstractRelatedView {
33  
34      private Boolean purchaseOrderCurrentIndicator;
35      private String recurringPaymentTypeCode;
36      private String vendorChoiceCode;
37      private Timestamp recurringPaymentEndDate;
38      private Timestamp purchaseOrderInitialOpenTimestamp;
39  
40      private List<Note> notes;
41  
42      public boolean isPurchaseOrderCurrentIndicator() {
43          return purchaseOrderCurrentIndicator;
44      }
45  
46      public boolean getPurchaseOrderCurrentIndicator() {
47          return purchaseOrderCurrentIndicator;
48      }
49  
50      public void setPurchaseOrderCurrentIndicator(boolean purchaseOrderCurrentIndicator) {
51          this.purchaseOrderCurrentIndicator = purchaseOrderCurrentIndicator;
52      }
53  
54      public String getRecurringPaymentTypeCode() {
55          return recurringPaymentTypeCode;
56      }
57  
58      public void setRecurringPaymentTypeCode(String recurringPaymentTypeCode) {
59          this.recurringPaymentTypeCode = recurringPaymentTypeCode;
60      }
61  
62      public String getVendorChoiceCode() {
63          return vendorChoiceCode;
64      }
65  
66      public void setVendorChoiceCode(String vendorChoiceCode) {
67          this.vendorChoiceCode = vendorChoiceCode;
68      }
69  
70      public Timestamp getRecurringPaymentEndDate() {
71          return recurringPaymentEndDate;
72      }
73  
74      public void setRecurringPaymentEndDate(Timestamp recurringPaymentEndDate) {
75          this.recurringPaymentEndDate = recurringPaymentEndDate;
76      }
77  
78      public Timestamp getPurchaseOrderInitialOpenTimestamp() {
79          return purchaseOrderInitialOpenTimestamp;
80      }
81  
82      public void setPurchaseOrderInitialOpenTimestamp(Timestamp purchaseOrderInitialOpenTimestamp) {
83          this.purchaseOrderInitialOpenTimestamp = purchaseOrderInitialOpenTimestamp;
84      }
85  
86      /**
87       * @see org.kuali.ole.module.purap.businessobject.AbstractRelatedView#getNotes()
88       */
89      @Override
90      public List<Note> getNotes() {
91          if (this.isPurchaseOrderCurrentIndicator()) {
92              if (notes == null) {
93                  notes = new ArrayList<Note>();
94                  List<Note> tmpNotes = SpringContext.getBean(PurchaseOrderService.class).getPurchaseOrderNotes(this.getPurapDocumentIdentifier());
95                  //FIXME if NoteService returns notes in descending order (newer ones first) then remove the following
96                  // reverse the order of notes retrieved so that newest note is in the front
97                  for (int i = tmpNotes.size() - 1; i >= 0; i--) {
98                      Note note = tmpNotes.get(i);
99                      notes.add(note);
100                 }
101             }
102         } else {
103             notes = null;
104         }
105         return notes;
106     }
107 
108     /**
109      * The next four methods are overridden but shouldn't be! If they aren't overridden, they don't show up in the tag, not sure why at
110      * this point! (AAP)
111      *
112      * @see org.kuali.ole.module.purap.businessobject.AbstractRelatedView#getPurapDocumentIdentifier()
113      */
114     @Override
115     public Integer getPurapDocumentIdentifier() {
116         return super.getPurapDocumentIdentifier();
117     }
118 
119     @Override
120     public String getDocumentIdentifierString() {
121         return super.getDocumentIdentifierString();
122     }
123 
124     /**
125      * @see org.kuali.ole.module.purap.businessobject.AbstractRelatedView#getDocumentNumber()
126      */
127     @Override
128     public String getDocumentNumber() {
129         return super.getDocumentNumber();
130     }
131 
132     /**
133      * @see org.kuali.ole.module.purap.businessobject.AbstractRelatedView#getUrl()
134      */
135     @Override
136     public String getUrl() {
137         return super.getUrl();
138     }
139 
140     /**
141      * Checks whether the purchase order view needs a warning to be displayed, i.e. it never has been opened.
142      *
143      * @return true if the purchase order needs a warning; false otherwise.
144      */
145     public boolean getNeedWarning() {
146         return getPurchaseOrderInitialOpenTimestamp() == null;
147     }
148 
149     /**
150      * @see org.kuali.ole.module.purap.businessobject.AbstractRelatedView#getDocumentTypeName()
151      */
152     @Override
153     public String getDocumentTypeName() {
154         Document document = findDocument(this.getDocumentNumber());
155         if (ObjectUtils.isNotNull(document)) {
156             return document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName();
157         }
158 
159         return OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER;
160     }
161 }