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.HashMap;
19  import java.util.HashSet;
20  import java.util.List;
21  import java.util.Vector;
22  
23  import javax.faces.context.FacesContext;
24  
25  import net.sf.imca.model.MembershipBO;
26  import net.sf.imca.model.PersonBO;
27  import net.sf.imca.model.entities.PersonEntity;
28  import net.sf.imca.model.exceptions.DataCheckingException;
29  import net.sf.imca.services.EditDataService;
30  import net.sf.imca.services.JoinImcaService;
31  
32  /**
33   * Backing bean for the use case where the user edits their profile data.
34   *
35   * @author dougculnane
36   */
37  public class MyDataBean {
38      
39      private PersonEntity personEntity = 
40          Utils.getWebUser().getPerson().getEntity();
41  
42      private String password = "";
43      
44      private String search = "";
45      
46      private List<PersonBO> foundPeopleList = null;
47  
48      /**
49       * User feedback message.
50       */
51      private String userFeedbackMessage = "";
52      
53      private String confirmPassword = "";
54      
55      
56      public void actionSave() {
57          
58          EditDataService service = new EditDataService();
59          try {
60              service.saveMyData(personEntity, password, confirmPassword);
61              userFeedbackMessage = "Data Saved";
62          } catch (DataCheckingException e) {
63              userFeedbackMessage = e.getMessage();
64          }
65          
66          // Set web application locale.
67          FacesContext context = FacesContext.getCurrentInstance();
68          context.getViewRoot().setLocale(
69                  Utils.getWebUser().getPerson().getLocale());
70      }
71      
72      
73      @SuppressWarnings("unchecked")
74      public void actionSearch() {
75          
76          EditDataService service = new EditDataService();
77          List<PersonEntity> list = service.search("Person", search);
78          
79          foundPeopleList = new Vector<PersonBO>();
80          for (int i=0; i < list.size(); i++) {
81              foundPeopleList.add(new PersonBO(list.get(i)));
82          }
83          
84          userFeedbackMessage = "Found " + foundPeopleList.size() + " results";
85          
86      }
87      
88      public List<PersonBO>  getFoundPeople() {
89          if (foundPeopleList == null) {
90              return new Vector<PersonBO>();
91          } else {
92              return foundPeopleList;
93          }
94      }
95      
96      public String getPassword() {
97          return password;
98      }
99  
100     public void setPassword(String password) {
101         this.password = password;
102     }
103 
104     public String getUserFeedbackMessage() {
105         return userFeedbackMessage;
106     }
107 
108     public void setUserFeedbackMessage(String userFeedbackMessage) {
109         this.userFeedbackMessage = userFeedbackMessage;
110     }
111 
112     public String getConfirmPassword() {
113         return confirmPassword;
114     }
115 
116     public void setConfirmPassword(String confirmPassword) {
117         this.confirmPassword = confirmPassword;
118     }
119 
120     public PersonEntity getPersonEntity() {
121         return personEntity;
122     }
123 
124     public void setPersonEntity(PersonEntity personEntity) {
125         this.personEntity = personEntity;
126     }
127     
128     public MembershipBO[] getImcaMemberships(){
129         JoinImcaService service = new JoinImcaService();
130         return service.getImcaMemberships(Utils.getWebUser().getPerson());
131     }
132     
133     public boolean getActiveMember(){
134         JoinImcaService service = new JoinImcaService();
135         return service.getActiveMember(Utils.getWebUser().getPerson());
136     }
137 
138 
139     public String getSearch() {
140         return search;
141     }
142 
143 
144     public void setSearch(String search) {
145         this.search = search;
146     }
147     
148 }