Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package web;
- import ejbs.CourseBean;
- import ejbs.StudentBean;
- import entities.Course;
- import entities.Student;
- import javax.inject.Named;
- import javax.enterprise.context.SessionScoped;
- import java.io.Serializable;
- import java.util.List;
- import java.util.logging.Logger;
- import javax.ejb.EJB;
- import javax.faces.component.UIParameter;
- import javax.faces.event.ActionEvent;
- @Named(value = "administratorManager")
- @SessionScoped
- public class AdministratorManager implements Serializable {
- private static final Logger logger = Logger.getLogger("web.AdministratorManager");
- @EJB
- private StudentBean studentBean;
- @EJB
- private CourseBean courseBean;
- private Student currentStudent;
- private Course currentCourse;
- private String newStudentUsername;
- private String newStudentPassword;
- private String newStudentName;
- private String newStudentEmail;
- private int newStudentCourseCode;
- private int newCourseCode;
- private String newCourseName;
- public AdministratorManager() {
- }
- public String createStudent() {
- try {
- studentBean.create(
- newStudentUsername,
- newStudentPassword,
- newStudentName,
- newStudentEmail,
- newStudentCourseCode);
- clearNewStudent();
- } catch (Exception e) {
- logger.warning("Problem creating student in method creatStudent.");
- }
- return "index?faces-redirect=true";
- }
- public String createCourse() {
- try {
- courseBean.create(
- newCourseCode,
- newCourseName);
- clearNewCourse();
- } catch (Exception e) {
- logger.warning("Problem creating course in method creatCourse.");
- }
- return "admin_courses_list?faces-redirect=true";
- }
- private void clearNewStudent() {
- newStudentUsername = null;
- newStudentPassword = null;
- newStudentName = null;
- newStudentEmail = null;
- newStudentCourseCode = 0;
- }
- private void clearNewCourse() {
- newCourseCode = 0;
- newCourseName = null;
- }
- public List<Student> getAllStudents() {
- try {
- return studentBean.getAll();
- } catch (Exception e) {
- logger.warning("Problem getting all students in method getAllStudants.");
- return null;
- }
- }
- public String updateStudent() {
- try {
- studentBean.update(currentStudent.getUsername(),
- currentStudent.getPassword(),
- currentStudent.getName(),
- currentStudent.getEmail(),
- newStudentCourseCode);
- newStudentCourseCode = -1;
- } catch (Exception e) {
- logger.warning("Problem updating student in method updateStudent.");
- return "admin_students_update";
- }
- return "index?faces-redirect=true";
- }
- public String updateCourse() {
- try {
- courseBean.update(currentCourse.getCode(),
- currentCourse.getName());
- } catch (Exception e) {
- logger.warning("Problem updating course in method updateCourse.");
- return "admin_courses_update";
- }
- return "admin_courses_list?faces-redirect=true";
- }
- public String removeStudent(ActionEvent event) {
- try {
- UIParameter param = (UIParameter) event.getComponent().findComponent("deleteStudentId");
- String username = param.getValue().toString();
- studentBean.remove(username);
- } catch (Exception e) {
- logger.warning("Problem removing student in method removeStudent.");
- }
- return "index?faces-redirect=true";
- }
- public String removeCourse(ActionEvent event) {
- try {
- UIParameter param = (UIParameter) event.getComponent().findComponent("deleteCourseCode");
- int code = Integer.parseInt(param.getValue().toString());
- courseBean.remove(code);
- } catch (Exception e) {
- logger.warning("Problem deleting student in method removeStudent.");
- }
- return "admin_courses_list?faces-redirect=true";
- }
- public String getNewStudentUsername() {
- return newStudentUsername;
- }
- public void setNewStudentUsername(String newStudentUsername) {
- this.newStudentUsername = newStudentUsername;
- }
- public String getNewStudentPassword() {
- return newStudentPassword;
- }
- public void setNewStudentPassword(String newStudentPassword) {
- this.newStudentPassword = newStudentPassword;
- }
- public String getNewStudentName() {
- return newStudentName;
- }
- public void setNewStudentName(String newStudentName) {
- this.newStudentName = newStudentName;
- }
- public String getNewStudentEmail() {
- return newStudentEmail;
- }
- public void setNewStudentEmail(String newStudentEmail) {
- this.newStudentEmail = newStudentEmail;
- }
- public Student getCurrentStudent() {
- return currentStudent;
- }
- public void setCurrentStudent(Student currentStudent) {
- this.currentStudent = currentStudent;
- }
- public List<Course> getAllCourses() {
- try {
- return courseBean.getAll();
- } catch (Exception e) {
- logger.warning("Problem getting all courses in method getAllCourses.");
- return null;
- }
- }
- public int getNewStudentCourseCode() {
- return newStudentCourseCode;
- }
- public void setNewStudentCourseCode(int newStudentCourseCode) {
- this.newStudentCourseCode = newStudentCourseCode;
- }
- public int getNewCourseCode() {
- return newCourseCode;
- }
- public void setNewCourseCode(int newCourseCode) {
- this.newCourseCode = newCourseCode;
- }
- public String getNewCourseName() {
- return newCourseName;
- }
- public void setNewCourseName(String newCourseName) {
- this.newCourseName = newCourseName;
- }
- public Course getCurrentCourse() {
- return currentCourse;
- }
- public void setCurrentCourse(Course currentCourse) {
- this.currentCourse = currentCourse;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement