Ignore:
Timestamp:
2005-01-12T11:39:22+13:00 (19 years ago)
Author:
schweer
Message:

notifications

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  
    3030    unique (subscription,predicate)
    3131);
     32
     33create table events (
     34    id int primary key auto_increment,
     35    timestamp datetime not null,
     36    content text not null
     37);
     38
     39create 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  
    11<?xml version="1.0"?>
    2 <?xml-stylesheet type="text/xsl" href="/alerting/rss2html.xsl"?>
     2<!--<?xml-stylesheet type="text/xml" href="/alerting/rss2html.xml"?>-->
    33<rss version="2.0">
    44   <channel>
    5       <title>$title</title>
    6       <link>TODO</link>
    7       <description>TDOD</description>
     5      <title>Events for Subscription $subscription.name</title>
     6      <link>/alerting/service?action=showFeed&amp;subscriptionID=$subscription.id</link>
     7      <description>TODO</description>
    88      <language>en</language>
    9       <lastBuildDate>TODO</lastBuildDate>
     9      <lastBuildDate>$lastBuildDate</lastBuildDate>
    1010      <generator>Alerting Service for Greenstone</generator>
    11       <webMaster>TODO</webMaster>
     11      <webMaster>$webmaster</webMaster>
    1212     
    1313      #foreach($event in $list)
  • trunk/greenstone3-extensions/gsdl-as/lib/templates/list.vm

    r8867 r8888  
    1414    <div class="subscription">
    1515        <p><span class="sub_id">Subscription $sub.Id</span><br/>
    16         <a href="service?action=showFeed&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">
    1818            <thead>
    1919                <tr><th>Field</th><th>Predicate</th></tr>
     
    2828                #end
    2929            </tbody>
    30         </table>
     30        </table> // -->
     31        <pre>
     32        $sub
     33        </pre>
    3134        <br/>
    3235    </div>
  • trunk/greenstone3-extensions/gsdl-as/lib/templates/sub_type-details.vm

    r8724 r8888  
    44<html xmlns="http://www.w3.org/1999/xhtml">
    55    <head>
    6         <title>Andrea Schweer</title>
     6        <title>Create a subscription</title>
    77        <link rel="stylesheet" href="/alerting/form.css" type="text/css"/>
    88    </head>
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java

    r8874 r8888  
    1010
    1111import java.lang.reflect.Method;
    12 import java.net.MalformedURLException;
    1312import java.net.URL;
    1413import java.sql.SQLException;
     
    2423import org.greenstone.gsdlas.database.DatabaseException;
    2524import org.greenstone.gsdlas.profiles.Predicate;
     25import org.greenstone.gsdlas.profiles.Subscription;
    2626import org.greenstone.gsdlas.users.UserManagementException;
    2727import org.greenstone.gsdlas.users.UserManager;
     
    5858            "deleteSubscription",
    5959            "editSubscription",
     60            "showEvents",
    6061            "showFeed",
    6162            "listSubscriptions",
     
    175176    }
    176177   
    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");
    179191        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";
    180206    }
    181207   
     
    250276        for (Iterator iter = rawEvent.keySet().iterator(); iter.hasNext();) {
    251277            String key = (String) iter.next();
     278            if (key.equals("action")) continue; // we don't want this
    252279            String[] value = (String[]) rawEvent.get(key);
    253280            event.put(key, value[0]);
     
    259286            String hostID = (String) event.get(Constants.HOST_ID_FIELD);
    260287            gsComm = new GreenstoneCommunicator(new URL(hostID));
    261         } catch (MalformedURLException e) {
    262             // TODO Auto-generated catch block
     288        } catch (Exception e) {
     289            System.err.println("Can't communicate to Greenstone: " + e.getMessage());
    263290            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);
    264298        } catch (Exception e) {
    265             // TODO Auto-generated catch block
     299            System.err.println("Couldn't save events: " + e.getMessage());
    266300            e.printStackTrace();
    267301        }
    268         Set matchedSubscriptions = ProfileStore.getInstance().filter(event, gsComm);
    269302        System.out.println(matchedSubscriptions.size() + " matching subscriptions: " + matchedSubscriptions);
    270         // TODO do something with the matched subscriptions
    271303    }
    272304
     
    322354     */
    323355    private String showSubscriptionWizardPage(Map arguments, Context context, boolean create) throws Exception {
     356        HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true);
    324357        if (create) {
    325358            context.put(Constants.ACTION_PARAM, "createSubscription");
    326359        } else {
     360            // prefill from existing subscription
    327361            context.put(Constants.ACTION_PARAM, "editSubscription");
     362            String subscriptionID = (String) arguments.get("subscriptionID");
     363            int subID = Integer.parseInt(subscriptionID);
     364            prefillFromSubscription(session, subID);
    328365        }
    329366        if (!arguments.containsKey("current_page")) {
     
    331368        }
    332369       
    333         HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true);
    334370        String currentPage = (String) arguments.get("current_page");
    335371        String direction = (String) arguments.get("next_page");
     
    412448
    413449    /**
     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    /**
    414467     * @param nextPage
    415468     * @param session
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java

    r8875 r8888  
    405405        }
    406406    }
     407
     408    /**
     409     * @param i
     410     * @return
     411     */
     412    public Subscription getSubscription(int id) {
     413        return (Subscription) subscriptions.get(new Integer(id));
     414    }
    407415   
    408416}
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/database/DatabaseManager.java

    r8738 r8888  
    99package org.greenstone.gsdlas.database;
    1010
     11import java.sql.*;
    1112import java.sql.Connection;
    1213import java.sql.DriverManager;
     
    4243                database = DriverManager.getConnection(connectionString);
    4344            } catch (Exception e) {
     45                if (e instanceof SQLException) {
     46                    SQLException sqle = (SQLException) e;
     47                    System.err.println("SQLState: " + sqle.getSQLState());
     48                }
    4449                throw new DatabaseException("Could not establish connection to database (" + connectionString + ")", e);
    4550            }
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java

    r8875 r8888  
    11/*
    22 * Created on Nov 1, 2004
    3  * Copyright (C) Andrea Schweer, 2004
     3 * Copyright (C) 2004, 2005 Andrea Schweer
    44 *
    55 * This file is part of the Greenstone Alerting Service.
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/QueryPredicate.java

    r8798 r8888  
    3131        return true;
    3232    }
     33   
     34    public String toString() {
     35        return field + " matches " + value;
     36    }
    3337}
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Subscription.java

    r8875 r8888  
    188188   
    189189    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();
    191215    }
    192216   
     
    255279        return id;
    256280    }
     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    }
    257299   
    258300}
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/SubstringMatchPredicate.java

    r8754 r8888  
    3333    }
    3434
     35    public String toString() {
     36        return field + " contains " + value;
     37    }
     38   
    3539}
Note: See TracChangeset for help on using the changeset viewer.