source: branches/alerting-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/notifier/NotifierManager.java@ 8416

Last change on this file since 8416 was 8416, checked in by schweer, 20 years ago

proof-of-concept implementation for detecting new documents

  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
1package org.greenstone.gsdl3.gs3build.notifier;
2
3import java.sql.ResultSet;
4import java.sql.SQLException;
5import java.sql.Statement;
6import java.util.Calendar;
7import java.util.GregorianCalendar;
8
9import org.greenstone.gsdl3.gs3build.util.*;
10
11public class NotifierManager {
12
13 public NotifierManager() {
14 }
15
16 public void detectEvents(GS3SQLConnection database, GregorianCalendar lastBuildDate) {
17 // quick and dirty: detect all new documents, i.e. all documents where
18 // AccessionDate >= CollectionLastRebuiltDate
19
20 StringBuffer lastBuild = new StringBuffer();
21 lastBuild.append(lastBuildDate.get(Calendar.YEAR));
22 int month = lastBuildDate.get(Calendar.MONTH) + 1;
23 lastBuild.append(month < 10 ? "0" + month : "" + month);
24 int date = lastBuildDate.get(Calendar.DATE);
25 lastBuild.append(date < 10 ? "0" + date : "" + date);
26 int hour = lastBuildDate.get(Calendar.HOUR_OF_DAY);
27 lastBuild.append(hour < 10 ? "0" + hour : "" + hour);
28 int minute = lastBuildDate.get(Calendar.MINUTE);
29 lastBuild.append(minute < 10 ? "0" + minute : "" + minute);
30 int sec = lastBuildDate.get(Calendar.SECOND);
31 lastBuild.append(sec < 10 ? "0" + sec : "" + sec);
32 System.out.println("last build: " + lastBuild);
33
34 Statement statement = database.createStatement();
35 try {
36 ResultSet results = statement.executeQuery("SELECT DocID from document where DocType != 'GSMETADATA' AND AccessionDate >= " + lastBuild);
37 while(results.next()) {
38 System.out.println("new document: " + results.getString("DocID"));
39 }
40 } catch (SQLException e) {
41 // TODO Auto-generated catch block
42 e.printStackTrace();
43 }
44 }
45}
46
Note: See TracBrowser for help on using the repository browser.