Ignore:
Timestamp:
2004-12-10T15:48:39+13:00 (19 years ago)
Author:
schweer
Message:

started to work on multi-valued predicates; started to rework the filter algorithm

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java

    r8753 r8777  
    2525    private static ProfileStore instance;
    2626
    27     private Map docIdEqualsSubscriptions = new TreeMap();
    28     private Map collectionIdEqualsSubscriptions = new TreeMap();
    29     private Map docCollectionIdEqualsSubscriptions = new TreeMap();
    3027    private Set noEqualsSubscriptions = new TreeSet();
     28    private Map subscriptions = new TreeMap();
    3129
    3230    private ProfileStore() {
     
    5048        Predicate documentIdPredicate = subscription.getPredicate("documentID");
    5149        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);
    9360    }
    9461
     
    10774    public Set getPartiallyMatchedSubscriptions(Map event) {
    10875        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       
    13494        return result;
    13595    }
     
    206166                    .hasNext();) {
    207167                // 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);
    210171                int newCountValue = (count == null ? 1 : count.intValue() + 1);
    211                 numMatchedPredicates.put(sub,
     172                numMatchedPredicates.put(subId,
    212173                        new Integer(newCountValue));
    213174            }
     
    218179        for (Iterator iter = notUnmatchedSubscriptions.iterator(); iter
    219180                .hasNext();) {
    220             Subscription sub = (Subscription) iter.next();
     181            Integer subId = (Integer) iter.next();
     182            Subscription sub = (Subscription) subscriptions.get(subId);
    221183            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();
    224186            }
    225187            if (matchedPredicatesCount == sub.getNumOfNonEqualsPredicates()) {
     
    229191        return matchedSubscriptions;
    230192    }
    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      * @return
    248      */
    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//    }
    269231
    270232
     
    296258       
    297259    }
     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    }
    298270   
    299271}
Note: See TracChangeset for help on using the changeset viewer.