예제 #1
0
 @Autowired
 public ReminderController(
     ReminderValidator reminderValidator,
     UserService userService,
     ReminderService reminderService) {
   try {
     this.qm = QuartzManager.getSingletonManager();
     this.reminderValidator = reminderValidator;
     this.userService = userService;
   } catch (SchedulerException e) {
     e.printStackTrace();
   }
   this.reminderService = reminderService;
 }
예제 #2
0
  @RequestMapping(value = "/reminder", method = RequestMethod.POST)
  public String submitReminder(
      @ModelAttribute("form") @Valid ReminderForm form, BindingResult result) {
    System.out.println("test reminder");

    if (result.hasErrors()) {
      /* show error to user */
      return "reminder";
    }

    Reminder reminder = Reminder.createReminder(form);

    /* Save to database code. should url be localhost:8080/reminder/{userId} ? */

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    String name = auth.getName();
    Optional<User> opUser = (Optional<User>) userService.getUserByEmail(name);
    User user = opUser.get();

    reminder.setUser(user);

    reminderService.save(reminder);

    System.out.println("Post reminder request from " + name);
    System.out.println("details: " + user.getEmail());
    System.out.println(
        reminder.getMessage()
            + "+"
            + reminder.getRecipient()
            + "+"
            + reminder.getStart()
            + "+"
            + reminder.getInterval());

    try {
      qm.createCronJob(reminder);
    } catch (SchedulerException e) {
      e.printStackTrace();
    }

    return "redirect:/main";
  }