View Javadoc

1   /*
2    * Copyright 2007 The International Moth Class Association (IMCA)
3    *
4    * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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 net.sf.imca.web.backingbeans;
17  
18  import java.util.Currency;
19  import java.util.Date;
20  
21  import javax.faces.model.SelectItem;
22  
23  import net.sf.imca.model.AssociationBO;
24  import net.sf.imca.model.MembershipTypeBO;
25  import net.sf.imca.model.entities.MembershipEntity;
26  import net.sf.imca.services.CommitteeService;
27  
28  /**
29   * Backing bean for Committee member administration of Membership.
30   *
31   * @author dougculnane
32   */
33  public class CommitteeBean {
34  
35      /**
36       * Reference date.
37       */
38      private Date refDate = new Date();
39  
40      /**
41       * Start date.
42       */
43      private Date startDate = new Date();
44  
45      private String email = "";
46      
47      /**
48       * End date.
49       */
50      private Date endDate = new Date();
51     
52      /**
53       * Membership type text.
54       */
55      private String membershipType = "";
56  
57      /**
58       * Id for the membership type entity.
59       */
60      private long membershipTypeId;
61  
62      /**
63       * User feedback message.
64       */
65      private String userFeedbackMessage = "";
66      
67      private long associationId;
68      
69      private MembershipEntity[] memberList;
70      
71      private String currencyCode;
72      
73      private String paymentExplanation;
74      
75      private String url;
76      
77      MembershipTableModel dataModel = null;
78      
79      private double fee = 0;
80      
81      CommitteeService service = new CommitteeService();
82  
83      public String actionListMembership(){
84          memberList = service.getMembershipList(Utils.getWebUser().getPerson());
85          return Utils.ACTION_SUCCESS;
86      }
87      
88      public String actionSelectAssociation() {
89          AssociationBO association = service.getAssociation(this.associationId);
90          this.paymentExplanation = association.getEntity().getPaymentExplanation();
91          this.url = association.getEntity().getUrl();
92          
93          return Utils.ACTION_SUCCESS;
94      }
95      
96      public String actionSelectMembershipType() {
97          MembershipTypeBO membershipType = service.getMembershipType(this.membershipTypeId);
98          this.membershipType = membershipType.getEntity().getName();
99          this.startDate = membershipType.getEntity().getValidFrom();
100         this.endDate = membershipType.getEntity().getValidTo();
101         this.fee = membershipType.getEntity().getCurrentFee().getAmount();
102         this.currencyCode = membershipType.getEntity().getCurrentFee().getCurrency();
103         this.userFeedbackMessage = "";
104         return Utils.ACTION_SUCCESS;
105     }
106     
107     public String actionAddMembershipType(){
108         
109         service.saveNewMembershipType(
110                 associationId, membershipType, currencyCode, fee, startDate, endDate);
111         userFeedbackMessage = "Data Saved.";
112         
113         return Utils.ACTION_SUCCESS;
114     }
115     
116     public String actionSaveMembershipType(){
117         
118         service.saveMembershipType(membershipTypeId, membershipType, 
119                 currencyCode, fee, startDate, endDate);
120         userFeedbackMessage = "Data Saved.";
121         
122         return Utils.ACTION_SUCCESS;
123     }
124     
125     
126     
127     public String actionConfirmPaidMembershipRequests(){
128         
129         dataModel.actionConfirmPaidMembers();
130         getMembershipRequestsList();
131         userFeedbackMessage = Utils.getMessage("ConfirmPaidMarkedMembershipRequests");
132         return Utils.ACTION_SUCCESS;
133     }
134     
135     public String actionDeleteMembershipRequests(){
136         
137         dataModel.actionDeleteMembers();
138         getMembershipRequestsList();
139         userFeedbackMessage = Utils.getMessage("DeletedMarkedMembershipRequests");
140         return Utils.ACTION_SUCCESS;
141     }
142     
143     public String actionDeleteMembershipType() {
144         if (getMembershipTypeCanBeDeleted()) {
145             service.deleteMembershipTypeEntity(this.membershipTypeId);
146             membershipTypeId = -1;
147         }
148         return Utils.ACTION_SUCCESS;
149     }
150     
151     public boolean getMembershipTypeCanBeDeleted() {
152         return !service.getHasLinkedMemberships(this.membershipTypeId);
153     }
154     
155     
156     public String  actionSaveAssociationData(){
157         service.saveAssociationData(this.associationId, paymentExplanation, url);
158         return actionSelectAssociation();
159     }
160     
161     public String  actionAddMember(){
162         this.userFeedbackMessage = "";
163         if (service.addMember(this.membershipTypeId, this.email)) {
164             userFeedbackMessage = Utils.getMessage("addedMember") + " " + email;
165         } else {
166             userFeedbackMessage = Utils.getMessage("failedtoAddMember") + " " + email;
167         }
168         return Utils.ACTION_SUCCESS;
169     }
170     
171     public String getUserFeedbackMessage() {
172         return userFeedbackMessage;
173     }
174 
175     public void setUserFeedbackMessage(String userFeedbackMessage) {
176         this.userFeedbackMessage = userFeedbackMessage;
177     }
178 
179     public Date getStartDate() {
180         return startDate;
181     }
182 
183     public void setStartDate(Date startDate) {
184         this.startDate = startDate;
185     }
186 
187     public Date getEndDate() {
188         return endDate;
189     }
190 
191     public void setEndDate(Date endDate) {
192         this.endDate = endDate;
193     }
194 
195     public String getMembershipType() {
196         return membershipType;
197     }
198 
199     public void setMembershipType(String membershipType) {
200         this.membershipType = membershipType;
201     }
202 
203     public double getFee() {
204         return fee;
205     }
206 
207     public void setFee(double fee) {
208         this.fee = fee;
209     }
210 
211     public MembershipEntity[] getMemberList() {
212         return memberList;
213     }
214 
215     public void setMemberList(MembershipEntity[] memberList) {
216         this.memberList = memberList;
217     }
218 
219     public SelectItem[] getOfficalImcaAssociationItems() {
220         
221         AssociationBO[] associations = 
222             service.getOficialIMCACommitteeMemberships(Utils.getWebUser().getPerson());
223         
224         SelectItem[] selectItems = new SelectItem[associations.length];
225         
226         for (int i=0; i < selectItems.length; i++) {
227             selectItems[i] = new SelectItem(
228                     associations[i].getEntity().getId(), 
229                     associations[i].getEntity().toString());
230         }
231         return selectItems;
232     } 
233     
234     public SelectItem[] getMembershipTypeItems() {
235         
236         MembershipTypeBO[] membershipTypes = 
237             service.getEditableMembershipTypes(Utils.getWebUser().getPerson());
238         
239         SelectItem[] selectItems = new SelectItem[membershipTypes.length];
240         
241         for (int i=0; i < selectItems.length; i++) {
242             selectItems[i] = new SelectItem(
243                     membershipTypes[i].getEntity().getId(), 
244                     membershipTypes[i].getEntity().toString());
245         }
246         return selectItems;
247     } 
248     
249     public String getAssociationName() {
250         AssociationBO association = service.getAssociation(this.associationId);
251         return association.getName();
252     }
253     
254     public SelectItem[] getAssociationItems() {
255         
256         AssociationBO[] associations = 
257             service.getCommitteeMemberships(Utils.getWebUser().getPerson());
258         
259         SelectItem[] selectItems = new SelectItem[associations.length];
260         
261         for (int i=0; i < selectItems.length; i++) {
262             selectItems[i] = new SelectItem(
263                     associations[i].getEntity().getId(), 
264                     associations[i].getEntity().toString());
265         }
266         return selectItems;
267     } 
268 
269     public long getAssociationId() {
270         return associationId;
271     }
272 
273     public void setAssociationId(long associationId) {
274         this.associationId = associationId;
275     }
276 
277     public String getCurrencyCode() {
278         if (currencyCode == null) {
279             try {
280                 currencyCode = Currency.getInstance(
281                         Utils.getWebAppLocale()).getCurrencyCode();
282             } catch (IllegalArgumentException ilgex) {
283                 currencyCode = "";
284             }
285         }
286         return currencyCode;
287     }
288 
289     public void setCurrencyCode(String currencyCode) {
290         this.currencyCode = currencyCode;
291     }
292     
293     
294     public MembershipTableModel getMembershipRequestsList() {
295         dataModel = new MembershipTableModel();
296         dataModel.setMembershipEntities(service.getMembershipRequestList(
297                     Utils.getWebUser().getPerson()));
298         return dataModel;
299     }
300     
301     public MembershipTableModel getMembershipList() {
302         dataModel = new MembershipTableModel();
303         dataModel.setMembershipEntities(service.getMembershipList(
304                     Utils.getWebUser().getPerson(), refDate));
305         return dataModel;
306     }
307 
308     public Date getRefDate() {
309         return refDate;
310     }
311 
312     public void setRefDate(Date refDate) {
313         this.refDate = refDate;
314     }
315 
316     public String getPaymentExplanation() {
317         return paymentExplanation;
318     }
319 
320     public void setPaymentExplanation(String paymentExplanation) {
321         this.paymentExplanation = paymentExplanation;
322     }
323 
324     public String getUrl() {
325         return url;
326     }
327 
328     public void setUrl(String url) {
329         this.url = url;
330     }
331 
332     public long getMembershipTypeId() {
333         return membershipTypeId;
334     }
335 
336     public void setMembershipTypeId(long membershipTypeId) {
337         this.membershipTypeId = membershipTypeId;
338     }
339 
340     public String getEmail() {
341         return email;
342     }
343 
344     public void setEmail(String email) {
345         this.email = email;
346     }
347 
348     
349 }