📄 registeruseraction.java
字号:
package com.sush.webstore.store.web.struts;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.sush.webstore.store.domain.IAddress;
import com.sush.webstore.store.domain.ICart;
import com.sush.webstore.store.domain.IOrder;
import com.sush.webstore.store.domain.IUserAccount;
import com.sush.webstore.store.domain.IWebStoreFacade;
import com.sush.webstore.store.domain.constants.IAddressType;
import com.sush.webstore.store.domain.facade.WebStorePOJO;
public class RegisterUserAction {
private String address;
private ICart cart;
private String city;
private String confirmPassword;
private String country;
private String firstName;
private String lastName;
private String password;
private String phoneNumber;
private String state;
private IUserAccount userAccount;
private String userName;
private IWebStoreFacade webStore = new WebStorePOJO();
private String zip;
private boolean createCart() {
Map session = (Map) ActionContext.getContext().get("session");
if (session == null) {
return false;
}
cart = webStore.createCart();
session.put("cart", cart);
return true;
}
public String execute() {
if (!validate())
return "reenter";
userAccount = webStore.createUserAccount();
if (userAccount == null)
return "error";
Map session = (Map) ActionContext.getContext().get("session");
if (session == null) {
return "error";
}
session.put("userAccount", userAccount);
IAddress mailingAddress = webStore.createAddress();
mailingAddress.setAddress(address);
mailingAddress.setCity(city);
mailingAddress.setCountry(country);
mailingAddress.setState(state);
mailingAddress.setType(IAddressType.BILLING);
mailingAddress.setZip(zip);
mailingAddress.setPhoneNumber(phoneNumber);
userAccount.setIAddress(mailingAddress);
userAccount.setFirstName(firstName);
userAccount.setLastName(lastName);
userAccount.setPassword(password);
userAccount.setUserName(userName);
webStore.addUserAccount(userAccount);
if (getCartFromSession()) {
return (!getOrderFromSession()) ? "success" : "showBillingDetails";
} else if (createCart()) {
return "success";
} else
return "error";
}
/**
* @return the address
*/
public String getAddress() {
return address;
}
/**
* @return the cart
*/
public ICart getCart() {
return cart;
}
private boolean getCartFromSession() {
Map session = (Map) ActionContext.getContext().get("session");
if (session == null) {
return false;
}
cart = (ICart) session.get("cart");
return (cart == null) ? false : true;
}
/**
* @return the city
*/
public String getCity() {
return city;
}
/**
* @return the confirmPassword
*/
public String getConfirmPassword() {
return confirmPassword;
}
/**
* @return the country
*/
public String getCountry() {
return country;
}
/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
private boolean getOrderFromSession() {
Map session = (Map) ActionContext.getContext().get("session");
if (session == null) {
return false;
}
IOrder order = (IOrder) session.get("order");
return (order == null) ? false : true;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @return the phoneNumber
*/
public String getPhoneNumber() {
return phoneNumber;
}
/**
* @return the state
*/
public String getState() {
return state;
}
/**
* @return the userAccount
*/
public IUserAccount getUserAccount() {
return userAccount;
}
/**
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* @return the webStore
*/
public IWebStoreFacade getWebStore() {
return webStore;
}
/**
* @return the zip
*/
public String getZip() {
return zip;
}
/**
* @param address
* the address to set
*/
public void setAddress(String address) {
this.address = address;
}
/**
* @param cart
* the cart to set
*/
public void setCart(ICart cart) {
this.cart = cart;
}
/**
* @param city
* the city to set
*/
public void setCity(String city) {
this.city = city;
}
/**
* @param confirmPassword
* the confirmPassword to set
*/
public void setConfirmPassword(String confirmPassword) {
this.confirmPassword = confirmPassword;
}
/**
* @param country
* the country to set
*/
public void setCountry(String country) {
this.country = country;
}
/**
* @param firstName
* the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @param lastName
* the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @param password
* the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @param phoneNumber
* the phoneNumber to set
*/
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
/**
* @param state
* the state to set
*/
public void setState(String state) {
this.state = state;
}
/**
* @param userAccount
* the userAccount to set
*/
public void setUserAccount(IUserAccount userAccount) {
this.userAccount = userAccount;
}
/**
* @param userName
* the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* @param webStore
* the webStore to set
*/
public void setWebStore(IWebStoreFacade webStore) {
this.webStore = webStore;
}
/**
* @param zip
* the zip to set
*/
public void setZip(String zip) {
this.zip = zip;
}
private boolean validate() {
if (!this.password.equals(confirmPassword))
return false;
if (this.address == null || this.city == null || this.country == null
|| this.firstName == null || this.lastName == null
|| this.password == null || this.phoneNumber == null
|| this.state == null || this.userName == null
|| this.zip == null)
return false;
if (this.address.isEmpty() || this.city.isEmpty()
|| this.country.isEmpty() || this.firstName.isEmpty()
|| this.lastName.isEmpty() || this.password.isEmpty()
|| this.phoneNumber.isEmpty() || this.state.isEmpty()
|| this.userName.isEmpty() || this.zip.isEmpty())
return false;
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -