package in.co.sunrays.proj1.action;
import in.co.sunrays.proj1.dto.CollegeDTO; import in.co.sunrays.proj1.exception.ApplicationException; import in.co.sunrays.proj1.exception.DuplicateRecordException; import in.co.sunrays.proj1.service.CollegeServiceInt; import org.apache.log4j.Logger; /** * College functionality Action. Performs operation for add, update, delete and * get College * * @author SUNRAYS Technologies * @version 1.0 * @Copyright (c) SUNRAYS Technologies */ public class CollegeAction extends BaseAction { private static Logger log = Logger.getLogger(CollegeAction.class); private String name; private String address; private String state; private String city; private String phoneNo; private CollegeServiceInt service; public void setService(CollegeServiceInt service) { this.service = service; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getState() { return state; } public void setState(String state) { this.state = state; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getPhoneNo() { return phoneNo; } public void setPhoneNo(String phoneNo) { this.phoneNo = phoneNo; } /** * Performs display operations for CollegeAction * * @return type String * @return INPUT */ @Override public String input() { log.debug("CollegeAction.input() Start"); if (id > 0) { try { CollegeDTO dto = service.findByPK(id); if (dto != null) { id = dto.getId(); name = dto.getName(); address = dto.getAddress(); state = dto.getState(); city = dto.getCity(); phoneNo = dto.getPhoneNo(); 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("CollegeAction.input() End"); return INPUT; } /** * Populates CollegeDTO from Action attributes */ protected CollegeDTO populateDTO(CollegeDTO dto) { super.populateDTO(dto); dto.setId(id); dto.setName(name); dto.setAddress(address); dto.setState(state); dto.setCity(city); dto.setPhoneNo(phoneNo); return dto; } /** * Performs submit operations for CollegeAction * * @return type String * @return SUCCESS */ @Override public String execute() { log.debug("CollegeAction.execute() Start"); try { CollegeDTO dto = populateDTO(new CollegeDTO()); 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("Collge Name already exist.", e); addActionError("Collge Name already exist"); return INPUT; } log.debug("CollegeAction.execute() End " + operation); return operation; } } |