Ignore:
Timestamp:
2005-05-10T15:49:29+12:00 (19 years ago)
Author:
kjdon
Message:

indented the code properly, and closed off the statement

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/notifier/NotifierManager.java

    r8869 r9848  
    1212public class NotifierManager {
    1313
    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;
    1621   
    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();
    3030        try {
    3131            // detect all new documents. A document is new if and only if
    3232            // 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?
    4344        } catch (SQLException e) {
    44             // TODO Auto-generated catch block
    45             e.printStackTrace();
     45        // TODO Auto-generated catch block
     46        e.printStackTrace();
    4647        }
    47     }
    48 
     48    }
     49   
    4950    /**
    5051     * @param collName
     
    5859     * @throws SQLException
    5960     */
    60     private void notify(String collName, String hostURL, String notifyHost, ResultSet results, GS3SQLConnection database, Date date, String eventType) {
    61         try {
    62             System.out.println("notifyHost is " + notifyHost);
    63             URL url = new URL("http://" + notifyHost + "/alerting/service");
    64             System.out.println("trying to send to " + url);
    65            
    66             while(results.next()) {
    67                 System.out.println(eventType + ": " + results.getString("DocID"));
     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"));
    6869               
    6970                String documentID = results.getString("DocID");
    7071               
    71                 try {
     72        try {
    7273                    HttpURLConnection conn = (HttpURLConnection) url.openConnection(); // TODO what about proxies?
    7374                    conn.setUseCaches(false);
     
    112113                    e1.printStackTrace();
    113114                }
    114             }
    115         } catch (SQLException e) {
    116             // TODO Auto-generated catch block
    117             e.printStackTrace();
    118         } catch (MalformedURLException e) {
     115        }
     116    } catch (SQLException e) {
     117        // TODO Auto-generated catch block
     118        e.printStackTrace();
     119    } catch (MalformedURLException e) {
    119120            // TODO Auto-generated catch block
    120121            e.printStackTrace();
    121122        }
    122     }
     123    }
    123124
    124125    /**
     
    134135        try {
    135136            String sqlString = "SELECT mdvalues.value " +
    136                     "FROM structure s JOIN divisions d ON (s.structureref = d.parentref) " +
    137                     "                 JOIN divisionmetarefs USING (divisionref) " +
    138                     "                 JOIN metadata m USING (metaid) " +
    139                     "                 JOIN namespaces USING (metadataref) " +
    140                     "                 JOIN mdvalues USING (namespaceref) " +
    141                     "  WHERE mdvalues.label = 'Title' AND s.docid = '" + documentID + "'" +
    142                     "                                 AND s.structureType = 'Whole Document' " +
    143                     "                                 AND d.parenttype = 'Structure' " +
    144                     "                                 AND m.docID = s.docid;";
     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;";
    145146            results = statement.executeQuery(sqlString);
    146147            if (results.next()) {
     
    149150                return title;
    150151            }
     152        statement.close();
    151153        } catch (SQLException e) {
    152154            e.printStackTrace();
Note: See TracChangeset for help on using the changeset viewer.