Example usage for java.util.logging Handler close

List of usage examples for java.util.logging Handler close

Introduction

In this page you can find the example usage for java.util.logging Handler close.

Prototype

public abstract void close() throws SecurityException;

Source Link

Document

Close the Handler and free all associated resources.

Usage

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/rejectfriend", method = RequestMethod.POST)
public String rejectfriend(Model model, @RequestParam(value = "id") int id) {
    try {//from w  ww. ja  v  a  2s.  co m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentFriends.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        FriendshipsDAO.deletefriend(currentStudent.getStudentid(), id);
        logger.info("Rejected friendship between " + currentStudent.getStudentid() + " and " + id);
        List<Students> friendrequests = StudentDAO.getFriendRequests(currentStudent.getStudentid());
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("friendrequests", friendrequests);
        logger.info("Friend requests updated to model.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentmanagefriends";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(Model model, @RequestParam(value = "firstName") String firstName,
        @RequestParam(value = "lastName") String lastName, @RequestParam(value = "email") String email,
        @RequestParam(value = "password") String password, @RequestParam(value = "school") String school) {
    try {// ww w  . jav  a  2 s  .  c o  m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentAccount.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        List<Schools> schools = SchoolDAO.allSchools();
        if (schools != null) {
            model.addAttribute("school", schools);
        }
        Students student = StudentDAO.getStudent(email);
        if (firstName.isEmpty() || lastName.isEmpty() || email.isEmpty() || password.isEmpty()) {
            model.addAttribute("fillout", "Please fill out all Required Fields");
            logger.info("A field was not filled.");
        } else if (student != null) {
            model.addAttribute("taken", "The email address is taken");
            logger.info("Email address was taken.");
        } else {
            StudentDAO.register(firstName, lastName, email, password, school);
            model.addAttribute("registered", "You have been successfully registered. Please Login");
            logger.info("Successfully registered an account with email " + email);
        }
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "index";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/studenteditassigned", method = RequestMethod.GET)
public String editAssigned(Model model) {
    try {/*w  w  w .  j av  a2 s.c o m*/
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentAssignedCourses.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        List<Courses> courses = CourseDAO.getCoursesForStudent(currentStudent.getStudentid());
        List<Scheduleblocks> scheduleblocks = new ArrayList<Scheduleblocks>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
        }
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("scheduleblocks", scheduleblocks);
        model.addAttribute("courses", courses);
        logger.info("Courses for this student added to model.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studenteditassigned";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/removeassign", method = RequestMethod.POST)
public String removeAssigned(Model model, @RequestParam(value = "id") int id) {
    try {//from  ww w. ja va2s .co  m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentAssignedCourses.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        RegistrationDAO.removereg(id, currentStudent.getStudentid());
        CourseDAO.decrementCourseStudentsAndDelete(id);
        logger.info("Course successfully deleted");
        List<Courses> courses = CourseDAO.getCoursesForStudent(currentStudent.getStudentid());
        List<Scheduleblocks> scheduleblocks = new ArrayList<Scheduleblocks>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
        }
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("scheduleblocks", scheduleblocks);
        model.addAttribute("courses", courses);
        logger.info("Courses for this student added to model.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studenteditassigned";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/studentcourseofferings", method = RequestMethod.GET)
public String courseOfferings(Model model, @RequestParam(value = "year") String year) {
    try {/*from  www .j av a  2  s .c  o  m*/
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentCourseOfferings.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        int schoolid = currentStudent.getSchoolid();
        Schools sc = SchoolDAO.getSchool(schoolid);
        String schoolName = sc.getSchoolname();
        Schools schoolYear = SchoolDAO.getSchoolByNameYear(schoolName, year);
        int schoolYearID = schoolYear.getSchoolid();
        List<Courses> courses = CourseDAO.getCourseOfferingForSchool(schoolYearID);
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        List<Scheduleblocks> scheduleblocks = new ArrayList<>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
            logger.info("Retrieved course: " + course.getCourseidentifier());
        }
        model.addAttribute("scheduleblocks", scheduleblocks);
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("courses", courses);
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentcourseofferings";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/addfriend", method = RequestMethod.POST)
public String addfriend(Model model, @RequestParam(value = "email") String email) {
    try {//from  w  w  w .  j av a 2 s  .c o m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentFriends.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        Students friend = StudentDAO.getStudent(email);
        if (friend == null) {
            model.addAttribute("msg", "The email you have entered doesn't belong to any student");
            logger.info(email + " does not exist in database.");
        } else if (friend.getStudentid() == currentStudent.getStudentid()) {
            model.addAttribute("msg", "Can't friend yourself...");
            logger.info("This is your email.");
        } else if (friend.getSchoolid() != currentStudent.getSchoolid()) {
            model.addAttribute("msg", "Can not add a student from different school");
            logger.info("This student belongs to a different school");
        } else {
            model.addAttribute("msg", FriendshipsDAO.addfriend(friend, currentStudent));
            logger.info("Successfully created a friend request.");
        }
        List<Students> friendrequests = StudentDAO.getFriendRequests(currentStudent.getStudentid());
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("friendrequests", friendrequests);
        logger.info("Friend requests updated to model.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentmanagefriends";
}

From source file:BSxSB.Controllers.AdminController.java

@RequestMapping(value = "/addschool", method = RequestMethod.POST)
public String addSchool(Model model, @RequestParam(value = "schoolname") String schoolName,
        @RequestParam(value = "academicyear") String academicYear,
        @RequestParam(value = "numsemesters") String numSemesters,
        @RequestParam(value = "numperiods") String numPeriods, @RequestParam(value = "numdays") String numDays,
        @RequestParam(value = "legalblocks") String legalBlocks,
        @RequestParam(value = "lunchrange") String lunchRange) {
    try {//w w  w .j  a v  a 2s . c o m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBAddSchool.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        boolean valid = true;
        if (schoolName.isEmpty() || academicYear.isEmpty() || numSemesters.isEmpty() || numPeriods.isEmpty()
                || legalBlocks.isEmpty() || lunchRange.isEmpty()) {
            model.addAttribute("fillout", "Please fill out all Required Fields");
            valid = false;
        }
        Schools school = SchoolDAO.getSchoolByNameYear(schoolName, academicYear);
        String academicYearRegex = "[0-9]{4}-[0-9]{4}";
        String lunchRangeRegex = "[0-9]-[0-9]";
        int periods = Integer.parseInt(numPeriods);
        int days = Integer.parseInt(numDays);
        int semesters = Integer.parseInt(numSemesters);
        String legalBlockRegex = "(<[1-" + periods + "];([1-" + days + "](,[1-" + days + "]){0," + days + "})>)"
                + "(#<[1-" + periods + "];([1-" + days + "](,[1-" + days + "]){0," + days + "})>)*";
        if (!academicYear.matches(academicYearRegex)) {
            model.addAttribute("ayregex", "Academic Year is invalid");
            logger.info("Invalid Academic Year");
            valid = false;
        }
        if (!lunchRange.matches(lunchRangeRegex)) {
            model.addAttribute("lrregex", "Lunch Range is invalid");
            logger.info("Invalid Lunch Range");
            valid = false;
        }
        if (periods <= 9) {
            if (!legalBlocks.matches(legalBlockRegex)) {
                model.addAttribute("lbregex", "Legal Block set is invalid");
                logger.info("Invalid Legal Block");
                valid = false;
            }
        }
        if (school != null) {
            model.addAttribute("taken", "There is already a school with this name and academic year.");
            logger.info("Invalid name and academic year");
            valid = false;
        }
        if (valid == true) {
            SchoolDAO.addSchool(schoolName, academicYear, semesters, days, periods, lunchRange);
            Schools tempSchool = SchoolDAO.getSchoolByNameYear(schoolName, academicYear);
            int schoolIDForSB = tempSchool.getSchoolid();
            //Add all scheduleblocks
            String[] lbArray = legalBlocks.split("#");
            //Array of strings in the format ({1;1,2,3}
            for (String s : lbArray) {
                String temp = s.substring(1, s.length() - 1);
                String[] tempArray = temp.split(";");
                int pd = Integer.parseInt(tempArray[0]);
                ScheduleBlockDAO.addScheduleBlock(schoolIDForSB, pd, tempArray[1]);
            }

            model.addAttribute("added", "School has been successfully added.");
            logger.info("Successfully added school " + schoolName);
        }
        handler.close();
        logger.removeHandler(handler);
        // Scheduleblocks are in the form of <period;day1,day2..>#<period;day1,day2..>.
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "adminaddschool";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/addlunch", method = RequestMethod.POST)
public String addlunch(Model model, @RequestParam("lunch") String lunchday) {
    try {/* w  w w  .  j  a  v a 2s.  co m*/
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentGenerateCourses.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        GenerationcriteriaDAO.addLunch(currentStudent.getStudentid(), lunchday);
        logger.info(lunchday + " successfully added to Generation Criteria.");
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Courses> courses = CourseDAO.getCourseOfferingForSchool(currentSchool.getSchoolid());
        List<Scheduleblocks> scheduleblocks = new ArrayList<>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
        }
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        Generationcriteria gencriteria = GenerationcriteriaDAO
                .getGenerationCriteria(currentStudent.getStudentid());
        String[] courseids = gencriteria.getCourseids().split(",");
        List<Courses> genCourses = new ArrayList<>();
        List<Scheduleblocks> genscheduleblocks = new ArrayList<>();
        for (String courseid : courseids) {
            Courses genCourse = CourseDAO.getCourse(Integer.parseInt(courseid));
            genCourses.add(genCourse);
            genscheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(genCourse.getScheduleblockid()));
        }
        if (gencriteria.getLunch() != null && !gencriteria.getLunch().isEmpty()) {
            String[] lunch = gencriteria.getLunch().split(",");
            model.addAttribute("lunch", lunch);
        }
        String lunchrange = currentSchool.getLunchrange();
        model.addAttribute("lunchrange", lunchrange);
        int numdays = currentSchool.getNumdays();
        String lunchdays = lunchToText(numdays);
        String[] lunchdays2 = lunchdays.split(",");
        model.addAttribute("lunchdays", lunchdays2);
        model.addAttribute("genscheduleblocks", genscheduleblocks);
        model.addAttribute("gencourses", genCourses);
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("scheduleblocks", scheduleblocks);
        model.addAttribute("courses", courses);
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentgeneratecourses";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/removelunch", method = RequestMethod.POST)
public String removelunch(Model model, @RequestParam("lunch") String lunchday) {
    try {//  w ww.  j a  va2 s.  co  m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentGenerateCourses.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        GenerationcriteriaDAO.removeLunch(currentStudent.getStudentid(), lunchday);
        logger.info(lunchday + " removed from generation crtieria.");
        List<Courses> courses = CourseDAO.getCourseOfferingForSchool(currentSchool.getSchoolid());
        List<Scheduleblocks> scheduleblocks = new ArrayList<>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
        }
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        Generationcriteria gencriteria = GenerationcriteriaDAO
                .getGenerationCriteria(currentStudent.getStudentid());
        String[] courseids = gencriteria.getCourseids().split(",");
        List<Courses> genCourses = new ArrayList<>();
        List<Scheduleblocks> genscheduleblocks = new ArrayList<>();
        for (String courseid : courseids) {
            Courses genCourse = CourseDAO.getCourse(Integer.parseInt(courseid));
            genCourses.add(genCourse);
            genscheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(genCourse.getScheduleblockid()));
        }
        if (gencriteria.getLunch() != null && !gencriteria.getLunch().isEmpty()) {
            String[] lunch = gencriteria.getLunch().split(",");
            model.addAttribute("lunch", lunch);
        }
        String lunchrange = currentSchool.getLunchrange();
        model.addAttribute("lunchrange", lunchrange);
        int numdays = currentSchool.getNumdays();
        String lunchdays = lunchToText(numdays);
        String[] lunchdays2 = lunchdays.split(",");
        model.addAttribute("lunchdays", lunchdays2);
        model.addAttribute("genscheduleblocks", genscheduleblocks);
        model.addAttribute("gencourses", genCourses);
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("scheduleblocks", scheduleblocks);
        model.addAttribute("courses", courses);
        logger.info("Generation criteria successfully updated.");
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentgeneratecourses";
}

From source file:BSxSB.Controllers.StudentController.java

@RequestMapping(value = "/adddesiredcourse", method = RequestMethod.POST)
public String adddesiredcourses(Model model, @RequestParam("id") String id) {
    try {//from w  ww. j a  v a2 s  .c o  m
        //Initialize the file that the logger writes to.
        Handler handler = new FileHandler("%tBSxSBStudentGenerateCourses.log", true);
        handler.setFormatter(new SimpleFormatter());
        logger.addHandler(handler);
        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
        String name = auth.getName();
        Students currentStudent = StudentDAO.getStudent(name);
        GenerationcriteriaDAO.addDesiredCourses(currentStudent.getStudentid(), id);
        logger.info("Course successfully added to generation criteria.");
        Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid());
        List<Courses> courses = CourseDAO.getCourseOfferingForSchool(currentSchool.getSchoolid());
        List<Scheduleblocks> scheduleblocks = new ArrayList<>();
        for (Courses course : courses) {
            scheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()));
        }
        List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname());
        Generationcriteria gencriteria = GenerationcriteriaDAO
                .getGenerationCriteria(currentStudent.getStudentid());
        String[] courseids = gencriteria.getCourseids().split(",");
        List<Courses> genCourses = new ArrayList<>();
        List<Scheduleblocks> genscheduleblocks = new ArrayList<>();
        for (String courseid : courseids) {
            Courses genCourse = CourseDAO.getCourse(Integer.parseInt(courseid));
            genCourses.add(genCourse);
            genscheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(genCourse.getScheduleblockid()));
        }
        if (gencriteria.getLunch() != null && !gencriteria.getLunch().isEmpty()) {
            String[] lunch = gencriteria.getLunch().split(",");
            model.addAttribute("lunch", lunch);
        }
        logger.info("Generation Criteria successfully updated.");
        String lunchrange = currentSchool.getLunchrange();
        model.addAttribute("lunchrange", lunchrange);
        int numdays = currentSchool.getNumdays();
        String lunchdays = lunchToText(numdays);
        String[] lunchdays2 = lunchdays.split(",");
        model.addAttribute("lunchdays", lunchdays2);
        model.addAttribute("genscheduleblocks", genscheduleblocks);
        model.addAttribute("gencourses", genCourses);
        model.addAttribute("schoolyears", schoolyears);
        model.addAttribute("scheduleblocks", scheduleblocks);
        model.addAttribute("courses", courses);
        handler.close();
        logger.removeHandler(handler);
    } catch (IOException ex) {
        logger.log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        logger.log(Level.SEVERE, null, ex);
    }
    return "studentgeneratecourses";
}