1

We have a calendar in our web application. Events can be added to the calendar, and events will have some start date and end date.

Events can also have a reminder. So, while adding an event, if a user decides to he notified of the event by a reminder email, the user can set the reminder value in the event. Similar to what we have in Outlook.

For example, Event Name: Weekly Meeting

Start date: 1st March, 10 AM

Reminder: 1 hour (it can be 15min, 30 min, 1 hr, 2 hr, 1 day, 2 day, etc).

So, in this case an email should be sent to the user before the event, that is, 1 hour before.

An event table in the database has event name, start date, reminder.

How do I implement this in Java?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ajm
  • 12,863
  • 58
  • 163
  • 234

3 Answers3

1

You might want to run a scheduled job that checks the events and reminders and sends emails if necessary.

If you're using an application server like JBoss you could use the Quartz scheduler (JBoss normally contains a version of quartz already). Then set the job to run at the lowest reminder granularity, e.g. every 15 minutes.

Thomas
  • 87,414
  • 12
  • 119
  • 157
1

If you don't want to use an external scheduler, a Java Timer can be used. You need to implement the TimerTask interface and schedule it using the Timer for whatever frequency you require. The TimerTask should simply query the database to get all the upcoming events and send emails.

To get all the upcoming events, use the proper SQL syntax for your database -

WHERE (START_DATE - TODAY) < REMINDER_ADVANCE

To send email, use the Java mail API.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
rahulmohan
  • 1,285
  • 11
  • 19
  • We will be using quartz and spring integration for scheduling the notification emails. The real problem is to get the upcoming events accurately. What will be the proper query to get the events to be notified? – ajm Mar 10 '11 at 10:58
  • @rahulmohan Do I have to run separate query for each of the reminder_advances? i.e. a query to check if there are events in next 15 minutes, another query for 30 minutes and so on for 1 day , 2 day etc? – ajm Mar 10 '11 at 11:02
  • @Ashish: No, you need only one query "SELECT * FROM EVENTS WHERE START_DATE - SYSDATE < REMINDER_ADVANCE" ( For oracle ). This will give you all the events. – rahulmohan Mar 10 '11 at 11:37
  • @rahulmohan But what will be the value of the REMINDER_ADVANCE? – ajm Mar 10 '11 at 11:40
  • @Ashish: oops. I should have written REMINDER - the column in your event table that stores the reminder advance time. It will have 1 if the reminder is 1 day in advance, 1/24 if it is 1 hour in advance, 1/(24*60) if it is 1 minute in advance and so on. – rahulmohan Mar 10 '11 at 12:08
  • @rahulmohan I will need for all the reminders at once. – ajm Mar 10 '11 at 12:10
0

Modern way: You may integrate your web application with some of the cloud reminder services - Google calendar, RTM, ToodleDo, etc. Google calendar has a Java API to their calendar service, others have useful APIs as well.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alexey Sviridov
  • 3,360
  • 28
  • 33
  • Using something entirely different now is not possible. So we will have to carry on with what we have and try to implement it. :( – ajm Mar 10 '11 at 11:05
  • I'm not about entirely different. You may integrate your site wtth for example google through API, so, your users will be still using your site, but your site will be use google as backend reminder engine. – Alexey Sviridov Mar 10 '11 at 12:20