Index: trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java
===================================================================
--- trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java	(revision 8775)
+++ trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java	(revision 8777)
@@ -21,4 +21,5 @@
 import org.greenstone.gsdlas.users.UserManagementException;
 import org.greenstone.gsdlas.users.UserManager;
+import org.greenstone.gsdlas.util.ArrayHelper;
 
 /**
@@ -30,20 +31,16 @@
 public class AlertingService extends VelocityServlet {
     
-    public static final Set actions;
-    static {
-        Set set = new TreeSet();
-        set.add("createSubscription");
-        set.add("deleteSubscription");
-        set.add("editSubscription");
-        set.add("showFeed");
-        set.add("listSubscriptions");
-        
-        set.add("login");
-        set.add("register");
-        set.add("logout");
-        set.add("showLoginForm");
-        set.add("showRegistrationForm");
-        actions = Collections.unmodifiableSet(set);
-    }
+    public static final String[] actions = new String[] {
+            "createSubscription",
+            "deleteSubscription",
+            "editSubscription",
+            "showFeed",
+            "listSubscriptions",
+            "login",
+            "register",
+            "logout",
+            "showLoginForm",
+            "showRegistrationForm"
+    };
     
     
@@ -52,17 +49,21 @@
         
         String action = req.getParameter("action");
-        
-        if (action == null || !actions.contains(action)) {
-            String title = "Unknown action";
-            String message = "I don't know how to " + action;
-            String details = "The only actions I know are " + actions;
-            return showError(context, message, details);
-        }
-        
 
         Map args = req.getParameterMap();
         // TODO stop this, we need multi-valued stuff
         args = normalise(args);
-        
+
+        if (action != null && action.equals("receiveEvent")) {
+            receiveEvent(args);
+            return null;
+        }
+        
+        if (action == null || !ArrayHelper.contains(actions, action)) {
+            String title = "Unknown action";
+            String message = "I don't know how to " + action;
+            String details = "The only actions I know are " + Arrays.toString(actions);
+            return showError(context, message, details);
+        }
+                
         String templateString = "";
         
@@ -163,5 +164,5 @@
         String username = (String) session.getAttribute("username");
         context.put("title", "List of Subscriptions for " + username);
-        context.put("list", ProfileStore.getInstance().getAllSubscriptions());
+        context.put("list", ProfileStore.getInstance().getAllSubscriptionsFor(username));
         return "list.vm";
     }
Index: trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java
===================================================================
--- trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java	(revision 8775)
+++ trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java	(revision 8777)
@@ -25,8 +25,6 @@
     private static ProfileStore instance;
 
-    private Map docIdEqualsSubscriptions = new TreeMap();
-    private Map collectionIdEqualsSubscriptions = new TreeMap();
-    private Map docCollectionIdEqualsSubscriptions = new TreeMap();
     private Set noEqualsSubscriptions = new TreeSet(); 
+    private Map subscriptions = new TreeMap();
 
     private ProfileStore() {
@@ -50,45 +48,14 @@
         Predicate documentIdPredicate = subscription.getPredicate("documentID");
         Predicate collectionIdPredicate = subscription.getPredicate("collectionID");
-        
-        if (documentIdPredicate != null) {
-            IdEqualsPredicate docIdPredicate 
-            	= (IdEqualsPredicate) documentIdPredicate;
-            if (collectionIdPredicate != null) {
-                IdEqualsPredicate collIdPredicate 
-                	= (IdEqualsPredicate) collectionIdPredicate;
-                
-                String[] values = new String[2];
-                values[0] = docIdPredicate.getValue();
-                values[1] = collIdPredicate.getValue();
-                
-                Set subList = (Set) docCollectionIdEqualsSubscriptions.get(values);
-                if (subList == null) {
-                    subList = new TreeSet();
-                    docCollectionIdEqualsSubscriptions.put(values, subList);
-                }
-                subList.add(subscription);
-            } else {
-                String value = docIdPredicate.getValue();
-                Set subList = (Set) docIdEqualsSubscriptions.get(value);
-                if (subList == null) {
-                    subList = new TreeSet();
-                    docIdEqualsSubscriptions.put(value, subList);
-                }
-                subList.add(subscription);
-            }
-        } else if (collectionIdPredicate != null) {
-            IdEqualsPredicate collIdPredicate 
-            	= (IdEqualsPredicate) collectionIdPredicate;
-            
-            String value = collIdPredicate.getValue();
-            Set subList = (Set) collectionIdEqualsSubscriptions.get(value);
-            if (subList == null) {
-                subList = new TreeSet();
-                collectionIdEqualsSubscriptions.put(value, subList);
-            }
-            subList.add(subscription);
-        } else {
-            noEqualsSubscriptions.add(subscription);
-        }
+        Predicate hostIdPredicate = subscription.getPredicate("host");
+        Predicate typePredicate = subscription.getPredicate("type");
+        
+        Integer subId = new Integer(subscription.getId());
+        
+        if (documentIdPredicate == null && collectionIdPredicate == null 
+                && hostIdPredicate == null && typePredicate == null) {
+            noEqualsSubscriptions.add(subId);
+        }
+        subscriptions.put(subId, subscription);
     }
 
@@ -107,29 +74,22 @@
     public Set getPartiallyMatchedSubscriptions(Map event) {
         Set result = new TreeSet();
-        if (event.get("documentID") != null) {
-            String documentID = (String) event.get("documentID");
-            if (event.get("collectionID") != null) {
-                String collectionID = (String) event.get("collectionID");
-                String[] values = new String[] {documentID, collectionID};
-                Set fromDocAndCollectionId = (Set) docCollectionIdEqualsSubscriptions.get(values);
-                if (fromDocAndCollectionId != null) {
-                    result.addAll(fromDocAndCollectionId);
-                }
-                Set fromCollectionId = (Set) collectionIdEqualsSubscriptions.get(collectionID);
-                if (fromCollectionId != null) {
-                    result.addAll(fromCollectionId);
-                }
-            }
-            Set fromDocId = (Set) collectionIdEqualsSubscriptions.get(documentID);
-            if (fromDocId != null) {
-                result.addAll(fromDocId);
-            }
-        } else if (event.get("collectionID") != null){
-            String collectionID = (String) event.get("collectionID");
-            Set fromCollectionId = (Set) collectionIdEqualsSubscriptions.get(collectionID);
-            if (fromCollectionId != null) {
-                result.addAll(fromCollectionId);
-            }
-        }
+        // TODO rework algo for getting partially matched subs
+        result.addAll(PredicateFactory.getIdEqualsPredicate("type", (String)event.get("type")).getSubscriptionIDs());
+        
+        Set docIDSubs = new TreeSet();
+        docIDSubs.addAll(PredicateFactory.getIdEqualsPredicate("documentID", (String)event.get("documentID")).getSubscriptionIDs());
+        docIDSubs.addAll(PredicateFactory.getIdEqualsPredicate("documentID", null).getSubscriptionIDs());
+        result.retainAll(docIDSubs);
+        
+        Set collIDSubs = new TreeSet();
+        collIDSubs.addAll(PredicateFactory.getIdEqualsPredicate("collectionID", (String)event.get("collectionID")).getSubscriptionIDs());
+        collIDSubs.addAll(PredicateFactory.getIdEqualsPredicate("collectionID", null).getSubscriptionIDs());
+        result.retainAll(collIDSubs);
+        
+        Set hostIDSubs = new TreeSet();
+        hostIDSubs.addAll(PredicateFactory.getIdEqualsPredicate("host", (String)event.get("host")).getSubscriptionIDs());
+        hostIDSubs.addAll(PredicateFactory.getIdEqualsPredicate("host", null).getSubscriptionIDs());
+        result.retainAll(hostIDSubs);
+        
         return result;
     }
@@ -206,8 +166,9 @@
                     .hasNext();) {
                 // TODO change to subscription IDs
-                Subscription sub = (Subscription) iterator.next();
-                Integer count = (Integer) numMatchedPredicates.get(sub);
+                Integer subId = (Integer) iterator.next();
+                Subscription sub = (Subscription) subscriptions.get(subId);
+                Integer count = (Integer) numMatchedPredicates.get(subId);
                 int newCountValue = (count == null ? 1 : count.intValue() + 1);
-                numMatchedPredicates.put(sub,
+                numMatchedPredicates.put(subId,
                         new Integer(newCountValue));
             }
@@ -218,8 +179,9 @@
         for (Iterator iter = notUnmatchedSubscriptions.iterator(); iter
                 .hasNext();) {
-            Subscription sub = (Subscription) iter.next();
+            Integer subId = (Integer) iter.next();
+            Subscription sub = (Subscription) subscriptions.get(subId);
             int matchedPredicatesCount = 0;
-            if (numMatchedPredicates.get(sub) != null) {
-                matchedPredicatesCount = ((Integer) numMatchedPredicates.get(sub)).intValue();
+            if (numMatchedPredicates.get(subId) != null) {
+                matchedPredicatesCount = ((Integer) numMatchedPredicates.get(subId)).intValue();
             }
             if (matchedPredicatesCount == sub.getNumOfNonEqualsPredicates()) {
@@ -229,42 +191,42 @@
         return matchedSubscriptions;
     }
-
-    public String toString() {
-        Set allSubscriptions = getAllSubscriptions();
-        
-        StringBuffer buffer = new StringBuffer();
-        
-        for (Iterator iter = allSubscriptions.iterator(); iter.hasNext();) {
-            Subscription sub = (Subscription) iter.next();
-            buffer.append(sub);
-            buffer.append("\n");
-        }
-        
-        return buffer.toString();
-    }
-
-    /**
-     * @return
-     */
-    public Set getAllSubscriptions() {
-        Set allSubscriptions = new TreeSet();
-        allSubscriptions.addAll(noEqualsSubscriptions);
-        
-        for(Iterator iter = docIdEqualsSubscriptions.values().iterator(); iter.hasNext();) {
-            Set values = (Set) iter.next();
-            allSubscriptions.addAll(values);
-        }
-        
-        for(Iterator iter = docCollectionIdEqualsSubscriptions.values().iterator(); iter.hasNext();) {
-            Set values = (Set) iter.next();
-            allSubscriptions.addAll(values);
-        }
-        
-        for(Iterator iter = collectionIdEqualsSubscriptions.values().iterator(); iter.hasNext();) {
-            Set values = (Set) iter.next();
-            allSubscriptions.addAll(values);
-        }
-        return Collections.unmodifiableSet(allSubscriptions);
-    }
+//
+//    public String toString() {
+//        Set allSubscriptions = getAllSubscriptions();
+//        
+//        StringBuffer buffer = new StringBuffer();
+//        
+//        for (Iterator iter = allSubscriptions.iterator(); iter.hasNext();) {
+//            Subscription sub = (Subscription) iter.next();
+//            buffer.append(sub);
+//            buffer.append("\n");
+//        }
+//        
+//        return buffer.toString();
+//    }
+//
+//    /**
+//     * @return
+//     */
+//    public Set getAllSubscriptions() {
+//        Set allSubscriptions = new TreeSet();
+//        allSubscriptions.addAll(noEqualsSubscriptions);
+//        
+//        for(Iterator iter = docIdEqualsSubscriptions.values().iterator(); iter.hasNext();) {
+//            Set values = (Set) iter.next();
+//            allSubscriptions.addAll(values);
+//        }
+//        
+//        for(Iterator iter = docCollectionIdEqualsSubscriptions.values().iterator(); iter.hasNext();) {
+//            Set values = (Set) iter.next();
+//            allSubscriptions.addAll(values);
+//        }
+//        
+//        for(Iterator iter = collectionIdEqualsSubscriptions.values().iterator(); iter.hasNext();) {
+//            Set values = (Set) iter.next();
+//            allSubscriptions.addAll(values);
+//        }
+//        return Collections.unmodifiableSet(allSubscriptions);
+//    }
 
 
@@ -296,4 +258,14 @@
         
     }
+
+    /**
+     * @param username
+     * @return
+     */
+    public Set getAllSubscriptionsFor(String username) {
+        Set result = new TreeSet();
+        // TODO get subscriptions from database
+        return result;
+    }
     
 }
Index: trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Predicate.java
===================================================================
--- trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Predicate.java	(revision 8775)
+++ trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Predicate.java	(revision 8777)
@@ -43,5 +43,6 @@
             "type",
             "host",
-            "collection" };
+            "collection",
+            "documentID" };
     
     public void addSubscription(int subscriptionID) {
@@ -139,4 +140,11 @@
         }
     }
+
+    /**
+     * @return
+     */
+    public List getValueList() {
+        throw new UnsupportedOperationException("you can only call this method for multi-valued predicates");
+    }
     
 }
Index: trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java
===================================================================
--- trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java	(revision 8775)
+++ trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java	(revision 8777)
@@ -27,10 +27,7 @@
     private static int id = 0; 
     
-    // documentID -> IdEqualsPredicate referring to it
-    private static Map documentIdEqualsPredicates = new TreeMap();
-    // collectionID -> IdEqualsPredicate referring to it
-    private static Map collectionIdEqualsPredicates = new TreeMap();
+    private static Map idEqualsPredicates = new TreeMap();
     
-    // substring for collection_name -> SubstringMatchPredicate referring to it
+    // substring for collection_name -> SubstringMatchPredicates referring to it
     private static Map collectionNameMatchPredicates = new TreeMap();
     
@@ -59,8 +56,8 @@
         }
         
-        if (key.equals("type")) {
-            return result;
-        } else if (key.endsWith("ID")) {
-            result = createIdEqualsPredicate(key, value);
+        if (Predicate.isMultiValued(key)) {
+            List list = new ArrayList();
+            list.add(value);
+            return createPredicate(key, list);
         } else if (key.startsWith("document")) {
             result = createQueryPredicate(key, value);
@@ -78,6 +75,7 @@
             return null;
         }
-        // TODO properly handle multi-valued predicates
-        return createPredicate(key, (String) values.get(0));
+        Predicate result = createIdEqualsPredicate(key, values);
+        result.setID(result.saveToDatabase());
+        return result;
     }
 
@@ -102,24 +100,26 @@
     /**
      * @param key
-     * @param value
+     * @param values
      * @return
      */
-    private static IdEqualsPredicate createIdEqualsPredicate(String key, String value) {
+    private static IdEqualsPredicate createIdEqualsPredicate(String key, List values) {
         IdEqualsPredicate predicate = null;
-        if (key.equals("documentID")) {
-            if (documentIdEqualsPredicates.containsKey(value)) {
-                predicate = (IdEqualsPredicate) (documentIdEqualsPredicates.get(value));
+        
+        Map keyToPredicates;
+        if (!idEqualsPredicates.containsKey(key)) {
+            keyToPredicates = new HashMap();
+            idEqualsPredicates.put(key, keyToPredicates);
+        }
+        keyToPredicates = (Map) idEqualsPredicates.get(key);
+        
+        for (Iterator iter = values.iterator(); iter.hasNext();) {
+            String value = (String) iter.next();
+            if (keyToPredicates.containsKey(value)) {
+                predicate = (IdEqualsPredicate) keyToPredicates.get(value);
             } else {
                 predicate = new IdEqualsPredicate(key, value);
-                documentIdEqualsPredicates.put(value, predicate);
+                keyToPredicates.put(value, predicate);
             }
-        } else if (key.equals("collectionID")) {
-            if (collectionIdEqualsPredicates.containsKey(value)) {
-                predicate = (IdEqualsPredicate) collectionIdEqualsPredicates.get(value);
-            } else {
-                predicate = new IdEqualsPredicate(key, value);
-                collectionIdEqualsPredicates.put(value, predicate);
-            }
-        } // TODO other IDs
+        }
         return predicate;
     }
@@ -161,4 +161,13 @@
         return Collections.unmodifiableCollection(collectionNameMatchPredicates.values());
     }
+
+    /**
+     * @param string
+     * @param string2
+     * @return
+     */
+    public static Predicate getIdEqualsPredicate(String key, String value) {
+        return (Predicate) ((Map)idEqualsPredicates.get(key)).get(value);
+    }
     
 }
Index: trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Subscription.java
===================================================================
--- trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Subscription.java	(revision 8775)
+++ trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Subscription.java	(revision 8777)
@@ -170,3 +170,4 @@
         return id;
     }
+    
 }
