Changeset 8888 for trunk/greenstone3-extensions/gsdl-as
- Timestamp:
- 2005-01-12T11:39:22+13:00 (19 years ago)
- Location:
- trunk/greenstone3-extensions/gsdl-as
- Files:
-
- 6 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/greenstone3-extensions/gsdl-as/create-tables.sql
r8875 r8888 30 30 unique (subscription,predicate) 31 31 ); 32 33 create table events ( 34 id int primary key auto_increment, 35 timestamp datetime not null, 36 content text not null 37 ); 38 39 create table events_to_subs ( 40 event int not null references events.id, 41 subscription int not null references subscriptions.id, 42 43 unique (event,subscription) 44 ); -
trunk/greenstone3-extensions/gsdl-as/lib/templates/feed.vm
r8720 r8888 1 1 <?xml version="1.0"?> 2 < ?xml-stylesheet type="text/xsl" href="/alerting/rss2html.xsl"?>2 <!--<?xml-stylesheet type="text/xml" href="/alerting/rss2html.xml"?>--> 3 3 <rss version="2.0"> 4 4 <channel> 5 <title> $title</title>6 <link> TODO</link>7 <description>T DOD</description>5 <title>Events for Subscription $subscription.name</title> 6 <link>/alerting/service?action=showFeed&subscriptionID=$subscription.id</link> 7 <description>TODO</description> 8 8 <language>en</language> 9 <lastBuildDate> TODO</lastBuildDate>9 <lastBuildDate>$lastBuildDate</lastBuildDate> 10 10 <generator>Alerting Service for Greenstone</generator> 11 <webMaster> TODO</webMaster>11 <webMaster>$webmaster</webMaster> 12 12 13 13 #foreach($event in $list) -
trunk/greenstone3-extensions/gsdl-as/lib/templates/list.vm
r8867 r8888 14 14 <div class="subscription"> 15 15 <p><span class="sub_id">Subscription $sub.Id</span><br/> 16 <a href="service?action=show Feed&subscriptionID=$sub.Id">show matching events</a> | <a href="service?action=editSubscription&subscriptionID=$sub.Id">edit subscription</a> | <a href="service?action=deleteSubscription&subscriptionID=$sub.Id">delete subscription</a></p>17 <table class="subscription">16 <a href="service?action=showEvents&subscriptionID=$sub.Id">show matching events</a> | <a href="service?action=editSubscription&subscriptionID=$sub.Id">edit subscription</a> | <a href="service?action=deleteSubscription&subscriptionID=$sub.Id">delete subscription</a></p> 17 <!-- <table class="subscription"> 18 18 <thead> 19 19 <tr><th>Field</th><th>Predicate</th></tr> … … 28 28 #end 29 29 </tbody> 30 </table> 30 </table> // --> 31 <pre> 32 $sub 33 </pre> 31 34 <br/> 32 35 </div> -
trunk/greenstone3-extensions/gsdl-as/lib/templates/sub_type-details.vm
r8724 r8888 4 4 <html xmlns="http://www.w3.org/1999/xhtml"> 5 5 <head> 6 <title> Andrea Schweer</title>6 <title>Create a subscription</title> 7 7 <link rel="stylesheet" href="/alerting/form.css" type="text/css"/> 8 8 </head> -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java
r8874 r8888 10 10 11 11 import java.lang.reflect.Method; 12 import java.net.MalformedURLException;13 12 import java.net.URL; 14 13 import java.sql.SQLException; … … 24 23 import org.greenstone.gsdlas.database.DatabaseException; 25 24 import org.greenstone.gsdlas.profiles.Predicate; 25 import org.greenstone.gsdlas.profiles.Subscription; 26 26 import org.greenstone.gsdlas.users.UserManagementException; 27 27 import org.greenstone.gsdlas.users.UserManager; … … 58 58 "deleteSubscription", 59 59 "editSubscription", 60 "showEvents", 60 61 "showFeed", 61 62 "listSubscriptions", … … 175 176 } 176 177 177 public String showFeed(Map arguments, Context context) { 178 context.put("list", ""/* TODO pass subscription list */); 178 public String showFeed(Map arguments, Context context) throws NumberFormatException, DatabaseException, SQLException { 179 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 180 if (!UserManager.getInstance().isLoggedIn(session)) { 181 session.setAttribute("next_action", "showFeed"); 182 return showLoginForm(arguments, context); 183 } 184 String subscriptionID = (String) arguments.get("subscriptionID"); 185 Integer subID = new Integer(subscriptionID); 186 Set events = EventStore.getInstance().getEvents(subID); 187 context.put("list", events); 188 context.put("subscription", ProfileStore.getInstance().getSubscription(subID.intValue())); 189 HttpServletResponse res = (HttpServletResponse) context.get(RESPONSE); 190 res.setContentType("text/xml"); 179 191 return "feed.vm"; 192 } 193 194 public String showEvents(Map arguments, Context context) throws NumberFormatException, DatabaseException, SQLException { 195 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 196 if (!UserManager.getInstance().isLoggedIn(session)) { 197 session.setAttribute("next_action", "showEvents"); 198 return showLoginForm(arguments, context); 199 } 200 String subscriptionID = (String) arguments.get("subscriptionID"); 201 Integer subID = new Integer(subscriptionID); 202 Set events = EventStore.getInstance().getEvents(subID); 203 context.put("list", events); 204 context.put("subscription", ProfileStore.getInstance().getSubscription(subID.intValue())); 205 return "events.vm"; 180 206 } 181 207 … … 250 276 for (Iterator iter = rawEvent.keySet().iterator(); iter.hasNext();) { 251 277 String key = (String) iter.next(); 278 if (key.equals("action")) continue; // we don't want this 252 279 String[] value = (String[]) rawEvent.get(key); 253 280 event.put(key, value[0]); … … 259 286 String hostID = (String) event.get(Constants.HOST_ID_FIELD); 260 287 gsComm = new GreenstoneCommunicator(new URL(hostID)); 261 } catch ( MalformedURLException e) {262 // TODO Auto-generated catch block288 } catch (Exception e) { 289 System.err.println("Can't communicate to Greenstone: " + e.getMessage()); 263 290 e.printStackTrace(); 291 } 292 293 Set matchedSubscriptions = ProfileStore.getInstance().filter(event, gsComm); 294 295 try { 296 EventStore.getInstance().add(event, matchedSubscriptions); 297 Notifier.getInstance().sendNotifications(event, matchedSubscriptions); 264 298 } catch (Exception e) { 265 // TODO Auto-generated catch block299 System.err.println("Couldn't save events: " + e.getMessage()); 266 300 e.printStackTrace(); 267 301 } 268 Set matchedSubscriptions = ProfileStore.getInstance().filter(event, gsComm);269 302 System.out.println(matchedSubscriptions.size() + " matching subscriptions: " + matchedSubscriptions); 270 // TODO do something with the matched subscriptions271 303 } 272 304 … … 322 354 */ 323 355 private String showSubscriptionWizardPage(Map arguments, Context context, boolean create) throws Exception { 356 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 324 357 if (create) { 325 358 context.put(Constants.ACTION_PARAM, "createSubscription"); 326 359 } else { 360 // prefill from existing subscription 327 361 context.put(Constants.ACTION_PARAM, "editSubscription"); 362 String subscriptionID = (String) arguments.get("subscriptionID"); 363 int subID = Integer.parseInt(subscriptionID); 364 prefillFromSubscription(session, subID); 328 365 } 329 366 if (!arguments.containsKey("current_page")) { … … 331 368 } 332 369 333 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true);334 370 String currentPage = (String) arguments.get("current_page"); 335 371 String direction = (String) arguments.get("next_page"); … … 412 448 413 449 /** 450 * @param session 451 * @param subID 452 */ 453 private void prefillFromSubscription(HttpSession session, int subID) { 454 Subscription sub = ProfileStore.getInstance().getSubscription(subID); 455 Map typeArgs = new HashMap(); 456 // TODO really fill stuff 457 savePageArgsToSession("type-details", typeArgs, session); 458 Map hostArgs = new HashMap(); 459 savePageArgsToSession("host", hostArgs, session); 460 Map collArgs = new HashMap(); 461 savePageArgsToSession("collection", collArgs, session); 462 Map notificationArgs = new HashMap(); 463 savePageArgsToSession("notification", notificationArgs, session); 464 } 465 466 /** 414 467 * @param nextPage 415 468 * @param session -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java
r8875 r8888 405 405 } 406 406 } 407 408 /** 409 * @param i 410 * @return 411 */ 412 public Subscription getSubscription(int id) { 413 return (Subscription) subscriptions.get(new Integer(id)); 414 } 407 415 408 416 } -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/database/DatabaseManager.java
r8738 r8888 9 9 package org.greenstone.gsdlas.database; 10 10 11 import java.sql.*; 11 12 import java.sql.Connection; 12 13 import java.sql.DriverManager; … … 42 43 database = DriverManager.getConnection(connectionString); 43 44 } catch (Exception e) { 45 if (e instanceof SQLException) { 46 SQLException sqle = (SQLException) e; 47 System.err.println("SQLState: " + sqle.getSQLState()); 48 } 44 49 throw new DatabaseException("Could not establish connection to database (" + connectionString + ")", e); 45 50 } -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java
r8875 r8888 1 1 /* 2 2 * Created on Nov 1, 2004 3 * Copyright (C) Andrea Schweer, 20043 * Copyright (C) 2004, 2005 Andrea Schweer 4 4 * 5 5 * This file is part of the Greenstone Alerting Service. -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/QueryPredicate.java
r8798 r8888 31 31 return true; 32 32 } 33 34 public String toString() { 35 return field + " matches " + value; 36 } 33 37 } -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Subscription.java
r8875 r8888 188 188 189 189 public String toString() { 190 return "Subscription id " + id + ": " + map; 190 StringBuffer result = new StringBuffer("Subscription "); 191 result.append(name != null ? name : "(no name) "); 192 result.append(" (id "); 193 result.append(id); 194 result.append("):\n"); 195 for (Iterator iter = map.keySet().iterator(); iter.hasNext();) { 196 String key = (String) iter.next(); 197 Object value = map.get(key); 198 if (value instanceof Predicate) { 199 Predicate pred = (Predicate) value; 200 result.append(pred); 201 } 202 if (value instanceof List) { 203 List list = (List) value; 204 for (Iterator iterator = list.iterator(); iterator.hasNext();) { 205 Predicate pred = (Predicate) iterator.next(); 206 result.append(pred); 207 if (iterator.hasNext()) { 208 result.append(" or "); 209 } 210 } 211 } 212 result.append("\n"); 213 } 214 return result.toString(); 191 215 } 192 216 … … 255 279 return id; 256 280 } 281 282 /** 283 * @return 284 */ 285 public boolean wantsEMailNotification() { 286 return email != null && email.length() > 1; 287 } 288 289 /** 290 * @return 291 */ 292 public String getMailAddress() { 293 return email; 294 } 295 296 public String getName() { 297 return name; 298 } 257 299 258 300 } -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/SubstringMatchPredicate.java
r8754 r8888 33 33 } 34 34 35 public String toString() { 36 return field + " contains " + value; 37 } 38 35 39 }
Note:
See TracChangeset
for help on using the changeset viewer.