List of usage examples for java.util.logging SimpleFormatter SimpleFormatter
SimpleFormatter
From source file:BSxSB.Controllers.StudentController.java
@RequestMapping(value = "/removedesiredcourse", method = RequestMethod.POST) public String removedesiredcourses(Model model, @RequestParam("id") String id) { try {/*from w w w . jav a 2 s . com*/ //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.removeDesiredCourses(currentStudent.getStudentid(), id); logger.info("Course sucessfully removed from 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<>(); if (!gencriteria.getCourseids().isEmpty()) { 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 = "/removelunch", method = RequestMethod.POST) public String removelunch(Model model, @RequestParam("lunch") String lunchday) { try {/* w ww . j a v a2s .c om*/ //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:org.openconcerto.sql.PropsConfiguration.java
public void setupLogging(final String dirName, final boolean redirectToFile) { final File logDir; synchronized (this.restLock) { if (this.logDir != null) throw new IllegalStateException("Already set to " + this.logDir); logDir = getValidLogDir(dirName); this.logDir = logDir; }/*from www . ja v a 2 s . c om*/ final String logNameBase = this.getAppName() + "_" + getLogDateFormat().format(new Date()); // must be done before setUpConsoleHandler(), otherwise log output not redirected if (redirectToFile) { final File logFile = new File(logDir, (logNameBase + ".txt")); try { FileUtils.mkdir_p(logFile.getParentFile()); System.out.println("Log file: " + logFile.getAbsolutePath()); final OutputStream fileOut = new FileOutputStream(logFile, true); final OutputStream out, err; System.out.println("Java System console:" + System.console()); boolean launchedFromEclipse = new File(".classpath").exists(); if (launchedFromEclipse) { System.out.println("Launched from eclipse"); } if ((System.console() != null || launchedFromEclipse) && this.keepStandardStreamsWhenRedirectingToFile()) { System.out.println("Redirecting standard output to file and console"); out = new MultipleOutputStream(fileOut, new FileOutputStream(FileDescriptor.out)); System.out.println("Redirecting error output to file and console"); err = new MultipleOutputStream(fileOut, new FileOutputStream(FileDescriptor.err)); } else { out = fileOut; err = fileOut; } System.setErr(new PrintStream(new BufferedOutputStream(err, 128), true)); System.setOut(new PrintStream(new BufferedOutputStream(out, 128), true)); // Takes about 350ms so run it async new Thread(new Runnable() { @Override public void run() { try { FileUtils.ln(logFile, new File(logDir, "last.log")); } catch (final IOException e) { // the link is not important e.printStackTrace(); } } }).start(); } catch (final Exception e) { ExceptionHandler.handle("Redirection des sorties standards impossible", e); } } else { System.out.println("Standard streams not redirected to file"); } // removes default LogUtils.rmRootHandlers(); // add console handler LogUtils.setUpConsoleHandler(); // add file handler (supports concurrent launches, doesn't depend on date) try { final File logFile = new File(logDir, this.getAppName() + "-%u-age%g.log"); FileUtils.mkdir_p(logFile.getParentFile()); System.out.println("Logger logs: " + logFile.getAbsolutePath()); // 2 files of at most 5M, each new launch append // if multiple concurrent launches %u is used final FileHandler fh = new FileHandler(logFile.getPath(), 5 * 1024 * 1024, 2, true); fh.setFormatter(new SimpleFormatter()); Logger.getLogger("").addHandler(fh); } catch (final Exception e) { ExceptionHandler.handle("Enregistrement du Logger dsactiv", e); } this.setLoggersLevel(); }
From source file:BSxSB.Controllers.StudentController.java
@RequestMapping(value = "/addlunch", method = RequestMethod.POST) public String addlunch(Model model, @RequestParam("lunch") String lunchday) { try {/*from ww w. jav a 2 s . c om*/ //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 = "/generateschedule", method = RequestMethod.GET) public String generateSchedule(Model model, @RequestParam("instructors") String instructors) { try {//from w w w.j a v a 2 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); Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid()); Generationcriteria gencriteria = GenerationcriteriaDAO .getGenerationCriteria(currentStudent.getStudentid()); String[] courseids = gencriteria.getCourseids().split(","); List<Courses> genCourses = new ArrayList<>(); List<Scheduleblocks> genscheduleblocks = new ArrayList<>(); if (!gencriteria.getCourseids().isEmpty()) { for (String courseid : courseids) { Courses genCourse = CourseDAO.getCourse(Integer.parseInt(courseid)); genCourses.add(genCourse); genscheduleblocks.add(ScheduleBlockDAO.getScheduleBlock(genCourse.getScheduleblockid())); } } List<List<Courses>> conflictCourses = new ArrayList<>(); String lunches = gencriteria.getLunch(); String[] lunch = lunches.split(","); for (int i = 0; i < lunch.length; i++) { if (lunch[i].equals("monday")) { lunch[i] = "1"; } else if (lunch[i].equals("tuesday")) { lunch[i] = "2"; } else if (lunch[i].equals("wednesday")) { lunch[i] = "3"; } else if (lunch[i].equals("thursday")) { lunch[i] = "4"; } else if (lunch[i].equals("friday")) { lunch[i] = "5"; } else if (lunch[i].equals("saturday")) { lunch[i] = "6"; } else if (lunch[i].equals("sunday")) { lunch[i] = "7"; } } String lunchperiods = currentSchool.getLunchrange(); String[] temp = lunchperiods.split("-"); int length = Integer.parseInt(temp[1]) - Integer.parseInt(temp[0]); int[] lunchperiod = new int[length + 1]; int low = Integer.parseInt(temp[0]); for (int i = 0; i <= length; i++) { lunchperiod[i] = low; low++; } int conlunchcount = 0; List<List<Courses>> conflictLunches = new ArrayList<>(); for (int i = 0; i < genscheduleblocks.size(); i++) { Scheduleblocks firstBlock = genscheduleblocks.get(i); conflictLunch: { for (int period : lunchperiod) { if (firstBlock.getPeriod().equals(period)) { String[] gendays = firstBlock.getDays().split(","); for (String days : lunch) { for (String genday : gendays) { if (days.equals(genday)) { List<Courses> conflictCourse = new ArrayList<>(); conflictCourse.add(genCourses.get(i)); Courses lunchCourse = new Courses(0, "lunch", "", "", 0); conflictCourse.add(lunchCourse); conflictLunches.add(conflictCourse); conlunchcount++; break conflictLunch; } } } } } } for (int i2 = i + 1; i2 < genscheduleblocks.size(); i2++) { Scheduleblocks secondBlock = genscheduleblocks.get(i2); checkConflict: { if (firstBlock.getPeriod().equals(secondBlock.getPeriod())) { String[] days = firstBlock.getDays().split(","); String[] days2 = secondBlock.getDays().split(","); for (String d : days) { for (String d2 : days2) { if (d.equals(d2)) { Courses genCourse = genCourses.get(i); Courses genCourse2 = genCourses.get(i2); String[] semesters = genCourse.getSemester().split(","); String[] semesters2 = genCourse2.getSemester().split(","); for (String s : semesters) { for (String s2 : semesters2) { if (s.equals(s2)) { List<Courses> conflictCourse = new ArrayList<>(); conflictCourse.add(genCourse); conflictCourse.add(genCourse2); conflictCourses.add(conflictCourse); break checkConflict; } } } } } } } } } } System.out.print(conlunchcount + " " + lunchperiod.length); if (conlunchcount >= lunchperiod.length) { for (List<Courses> conlunch : conflictLunches) { System.out.print(conlunch); conflictCourses.add(conlunch); } } if (conflictCourses.isEmpty()) { String[] instructor = instructors.split(","); for (int i = 0; i < genCourses.size(); i++) { Courses course1 = genCourses.get(i); String courseiden = course1.getCourseidentifier(); for (int i2 = i + 1; i2 < genCourses.size(); i2++) { Courses course2 = genCourses.get(i2); checkCourse: { if (courseiden.equals(course2.getCourseidentifier())) { if (instructors.isEmpty()) { List<Students> friends = StudentDAO.getFriends(currentStudent.getStudentid()); int friendcourse1 = 0; int friendcourse2 = 0; for (Students friend : friends) { if (RegistrationDAO.isRegistered(course1, friend)) { friendcourse1++; } else if (RegistrationDAO.isRegistered(course2, friend)) { friendcourse2++; } } if (friendcourse1 >= friendcourse2) { genCourses.remove(i2); break checkCourse; } else if (friendcourse1 < friendcourse2) { genCourses.remove(i); break checkCourse; } else { genCourses.remove(i); break checkCourse; } } else { for (String inst : instructor) { if (course1.getInstructor().equals(inst)) { genCourses.remove(i2); break checkCourse; } else if (course2.getInstructor().equals(inst)) { genCourses.remove(i); break checkCourse; } else { List<Students> friends = StudentDAO .getFriends(currentStudent.getStudentid()); int friendcourse1 = 0; int friendcourse2 = 0; for (Students friend : friends) { if (RegistrationDAO.isRegistered(course1, friend)) { friendcourse1++; } else if (RegistrationDAO.isRegistered(course2, friend)) { friendcourse2++; } } if (friendcourse1 >= friendcourse2) { genCourses.remove(i2); break checkCourse; } else if (friendcourse1 < friendcourse2) { genCourses.remove(i); break checkCourse; } else { genCourses.remove(i); break checkCourse; } } } } } } } } List<List<Courses[]>> semesters = new ArrayList<>(); List<Students> friends = StudentDAO.getFriends(currentStudent.getStudentid()); for (Courses course : genCourses) { for (Students friend : friends) { List<Courses> friendCourses = CourseDAO.getCoursesForStudent(friend.getStudentid()); for (Courses friendCourse : friendCourses) { if (friendCourse.getCourseid() == (course.getCourseid())) { if (course.getFriends() != null) { course.setFriends(course.getFriends() + " " + friend.getFirstname() + " " + friend.getLastname()); } else { course.setFriends(friend.getFirstname() + " " + friend.getLastname()); } } } } } for (int s = 0; s < currentSchool.getNumsemesters(); s++) { List<Courses[]> schedule = new ArrayList<>(); for (int i = 0; i < currentSchool.getNumperiods(); i++) { Courses[] period = new Courses[7]; for (Courses course : genCourses) { Scheduleblocks sb = ScheduleBlockDAO.getScheduleBlock(course.getScheduleblockid()); if (sb.getPeriod() == i + 1) { String[] days = sb.getDays().split(","); String[] semester = course.getSemester().split(","); for (String sem : semester) { if (Integer.parseInt(sem) == s + 1) { for (String day : days) { period[Integer.parseInt(day) - 1] = course; } } } } } schedule.add(period); } semesters.add(schedule); } model.addAttribute("semester", semesters); logger.info("Generated schedule complete."); } else { model.addAttribute("conflictCourses", conflictCourses); logger.info("Conflicting courses displayed."); } List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname()); model.addAttribute("schoolyears", schoolyears); handler.close(); logger.removeHandler(handler); } catch (IOException ex) { logger.log(Level.SEVERE, null, ex); } catch (SecurityException ex) { logger.log(Level.SEVERE, null, ex); } return "studentviewgenerated"; }
From source file:BSxSB.Controllers.StudentController.java
@RequestMapping(value = "/acceptfriend", method = RequestMethod.POST) public String acceptfriend(Model model, @RequestParam(value = "id") int id) { try {/*from w w w. ja v a 2s .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); FriendshipsDAO.acceptfriend(currentStudent.getStudentid(), id); logger.info("Approved 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:com.openbravo.pos.sales.JRetailPanelTicket.java
public void init(AppView app) throws BeanFactoryException { m_App = app;//from www. j a v a 2 s. c o m dlSystem = (DataLogicSystem) m_App.getBean("com.openbravo.pos.forms.DataLogicSystem"); dlSales = (DataLogicSales) m_App.getBean("com.openbravo.pos.forms.DataLogicSales"); dlCustomers = (DataLogicCustomers) m_App.getBean("com.openbravo.pos.customers.DataLogicCustomers"); dlReceipts = (DataLogicReceipts) m_App.getBean("com.openbravo.pos.sales.DataLogicReceipts"); // borramos el boton de bascula si no hay bascula conectada if (!m_App.getDeviceScale().existsScale()) { // m_jbtnScale.setVisible(false); } if (m_App.getProperties().getProperty("machine.ticketsbag").equals("restaurant")) { m_jbtnPrintBill.setVisible(true); } else { m_jbtnPrintBill.setVisible(false); } customerFocus(); menuStatus = m_App.getProperties().getProperty("machine.menustatus"); m_jPor.setVisible(false); m_ticketsbag = getJTicketsBag(); m_oTicket.setCancelTicket(false); m_jPanelBag.add(m_ticketsbag.getBagComponent(), BorderLayout.LINE_START); add(m_ticketsbag.getNullComponent(), "null"); m_ticketlines = new JRetailTicketLines(dlSystem.getResourceAsXML("Ticket.Line")); m_jPanelCentral.add(m_ticketlines, java.awt.BorderLayout.CENTER); m_TTP = new TicketParser(m_App.getDeviceTicket(), dlSystem); // The configurable buttons m_jbtnconfig = new JRetailPanelButtons("Ticket.Buttons", this); m_jButtonsExt.add(m_jbtnconfig); // The panel product lines catcontainer.add(getSouthComponent(), BorderLayout.CENTER); catcontainer.setVisible(true); m_jCalculatePromotion.setVisible(true); m_jCalculatePromotion.setEnabled(false); //m_jBtnServed.setVisible(false); // The model tax senttax = dlSales.getRetailTaxList(); sentcharge = dlSales.getRetailServiceChargeList(); senttaxcategories = dlSales.getTaxCategoriesList(); sentsertax = dlSales.getRetailServiceTaxList(); sentSBtax = dlSales.getRetailSwachBharatTaxList(); taxcategoriesmodel = new ComboBoxValModel(); // ponemos a cero el estado stateToZero(); //creating log file for kot String logpath = m_App.getProperties().getProperty("machine.kotlogfile"); logpath = logpath + getLogDate() + "-POS" + m_App.getProperties().getPosNo() + ".txt"; try { fh1 = new FileHandler(logpath, true); } catch (IOException ex) { Logger.getLogger(JRetailPanelTicket.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(JRetailPanelTicket.class.getName()).log(Level.SEVERE, null, ex); } kotlogger.addHandler(fh1); SimpleFormatter formatter = new SimpleFormatter(); fh1.setFormatter(formatter); //creating log file for print bill logpath = m_App.getProperties().getProperty("machine.printlogfile"); logpath = logpath + getLogDate() + "-POS" + m_App.getProperties().getPosNo() + ".txt"; try { fh2 = new FileHandler(logpath, true); } catch (IOException ex) { Logger.getLogger(JRetailPanelTicket.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(JRetailPanelTicket.class.getName()).log(Level.SEVERE, null, ex); } printlogger.addHandler(fh2); fh2.setFormatter(formatter); //creating log file for settle bill logpath = m_App.getProperties().getProperty("machine.settlelogfile"); logpath = logpath + getLogDate() + "-POS" + m_App.getProperties().getPosNo() + ".txt"; try { fh3 = new FileHandler(logpath, true); } catch (IOException ex) { Logger.getLogger(JRetailPanelTicket.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(JRetailPanelTicket.class.getName()).log(Level.SEVERE, null, ex); } settlelogger.addHandler(fh3); fh3.setFormatter(formatter); }
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.j a va2 s . c om //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 = "/unfriend", method = RequestMethod.POST) public String unfriend(Model model, @RequestParam(value = "id") int id) { try {// w w w . java 2 s . com //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("Successfully deleted friendship between " + currentStudent.getStudentid() + " and " + id); List<Students> friends = StudentDAO.getFriends(currentStudent.getStudentid()); Schools currentSchool = SchoolDAO.getSchool(currentStudent.getSchoolid()); List<Schools> schoolyears = SchoolDAO.getSchoolSameName(currentSchool.getSchoolname()); model.addAttribute("schoolyears", schoolyears); model.addAttribute("friends", friends); logger.info("Friends 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 "studentdisplayfriends"; }
From source file:BSxSB.Controllers.StudentController.java
@RequestMapping(value = "/addfriend", method = RequestMethod.POST) public String addfriend(Model model, @RequestParam(value = "email") String email) { try {//ww w . j a va 2s .com //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"; }