1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package jim.sums.register.actions;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.EmailValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
import com.opensymphony.xwork2.validator.annotations.Validation;
import com.opensymphony.xwork2.validator.annotations.ValidatorType;
import java.util.HashSet;
import java.util.Set;
import jim.common.jimaas.struts2.User;
import jim.common.jimaas.struts2.UserAware;
import jim.sums.db.Cohort;
import jim.sums.db.Person;
import jim.sums.db.PersonStatus;
import jim.sums.service.CommonService;
import jim.sums.service.RegisterService;
@Validation()
public class UpdateAction extends ActionSupport implements UserAware {
private User user = null;
private String message;
private Long id;
private String username;
private String forename;
private String surname;
private String password;
private String hemis;
private String orgaName;
private String orgaAddress;
private String orgaActivity;
private String orgaPostcode;
private Set<String> address = new HashSet<String>();
private Set<String> number = new HashSet<String>();
private Set<Integer> title = new HashSet<Integer>();
private String result;
private Set<Cohort> resultCohort = new HashSet<Cohort>();
private PersonStatus status;
private Set<String> suspendedReason = new HashSet<String>();
private Set<String> instigaterReason = new HashSet<String>();
public Set<String> getInstigaterReason() {
return instigaterReason;
}
public void setInstigaterReason(Set<String> instigaterReason) {
this.instigaterReason = instigaterReason;
}
public Set<String> getSuspendedReason() {
return suspendedReason;
}
public void setSuspendedReason(Set<String> suspendedReason) {
this.suspendedReason = suspendedReason;
}
public PersonStatus getStatus() {
return status;
}
public void setStatus(PersonStatus status) {
this.status = status;
}
@Override
public void setUser(User user) {
this.user = user;
}
public User getUser() {
return user;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getHemis() {
return hemis;
}
public void setHemis(String hemis) {
this.hemis = hemis;
}
public String getOrgaActivity() {
return orgaActivity;
}
public void setOrgaActivity(String orgaActivity) {
this.orgaActivity = orgaActivity;
}
public String getOrgaAddress() {
return orgaAddress;
}
public void setOrgaAddress(String orgaAddress) {
this.orgaAddress = orgaAddress;
}
public String getOrgaName() {
return orgaName;
}
public void setOrgaName(String orgaName) {
this.orgaName = orgaName;
}
public String getOrgaPostcode() {
return orgaPostcode;
}
public void setOrgaPostcode(String orgaPostcode) {
this.orgaPostcode = orgaPostcode;
}
public Set<Cohort> getResultCohort() {
return resultCohort;
}
public void setResultCohort(Set<Cohort> resultCohort) {
this.resultCohort = resultCohort;
}
public Set<Integer> getTitle() {
return title;
}
public void setTitle(Set<Integer> title) {
this.title = title;
}
public Set<String> getAddress() {
return address;
}
@EmailValidator(type = ValidatorType.FIELD, message = "You must enter a valid email address.")
public void setAddress(Set<String> address) {
this.address = address;
}
public Set<String> getNumber() {
return number;
}
@RequiredFieldValidator(type = ValidatorType.FIELD, message = "You must enter a phone number.")
public void setNumber(Set<String> number) {
this.number = number;
}
public String getPassword() {
return password;
}
@RequiredFieldValidator(type = ValidatorType.FIELD, message = "You must enter a password.")
public void setPassword(String password) {
this.password = password;
}
public String getForename() {
return forename;
}
@RequiredFieldValidator(type = ValidatorType.FIELD, message = "You must enter a forename.")
public void setForename(String forename) {
this.forename = forename;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getSurname() {
return surname;
}
@RequiredFieldValidator(type = ValidatorType.FIELD, message = "You must enter a surname.")
public void setSurname(String surname) {
this.surname = surname;
}
public String getUsername() {
return username;
}
@RequiredFieldValidator(type = ValidatorType.FIELD, message = "You must enter an username.")
public void setUsername(String username) {
this.username = username;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
@Override
public String execute() throws Exception {
//Default login mechanism is to allow the user in
try {
CommonService cs = new CommonService();
Person p = cs.getPersonById(user.getId());
RegisterService rs = new RegisterService();
this.status = p.getStatus();
if (this.getTitle().isEmpty()) {
rs.updatePerson(this.getId(), this.getForename(), this.getSurname(), this.getUsername(), this.getPassword(), this.getAddress(), this.getNumber());
} else {
this.setResultCohort(rs.getSelectedCohort(this.getTitle()));
rs.updatePerson(this.getId(), this.getForename(), this.getSurname(), this.getUsername(), this.getPassword(), this.getAddress(), this.getNumber(), this.getResultCohort());
}
if (this.getStatus().getName().equals("Student")) {
rs.updateStudent(this.getId(), this.getHemis());
} else if (this.getStatus().getName().equals("External actor")) {
rs.updateOrganisation(this.getId(), this.getOrgaName(), this.getOrgaActivity(), this.getOrgaAddress(), this.getOrgaPostcode());
}
if (!this.getInstigaterReason().isEmpty()) {
rs.updateInstigaterReason(this.getId(), this.getInstigaterReason());
}
if (!this.getSuspendedReason().isEmpty()) {
rs.updateSuspendedReason(this.getId(), this.getSuspendedReason());
}
setMessage("Logged in as " + user.getUsername());
return SUCCESS;
} catch (Exception e) {
this.setResult("EXCEPTION : " + e);
return ERROR;
}
}
} |
Partager