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
|
public class AlertingForm extends ActionForm implements Serializable {
private static final long serialVersionUID = 1L;
private static Log log = LogFactory.getLog(AlertingForm.class);
private boolean contactToValidate = false; //vrai si contact est à valider
private String contact="";
private boolean advertisingToValidate = false;
private String advertising="";
private boolean startHourToValidate = false;
private String startHour="";
private boolean stopHourToValidate = false;
private String stopHour="";
private boolean momentInDayToValidate = false;
private String momentInDay="";
private boolean frequencyToValidate = false;
private String frequency="";
private boolean phoneNumberToValidate = false;
private String phoneNumber="";
/**
* init du formulaire
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
/* Retrieve from session or from server the last user's preferences */
UserServicePreferences pref = null;
if (request.getAttribute("contact") != null) {
this.contact = "true";
log.debug("The contact field is activated.");
}
if (request.getAttribute("advertising") != null) {
this.advertising = "true";
log.debug("The advertising field is activated.");
}
try {
if(Boolean.parseBoolean(this.contact)) {
pref = AlertingUserInfoRetriever.getUsersPreferencesByService(request,
AlertingServiceType.CONTACT_ALERTING);
//Verification des anciennes preferences avec les nouvelles
} else if (Boolean.parseBoolean(this.advertising)) {
pref = AlertingUserInfoRetriever.getUsersPreferencesByService(request,
AlertingServiceType.ADVERTISING_ALERTING);
}
} catch (AlertingException e) {
// Nothing to do, the user's preferences wont be initialized.
log.error("Unable to initialize form " + e, e);
}
/**
* if pref == null maybe is because the user is not subscribed yet.
*/
if (pref != null) {
this.startHour = pref.getStartHour();
this.stopHour = pref.getStopHour();
this.momentInDay = pref.getMomentInDay();
this.frequency = pref.getFrequency();
}
if (request.getAttribute("phoneNumber") != null) {
this.phoneNumber = Boolean.toString((Boolean)request.getAttribute("phoneNumber"));
}
log.debug("reset : contact="+this.contact+" advertising="+this.advertising+" startHour="+this.startHour+ " stopHour="+this.stopHour+" frequency="+this.frequency);
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
log.debug("validate : " +
"contact="+this.contact+
"advertising="+this.advertising+
" startHour="+this.startHour+
" stopHour="+this.stopHour+
" frequency="+this.frequency);
ActionErrors errors=new ActionErrors();
//si les champs contact et advertising sont présent : un des 2 doit etre choisi
if(contactToValidate && advertisingToValidate){
//erreur si les deux sont à non
if(!Boolean.parseBoolean(contact) && !Boolean.parseBoolean(advertising)){
ActionMessage newError = new ActionMessage("error.alerts.contactAdvertising.allfalse");
errors.add(ActionMessages.GLOBAL_MESSAGE, newError);
errors=new ActionErrors();
return errors;
}
}
//si les champs startHour et stopHour sont à valider
if(startHourToValidate && stopHourToValidate){
if(startHour.equals("") || stopHour.equals("")){
ActionMessage newError =
new ActionMessage("error.alerts.periodicity.badValue");
errors.add(ActionMessages.GLOBAL_MESSAGE, newError);
return errors;
}
}
//si le champs momentInDay est à valider
if(momentInDayToValidate){
if(momentInDay==null || momentInDay.equals("")){
ActionMessage newError = new ActionMessage("error.alert.form.momentInDay.required");
errors.add("global", newError);
errors=new ActionErrors();
return errors;
}
}
//si le champs fréquence est à valider
if(frequencyToValidate){
if(frequency==null || frequency.equals("")){
ActionMessage newError = new ActionMessage("error.alert.form.frequency.required");
errors.add("global", newError);
return errors;
}
}
//si le numéro de téléphone est a valider
if(phoneNumberToValidate){
//phone Number
if(phoneNumber==null || phoneNumber.equals("")){
ActionMessage newError = new ActionMessage("error.alert.form.phoneNumber.required");
errors.add("global", newError);
return errors;
}else if(!phoneNumberGoodFormat(phoneNumber)){
ActionMessage newError = new ActionMessage("error.alert.form.phoneNumber.notValid");
errors.add("global", newError);
}
}
log.debug("contactToValidate : "+contactToValidate+" contact : "+contact+" advertisingToValidate : "+advertisingToValidate+" advertising : "+advertising);
return null;
}
/**
* vrrai si num de tel valide
* @param phoneNumber
* @return
*/
public boolean phoneNumberGoodFormat(String phoneNumber){
Pattern pattern = Pattern.compile("^06\\d{8}$");
Matcher matcher = pattern.matcher(phoneNumber);
return matcher.find();
}
public boolean isContact() {
return Boolean.getBoolean(contact);
}
public String getContact(){
return contact;
}
public void setContact(String contact) {
log.error("setContact="+contact);
if(contact.equalsIgnoreCase("oui")){
this.contact="true";
}else{
this.contact="false";
}
//this.contact = contact;
}
public boolean isAdvertising() {
return Boolean.getBoolean(advertising);
}
public String getAdvertising() {
return advertising;
}
public void setAdvertising(String advertising) {
log.error("setAdvertising="+advertising);
if(advertising.equalsIgnoreCase("oui")){
this.advertising="true";
}else{
this.advertising="false";
}
this.advertising = advertising;
}
public String getFrequency() {
return frequency;
}
public void setFrequency(String freq) {
this.frequency = freq;
}
public String getStartHour() {
return startHour;
}
public void setStartHour(String start) {
this.startHour = start;
}
public String getStopHour() {
return stopHour;
}
public void setStopHour(String stop) {
this.stopHour = stop;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getMomentInDay() {
return momentInDay;
}
public void setMomentInDay(String momentInDay) {
this.momentInDay = momentInDay;
} |
Partager