Changeset 8777 for trunk/greenstone3-extensions
- Timestamp:
- 2004-12-10T15:48:39+13:00 (19 years ago)
- Location:
- trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java
r8775 r8777 21 21 import org.greenstone.gsdlas.users.UserManagementException; 22 22 import org.greenstone.gsdlas.users.UserManager; 23 import org.greenstone.gsdlas.util.ArrayHelper; 23 24 24 25 /** … … 30 31 public class AlertingService extends VelocityServlet { 31 32 32 public static final Set actions; 33 static { 34 Set set = new TreeSet(); 35 set.add("createSubscription"); 36 set.add("deleteSubscription"); 37 set.add("editSubscription"); 38 set.add("showFeed"); 39 set.add("listSubscriptions"); 40 41 set.add("login"); 42 set.add("register"); 43 set.add("logout"); 44 set.add("showLoginForm"); 45 set.add("showRegistrationForm"); 46 actions = Collections.unmodifiableSet(set); 47 } 33 public static final String[] actions = new String[] { 34 "createSubscription", 35 "deleteSubscription", 36 "editSubscription", 37 "showFeed", 38 "listSubscriptions", 39 "login", 40 "register", 41 "logout", 42 "showLoginForm", 43 "showRegistrationForm" 44 }; 48 45 49 46 … … 52 49 53 50 String action = req.getParameter("action"); 54 55 if (action == null || !actions.contains(action)) {56 String title = "Unknown action";57 String message = "I don't know how to " + action;58 String details = "The only actions I know are " + actions;59 return showError(context, message, details);60 }61 62 51 63 52 Map args = req.getParameterMap(); 64 53 // TODO stop this, we need multi-valued stuff 65 54 args = normalise(args); 66 55 56 if (action != null && action.equals("receiveEvent")) { 57 receiveEvent(args); 58 return null; 59 } 60 61 if (action == null || !ArrayHelper.contains(actions, action)) { 62 String title = "Unknown action"; 63 String message = "I don't know how to " + action; 64 String details = "The only actions I know are " + Arrays.toString(actions); 65 return showError(context, message, details); 66 } 67 67 68 String templateString = ""; 68 69 … … 163 164 String username = (String) session.getAttribute("username"); 164 165 context.put("title", "List of Subscriptions for " + username); 165 context.put("list", ProfileStore.getInstance().getAllSubscriptions ());166 context.put("list", ProfileStore.getInstance().getAllSubscriptionsFor(username)); 166 167 return "list.vm"; 167 168 } -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java
r8753 r8777 25 25 private static ProfileStore instance; 26 26 27 private Map docIdEqualsSubscriptions = new TreeMap();28 private Map collectionIdEqualsSubscriptions = new TreeMap();29 private Map docCollectionIdEqualsSubscriptions = new TreeMap();30 27 private Set noEqualsSubscriptions = new TreeSet(); 28 private Map subscriptions = new TreeMap(); 31 29 32 30 private ProfileStore() { … … 50 48 Predicate documentIdPredicate = subscription.getPredicate("documentID"); 51 49 Predicate collectionIdPredicate = subscription.getPredicate("collectionID"); 52 53 if (documentIdPredicate != null) { 54 IdEqualsPredicate docIdPredicate 55 = (IdEqualsPredicate) documentIdPredicate; 56 if (collectionIdPredicate != null) { 57 IdEqualsPredicate collIdPredicate 58 = (IdEqualsPredicate) collectionIdPredicate; 59 60 String[] values = new String[2]; 61 values[0] = docIdPredicate.getValue(); 62 values[1] = collIdPredicate.getValue(); 63 64 Set subList = (Set) docCollectionIdEqualsSubscriptions.get(values); 65 if (subList == null) { 66 subList = new TreeSet(); 67 docCollectionIdEqualsSubscriptions.put(values, subList); 68 } 69 subList.add(subscription); 70 } else { 71 String value = docIdPredicate.getValue(); 72 Set subList = (Set) docIdEqualsSubscriptions.get(value); 73 if (subList == null) { 74 subList = new TreeSet(); 75 docIdEqualsSubscriptions.put(value, subList); 76 } 77 subList.add(subscription); 78 } 79 } else if (collectionIdPredicate != null) { 80 IdEqualsPredicate collIdPredicate 81 = (IdEqualsPredicate) collectionIdPredicate; 82 83 String value = collIdPredicate.getValue(); 84 Set subList = (Set) collectionIdEqualsSubscriptions.get(value); 85 if (subList == null) { 86 subList = new TreeSet(); 87 collectionIdEqualsSubscriptions.put(value, subList); 88 } 89 subList.add(subscription); 90 } else { 91 noEqualsSubscriptions.add(subscription); 92 } 50 Predicate hostIdPredicate = subscription.getPredicate("host"); 51 Predicate typePredicate = subscription.getPredicate("type"); 52 53 Integer subId = new Integer(subscription.getId()); 54 55 if (documentIdPredicate == null && collectionIdPredicate == null 56 && hostIdPredicate == null && typePredicate == null) { 57 noEqualsSubscriptions.add(subId); 58 } 59 subscriptions.put(subId, subscription); 93 60 } 94 61 … … 107 74 public Set getPartiallyMatchedSubscriptions(Map event) { 108 75 Set result = new TreeSet(); 109 if (event.get("documentID") != null) { 110 String documentID = (String) event.get("documentID"); 111 if (event.get("collectionID") != null) { 112 String collectionID = (String) event.get("collectionID"); 113 String[] values = new String[] {documentID, collectionID}; 114 Set fromDocAndCollectionId = (Set) docCollectionIdEqualsSubscriptions.get(values); 115 if (fromDocAndCollectionId != null) { 116 result.addAll(fromDocAndCollectionId); 117 } 118 Set fromCollectionId = (Set) collectionIdEqualsSubscriptions.get(collectionID); 119 if (fromCollectionId != null) { 120 result.addAll(fromCollectionId); 121 } 122 } 123 Set fromDocId = (Set) collectionIdEqualsSubscriptions.get(documentID); 124 if (fromDocId != null) { 125 result.addAll(fromDocId); 126 } 127 } else if (event.get("collectionID") != null){ 128 String collectionID = (String) event.get("collectionID"); 129 Set fromCollectionId = (Set) collectionIdEqualsSubscriptions.get(collectionID); 130 if (fromCollectionId != null) { 131 result.addAll(fromCollectionId); 132 } 133 } 76 // TODO rework algo for getting partially matched subs 77 result.addAll(PredicateFactory.getIdEqualsPredicate("type", (String)event.get("type")).getSubscriptionIDs()); 78 79 Set docIDSubs = new TreeSet(); 80 docIDSubs.addAll(PredicateFactory.getIdEqualsPredicate("documentID", (String)event.get("documentID")).getSubscriptionIDs()); 81 docIDSubs.addAll(PredicateFactory.getIdEqualsPredicate("documentID", null).getSubscriptionIDs()); 82 result.retainAll(docIDSubs); 83 84 Set collIDSubs = new TreeSet(); 85 collIDSubs.addAll(PredicateFactory.getIdEqualsPredicate("collectionID", (String)event.get("collectionID")).getSubscriptionIDs()); 86 collIDSubs.addAll(PredicateFactory.getIdEqualsPredicate("collectionID", null).getSubscriptionIDs()); 87 result.retainAll(collIDSubs); 88 89 Set hostIDSubs = new TreeSet(); 90 hostIDSubs.addAll(PredicateFactory.getIdEqualsPredicate("host", (String)event.get("host")).getSubscriptionIDs()); 91 hostIDSubs.addAll(PredicateFactory.getIdEqualsPredicate("host", null).getSubscriptionIDs()); 92 result.retainAll(hostIDSubs); 93 134 94 return result; 135 95 } … … 206 166 .hasNext();) { 207 167 // TODO change to subscription IDs 208 Subscription sub = (Subscription) iterator.next(); 209 Integer count = (Integer) numMatchedPredicates.get(sub); 168 Integer subId = (Integer) iterator.next(); 169 Subscription sub = (Subscription) subscriptions.get(subId); 170 Integer count = (Integer) numMatchedPredicates.get(subId); 210 171 int newCountValue = (count == null ? 1 : count.intValue() + 1); 211 numMatchedPredicates.put(sub ,172 numMatchedPredicates.put(subId, 212 173 new Integer(newCountValue)); 213 174 } … … 218 179 for (Iterator iter = notUnmatchedSubscriptions.iterator(); iter 219 180 .hasNext();) { 220 Subscription sub = (Subscription) iter.next(); 181 Integer subId = (Integer) iter.next(); 182 Subscription sub = (Subscription) subscriptions.get(subId); 221 183 int matchedPredicatesCount = 0; 222 if (numMatchedPredicates.get(sub ) != null) {223 matchedPredicatesCount = ((Integer) numMatchedPredicates.get(sub )).intValue();184 if (numMatchedPredicates.get(subId) != null) { 185 matchedPredicatesCount = ((Integer) numMatchedPredicates.get(subId)).intValue(); 224 186 } 225 187 if (matchedPredicatesCount == sub.getNumOfNonEqualsPredicates()) { … … 229 191 return matchedSubscriptions; 230 192 } 231 232 public String toString() {233 Set allSubscriptions = getAllSubscriptions();234 235 StringBuffer buffer = new StringBuffer();236 237 for (Iterator iter = allSubscriptions.iterator(); iter.hasNext();) {238 Subscription sub = (Subscription) iter.next();239 buffer.append(sub);240 buffer.append("\n");241 }242 243 return buffer.toString();244 }245 246 /**247 * @return248 */249 public Set getAllSubscriptions() {250 Set allSubscriptions = new TreeSet();251 allSubscriptions.addAll(noEqualsSubscriptions);252 253 for(Iterator iter = docIdEqualsSubscriptions.values().iterator(); iter.hasNext();) {254 Set values = (Set) iter.next();255 allSubscriptions.addAll(values);256 }257 258 for(Iterator iter = docCollectionIdEqualsSubscriptions.values().iterator(); iter.hasNext();) {259 Set values = (Set) iter.next();260 allSubscriptions.addAll(values);261 }262 263 for(Iterator iter = collectionIdEqualsSubscriptions.values().iterator(); iter.hasNext();) {264 Set values = (Set) iter.next();265 allSubscriptions.addAll(values);266 }267 return Collections.unmodifiableSet(allSubscriptions);268 }193 // 194 // public String toString() { 195 // Set allSubscriptions = getAllSubscriptions(); 196 // 197 // StringBuffer buffer = new StringBuffer(); 198 // 199 // for (Iterator iter = allSubscriptions.iterator(); iter.hasNext();) { 200 // Subscription sub = (Subscription) iter.next(); 201 // buffer.append(sub); 202 // buffer.append("\n"); 203 // } 204 // 205 // return buffer.toString(); 206 // } 207 // 208 // /** 209 // * @return 210 // */ 211 // public Set getAllSubscriptions() { 212 // Set allSubscriptions = new TreeSet(); 213 // allSubscriptions.addAll(noEqualsSubscriptions); 214 // 215 // for(Iterator iter = docIdEqualsSubscriptions.values().iterator(); iter.hasNext();) { 216 // Set values = (Set) iter.next(); 217 // allSubscriptions.addAll(values); 218 // } 219 // 220 // for(Iterator iter = docCollectionIdEqualsSubscriptions.values().iterator(); iter.hasNext();) { 221 // Set values = (Set) iter.next(); 222 // allSubscriptions.addAll(values); 223 // } 224 // 225 // for(Iterator iter = collectionIdEqualsSubscriptions.values().iterator(); iter.hasNext();) { 226 // Set values = (Set) iter.next(); 227 // allSubscriptions.addAll(values); 228 // } 229 // return Collections.unmodifiableSet(allSubscriptions); 230 // } 269 231 270 232 … … 296 258 297 259 } 260 261 /** 262 * @param username 263 * @return 264 */ 265 public Set getAllSubscriptionsFor(String username) { 266 Set result = new TreeSet(); 267 // TODO get subscriptions from database 268 return result; 269 } 298 270 299 271 } -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Predicate.java
r8775 r8777 43 43 "type", 44 44 "host", 45 "collection" }; 45 "collection", 46 "documentID" }; 46 47 47 48 public void addSubscription(int subscriptionID) { … … 139 140 } 140 141 } 142 143 /** 144 * @return 145 */ 146 public List getValueList() { 147 throw new UnsupportedOperationException("you can only call this method for multi-valued predicates"); 148 } 141 149 142 150 } -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java
r8738 r8777 27 27 private static int id = 0; 28 28 29 // documentID -> IdEqualsPredicate referring to it 30 private static Map documentIdEqualsPredicates = new TreeMap(); 31 // collectionID -> IdEqualsPredicate referring to it 32 private static Map collectionIdEqualsPredicates = new TreeMap(); 29 private static Map idEqualsPredicates = new TreeMap(); 33 30 34 // substring for collection_name -> SubstringMatchPredicate referring to it31 // substring for collection_name -> SubstringMatchPredicates referring to it 35 32 private static Map collectionNameMatchPredicates = new TreeMap(); 36 33 … … 59 56 } 60 57 61 if ( key.equals("type")) {62 return result;63 } else if (key.endsWith("ID")) {64 re sult = createIdEqualsPredicate(key, value);58 if (Predicate.isMultiValued(key)) { 59 List list = new ArrayList(); 60 list.add(value); 61 return createPredicate(key, list); 65 62 } else if (key.startsWith("document")) { 66 63 result = createQueryPredicate(key, value); … … 78 75 return null; 79 76 } 80 // TODO properly handle multi-valued predicates 81 return createPredicate(key, (String) values.get(0)); 77 Predicate result = createIdEqualsPredicate(key, values); 78 result.setID(result.saveToDatabase()); 79 return result; 82 80 } 83 81 … … 102 100 /** 103 101 * @param key 104 * @param value 102 * @param values 105 103 * @return 106 104 */ 107 private static IdEqualsPredicate createIdEqualsPredicate(String key, String value) {105 private static IdEqualsPredicate createIdEqualsPredicate(String key, List values) { 108 106 IdEqualsPredicate predicate = null; 109 if (key.equals("documentID")) { 110 if (documentIdEqualsPredicates.containsKey(value)) { 111 predicate = (IdEqualsPredicate) (documentIdEqualsPredicates.get(value)); 107 108 Map keyToPredicates; 109 if (!idEqualsPredicates.containsKey(key)) { 110 keyToPredicates = new HashMap(); 111 idEqualsPredicates.put(key, keyToPredicates); 112 } 113 keyToPredicates = (Map) idEqualsPredicates.get(key); 114 115 for (Iterator iter = values.iterator(); iter.hasNext();) { 116 String value = (String) iter.next(); 117 if (keyToPredicates.containsKey(value)) { 118 predicate = (IdEqualsPredicate) keyToPredicates.get(value); 112 119 } else { 113 120 predicate = new IdEqualsPredicate(key, value); 114 documentIdEqualsPredicates.put(value, predicate);121 keyToPredicates.put(value, predicate); 115 122 } 116 } else if (key.equals("collectionID")) { 117 if (collectionIdEqualsPredicates.containsKey(value)) { 118 predicate = (IdEqualsPredicate) collectionIdEqualsPredicates.get(value); 119 } else { 120 predicate = new IdEqualsPredicate(key, value); 121 collectionIdEqualsPredicates.put(value, predicate); 122 } 123 } // TODO other IDs 123 } 124 124 return predicate; 125 125 } … … 161 161 return Collections.unmodifiableCollection(collectionNameMatchPredicates.values()); 162 162 } 163 164 /** 165 * @param string 166 * @param string2 167 * @return 168 */ 169 public static Predicate getIdEqualsPredicate(String key, String value) { 170 return (Predicate) ((Map)idEqualsPredicates.get(key)).get(value); 171 } 163 172 164 173 } -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Subscription.java
r8738 r8777 170 170 return id; 171 171 } 172 172 173 }
Note:
See TracChangeset
for help on using the changeset viewer.