package in.co.sunrays.proj1.action; import in.co.sunrays.proj1.dto.RoleDTO; import in.co.sunrays.proj1.dto.UserDTO; import in.co.sunrays.proj1.exception.ApplicationException; import in.co.sunrays.proj1.exception.DuplicateRecordException; import in.co.sunrays.proj1.service.RoleServiceInt; import in.co.sunrays.proj1.service.UserServiceInt; import java.sql.Timestamp; import java.util.Date; import java.util.List; import org.apache.log4j.Logger; /** * User functionality Action. Performs operation for add, update and get User * * @author SUNRAYS Technologies * @version 1.0 * @Copyright (c) SUNRAYS Technologies */ public class UserAction extends BaseAction { private static Logger log = Logger.getLogger(UserAction.class); private String firstName; private String lastName; private String login; private String password; private String confirmPassword; private long roleId; private String gender; private String mobileNo; private Date dob; private Timestamp lastLogin; private String registeredIP; private List roleList; private UserServiceInt service; private RoleServiceInt roleService; public void setService(UserServiceInt service) { this.service = service; } public void setRoleService(RoleServiceInt roleService) { this.roleService = roleService; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getConfirmPassword() { return confirmPassword; } public void setConfirmPassword(String confirmPassword) { this.confirmPassword = confirmPassword; } public long getRoleId() { return roleId; } public void setRoleId(long roleId) { this.roleId = roleId; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public String getMobileNo() { return mobileNo; } public void setMobileNo(String mobileNo) { this.mobileNo = mobileNo; } public Date getDob() { return dob; } public void setDob(Date dob) { this.dob = dob; } public Timestamp getLastLogin() { return lastLogin; } public void setLastLogin(Timestamp lastLogin) { this.lastLogin = lastLogin; } public String getRegisteredIP() { return registeredIP; } public void setRegisteredIP(String registeredIP) { this.registeredIP = registeredIP; } public List getRoleList() { return roleList; } public void setRoleList(List roleList) { this.roleList = roleList; } /** * Performs display operations for UserAction * * @return type String * @return INPUT */ @Override public String input() { log.debug("UserAction.input() Start"); if (id > 0) { try { UserDTO dto = service.findByPK(id); if (dto != null) { id = dto.getId(); firstName = dto.getFirstName(); lastName = dto.getLastName(); login = dto.getLogin(); password = dto.getFirstName(); roleId = dto.getRoleId(); gender = dto.getGender(); mobileNo = dto.getMobileNo(); dob = dto.getDob(); lastLogin = dto.getLastLogin(); registeredIP = dto.getRegisteredIP(); createdBy = dto.getCreatedBy(); modifiedBy = dto.getModifiedBy(); createdDatetime = dto.getCreatedDatetime().getTime(); modifiedDatetime = dto.getModifiedDatetime().getTime(); } } catch (ApplicationException e) { log.error("Critical Issue", e); addActionError("Critical issue : " + e.getMessage()); } } log.debug("UserAction.input() End"); return INPUT; } /** * Populates UserDTO from Action attributes */ protected UserDTO populateDTO(UserDTO dto) { super.populateDTO(dto); dto.setId(id); dto.setFirstName(firstName); dto.setLastName(lastName); dto.setLogin(login); dto.setPassword(password); dto.setRoleId(roleId); dto.setGender(gender); dto.setMobileNo(mobileNo); dto.setDob(dob); dto.setLastLogin(lastLogin); dto.setRegisteredIP(registeredIP); dto.setLastLoginIP(request.getRemoteAddr()); return dto; } /** * Performs submit operations for UserAction * * @return type String * @return SUCCESS */ @Override public String execute() { log.debug("UserAction.execute() Start"); try { UserDTO dto = populateDTO(new UserDTO()); if (OP_SAVE.equalsIgnoreCase(operation)) { if (id > 0) { service.update(dto); addActionMessage("Data is Updated Successfully"); } else { //dto.setRoleId(RoleDTO.ROLE_STUDENT); dto.setRegisteredIP(request.getRemoteAddr()); id = service.add(dto); addActionMessage("Data is Successfully added"); } } else if (OP_DELETE.equalsIgnoreCase(operation)) { service.delete(dto); log.debug("Marksheet Deleted Successfully."); } } catch (DuplicateRecordException e) { log.error("User already exist.", e); addActionError("User already exist."); return INPUT; } catch (ApplicationException e) { log.error("Critical Issue ", e); return OP_ERROR; } log.debug("UserAction.execute() End " + operation); return operation; } /** * Loads pre-loaded data */ @Override public void prepare() throws Exception { roleList = roleService.list(); } } |