001/*
002 * Copyright 2007 The Kuali Foundation
003 * 
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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 */
016package org.kuali.ole.module.purap.businessobject;
017
018import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
019import org.kuali.ole.sys.OLEConstants;
020import org.kuali.ole.sys.context.SpringContext;
021import org.kuali.rice.krad.bo.Note;
022import org.kuali.rice.krad.document.Document;
023import org.kuali.rice.krad.util.ObjectUtils;
024
025import java.sql.Timestamp;
026import java.util.ArrayList;
027import java.util.List;
028
029/**
030 * Purchase Order View Business Object.
031 */
032public class PurchaseOrderView extends AbstractRelatedView {
033
034    private Boolean purchaseOrderCurrentIndicator;
035    private String recurringPaymentTypeCode;
036    private String vendorChoiceCode;
037    private Timestamp recurringPaymentEndDate;
038    private Timestamp purchaseOrderInitialOpenTimestamp;
039
040    private List<Note> notes;
041
042    public boolean isPurchaseOrderCurrentIndicator() {
043        return purchaseOrderCurrentIndicator;
044    }
045
046    public boolean getPurchaseOrderCurrentIndicator() {
047        return purchaseOrderCurrentIndicator;
048    }
049
050    public void setPurchaseOrderCurrentIndicator(boolean purchaseOrderCurrentIndicator) {
051        this.purchaseOrderCurrentIndicator = purchaseOrderCurrentIndicator;
052    }
053
054    public String getRecurringPaymentTypeCode() {
055        return recurringPaymentTypeCode;
056    }
057
058    public void setRecurringPaymentTypeCode(String recurringPaymentTypeCode) {
059        this.recurringPaymentTypeCode = recurringPaymentTypeCode;
060    }
061
062    public String getVendorChoiceCode() {
063        return vendorChoiceCode;
064    }
065
066    public void setVendorChoiceCode(String vendorChoiceCode) {
067        this.vendorChoiceCode = vendorChoiceCode;
068    }
069
070    public Timestamp getRecurringPaymentEndDate() {
071        return recurringPaymentEndDate;
072    }
073
074    public void setRecurringPaymentEndDate(Timestamp recurringPaymentEndDate) {
075        this.recurringPaymentEndDate = recurringPaymentEndDate;
076    }
077
078    public Timestamp getPurchaseOrderInitialOpenTimestamp() {
079        return purchaseOrderInitialOpenTimestamp;
080    }
081
082    public void setPurchaseOrderInitialOpenTimestamp(Timestamp purchaseOrderInitialOpenTimestamp) {
083        this.purchaseOrderInitialOpenTimestamp = purchaseOrderInitialOpenTimestamp;
084    }
085
086    /**
087     * @see org.kuali.ole.module.purap.businessobject.AbstractRelatedView#getNotes()
088     */
089    @Override
090    public List<Note> getNotes() {
091        if (this.isPurchaseOrderCurrentIndicator()) {
092            if (notes == null) {
093                notes = new ArrayList<Note>();
094                List<Note> tmpNotes = SpringContext.getBean(PurchaseOrderService.class).getPurchaseOrderNotes(this.getPurapDocumentIdentifier());
095                //FIXME if NoteService returns notes in descending order (newer ones first) then remove the following
096                // reverse the order of notes retrieved so that newest note is in the front
097                for (int i = tmpNotes.size() - 1; i >= 0; i--) {
098                    Note note = tmpNotes.get(i);
099                    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}