Changeset 8798 for trunk/greenstone3-extensions
- Timestamp:
- 2004-12-14T14:28:42+13:00 (19 years ago)
- Location:
- trunk/greenstone3-extensions/gsdl-as
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/greenstone3-extensions/gsdl-as/lib/templates/sub_collection.vm
r8738 r8798 37 37 <ol> 38 38 <li>You can choose one or more collections from the list below. Only events from the collections(s) you have chosen will be sent to you<br/> 39 <select multiple="multiple" name="collection " size="7" style="margin:5px 0px;">39 <select multiple="multiple" name="collectionID" size="7" style="margin:5px 0px;"> 40 40 #foreach($host in $hostnames) 41 41 <optgroup label="$host"> -
trunk/greenstone3-extensions/gsdl-as/lib/templates/sub_host.vm
r8738 r8798 37 37 <ol> 38 38 <li>You can choose one or more hosts from the list below. Only events from the host(s) you have chosen will be sent to you.<br/> 39 <select multiple="multiple" name="host " size="3" style="margin:5px 0px;">39 <select multiple="multiple" name="hostID" size="3" style="margin:5px 0px;"> 40 40 #set($firstoption = true); 41 41 #foreach($host in $hostnames) -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java
r8778 r8798 19 19 import org.apache.velocity.context.Context; 20 20 import org.apache.velocity.servlet.VelocityServlet; 21 import org.greenstone.gsdlas.database.DatabaseException; 22 import org.greenstone.gsdlas.profiles.Predicate; 21 23 import org.greenstone.gsdlas.users.UserManagementException; 22 24 import org.greenstone.gsdlas.users.UserManager; … … 112 114 if (arguments.containsKey("next_page") && arguments.get("next_page").equals("finish")) { 113 115 arguments.putAll(getPageArgsFromSession(session)); 116 arguments.put("username", session.getAttribute("username")); 114 117 ProfileStore.getInstance().createSubscription(arguments); 115 118 return listSubscriptions(arguments, context); … … 165 168 String username = (String) session.getAttribute("username"); 166 169 context.put("title", "List of Subscriptions for " + username); 167 context.put("list", ProfileStore.getInstance().getAllSubscriptionsFor(username)); 168 return "list.vm"; 170 try { 171 Collection subscriptions = ProfileStore.getInstance().getAllSubscriptionsFor(username); 172 context.put("list", subscriptions); 173 return "list.vm"; 174 } catch (DatabaseException de) { 175 context.put("message", "couldn't get list of subscriptions for " + username); 176 context.put("details", de.getMessage()); 177 return "error.vm"; 178 } 169 179 } 170 180 … … 218 228 GreenstoneCommunicator gsComm = null; 219 229 try { 220 gsComm = new GreenstoneCommunicator(new URL((String) event.get("host _url")));230 gsComm = new GreenstoneCommunicator(new URL((String) event.get("hostID"))); 221 231 } catch (MalformedURLException e) { 222 232 // TODO Auto-generated catch block … … 238 248 for (Iterator iter = args.keySet().iterator(); iter.hasNext();) { 239 249 String key = (String) iter.next(); 240 if (key.equals("type") || key.equals("host") 241 || key.equals("collection") || key.equals("way")) { 250 if (Predicate.isMultiValued(key) || key.equals("way")) { 242 251 // multi-valued attributes 243 252 String[] values = ((String[]) args.get(key)); … … 320 329 } else if (nextPage.equals("collection")) { 321 330 // TODO might be query instead of just name 322 List hostNames = (List) arguments.get("host ");331 List hostNames = (List) arguments.get("hostID"); 323 332 GreenstoneCommunicator gsComm = null; 324 333 Map collNames = new TreeMap(); -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/GreenstoneCommunicator.java
r8779 r8798 146 146 // TODO what about the nodeType 147 147 // make sure to pass IDs of whole documents, not of parts of docs 148 Matcher matcher = Pattern.compile("(\\d{8}:\\d+) *").matcher(docID);148 Matcher matcher = Pattern.compile("(\\d{8}:\\d+).*").matcher(docID); 149 149 if (matcher.matches()) { 150 150 docID = matcher.group(1); … … 159 159 Call call = new Call(); 160 160 // TODO get the uri from a configuration file 161 call.setTargetObjectURI(" teevee.localsite");161 call.setTargetObjectURI("localsite"); 162 162 call.setMethodName("process"); 163 163 // set Encoding Style to use literal XML -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java
r8780 r8798 9 9 package org.greenstone.gsdlas; 10 10 11 import java.sql.*; 12 import java.sql.Connection; 13 import java.sql.Statement; 11 14 import java.util.*; 12 15 13 16 import javax.servlet.http.HttpSession; 14 17 18 import org.greenstone.gsdlas.database.DatabaseException; 19 import org.greenstone.gsdlas.database.DatabaseManager; 15 20 import org.greenstone.gsdlas.profiles.*; 16 21 … … 25 30 private static ProfileStore instance; 26 31 27 private Set noEqualsSubscriptions = new TreeSet(); 32 private Set noEqualsSubscriptions = new TreeSet(); 33 private Map dontCareSubscriptions = new TreeMap(); 28 34 private Map subscriptions = new TreeMap(); 35 29 36 30 37 private ProfileStore() { 38 // TODO restore subscriptions from database 31 39 } 32 40 … … 46 54 */ 47 55 private void addSubscription(Subscription subscription) { 48 Predicate documentIdPredicate = subscription.getPredicate("documentID"); 49 Predicate collectionIdPredicate = subscription.getPredicate("collectionID"); 50 Predicate hostIdPredicate = subscription.getPredicate("host"); 51 Predicate typePredicate = subscription.getPredicate("type"); 56 // TODO change to lists 57 List documentIdPredicate = subscription.getPredicateList("documentID"); 58 List collectionIdPredicate = subscription.getPredicateList("collectionID"); 59 List hostIdPredicate = subscription.getPredicateList("hostID"); 60 List typePredicate = subscription.getPredicateList("type"); 52 61 53 62 Integer subId = new Integer(subscription.getId()); 54 63 55 if (documentIdPredicate == null && collectionIdPredicate == null 56 && hostIdPredicate == null && typePredicate == null) { 64 if (documentIdPredicate.isEmpty()) { 65 if (!dontCareSubscriptions.containsKey("documentID")) { 66 dontCareSubscriptions.put("documentID", new TreeSet()); 67 } 68 Set list = (Set) dontCareSubscriptions.get("documentID"); 69 list.add(subId); 70 } 71 if (collectionIdPredicate.isEmpty()) { 72 if (!dontCareSubscriptions.containsKey("collectionID")) { 73 dontCareSubscriptions.put("collectionID", new TreeSet()); 74 } 75 Set list = (Set) dontCareSubscriptions.get("collectionID"); 76 list.add(subId); 77 } 78 if (hostIdPredicate.isEmpty()) { 79 if (!dontCareSubscriptions.containsKey("hostID")) { 80 dontCareSubscriptions.put("hostID", new TreeSet()); 81 } 82 Set list = (Set) dontCareSubscriptions.get("hostID"); 83 list.add(subId); 84 } 85 if (typePredicate.isEmpty()) { 86 if (!dontCareSubscriptions.containsKey("type")) { 87 dontCareSubscriptions.put("type", new TreeSet()); 88 } 89 Set list = (Set) dontCareSubscriptions.get("type"); 90 list.add(subId); 91 } 92 93 if (documentIdPredicate.isEmpty() && collectionIdPredicate.isEmpty() 94 && hostIdPredicate.isEmpty() && typePredicate.isEmpty()) { 57 95 noEqualsSubscriptions.add(subId); 58 96 } … … 84 122 if (predicate != null) 85 123 docIDSubs.addAll(predicate.getSubscriptionIDs()); 86 predicate = PredicateFactory.getIdEqualsPredicate("documentID", null); 87 if (predicate != null) 88 docIDSubs.addAll(predicate.getSubscriptionIDs()); 124 docIDSubs.addAll(getDontCareSubscriptions("documentID")); 89 125 result.retainAll(docIDSubs); 90 126 … … 93 129 if (predicate != null) 94 130 collIDSubs.addAll(predicate.getSubscriptionIDs()); 95 predicate = PredicateFactory.getIdEqualsPredicate("collectionID", null); 96 if (predicate != null) 97 collIDSubs.addAll(predicate.getSubscriptionIDs()); 131 collIDSubs.addAll(getDontCareSubscriptions("collectionID")); 98 132 result.retainAll(collIDSubs); 99 133 100 134 Set hostIDSubs = new TreeSet(); 101 predicate = PredicateFactory.getIdEqualsPredicate("host ", (String)event.get("host"));135 predicate = PredicateFactory.getIdEqualsPredicate("hostID", (String)event.get("hostID")); 102 136 if (predicate != null) 103 137 hostIDSubs.addAll(predicate.getSubscriptionIDs()); 104 predicate = PredicateFactory.getIdEqualsPredicate("host", null); 105 if (predicate != null) 106 hostIDSubs.addAll(predicate.getSubscriptionIDs()); 138 hostIDSubs.addAll(getDontCareSubscriptions("hostID")); 107 139 result.retainAll(hostIDSubs); 108 140 … … 180 212 for (Iterator iterator = pred.getSubscriptionIDs().iterator(); iterator 181 213 .hasNext();) { 182 // TODO change to subscription IDs183 214 Integer subId = (Integer) iterator.next(); 184 215 Subscription sub = (Subscription) subscriptions.get(subId); … … 260 291 */ 261 292 public void deleteSubscription(String subscriptionID) { 293 // delete row from subscriptions table 294 // for each predicate: 295 // delete row from subs_to_predicates 296 // if there aren't any other subscriptions using this predicate, delete predicate 262 297 // TODO Auto-generated method stub 263 298 … … 277 312 * @param username 278 313 * @return 279 */ 280 public Set getAllSubscriptionsFor(String username) { 314 * @throws DatabaseException 315 */ 316 public Set getAllSubscriptionsFor(String username) throws DatabaseException { 281 317 Set result = new TreeSet(); 282 // TODO get subscriptions from database 318 try { 319 Connection conn = DatabaseManager.getInstance().getDatabaseConnection(); 320 Statement statement = conn.createStatement(); 321 String sqlString = "SELECT id FROM subscriptions " + 322 "WHERE user like '" + username + "';"; 323 ResultSet idList = statement.executeQuery(sqlString); 324 while (idList.next()) { 325 int id = idList.getInt("id"); 326 result.add(subscriptions.get(new Integer(id))); 327 } 328 } catch (SQLException e) { 329 e.printStackTrace(); 330 } 331 283 332 return result; 284 333 } 334 335 /** 336 * @param string 337 * @return 338 */ 339 private Set getDontCareSubscriptions(String field) { 340 Set result = new TreeSet(); 341 if (dontCareSubscriptions.containsKey(field)) { 342 result = (Set) dontCareSubscriptions.get(field); 343 } 344 return result; 345 } 285 346 286 347 } -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Predicate.java
r8781 r8798 42 42 public static final String[] multiValueFields = new String[] { 43 43 "type", 44 "host ",45 "collection ",44 "hostID", 45 "collectionID", 46 46 "documentID" }; 47 47 … … 117 117 */ 118 118 int saveToDatabase() throws SQLException, DatabaseException { 119 // TODO handle multi-valued predicate (in subclass?)120 119 String query = "SELECT id FROM predicates " + 121 "WHERE type='single' ANDfield = '" + field +122 "' AND singleValue = '" + value + "';";120 "WHERE field = '" + field + 121 "' AND value = '" + value + "';"; 123 122 Statement statement = DatabaseManager.getInstance().getDatabaseConnection().createStatement(); 124 123 System.out.println(query); … … 129 128 } 130 129 // predicate has been newly created 131 String insert = "INSERT INTO predicates ( type, field, singleValue) " +132 "VALUES (' single', '" + field + "', '" + value + "');";130 String insert = "INSERT INTO predicates (field, value) " + 131 "VALUES ('" + field + "', '" + value + "');"; 133 132 System.out.println(insert); 134 133 statement.execute(insert); -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java
r8781 r8798 59 59 List list = new ArrayList(); 60 60 list.add(value); 61 return createPredicate(key, list);61 return (Predicate) createPredicates(key, list).get(0); 62 62 } else if (key.startsWith("document")) { 63 63 result = createQueryPredicate(key, value); … … 71 71 } 72 72 73 public static Predicate createPredicate(String key, List values) throws SQLException, DatabaseException {73 public static List createPredicates(String key, List values) throws SQLException, DatabaseException { 74 74 if (!Predicate.isMultiValued(key)) { 75 75 return null; 76 76 } 77 Predicate result = createIdEqualsPredicate(key, values); 78 result.setID(result.saveToDatabase()); 79 return result; 77 List results = createIdEqualsPredicates(key, values); 78 for (Iterator iter = results.iterator(); iter.hasNext();) { 79 IdEqualsPredicate pred = (IdEqualsPredicate) iter.next(); 80 81 pred.setID(pred.saveToDatabase()); 82 } 83 return results; 80 84 } 81 85 … … 103 107 * @return 104 108 */ 105 private static IdEqualsPredicate createIdEqualsPredicate(String key, List values) {106 IdEqualsPredicate predicate = null;109 private static List createIdEqualsPredicates(String key, List values) { 110 List result = new Vector(); 107 111 108 112 Map keyToPredicates; … … 116 120 String value = (String) iter.next(); 117 121 118 if (key.equals("host ") && !(key.startsWith("http://"))) {122 if (key.equals("hostID") && !(value.startsWith("http://"))) { 119 123 value = "http://" + value + ":8080/soap/servlet/rpcrouter"; 120 124 } 121 125 126 IdEqualsPredicate predicate = null; 122 127 if (keyToPredicates.containsKey(value)) { 123 128 predicate = (IdEqualsPredicate) keyToPredicates.get(value); … … 126 131 keyToPredicates.put(value, predicate); 127 132 } 133 result.add(predicate); 128 134 } 129 return predicate;135 return result; 130 136 } 131 137 -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/QueryPredicate.java
r8609 r8798 27 27 super.field = field; 28 28 super.value = query; 29 30 String[] words = query.split("\\s");31 for (int i = 0; i < words.length; i++) {32 String word = words[i];33 if (!word.startsWith("!")) {34 containsWords.add(word);35 } else {36 if (word.length() > 1) {37 notContainsWords.add(word);38 } else if (i < words.length - 1) {39 notContainsWords.add(words[i++]);40 }41 }42 }43 29 } 44 45 /* (non-Javadoc)46 * @see org.greenstone.gsdlas.profiles.Predicate#isSatisfied(java.util.Map)47 */48 30 public boolean isSatisfied(Map event) { 49 // TODO more efficient implementation50 51 String value = (String) event.get(field);52 if (value == null) return false;53 54 55 for (Iterator iter = containsWords.iterator(); iter.hasNext();) {56 String word = (String) iter.next();57 if (value.indexOf(word) == -1) {58 return false;59 }60 }61 62 for (Iterator iter = notContainsWords.iterator(); iter.hasNext();) {63 String word = (String) iter.next();64 if (value.indexOf(word) >= 0) {65 return false;66 }67 }68 69 31 return true; 70 32 } -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Subscription.java
r8781 r8798 48 48 Object value = valueMap.get(key); 49 49 50 Predicate predicate = null;51 50 if (value instanceof String) { 52 predicate = PredicateFactory.createPredicate(key, (String) value);51 Predicate predicate = PredicateFactory.createPredicate(key, (String) value); 53 52 map.put(key, predicate); 53 54 if (predicate != null && !(predicate instanceof IdEqualsPredicate)) { 55 numOfNonEqualsPredicates++; 56 } 54 57 } else if (value instanceof List) { 55 58 List values = (List)value; 56 predicate = PredicateFactory.createPredicate(key, values); 57 map.put(key, predicate); 59 List predicates = PredicateFactory.createPredicates(key, values); 60 map.put(key, predicates); 61 for (Iterator iterator = predicates.iterator(); iterator 62 .hasNext();) { 63 Predicate predicate = (Predicate) iterator.next(); 64 65 if (predicate != null && !(predicate instanceof IdEqualsPredicate)) { 66 numOfNonEqualsPredicates++; 67 } 68 } 58 69 } 59 70 60 if (predicate != null && !(predicate instanceof IdEqualsPredicate)) {61 numOfNonEqualsPredicates++;62 }63 71 } 64 72 … … 89 97 90 98 public Predicate getPredicate(String field) { 91 return (Predicate) map.get(field); 99 if (map.get(field) instanceof Predicate) { 100 return (Predicate) map.get(field); 101 } 102 return null; 103 } 104 105 public List getPredicateList(String field) { 106 if (map.get(field) instanceof List) { 107 return (List) map.get(field); 108 } 109 return new Vector(); 92 110 } 93 111 … … 99 117 Set result = new HashSet(); 100 118 for (Iterator iter = map.values().iterator(); iter.hasNext();) { 101 Predicate pred = (Predicate) iter.next(); 102 if (pred != null) { 103 result.add(pred); 119 Object next = iter.next(); 120 if (next == null) { 121 continue; 122 } else if (next instanceof Predicate) { 123 result.add(next); 124 } else if (next instanceof List) { 125 result.addAll((Collection) next); 104 126 } 105 127 } … … 149 171 // cannot change user 150 172 } 151 System.out.println(sqlString);152 173 statement.executeUpdate(sqlString); 153 174 -
trunk/greenstone3-extensions/gsdl-as/test-src/org/greenstone/gsdlas/ProfileStoreTest.java
r8738 r8798 46 46 event.put("documentID", "20041118:5"); 47 47 event.put("collectionID", "gs3mgdemo"); 48 event.put("host ", "http://localhost:8080/soap/servlet/rpcrouter");48 event.put("hostID", "http://localhost:8080/soap/servlet/rpcrouter"); 49 49 50 50 Set result = ProfileStore.getInstance().filter(event, gsComm);
Note:
See TracChangeset
for help on using the changeset viewer.