Ignore:
Timestamp:
2005-01-07T18:15:22+13:00 (19 years ago)
Author:
schweer
Message:

first changes towards treating collection ids as unique only on a per-host basis (addressing BTS #11)

Location:
trunk/greenstone3-extensions/gsdl-as
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/greenstone3-extensions/gsdl-as/create-tables.sql

    r8867 r8875  
    1919    field varchar(128) not null,
    2020    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,
    2222   
    2323    unique(field,type,value)
  • trunk/greenstone3-extensions/gsdl-as/lib/templates/sub_collection.vm

    r8847 r8875  
    3737                    <ol>
    3838                    <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>
    4041                        #foreach($host in $hostnames)
    4142                        <optgroup label="$host">
    4243                            #foreach($collection in $collectionnames.get($host))
    43                             <option>$collection</option>
     44                            <option>$host|$collection</option>
    4445                            #end
    45                             <option selected="selected" value="">any collection on host $host</option>
     46                            <option selected="selected" value="$host">any collection on host $host</option>
    4647                        </optgroup>
    4748                    #end
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/Constants.java

    r8872 r8875  
    2222    public static final String HOST_ID_FIELD = "hostID";
    2323    public static final String COLLECTION_ID_FIELD = "collectionID";
     24    public static final String HOST_COLLECTION_ID_FIELD = "hostCollectionID";
    2425    public static final String DOCUMENT_ID_FIELD = "documentID";
    2526    public static final String DOCUMENT_CONTENT_FIELD = "document_content";
    2627    public static final String DOCUMENT_TITLE_FIELD = "document_title";
    2728    public static final String TYPE_FIELD = "type";
     29
     30
    2831}
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java

    r8874 r8875  
    3636
    3737    private ProfileStore() {
     38        // hide default constructor
    3839    }
    3940
     
    6768            list.add(subId);
    6869        }
    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         }
    7670        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            }
    8278        }
    8379        if (typePredicate.isEmpty()) {
     
    110106    public Set getPartiallyMatchedSubscriptions(Map event) {
    111107        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,
    114113                (String)event.get(Constants.TYPE_FIELD));
    115114        if (predicate != null)
    116115            result.addAll(predicate.getSubscriptionIDs());
    117116       
     117        // ...but only those subscriptions where the doc id matches...
    118118        Set docIDSubs = new TreeSet();
    119         predicate = PredicateFactory.getIdEqualsPredicate(Constants.DOCUMENT_ID_FIELD,
     119        predicate = PredicateFactory.getEqualsPredicate(Constants.DOCUMENT_ID_FIELD,
    120120                (String)event.get(Constants.DOCUMENT_ID_FIELD));
    121121        if (predicate != null)
     
    124124        result.retainAll(docIDSubs);
    125125       
    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,
    128137                (String)event.get(Constants.COLLECTION_ID_FIELD));
    129138        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);
    141142       
    142143        return result;
     
    380381                    }
    381382                    String value = predicates.getString("value");
    382                     if (type.equals(IdEqualsPredicate.class.getName())) {
     383                    if (type.equals(EqualsPredicate.class.getName())) {
    383384                        if (!map.containsKey(field)) {
    384385                            map.put(field, new Vector());
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Predicate.java

    r8872 r8875  
    4545            Constants.HOST_ID_FIELD,
    4646            Constants.COLLECTION_ID_FIELD,
     47            Constants.HOST_COLLECTION_ID_FIELD,
    4748            Constants.DOCUMENT_ID_FIELD };
    4849   
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java

    r8872 r8875  
    2828    private static int id = 0;
    2929   
    30     private static Map idEqualsPredicates = new TreeMap();
     30    private static Map equalsPredicates = new TreeMap();
    3131   
    3232    // substring for collection_name -> SubstringMatchPredicates referring to it
     
    7777            return null;
    7878        }
    79         List results = createIdEqualsPredicates(key, values);
     79        List results = createEqualsPredicates(key, values);
    8080        for (Iterator iter = results.iterator(); iter.hasNext();) {
    81             IdEqualsPredicate pred = (IdEqualsPredicate) iter.next();
     81            EqualsPredicate pred = (EqualsPredicate) iter.next();
    8282
    8383            pred.setID(pred.saveToDatabase());
     
    117117     * @return
    118118     */
    119     private static List createIdEqualsPredicates(String key, List values) {
     119    private static List createEqualsPredicates(String key, List values) {
    120120        List result = new Vector();
    121121       
    122122        Map keyToPredicates;
    123         if (!idEqualsPredicates.containsKey(key)) {
     123        if (!equalsPredicates.containsKey(key)) {
    124124            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);
    128128       
    129129        for (Iterator iter = values.iterator(); iter.hasNext();) {
     
    137137            }
    138138           
    139             IdEqualsPredicate predicate = null;
     139            EqualsPredicate predicate = null;
    140140            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);
    144144                keyToPredicates.put(value, predicate);
    145145            }
     
    202202     * @return
    203203     */
    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);
    208208        }
    209209        return result;
     
    217217        String value = predicate.getValue();
    218218       
    219         if (predicate instanceof IdEqualsPredicate) {
    220             Map map = (Map) idEqualsPredicates.get(field);
     219        if (predicate instanceof EqualsPredicate) {
     220            Map map = (Map) equalsPredicates.get(field);
    221221            if (map.containsKey(value)) {
    222222                map.remove(value);
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Subscription.java

    r8867 r8875  
    1515import java.util.Map;
    1616import java.util.TreeMap;
    17 
     17import java.util.regex.Matcher;
     18import java.util.regex.Pattern;
     19
     20import org.greenstone.gsdlas.Constants;
    1821import org.greenstone.gsdlas.database.DatabaseException;
    1922import org.greenstone.gsdlas.database.DatabaseManager;
     
    3841   
    3942    public Subscription(Map valueMap) throws DatabaseException, SQLException {
     43        valueMap = cleanHostCollectionIDs(valueMap);
    4044        map = new TreeMap();
    4145        for (Iterator iter = valueMap.keySet().iterator(); iter.hasNext();) {
     
    5256                map.put(key, predicate);
    5357
    54                 if (predicate != null && !(predicate instanceof IdEqualsPredicate)) {
     58                if (predicate != null && !(predicate instanceof EqualsPredicate)) {
    5559                    numOfNonEqualsPredicates++;
    5660                }
     
    6367                    Predicate predicate = (Predicate) iterator.next();
    6468                   
    65                     if (predicate != null && !(predicate instanceof IdEqualsPredicate)) {
     69                    if (predicate != null && !(predicate instanceof EqualsPredicate)) {
    6670                        numOfNonEqualsPredicates++;
    6771                    }
     
    8892    }
    8993   
     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
    90137    public boolean containsKey(Object key) {
    91138        return map.containsKey(key);
Note: See TracChangeset for help on using the changeset viewer.