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

notifications

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/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
Note: See TracChangeset for help on using the changeset viewer.