Changeset 9848 for branches/ant-install-branch
- Timestamp:
- 2005-05-10T15:49:29+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/notifier/NotifierManager.java
r8869 r9848 12 12 public class NotifierManager { 13 13 14 public NotifierManager() { 15 } 14 public NotifierManager() { 15 } 16 17 public void detectEvents(CollectionManager collManager) { 18 String notifyHost = collManager.getNotifyHost(); 19 if (notifyHost == null) 20 return; 16 21 17 public void detectEvents(CollectionManager collManager) { 18 String notifyHost = collManager.getNotifyHost(); 19 if (notifyHost == null) 20 return; 21 22 System.out.println("detecting events"); 23 24 String collectionName = collManager.getCollectionName(); 25 String host = "http://localhost:8080/soap/servlet/rpcrouter"; 26 27 String lastBuild = dateToSqlString(collManager.getBuildDate()); 28 System.out.println("last build was " + lastBuild); 29 Statement statement = collManager.getDatabase().createStatement(); 22 System.out.println("detecting events"); 23 24 String collectionName = collManager.getCollectionName(); 25 String host = "http://localhost:8080/soap/servlet/rpcrouter"; 26 27 String lastBuild = dateToSqlString(collManager.getBuildDate()); 28 System.out.println("last build was " + lastBuild); 29 Statement statement = collManager.getDatabase().createStatement(); 30 30 try { 31 31 // detect all new documents. A document is new if and only if 32 32 // AccessionDate >= CollectionLastRebuiltDate 33 ResultSet results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate >= " + lastBuild); 34 notify(collectionName, host, notifyHost, results, collManager.getDatabase(), collManager.getBuildDate(), "new_document"); 35 36 // detect modified documents. A document is modified if and only if 37 // AccessionDate < CollectionLastRebuiltDate (ie, it is not new) and 38 // IndexedDate >= CollectionLastRebuiltDate 39 results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate < " + lastBuild + " AND IndexedDate >= " + lastBuild); 40 notify(collectionName, host, notifyHost, results, collManager.getDatabase(), collManager.getBuildDate(), "document_modified"); 41 42 // TODO deleted docs? 33 ResultSet results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate >= " + lastBuild); 34 notify(collectionName, host, notifyHost, results, collManager.getDatabase(), collManager.getBuildDate(), "new_document"); 35 36 // detect modified documents. A document is modified if and only if 37 // AccessionDate < CollectionLastRebuiltDate (ie, it is not new) and 38 // IndexedDate >= CollectionLastRebuiltDate 39 results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate < " + lastBuild + " AND IndexedDate >= " + lastBuild); 40 notify(collectionName, host, notifyHost, results, collManager.getDatabase(), collManager.getBuildDate(), "document_modified"); 41 42 statement.close(); 43 // TODO deleted docs? 43 44 } catch (SQLException e) { 44 45 45 // TODO Auto-generated catch block 46 e.printStackTrace(); 46 47 } 47 48 48 } 49 49 50 /** 50 51 * @param collName … … 58 59 * @throws SQLException 59 60 */ 60 61 62 63 64 65 66 67 61 private void notify(String collName, String hostURL, String notifyHost, ResultSet results, GS3SQLConnection database, Date date, String eventType) { 62 try { 63 System.out.println("notifyHost is " + notifyHost); 64 URL url = new URL("http://" + notifyHost + "/alerting/service"); 65 System.out.println("trying to send to " + url); 66 67 while(results.next()) { 68 System.out.println(eventType + ": " + results.getString("DocID")); 68 69 69 70 String documentID = results.getString("DocID"); 70 71 71 72 try { 72 73 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // TODO what about proxies? 73 74 conn.setUseCaches(false); … … 112 113 e1.printStackTrace(); 113 114 } 114 115 116 117 118 115 } 116 } catch (SQLException e) { 117 // TODO Auto-generated catch block 118 e.printStackTrace(); 119 } catch (MalformedURLException e) { 119 120 // TODO Auto-generated catch block 120 121 e.printStackTrace(); 121 122 } 122 123 } 123 124 124 125 /** … … 134 135 try { 135 136 String sqlString = "SELECT mdvalues.value " + 136 137 138 139 140 141 142 143 144 137 "FROM structure s JOIN divisions d ON (s.structureref = d.parentref) " + 138 " JOIN divisionmetarefs USING (divisionref) " + 139 " JOIN metadata m USING (metaid) " + 140 " JOIN namespaces USING (metadataref) " + 141 " JOIN mdvalues USING (namespaceref) " + 142 " WHERE mdvalues.label = 'Title' AND s.docid = '" + documentID + "'" + 143 " AND s.structureType = 'Whole Document' " + 144 " AND d.parenttype = 'Structure' " + 145 " AND m.docID = s.docid;"; 145 146 results = statement.executeQuery(sqlString); 146 147 if (results.next()) { … … 149 150 return title; 150 151 } 152 statement.close(); 151 153 } catch (SQLException e) { 152 154 e.printStackTrace();
Note:
See TracChangeset
for help on using the changeset viewer.