*
* @param actEvent contains information about the event that triggers the execution of this operation
*/
public void UserRegistration(ActionEvent actEvent) {
RequestContext ctx = RequestContext.getCurrentInstance();
FacesMessage msg = null;
boolean bIsRegistered = false;
try {
UserProfile profile = getNewUser();
if (!profile.getChangePin().getNewPin().equals(profile.getChangePin().getRetryPin())) {
bIsRegistered = false;
msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Password mismatch",
"Please make sure that your re-type your pin correctly!");
} else {
profile.getProfileData().setPassword(profile.getChangePin().getNewPin());
CustomerDTO _customerDTO = _customerWebService.getCustomerServiceImplPort().registerCustomer(
profile.getProfileData());
if (_customerDTO.getReturncode() == 0) {
bIsRegistered = true;
AddressDTO defaultAdr =_customerWebService.getCustomerServiceImplPort().maintainAddress(_customerDTO, profile.getBillingAddress());
if (defaultAdr.getReturncode() != 0) {
msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Profile Data missing",
"Could not store your billing address. Please check the data!");
SystemController.redirectUrl(ctx, "userprofile");
}
defaultAdr = _customerWebService.getCustomerServiceImplPort().maintainAddress(_customerDTO, profile.getShippingAddress());
if (defaultAdr.getReturncode() != 0) {
msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Profile Data missing",
"Could not store your shipping address. Please check the data!");
SystemController.redirectUrl(ctx, "userprofile");
}
if (msg == null)
msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", _customerDTO.getUserName());
} else {
bIsRegistered = false;
msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Registration failed!", _customerDTO.getMessage());
}
if (bIsRegistered) {
_loggedOnUser = getUserProfile(_customerDTO);
_newUser = null;
} else {
_loggedOnUser = null;
}
}
} catch (Exception ex) {
bIsRegistered = false;
msg = new FacesMessage(FacesMessage.SEVERITY_FATAL, "Error communicating with customer web service!",
String.format("Unable to access customer web service at %s: %s",
_customerWebService.getWSDLDocumentLocation(),
ex.getMessage()));
}
if (msg != null)
FacesContext.getCurrentInstance().addMessage(null, msg);
ctx.addCallbackParam("registered", bIsRegistered);
}