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.module.tem.document.web.struts;
20  
21  import java.util.ArrayList;
22  import java.util.Date;
23  import java.util.HashMap;
24  import java.util.List;
25  import java.util.Map;
26  
27  import javax.servlet.http.HttpServletRequest;
28  
29  import org.apache.commons.lang.StringUtils;
30  import org.apache.log4j.Logger;
31  import org.apache.struts.upload.FormFile;
32  import org.kuali.kfs.module.tem.TemConstants;
33  import org.kuali.kfs.module.tem.businessobject.Attendee;
34  import org.kuali.kfs.module.tem.document.TravelEntertainmentDocument;
35  import org.kuali.kfs.module.tem.document.service.TravelDocumentService;
36  import org.kuali.kfs.module.tem.document.web.bean.TravelEntertainmentMvcWrapperBean;
37  import org.kuali.kfs.sys.KFSConstants;
38  import org.kuali.kfs.sys.context.SpringContext;
39  import org.kuali.rice.kns.web.ui.ExtraButton;
40  
41  public class TravelEntertainmentForm extends TravelFormBase implements TravelEntertainmentMvcWrapperBean {
42  
43      public static Logger LOG = Logger.getLogger(TravelEntertainmentForm.class);
44  
45      private Date startDate;
46      private Date endDate;
47      private boolean canPrintHostCertification;
48      private boolean canUnmask = false;
49  
50      private Attendee newAttendeeLine;
51      private List<Attendee> newAttendeeLines;
52      private FormFile attendeesImportFile;
53  
54      private String attendesTagGroupLabelName = TemConstants.Attendee.ATTENDEES_GROUP_LABEL_NAME;
55  
56      private String travelDocumentIdentifier;
57      private String fromDocumentNumber;
58  
59      public TravelEntertainmentForm() {
60          super();
61  
62          setNewAttendeeLine(new Attendee());
63          List<Attendee> attendee = new ArrayList<Attendee>();
64          attendee.add(new Attendee());
65          setNewAttendeeLines(attendee);
66      }
67  
68      @Override
69      public void populate(final HttpServletRequest request) {
70          super.populate(request);
71      }
72  
73      public Date getStartDate() {
74          return startDate;
75      }
76  
77      public void setStartDate(Date startDate) {
78          this.startDate = startDate;
79      }
80  
81      public Date getEndDate() {
82          return endDate;
83      }
84  
85      public void setEndDate(Date endDate) {
86          this.endDate = endDate;
87      }
88  
89      public TravelEntertainmentDocument getEntertainmentDocument() {
90          return (TravelEntertainmentDocument) getDocument();
91      }
92  
93      @Override
94      protected String getDocumentIdentifierFieldName() {
95          return "travelDocumentIdentifier";
96      }
97  
98      @Override
99      protected String getDefaultDocumentTypeName() {
100         return "ENT";
101     }
102 
103     public String getAttendesTagGroupLabelName() {
104         return attendesTagGroupLabelName;
105     }
106 
107     public void setAttendesTagGroupLabelName(String attendesTagGroupLabelName) {
108         this.attendesTagGroupLabelName = attendesTagGroupLabelName;
109     }
110 
111     protected Map<String, ExtraButton> createButtonsMap() {
112         final HashMap<String, ExtraButton> result = new HashMap<String, ExtraButton>();
113 
114         // New Entertainment button
115         ExtraButton newEntertainmentButton = new ExtraButton();
116         newEntertainmentButton.setExtraButtonProperty("methodToCall.newEntertainment");
117         newEntertainmentButton.setExtraButtonSource("${" + KFSConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_newentertainment.png");
118         newEntertainmentButton.setExtraButtonAltText("New Entertainment");
119 
120         result.put(newEntertainmentButton.getExtraButtonProperty(), newEntertainmentButton);
121 
122         result.putAll(createPaymentExtraButtonMap());
123 
124         return result;
125     }
126 
127     @Override
128     public boolean isDefaultOpenPaymentInfoTab() {
129       if(TemConstants.EntertainmentStatusCodeKeys.AWAIT_ENT_MANAGER.equals(getDocument().getDocumentHeader().getWorkflowDocument().getApplicationDocumentStatus())) {
130           return true;
131       }
132         return super.isDefaultOpenPaymentInfoTab();
133     }
134 
135     @Override
136     public List<ExtraButton> getExtraButtons() {
137         super.getExtraButtons();
138         final Map<String, ExtraButton> buttonsMap = createButtonsMap();
139 
140         LOG.debug("Creating button map");
141         if (!SpringContext.getBean(TravelDocumentService.class).isUnsuccessful(this.getTravelDocument())) {
142             if (getEntertainmentDocument().canPayDVToVendor()) {
143                 extraButtons.add(buttonsMap.get("methodToCall.payDVToVendor"));
144             }
145         }
146 
147         if (getDocumentActions().keySet().contains(TemConstants.TravelAuthorizationActions.CAN_NEW_ENTERTAINMENT)) {
148             extraButtons.add(buttonsMap.get("methodToCall.newEntertainment"));
149         }
150 
151         return extraButtons;
152     }
153 
154     public boolean isCanUnmask() {
155         return canUnmask;
156     }
157 
158     public void setCanUnmask(boolean canUnmask) {
159         this.canUnmask = canUnmask;
160     }
161 
162     @Override
163     public Attendee getNewAttendeeLine() {
164         return newAttendeeLine;
165     }
166 
167     @Override
168     public void setNewAttendeeLine(Attendee newAttendeeLine) {
169         this.newAttendeeLine = newAttendeeLine;
170     }
171 
172     @Override
173     public List<Attendee> getNewAttendeeLines() {
174         return newAttendeeLines;
175     }
176 
177     @Override
178     public void setNewAttendeeLines(List<Attendee> newAttendeeLines) {
179         this.newAttendeeLines = newAttendeeLines;
180     }
181 
182     public FormFile getAttendeesImportFile() {
183         return attendeesImportFile;
184     }
185 
186     public void setAttendeesImportFile(FormFile attendeesImportFile) {
187         this.attendeesImportFile = attendeesImportFile;
188     }
189 
190     public boolean isCanPrintHostCertification() {
191         return getEntertainmentDocument().canShowHostCertification();
192     }
193 
194     public void setCanPrintHostCertification(boolean canPrintHostCertification) {
195         this.canPrintHostCertification = canPrintHostCertification;
196     }
197 
198     public boolean isEventHostandEventNameReadonly() {
199        return !StringUtils.isBlank(getTravelDocumentIdentifier()) && !StringUtils.isBlank(getFromDocumentNumber()) ? true : false;
200     }
201 
202 
203 
204     /**
205      * @see org.kuali.kfs.module.tem.document.web.struts.TravelFormBase#getTravelPaymentFormAction()
206      */
207     @Override
208     public String getTravelPaymentFormAction() {
209         return TemConstants.ENTERTAINMENT_ACTION_NAME;
210     }
211 
212     /**
213      * @return the travel document identifier if it has been set
214      */
215     public String getTravelDocumentIdentifier() {
216         return travelDocumentIdentifier;
217     }
218 
219     /**
220      * Sets the travel document identifier to populate from
221      * @param travelDocumentIdentifier the travel document identifier to populate from
222      */
223     public void setTravelDocumentIdentifier(String travelDocumentIdentifier) {
224         this.travelDocumentIdentifier = travelDocumentIdentifier;
225     }
226 
227     /**
228      * @return the document number this entertainment reimbursement should be built from
229      */
230     public String getFromDocumentNumber() {
231         return fromDocumentNumber;
232     }
233 
234     /**
235      * Sets the document number this entertainment reimbursement should be built from
236      * @param fromDocumentNumber the document number this entertainment reimbursement should be built from
237      */
238     public void setFromDocumentNumber(String fromDocumentNumber) {
239         this.fromDocumentNumber = fromDocumentNumber;
240     }
241 }