Advertisement
Guest User

Untitled

a guest
Oct 11th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.46 KB | None | 0 0
  1. package web;
  2.  
  3. import ejbs.CourseBean;
  4. import ejbs.StudentBean;
  5. import entities.Course;
  6. import entities.Student;
  7. import javax.inject.Named;
  8. import javax.enterprise.context.SessionScoped;
  9. import java.io.Serializable;
  10. import java.util.List;
  11. import java.util.logging.Logger;
  12. import javax.ejb.EJB;
  13. import javax.faces.component.UIParameter;
  14. import javax.faces.event.ActionEvent;
  15.  
  16. @Named(value = "administratorManager")
  17. @SessionScoped
  18. public class AdministratorManager implements Serializable {
  19.  
  20.     private static final Logger logger = Logger.getLogger("web.AdministratorManager");
  21.     @EJB
  22.     private StudentBean studentBean;
  23.     @EJB
  24.     private CourseBean courseBean;
  25.    
  26.     private Student currentStudent;
  27.    
  28.     private Course currentCourse;
  29.    
  30.     private String newStudentUsername;
  31.     private String newStudentPassword;
  32.     private String newStudentName;
  33.     private String newStudentEmail;
  34.     private int newStudentCourseCode;
  35.    
  36.     private int newCourseCode;
  37.     private String newCourseName;
  38.  
  39.     public AdministratorManager() {
  40.     }
  41.  
  42.     public String createStudent() {
  43.         try {
  44.             studentBean.create(
  45.                     newStudentUsername,
  46.                     newStudentPassword,
  47.                     newStudentName,
  48.                     newStudentEmail,
  49.                     newStudentCourseCode);
  50.             clearNewStudent();
  51.         } catch (Exception e) {
  52.             logger.warning("Problem creating student in method creatStudent.");
  53.         }
  54.         return "index?faces-redirect=true";
  55.     }
  56.    
  57.     public String createCourse() {
  58.         try {
  59.             courseBean.create(
  60.                     newCourseCode,
  61.                     newCourseName);
  62.             clearNewCourse();
  63.         } catch (Exception e) {
  64.             logger.warning("Problem creating course in method creatCourse.");
  65.         }
  66.         return "admin_courses_list?faces-redirect=true";
  67.     }
  68.  
  69.     private void clearNewStudent() {
  70.         newStudentUsername = null;
  71.         newStudentPassword = null;
  72.         newStudentName = null;
  73.         newStudentEmail = null;
  74.         newStudentCourseCode = 0;
  75.     }
  76.    
  77.     private void clearNewCourse() {
  78.         newCourseCode = 0;
  79.         newCourseName = null;
  80.     }
  81.    
  82.     public List<Student> getAllStudents() {
  83.         try {
  84.             return studentBean.getAll();
  85.         } catch (Exception e) {
  86.             logger.warning("Problem getting all students in method getAllStudants.");
  87.             return null;
  88.         }
  89.     }
  90.    
  91.     public String updateStudent() {
  92.         try {
  93.             studentBean.update(currentStudent.getUsername(),
  94.                     currentStudent.getPassword(),
  95.                     currentStudent.getName(),
  96.                     currentStudent.getEmail(),
  97.                     newStudentCourseCode);
  98.             newStudentCourseCode = -1;
  99.         } catch (Exception e) {
  100.             logger.warning("Problem updating student in method updateStudent.");
  101.             return "admin_students_update";
  102.         }
  103.         return "index?faces-redirect=true";
  104.     }
  105.    
  106.     public String updateCourse() {
  107.         try {
  108.             courseBean.update(currentCourse.getCode(),
  109.                     currentCourse.getName());
  110.         } catch (Exception e) {
  111.             logger.warning("Problem updating course in method updateCourse.");
  112.             return "admin_courses_update";
  113.         }
  114.         return "admin_courses_list?faces-redirect=true";
  115.     }
  116.    
  117.     public String removeStudent(ActionEvent event) {
  118.         try {
  119.             UIParameter param = (UIParameter) event.getComponent().findComponent("deleteStudentId");
  120.             String username = param.getValue().toString();
  121.             studentBean.remove(username);
  122.         } catch (Exception e) {
  123.             logger.warning("Problem removing student in method removeStudent.");
  124.         }
  125.         return "index?faces-redirect=true";
  126.     }
  127.    
  128.     public String removeCourse(ActionEvent event) {
  129.         try {
  130.             UIParameter param = (UIParameter) event.getComponent().findComponent("deleteCourseCode");
  131.             int code = Integer.parseInt(param.getValue().toString());
  132.             courseBean.remove(code);
  133.         } catch (Exception e) {
  134.             logger.warning("Problem deleting student in method removeStudent.");
  135.         }
  136.         return "admin_courses_list?faces-redirect=true";
  137.     }
  138.  
  139.     public String getNewStudentUsername() {
  140.         return newStudentUsername;
  141.     }
  142.  
  143.     public void setNewStudentUsername(String newStudentUsername) {
  144.         this.newStudentUsername = newStudentUsername;
  145.     }
  146.  
  147.     public String getNewStudentPassword() {
  148.         return newStudentPassword;
  149.     }
  150.  
  151.     public void setNewStudentPassword(String newStudentPassword) {
  152.         this.newStudentPassword = newStudentPassword;
  153.     }
  154.  
  155.     public String getNewStudentName() {
  156.         return newStudentName;
  157.     }
  158.  
  159.     public void setNewStudentName(String newStudentName) {
  160.         this.newStudentName = newStudentName;
  161.     }
  162.  
  163.     public String getNewStudentEmail() {
  164.         return newStudentEmail;
  165.     }
  166.  
  167.     public void setNewStudentEmail(String newStudentEmail) {
  168.         this.newStudentEmail = newStudentEmail;
  169.     }
  170.    
  171.     public Student getCurrentStudent() {
  172.         return currentStudent;
  173.     }
  174.  
  175.     public void setCurrentStudent(Student currentStudent) {
  176.         this.currentStudent = currentStudent;
  177.     }
  178.    
  179.     public List<Course> getAllCourses() {
  180.         try {
  181.             return courseBean.getAll();
  182.         } catch (Exception e) {
  183.             logger.warning("Problem getting all courses in method getAllCourses.");
  184.             return null;
  185.         }
  186.     }
  187.  
  188.     public int getNewStudentCourseCode() {
  189.         return newStudentCourseCode;
  190.     }
  191.  
  192.     public void setNewStudentCourseCode(int newStudentCourseCode) {
  193.         this.newStudentCourseCode = newStudentCourseCode;
  194.     }
  195.  
  196.     public int getNewCourseCode() {
  197.         return newCourseCode;
  198.     }
  199.  
  200.     public void setNewCourseCode(int newCourseCode) {
  201.         this.newCourseCode = newCourseCode;
  202.     }
  203.  
  204.     public String getNewCourseName() {
  205.         return newCourseName;
  206.     }
  207.  
  208.     public void setNewCourseName(String newCourseName) {
  209.         this.newCourseName = newCourseName;
  210.     }
  211.  
  212.     public Course getCurrentCourse() {
  213.         return currentCourse;
  214.     }
  215.  
  216.     public void setCurrentCourse(Course currentCourse) {
  217.         this.currentCourse = currentCourse;
  218.     }
  219.    
  220.    
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement