Changeset 8875 for trunk/greenstone3-extensions
- Timestamp:
- 2005-01-07T18:15:22+13:00 (19 years ago)
- Location:
- trunk/greenstone3-extensions/gsdl-as
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/greenstone3-extensions/gsdl-as/create-tables.sql
r8867 r8875 19 19 field varchar(128) not null, 20 20 value varchar(255), 21 type enum("org.greenstone.gsdlas.profiles. IdEqualsPredicate", "org.greenstone.gsdlas.profiles.SubstringMatchPredicate", "org.greenstone.gsdlas.profiles.QueryPredicate") not null,21 type enum("org.greenstone.gsdlas.profiles.EqualsPredicate", "org.greenstone.gsdlas.profiles.SubstringMatchPredicate", "org.greenstone.gsdlas.profiles.QueryPredicate") not null, 22 22 23 23 unique(field,type,value) -
trunk/greenstone3-extensions/gsdl-as/lib/templates/sub_collection.vm
r8847 r8875 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="collectionID" size="7" style="margin:5px 0px;"> 39 <select multiple="multiple" name="hostCollectionID" size="7" style="margin:5px 0px;"> 40 <option value="">any collection on any host</option> 40 41 #foreach($host in $hostnames) 41 42 <optgroup label="$host"> 42 43 #foreach($collection in $collectionnames.get($host)) 43 <option>$ collection</option>44 <option>$host|$collection</option> 44 45 #end 45 <option selected="selected" value=" ">any collection on host $host</option>46 <option selected="selected" value="$host">any collection on host $host</option> 46 47 </optgroup> 47 48 #end -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/Constants.java
r8872 r8875 22 22 public static final String HOST_ID_FIELD = "hostID"; 23 23 public static final String COLLECTION_ID_FIELD = "collectionID"; 24 public static final String HOST_COLLECTION_ID_FIELD = "hostCollectionID"; 24 25 public static final String DOCUMENT_ID_FIELD = "documentID"; 25 26 public static final String DOCUMENT_CONTENT_FIELD = "document_content"; 26 27 public static final String DOCUMENT_TITLE_FIELD = "document_title"; 27 28 public static final String TYPE_FIELD = "type"; 29 30 28 31 } -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java
r8874 r8875 36 36 37 37 private ProfileStore() { 38 // hide default constructor 38 39 } 39 40 … … 67 68 list.add(subId); 68 69 } 69 if (collectionIdPredicate.isEmpty()) {70 if (!dontCareSubscriptions.containsKey(Constants.COLLECTION_ID_FIELD)) {71 dontCareSubscriptions.put(Constants.COLLECTION_ID_FIELD, new TreeSet());72 }73 Set list = (Set) dontCareSubscriptions.get(Constants.COLLECTION_ID_FIELD);74 list.add(subId);75 }76 70 if (hostIdPredicate.isEmpty()) { 77 if (!dontCareSubscriptions.containsKey(Constants.HOST_ID_FIELD)) { 78 dontCareSubscriptions.put(Constants.HOST_ID_FIELD, new TreeSet()); 79 } 80 Set list = (Set) dontCareSubscriptions.get(Constants.HOST_ID_FIELD); 81 list.add(subId); 71 if (collectionIdPredicate.isEmpty()) { 72 if (!dontCareSubscriptions.containsKey(Constants.COLLECTION_ID_FIELD)) { 73 dontCareSubscriptions.put(Constants.COLLECTION_ID_FIELD, new TreeSet()); 74 } 75 Set list = (Set) dontCareSubscriptions.get(Constants.COLLECTION_ID_FIELD); 76 list.add(subId); 77 } 82 78 } 83 79 if (typePredicate.isEmpty()) { … … 110 106 public Set getPartiallyMatchedSubscriptions(Map event) { 111 107 Set result = new TreeSet(); 112 IdEqualsPredicate predicate; 113 predicate = PredicateFactory.getIdEqualsPredicate(Constants.TYPE_FIELD, 108 109 EqualsPredicate predicate; 110 111 // all subscriptions with matching type... 112 predicate = PredicateFactory.getEqualsPredicate(Constants.TYPE_FIELD, 114 113 (String)event.get(Constants.TYPE_FIELD)); 115 114 if (predicate != null) 116 115 result.addAll(predicate.getSubscriptionIDs()); 117 116 117 // ...but only those subscriptions where the doc id matches... 118 118 Set docIDSubs = new TreeSet(); 119 predicate = PredicateFactory.get IdEqualsPredicate(Constants.DOCUMENT_ID_FIELD,119 predicate = PredicateFactory.getEqualsPredicate(Constants.DOCUMENT_ID_FIELD, 120 120 (String)event.get(Constants.DOCUMENT_ID_FIELD)); 121 121 if (predicate != null) … … 124 124 result.retainAll(docIDSubs); 125 125 126 Set collIDSubs = new TreeSet(); 127 predicate = PredicateFactory.getIdEqualsPredicate(Constants.COLLECTION_ID_FIELD, 126 // ...and only those subscriptions where the host/collection id matches: 127 Set hostCollIDSubs = new TreeSet(); 128 // i.e.: host|coll is "don't care"... 129 hostCollIDSubs.addAll(getDontCareSubscriptions(Constants.COLLECTION_ID_FIELD)); 130 // ...or host matches (-> coll is "don't care" for this host)... 131 predicate = PredicateFactory.getEqualsPredicate(Constants.HOST_ID_FIELD, 132 (String)event.get(Constants.HOST_ID_FIELD)); 133 if (predicate != null) 134 hostCollIDSubs.addAll(predicate.getSubscriptionIDs()); 135 // ...or host|coll matches 136 predicate = PredicateFactory.getEqualsPredicate(Constants.COLLECTION_ID_FIELD, 128 137 (String)event.get(Constants.COLLECTION_ID_FIELD)); 129 138 if (predicate != null) 130 collIDSubs.addAll(predicate.getSubscriptionIDs()); 131 collIDSubs.addAll(getDontCareSubscriptions(Constants.COLLECTION_ID_FIELD)); 132 result.retainAll(collIDSubs); 133 134 Set hostIDSubs = new TreeSet(); 135 predicate = PredicateFactory.getIdEqualsPredicate(Constants.HOST_ID_FIELD, 136 (String)event.get(Constants.HOST_ID_FIELD)); 137 if (predicate != null) 138 hostIDSubs.addAll(predicate.getSubscriptionIDs()); 139 hostIDSubs.addAll(getDontCareSubscriptions(Constants.HOST_ID_FIELD)); 140 result.retainAll(hostIDSubs); 139 hostCollIDSubs.addAll(predicate.getSubscriptionIDs()); 140 141 result.retainAll(hostCollIDSubs); 141 142 142 143 return result; … … 380 381 } 381 382 String value = predicates.getString("value"); 382 if (type.equals( IdEqualsPredicate.class.getName())) {383 if (type.equals(EqualsPredicate.class.getName())) { 383 384 if (!map.containsKey(field)) { 384 385 map.put(field, new Vector()); -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Predicate.java
r8872 r8875 45 45 Constants.HOST_ID_FIELD, 46 46 Constants.COLLECTION_ID_FIELD, 47 Constants.HOST_COLLECTION_ID_FIELD, 47 48 Constants.DOCUMENT_ID_FIELD }; 48 49 -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java
r8872 r8875 28 28 private static int id = 0; 29 29 30 private static Map idEqualsPredicates = new TreeMap();30 private static Map equalsPredicates = new TreeMap(); 31 31 32 32 // substring for collection_name -> SubstringMatchPredicates referring to it … … 77 77 return null; 78 78 } 79 List results = create IdEqualsPredicates(key, values);79 List results = createEqualsPredicates(key, values); 80 80 for (Iterator iter = results.iterator(); iter.hasNext();) { 81 IdEqualsPredicate pred = (IdEqualsPredicate) iter.next();81 EqualsPredicate pred = (EqualsPredicate) iter.next(); 82 82 83 83 pred.setID(pred.saveToDatabase()); … … 117 117 * @return 118 118 */ 119 private static List create IdEqualsPredicates(String key, List values) {119 private static List createEqualsPredicates(String key, List values) { 120 120 List result = new Vector(); 121 121 122 122 Map keyToPredicates; 123 if (! idEqualsPredicates.containsKey(key)) {123 if (!equalsPredicates.containsKey(key)) { 124 124 keyToPredicates = new HashMap(); 125 idEqualsPredicates.put(key, keyToPredicates);126 } 127 keyToPredicates = (Map) idEqualsPredicates.get(key);125 equalsPredicates.put(key, keyToPredicates); 126 } 127 keyToPredicates = (Map) equalsPredicates.get(key); 128 128 129 129 for (Iterator iter = values.iterator(); iter.hasNext();) { … … 137 137 } 138 138 139 IdEqualsPredicate predicate = null;139 EqualsPredicate predicate = null; 140 140 if (keyToPredicates.containsKey(value)) { 141 predicate = ( IdEqualsPredicate) keyToPredicates.get(value);142 } else { 143 predicate = new IdEqualsPredicate(key, value);141 predicate = (EqualsPredicate) keyToPredicates.get(value); 142 } else { 143 predicate = new EqualsPredicate(key, value); 144 144 keyToPredicates.put(value, predicate); 145 145 } … … 202 202 * @return 203 203 */ 204 public static IdEqualsPredicate getIdEqualsPredicate(String key, String value) {205 IdEqualsPredicate result = null;206 if ( idEqualsPredicates.containsKey(key)) {207 result = ( IdEqualsPredicate) ((Map)idEqualsPredicates.get(key)).get(value);204 public static EqualsPredicate getEqualsPredicate(String key, String value) { 205 EqualsPredicate result = null; 206 if (equalsPredicates.containsKey(key)) { 207 result = (EqualsPredicate) ((Map)equalsPredicates.get(key)).get(value); 208 208 } 209 209 return result; … … 217 217 String value = predicate.getValue(); 218 218 219 if (predicate instanceof IdEqualsPredicate) {220 Map map = (Map) idEqualsPredicates.get(field);219 if (predicate instanceof EqualsPredicate) { 220 Map map = (Map) equalsPredicates.get(field); 221 221 if (map.containsKey(value)) { 222 222 map.remove(value); -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Subscription.java
r8867 r8875 15 15 import java.util.Map; 16 16 import java.util.TreeMap; 17 17 import java.util.regex.Matcher; 18 import java.util.regex.Pattern; 19 20 import org.greenstone.gsdlas.Constants; 18 21 import org.greenstone.gsdlas.database.DatabaseException; 19 22 import org.greenstone.gsdlas.database.DatabaseManager; … … 38 41 39 42 public Subscription(Map valueMap) throws DatabaseException, SQLException { 43 valueMap = cleanHostCollectionIDs(valueMap); 40 44 map = new TreeMap(); 41 45 for (Iterator iter = valueMap.keySet().iterator(); iter.hasNext();) { … … 52 56 map.put(key, predicate); 53 57 54 if (predicate != null && !(predicate instanceof IdEqualsPredicate)) {58 if (predicate != null && !(predicate instanceof EqualsPredicate)) { 55 59 numOfNonEqualsPredicates++; 56 60 } … … 63 67 Predicate predicate = (Predicate) iterator.next(); 64 68 65 if (predicate != null && !(predicate instanceof IdEqualsPredicate)) {69 if (predicate != null && !(predicate instanceof EqualsPredicate)) { 66 70 numOfNonEqualsPredicates++; 67 71 } … … 88 92 } 89 93 94 /** 95 * @param valueMap 96 * @return 97 */ 98 private Map cleanHostCollectionIDs(Map valueMap) { 99 Map result = new TreeMap(); 100 Pattern pattern = Pattern.compile("^(.*)\\|(.*)$"); 101 for (Iterator iter = valueMap.keySet().iterator(); iter.hasNext();) { 102 String key = (String) iter.next(); 103 if (!key.equals(Constants.HOST_COLLECTION_ID_FIELD)) { 104 result.put(key, valueMap.get(key)); 105 continue; 106 } 107 if (key.equals(Constants.HOST_ID_FIELD)) { continue; } 108 109 List values = (List) valueMap.get(key); 110 List hostIDs = new Vector(); 111 List collIDs = new Vector(); 112 for (Iterator iterator = values.iterator(); iterator.hasNext();) { 113 String id = (String) iterator.next(); 114 Matcher matcher = pattern.matcher(id); 115 if (matcher.matches()) { 116 String host = null; 117 String coll = null; 118 try { 119 host = matcher.group(1); 120 coll = matcher.group(2); 121 } catch (IndexOutOfBoundsException e) { /*ignore*/ } 122 if (host != null && host.length() > 0) { 123 if (coll != null && coll.length() > 0) { 124 if (!collIDs.contains(id)) collIDs.add(id); 125 } else { 126 if (!hostIDs.contains(host)) hostIDs.add(host); 127 } 128 } 129 } 130 } 131 result.put(Constants.HOST_ID_FIELD, hostIDs); 132 result.put(Constants.COLLECTION_ID_FIELD, collIDs); 133 } 134 return result; 135 } 136 90 137 public boolean containsKey(Object key) { 91 138 return map.containsKey(key);
Note:
See TracChangeset
for help on using the changeset viewer.