package in.co.sunrays.proj1.action;
import in.co.sunrays.proj1.dto.CollegeDTO; import in.co.sunrays.proj1.dto.StudentDTO; import in.co.sunrays.proj1.exception.ApplicationException; import in.co.sunrays.proj1.exception.DuplicateRecordException; import in.co.sunrays.proj1.service.CollegeServiceInt; import in.co.sunrays.proj1.service.StudentServiceInt; import java.util.Date; import java.util.List; import org.apache.log4j.Logger; /** * Student functionality Action. Performs operation for add, update, delete and * get Student * * @author SUNRAYS Technologies * @version 1.0 * @Copyright (c) SUNRAYS Technologies */ public class StudentAction extends BaseAction { private static Logger log = Logger.getLogger(StudentAction.class); private String firstName; private String lastName; private Date dob; private String mobileNo; private String email; private List<CollegeDTO> collegeList; private long collegeId; private StudentServiceInt service; private CollegeServiceInt collegeService; public void setService(StudentServiceInt service) { this.service = service; } public void setCollegeService(CollegeServiceInt collegeService) { this.collegeService = collegeService; } 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 Date getDob() { return dob; } public void setDob(Date dob) { this.dob = dob; } public String getMobileNo() { return mobileNo; } public void setMobileNo(String mobileNo) { this.mobileNo = mobileNo; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public List<CollegeDTO> getCollegeList() { return collegeList; } public void setCollegeList(List<CollegeDTO> collegeList) { this.collegeList = collegeList; } public long getCollegeId() { return collegeId; } public void setCollegeId(long collegeId) { this.collegeId = collegeId; } /** * Performs display operations for StudentAction * * @return type String * @return INPUT */ @Override public String input() { log.debug("StudentAction.input() Start"); if (id > 0) { try { StudentDTO dto = service.findByPK(id); if (dto != null) { id = dto.getId(); firstName = dto.getFirstName(); lastName = dto.getLastName(); dob = dto.getDob(); mobileNo = dto.getMobileNo(); email = dto.getEmail(); collegeId = dto.getCollegeId(); 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("StudentAction.input() End"); return INPUT; } /** * Populates StudentDTO from Action attributes */ protected StudentDTO populateDTO(StudentDTO dto) { super.populateDTO(dto); dto.setId(id); dto.setFirstName(firstName); dto.setLastName(lastName); dto.setDob(dob); dto.setMobileNo(mobileNo); dto.setEmail(email); dto.setCollegeId(collegeId); try { CollegeDTO collegeDTO = collegeService.findByPK(collegeId); dto.setCollegeName(collegeDTO.getValue()); } catch (ApplicationException e) { } return dto; } /** * Performs submit operations for StudentAction * * @return type String * @return SUCCESS */ @Override public String execute() { log.debug("StudentAction.execute() Start"); try { StudentDTO dto = populateDTO(new StudentDTO()); if (OP_SAVE.equalsIgnoreCase(operation)) { if (id > 0) { service.update(dto); addActionMessage("Data is Updated Successfully"); } else { id = service.add(dto); addActionMessage("Data is Successfully added"); } } else if (OP_DELETE.equalsIgnoreCase(operation)) { service.delete(dto); log.debug("Student Deleted Successfully."); } } catch (ApplicationException e) { log.error("Critical Issue ", e); return OP_ERROR; } catch (DuplicateRecordException e) { log.error("Email already exist.", e); addActionError("Email already exist"); return INPUT; } log.debug("StudentAction.execute() End " + operation); return operation; } /** * Loads pre-loaded data */ @Override public void prepare() throws Exception { log.debug("StudentAction.prepare() Start"); collegeList = collegeService.list(); log.debug("StudentAction.prepare() End"); } } |