package in.co.sunrays.proj1.action;
import in.co.sunrays.proj1.dto.MarksheetDTO; 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.MarksheetServiceInt; import in.co.sunrays.proj1.service.StudentServiceInt; import java.util.List; import org.apache.log4j.Logger; /** * Marksheet functionality Action. Performs operation for add, update, delete * and get Marksheet * * @author SUNRAYS Technologies * @version 1.0 * @Copyright (c) SUNRAYS Technologies */ public class MarksheetAction extends BaseAction { private static Logger log = Logger.getLogger(MarksheetAction.class); private String rollNo; private long studentId; private String name; private Integer physics; private Integer chemistry; private Integer maths; private List<StudentDTO> studentList; private MarksheetServiceInt service; private StudentServiceInt studentService; public void setService(MarksheetServiceInt service) { this.service = service; } public void setStudentService(StudentServiceInt studentService) { this.studentService = studentService; } public String getRollNo() { return rollNo; } public void setRollNo(String rollNo) { this.rollNo = rollNo; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getPhysics() { return physics; } public void setPhysics(Integer physics) { this.physics = physics; } public Integer getChemistry() { return chemistry; } public void setChemistry(Integer chemistry) { this.chemistry = chemistry; } public Integer getMaths() { return maths; } public void setMaths(Integer maths) { this.maths = maths; } public List<StudentDTO> getStudentList() { return studentList; } public void setStudentList(List<StudentDTO> studentList) { this.studentList = studentList; } public long getStudentId() { return studentId; } public void setStudentId(long studentId) { this.studentId = studentId; } /** * Performs display operations for MarksheetAction * * @return type String * @return INPUT */ @Override public String input() { log.debug("MarksheetAction.input() Start"); if (id > 0) { try { MarksheetDTO dto = service.findByPK(id); if (dto != null) { id = dto.getId(); rollNo = dto.getRollNo(); studentId = dto.getStudentId(); name = dto.getName(); physics = dto.getPhysics(); chemistry = dto.getChemistry(); maths = dto.getMaths(); 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("MarksheetAction.input() End"); return INPUT; } /** * Populates MarksheetDTO from Action attributes */ protected MarksheetDTO populateDTO(MarksheetDTO dto) { super.populateDTO(dto); dto.setId(id); dto.setRollNo(rollNo); dto.setStudentId(studentId); dto.setPhysics(physics); dto.setChemistry(chemistry); dto.setMaths(maths); try { StudentDTO studentDTO = studentService.findByPK(studentId); dto.setName(studentDTO.getValue()); } catch (ApplicationException e) { } return dto; } /** * Performs submit operations for MarksheetAction * * @return type String * @return SUCCESS */ @Override public String execute() { log.debug("MarksheetAction.execute() Start"); try { MarksheetDTO dto = populateDTO(new MarksheetDTO()); 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("Marksheet Deleted Successfully."); } } catch (ApplicationException e) { log.error("Critical Issue ", e); return OP_ERROR; } catch (DuplicateRecordException e) { log.error("RolNo already exist.", e); addActionError("Roll number already exist"); return INPUT; } log.debug("MarksheetAction.execute() End " + operation); return operation; } /** * Loads pre-loaded data */ @Override public void prepare() throws Exception { log.debug("MarksheetAction.prepare() Start"); studentList = studentService.list(); log.debug("MarksheetAction.prepare() End"); } } |