Changeset 8770
- Timestamp:
- 2004-12-09T16:26:32+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/notifier/NotifierManager.java
r8742 r8770 33 33 // AccessionDate >= CollectionLastRebuiltDate 34 34 ResultSet results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate >= " + lastBuild); 35 notify(collectionName, host, results, collManager.getDatabase(), "new_document");35 notify(collectionName, host, results, collManager.getDatabase(), collManager.getBuildDate(), "new_document"); 36 36 37 37 // detect modified documents. A document is modified if and only if … … 39 39 // ModifiedDate >= IndexedDate 40 40 results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate < " + lastBuild + " AND ModifiedDate >= IndexedDate"); 41 notify(collectionName, host, results, collManager.getDatabase(), "document_modified");41 notify(collectionName, host, results, collManager.getDatabase(), collManager.getBuildDate(), "document_modified"); 42 42 } catch (SQLException e) { 43 43 // TODO Auto-generated catch block … … 50 50 * @param hostURL 51 51 * @param results 52 * @param date 52 53 * @param eventType TODO 53 54 * @throws MalformedURLException … … 56 57 * @throws SQLException 57 58 */ 58 private void notify(String collName, String hostURL, ResultSet results, GS3SQLConnection database, String eventType) {59 private void notify(String collName, String hostURL, ResultSet results, GS3SQLConnection database, Date date, String eventType) { 59 60 try { 60 URL url = new URL( hostURL);61 System.out.println("trying to send (via SOAP)to " + url);61 URL url = new URL("http://localhost:8080/alerting/service"); 62 System.out.println("trying to send to " + url); 62 63 63 64 while(results.next()) { 64 65 System.out.println("new document: " + results.getString("DocID")); 65 Map event = new TreeMap();66 66 67 67 String documentID = results.getString("DocID"); 68 68 69 event.put("documentID", documentID);70 event.put("type", eventType);71 event.put("collectionID", collName);72 event.put("host_url", hostURL);73 event.put("document_title", getDocumentTitle(documentID, database));74 75 Call call = new Call();76 call.setTargetObjectURI("alerting");77 call.setMethodName("receiveEvent");78 call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);79 Vector params = new Vector();80 params.addElement(new Parameter("event", Map.class, event, null));81 call.setParams(params);82 69 try { 83 Response resp = call.invoke(url, ""); 84 if (!resp.generatedFault()) { 85 System.out.println("successfully posted event"); 86 return; 70 HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // TODO what about proxies? 71 conn.setUseCaches(false); 72 conn.setDoInput(true); 73 conn.setDoOutput(true); 74 conn.setRequestMethod("POST"); 75 conn.connect(); 76 // Construct data 77 OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); 78 79 writer.write("action=receiveEvent&"); 80 writer.write("documentID="); 81 writer.write(URLEncoder.encode(documentID, "UTF-8")); 82 writer.write("&type="); 83 writer.write(URLEncoder.encode(eventType, "UTF-8")); 84 writer.write("&collectionID="); 85 writer.write(URLEncoder.encode(collName, "UTF-8")); 86 writer.write("&host_url="); 87 writer.write(URLEncoder.encode(hostURL, "UTF-8")); 88 writer.write("&document_title="); 89 writer.write(URLEncoder.encode(getDocumentTitle(documentID, database), "UTF-8")); 90 writer.write("&document_url="); 91 writer.write(URLEncoder.encode("http://localhost:8080/gsdl3/library?a=d&c=" + collName + "&d=" + documentID, "UTF-8")); 92 writer.write("×tamp="); 93 writer.write(URLEncoder.encode(new SimpleDateFormat("yyyy-MM-dd HH:mm z").format(date), "UTF-8")); 94 writer.flush(); 95 System.out.println(conn.getResponseCode()); 96 InputStream fromReceiver = conn.getInputStream(); 97 int i; 98 while ((i = fromReceiver.read()) != -1) { 99 System.out.write(i); 87 100 } 88 System.err.println("Posting event was unsuccessful:"); 89 System.err.println(resp.getFault().getFaultString()); 90 } catch (SOAPException e1) { 91 System.err.println("Exception while posting event: "); 101 conn.disconnect(); 102 } catch (ProtocolException e1) { 103 // TODO Auto-generated catch block 104 e1.printStackTrace(); 105 } catch (UnsupportedEncodingException e1) { 106 // TODO Auto-generated catch block 107 e1.printStackTrace(); 108 } catch (IOException e1) { 109 // TODO Auto-generated catch block 92 110 e1.printStackTrace(); 93 111 } 112 // 113 // Call call = new Call(); 114 // call.setTargetObjectURI("alerting"); 115 // call.setMethodName("receiveEvent"); 116 // call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); 117 // Vector params = new Vector(); 118 // params.addElement(new Parameter("event", Map.class, event, null)); 119 // call.setParams(params); 120 // try { 121 // Response resp = call.invoke(url, ""); 122 // if (!resp.generatedFault()) { 123 // System.out.println("successfully posted event"); 124 // return; 125 // } 126 // System.err.println("Posting event was unsuccessful:"); 127 // System.err.println(resp.getFault().getFaultString()); 128 // 129 // Vector entries = resp.getFault().getDetailEntries(); 130 // for (Iterator i = entries.iterator(); i.hasNext(); ) { 131 // org.w3c.dom.Element entry = (org.w3c.dom.Element)i.next( ); 132 // System.err.println(entry.getFirstChild().getNodeValue( )); 133 // } 134 // } catch (SOAPException e1) { 135 // System.err.println("Exception while posting event: "); 136 // e1.printStackTrace(); 137 // } 94 138 } 95 } catch (IOException e) {96 // TODO Auto-generated catch block97 e.printStackTrace();98 139 } catch (SQLException e) { 99 140 // TODO Auto-generated catch block 100 141 e.printStackTrace(); 101 } 142 } catch (MalformedURLException e) { 143 // TODO Auto-generated catch block 144 e.printStackTrace(); 145 } 102 146 } 103 147 … … 107 151 * @throws SQLException 108 152 */ 109 private String getDocumentTitle(String documentID, GS3SQLConnection database) throws SQLException{153 private String getDocumentTitle(String documentID, GS3SQLConnection database) { 110 154 Statement statement = database.createStatement(); 111 ResultSet results = statement.executeQuery("select mdvalues.value " + 112 "from mdvalues join namespaces on (mdvalues.namespaceref = namespaces.namespaceid) " + 113 "join metadata on (metadata.metadataref = namespaces.metadataref) " + 114 "where label like 'Title' and metadata.docID = '" + documentID +"';"); 115 return results.getString(0); 155 ResultSet results; 156 try { 157 String sqlString = "SELECT mdvalues.value " + 158 "FROM structure s JOIN divisions d ON (s.structureref = d.parentref) " + 159 " JOIN divisionmetarefs USING (divisionref) " + 160 " JOIN metadata m USING (metaid) " + 161 " JOIN namespaces USING (metadataref) " + 162 " JOIN mdvalues USING (namespaceref) " + 163 " WHERE mdvalues.label = 'Title' AND s.docid = '" + documentID + "'" + 164 " AND s.structureType = 'Whole Document' " + 165 " AND d.parenttype = 'Structure' " + 166 " AND m.docID = s.docid;"; 167 results = statement.executeQuery(sqlString); 168 return results.getString(0); 169 } catch (SQLException e) { 170 return ""; 171 } 116 172 } 117 173
Note:
See TracChangeset
for help on using the changeset viewer.