Changeset 8633
- Timestamp:
- 2004-11-23T15:14:44+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/notifier/NotifierManager.java
r8610 r8633 21 21 public void detectEvents(CollectionManager collManager) { 22 22 23 String collectionName = collManager.getCollectionName(); 24 String host = "http://localhost:8080/soap/servlet/rpcrouter"; 25 23 26 String lastBuild = dateToSqlString(collManager.getBuildDate()); 24 // BTS 4 how to get the real host url 25 detectNewDocuments(collManager.getDatabase(), lastBuild, collManager.getCollectionName(), "http://localhost:8080/soap/servlet/rpcrouter"); 27 Statement statement = collManager.getDatabase().createStatement(); 28 try { 29 // detect all new documents. A document is new if and only if 30 // AccessionDate >= CollectionLastRebuiltDate 31 ResultSet results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate >= " + lastBuild); 32 notify(collectionName, host, results, collManager.getDatabase()); 33 34 // detect modified documents. A document is modified if and only if 35 // AccessionDate < CollectionLastRebuiltDate (ie, it is not new) and 36 // ModifiedDate >= IndexedDate 37 results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate < " + lastBuild + " AND ModifiedDate >= IndexedDate"); 38 notify(collectionName, host, results, collManager.getDatabase()); 39 } catch (SQLException e) { 40 // TODO Auto-generated catch block 41 e.printStackTrace(); 42 } 26 43 } 27 44 28 45 /** 29 * quick and dirty: detect all new documents. A document is new if and only if 30 * AccessionDate >= CollectionLastRebuiltDate 31 * @param database 32 * @param lastBuild 33 * @param collName TODO complete javadocs 46 * @param collName 47 * @param hostURL 48 * @param results 49 * @throws MalformedURLException 50 * @throws IOException 51 * @throws ProtocolException 52 * @throws SQLException 34 53 */ 35 private void detectNewDocuments(GS3SQLConnection database, String lastBuild, String collName, String hostURL) { 54 private void notify(String collName, String hostURL, ResultSet results, GS3SQLConnection database) { 55 try { 56 URL url = new URL("http://localhost:8080/alerting/service?receive"); 57 System.out.println("trying to POST to " + url); 58 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 59 conn.setDoOutput(true); 60 conn.setRequestMethod("POST"); 61 conn.setUseCaches(false); 62 while(results.next()) { 63 System.out.println("new document: " + results.getString("DocID")); 64 try { 65 conn.connect(); 66 OutputStream toReceiver = conn.getOutputStream(); 67 OutputStreamWriter writeToReceiver = new OutputStreamWriter(toReceiver); 68 69 // TODO HTTP Post -> SOAP 70 String documentID = results.getString("DocID"); 71 72 writeToReceiver.write("type=new_document&"); 73 writeToReceiver.write("collectionID=" + collName + "&"); 74 writeToReceiver.write("host_url=" + hostURL + "&"); 75 writeToReceiver.write("document_title=" + getDocumentTitle(documentID, database) + "&"); 76 writeToReceiver.write("documentID=" + documentID + "\n"); 77 writeToReceiver.close(); 78 79 System.out.println(conn.getResponseCode()); 80 InputStream fromReceiver = conn.getInputStream(); 81 int i; 82 while ((i = fromReceiver.read()) != -1) System.out.write(i); 83 conn.disconnect(); 84 } catch (IOException e1) { 85 // TODO Auto-generated catch block 86 System.out.println("Error talking to server."); 87 e1.printStackTrace(); 88 } 89 } 90 } catch (IOException e) { 91 // TODO Auto-generated catch block 92 e.printStackTrace(); 93 } catch (SQLException e) { 94 // TODO Auto-generated catch block 95 e.printStackTrace(); 96 } 97 } 98 99 /** 100 * @param documentID 101 * @return 102 * @throws SQLException 103 */ 104 private String getDocumentTitle(String documentID, GS3SQLConnection database) throws SQLException { 36 105 Statement statement = database.createStatement(); 37 try { 38 ResultSet results = statement.executeQuery("SELECT DocID from document where DocType != 'GSMETADATA' AND AccessionDate >= " + lastBuild); 39 while(results.next()) { 40 System.out.println("new document: " + results.getString("DocID")); 41 try { 42 URL url = new URL("http://localhost:8080/alerting/service?receive"); 43 System.out.println("trying to POST to " + url); 44 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 45 conn.setDoOutput(true); 46 conn.setRequestMethod("POST"); 47 conn.setUseCaches(false); 48 conn.connect(); 49 OutputStream toReceiver = conn.getOutputStream(); 50 OutputStreamWriter writeToReceiver = new OutputStreamWriter(toReceiver); 51 52 writeToReceiver.write("type=new_document&"); 53 writeToReceiver.write("collectionID=" + collName + "&"); 54 writeToReceiver.write("host_url=" + hostURL + "&"); 55 writeToReceiver.write("documentID=" + results.getString("DocID") + "\n"); 56 writeToReceiver.close(); 57 58 System.out.println(conn.getResponseCode()); 59 InputStream fromReceiver = conn.getInputStream(); 60 int i; 61 while ((i = fromReceiver.read()) != -1) System.out.write(i); 62 } catch (MalformedURLException e1) { 63 // TODO Auto-generated catch block 64 e1.printStackTrace(); 65 } catch (IOException e1) { 66 // TODO Auto-generated catch block 67 System.out.println("Error talking to server."); 68 e1.printStackTrace(); 69 } 70 } 71 } catch (SQLException e) { 72 // TODO Auto-generated catch block 73 e.printStackTrace(); 74 } 106 ResultSet results = statement.executeQuery("select mdvalues.value " + 107 "from mdvalues join namespaces on (mdvalues.namespaceref = namespaces.namespaceid) " + 108 "join metadata on (metadata.metadataref = namespaces.metadataref) " + 109 "where label like 'Title' and metadata.docID = '" + documentID +"';"); 110 return results.getString(0); 75 111 } 76 112
Note:
See TracChangeset
for help on using the changeset viewer.