Ignore:
Timestamp:
2004-12-21T16:18:32+13:00 (19 years ago)
Author:
schweer
Message:

started to use constants instead of strings

Location:
trunk/greenstone3-extensions/gsdl-as
Files:
1 added
6 edited

Legend:

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

    r8870 r8872  
    7171            HttpServletResponse res, Context context) {
    7272       
    73         String action = req.getParameter("action");
     73        String action = req.getParameter(Constants.ACTION_PARAM);
    7474
    7575        Map args = req.getParameterMap();
     
    257257        GreenstoneCommunicator gsComm = null;
    258258        try {
    259             String hostID = (String) event.get("hostID");
     259            String hostID = (String) event.get(Constants.HOST_ID_FIELD);
    260260            gsComm = new GreenstoneCommunicator(new URL(hostID));
    261261        } catch (MalformedURLException e) {
     
    323323    private String showSubscriptionWizardPage(Map arguments, Context context, boolean create) throws Exception {
    324324        if (create) {
    325             context.put("action", "createSubscription");
     325            context.put(Constants.ACTION_PARAM, "createSubscription");
    326326        } else {
    327             context.put("action", "editSubscription");
     327            context.put(Constants.ACTION_PARAM, "editSubscription");
    328328        }
    329329        if (!arguments.containsKey("current_page")) {
     
    335335        String direction = (String) arguments.get("next_page");
    336336       
    337         if (arguments.containsKey("host_query")) {
    338             String hostQuery = (String) arguments.get("host_query");
     337        if (arguments.containsKey(Constants.HOST_QUERY_FIELD)) {
     338            String hostQuery = (String) arguments.get(Constants.HOST_QUERY_FIELD);
    339339            if (hostQuery != null && hostQuery.length() != 0)
    340                 arguments.remove("hostID");
    341         }
    342         if (arguments.containsKey("collection_query")) {
    343             String collQuery = (String) arguments.get("collection_query");
     340                arguments.remove(Constants.HOST_ID_FIELD);
     341        }
     342        if (arguments.containsKey(Constants.COLLECTION_QUERY_FIELD)) {
     343            String collQuery = (String) arguments.get(Constants.COLLECTION_QUERY_FIELD);
    344344            if (collQuery != null && collQuery.length() != 0)
    345                 arguments.remove("collectionID");
     345                arguments.remove(Constants.COLLECTION_ID_FIELD);
    346346        }
    347347       
     
    370370        } else if (nextPage.equals("collection")) {
    371371            // TODO might be query instead of just name
    372             List hostNames = (List) arguments.get("hostID");
     372            List hostNames = (List) arguments.get(Constants.HOST_ID_FIELD);
    373373            if (hostNames == null || hostNames.isEmpty()) {
    374374                hostNames = new Vector();
     
    383383                    }
    384384                }
    385                 String hostQuery = (String) arguments.get("host_query");
     385                String hostQuery = (String) arguments.get(Constants.HOST_QUERY_FIELD);
    386386                for (int i = 0; i < hostsFromSession.length; i++) {
    387387                    if (hostsFromSession[i] != null && hostsFromSession[i].indexOf(hostQuery) >= 0) {
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java

    r8867 r8872  
    5454     */
    5555    private void addSubscription(Subscription subscription) {
    56         List documentIdPredicate = subscription.getPredicateList("documentID");
    57         List collectionIdPredicate = subscription.getPredicateList("collectionID");
    58         List hostIdPredicate = subscription.getPredicateList("hostID");
    59         List typePredicate = subscription.getPredicateList("type");
     56        List documentIdPredicate = subscription.getPredicateList(Constants.DOCUMENT_ID_FIELD);
     57        List collectionIdPredicate = subscription.getPredicateList(Constants.COLLECTION_ID_FIELD);
     58        List hostIdPredicate = subscription.getPredicateList(Constants.HOST_ID_FIELD);
     59        List typePredicate = subscription.getPredicateList(Constants.TYPE_FIELD);
    6060       
    6161        Integer subId = new Integer(subscription.getId());
    6262       
    6363        if (documentIdPredicate.isEmpty()) {
    64             if (!dontCareSubscriptions.containsKey("documentID")) {
    65                 dontCareSubscriptions.put("documentID", new TreeSet());
    66             }
    67             Set list = (Set) dontCareSubscriptions.get("documentID");
     64            if (!dontCareSubscriptions.containsKey(Constants.DOCUMENT_ID_FIELD)) {
     65                dontCareSubscriptions.put(Constants.DOCUMENT_ID_FIELD, new TreeSet());
     66            }
     67            Set list = (Set) dontCareSubscriptions.get(Constants.DOCUMENT_ID_FIELD);
    6868            list.add(subId);
    6969        }
    7070        if (collectionIdPredicate.isEmpty()) {
    71             if (!dontCareSubscriptions.containsKey("collectionID")) {
    72                 dontCareSubscriptions.put("collectionID", new TreeSet());
    73             }
    74             Set list = (Set) dontCareSubscriptions.get("collectionID");
     71            if (!dontCareSubscriptions.containsKey(Constants.COLLECTION_ID_FIELD)) {
     72                dontCareSubscriptions.put(Constants.COLLECTION_ID_FIELD, new TreeSet());
     73            }
     74            Set list = (Set) dontCareSubscriptions.get(Constants.COLLECTION_ID_FIELD);
    7575            list.add(subId);
    7676        }
    7777        if (hostIdPredicate.isEmpty()) {
    78             if (!dontCareSubscriptions.containsKey("hostID")) {
    79                 dontCareSubscriptions.put("hostID", new TreeSet());
    80             }
    81             Set list = (Set) dontCareSubscriptions.get("hostID");
     78            if (!dontCareSubscriptions.containsKey(Constants.HOST_ID_FIELD)) {
     79                dontCareSubscriptions.put(Constants.HOST_ID_FIELD, new TreeSet());
     80            }
     81            Set list = (Set) dontCareSubscriptions.get(Constants.HOST_ID_FIELD);
    8282            list.add(subId);
    8383        }
    8484        if (typePredicate.isEmpty()) {
    85             if (!dontCareSubscriptions.containsKey("type")) {
    86                 dontCareSubscriptions.put("type", new TreeSet());
    87             }
    88             Set list = (Set) dontCareSubscriptions.get("type");
     85            if (!dontCareSubscriptions.containsKey(Constants.TYPE_FIELD)) {
     86                dontCareSubscriptions.put(Constants.TYPE_FIELD, new TreeSet());
     87            }
     88            Set list = (Set) dontCareSubscriptions.get(Constants.TYPE_FIELD);
    8989            list.add(subId);
    9090        }
     
    113113        // TODO rework algo for getting partially matched subs
    114114        IdEqualsPredicate predicate;
    115         predicate = PredicateFactory.getIdEqualsPredicate("type", (String)event.get("type"));
     115        predicate = PredicateFactory.getIdEqualsPredicate(Constants.TYPE_FIELD,
     116                (String)event.get(Constants.TYPE_FIELD));
    116117        if (predicate != null)
    117118            result.addAll(predicate.getSubscriptionIDs());
    118119       
    119120        Set docIDSubs = new TreeSet();
    120         predicate = PredicateFactory.getIdEqualsPredicate("documentID", (String)event.get("documentID"));
     121        predicate = PredicateFactory.getIdEqualsPredicate(Constants.DOCUMENT_ID_FIELD,
     122                (String)event.get(Constants.DOCUMENT_ID_FIELD));
    121123        if (predicate != null)
    122124            docIDSubs.addAll(predicate.getSubscriptionIDs());
    123         docIDSubs.addAll(getDontCareSubscriptions("documentID"));
     125        docIDSubs.addAll(getDontCareSubscriptions(Constants.DOCUMENT_ID_FIELD));
    124126        result.retainAll(docIDSubs);
    125127       
    126128        Set collIDSubs = new TreeSet();
    127         predicate = PredicateFactory.getIdEqualsPredicate("collectionID", (String)event.get("collectionID"));
     129        predicate = PredicateFactory.getIdEqualsPredicate(Constants.COLLECTION_ID_FIELD,
     130                (String)event.get(Constants.COLLECTION_ID_FIELD));
    128131        if (predicate != null)
    129132            collIDSubs.addAll(predicate.getSubscriptionIDs());
    130         collIDSubs.addAll(getDontCareSubscriptions("collectionID"));
     133        collIDSubs.addAll(getDontCareSubscriptions(Constants.COLLECTION_ID_FIELD));
    131134        result.retainAll(collIDSubs);
    132135       
    133136        Set hostIDSubs = new TreeSet();
    134         predicate = PredicateFactory.getIdEqualsPredicate("hostID", (String)event.get("hostID"));
     137        predicate = PredicateFactory.getIdEqualsPredicate(Constants.HOST_ID_FIELD,
     138                (String)event.get(Constants.HOST_ID_FIELD));
    135139        if (predicate != null)
    136140            hostIDSubs.addAll(predicate.getSubscriptionIDs());
    137         hostIDSubs.addAll(getDontCareSubscriptions("hostID"));
     141        hostIDSubs.addAll(getDontCareSubscriptions(Constants.HOST_ID_FIELD));
    138142        result.retainAll(hostIDSubs);
    139143       
     
    154158        // predicate is matched iff the docID occurs in the query result
    155159       
    156         for (Iterator iter = PredicateFactory.getQueryPredicates("document_content").iterator(); iter.hasNext();) {
     160        for (Iterator iter = PredicateFactory.getQueryPredicates(Constants.DOCUMENT_CONTENT_FIELD).iterator(); iter.hasNext();) {
    157161            Predicate predicate = (Predicate) iter.next();
    158             String collection = (String) event.get("collectionID");
     162            String collection = (String) event.get(Constants.COLLECTION_ID_FIELD);
    159163            String query = predicate.getValue();
    160164            Set results;
    161165            try {
    162166                results = gsComm.fullTextSearch(collection, query);
    163                 if (results.contains(event.get("documentID"))) {
     167                if (results.contains(event.get(Constants.DOCUMENT_ID_FIELD))) {
    164168                    matchedPreds.add(predicate);
    165169                }
     
    368372                ResultSet predicates = stmnt.executeQuery(sqlString);
    369373                while (predicates.next()) {
    370                     String type = predicates.getString("type");
     374                    String type = predicates.getString(Constants.TYPE_FIELD);
    371375                    String field = predicates.getString("field");
    372376                    if (type.equals(SubstringMatchPredicate.class.getName())) {
    373                         if (field.equals("colletionID")) {
    374                             field = "collection_query";
    375                         } else if (field.equals("hostID")) {
    376                             field = "host_query";
     377                        if (field.equals(Constants.COLLECTION_ID_FIELD)) {
     378                            field = Constants.COLLECTION_QUERY_FIELD;
     379                        } else if (field.equals(Constants.HOST_ID_FIELD)) {
     380                            field = Constants.HOST_QUERY_FIELD;
    377381                        }
    378382                    }
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/Predicate.java

    r8867 r8872  
    1616import java.util.TreeSet;
    1717
     18import org.greenstone.gsdlas.Constants;
    1819import org.greenstone.gsdlas.database.DatabaseException;
    1920import org.greenstone.gsdlas.database.DatabaseManager;
     
    3536
    3637    public static final String[] singleValueFields = new String[] {
    37             "document_title",
    38             "document_content",
     38            Constants.DOCUMENT_TITLE_FIELD,
     39            Constants.DOCUMENT_CONTENT_FIELD,
    3940            "metadata_has_field",
    40             "host_query",
    41             "collection_query" };
     41            Constants.HOST_QUERY_FIELD,
     42            Constants.COLLECTION_QUERY_FIELD };
    4243    public static final String[] multiValueFields = new String[] {
    43             "type",
    44             "hostID",
    45             "collectionID",
    46             "documentID" };
     44            Constants.TYPE_FIELD,
     45            Constants.HOST_ID_FIELD,
     46            Constants.COLLECTION_ID_FIELD,
     47            Constants.DOCUMENT_ID_FIELD };
    4748   
    4849    public void addSubscription(int subscriptionID) {
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java

    r8867 r8872  
    1414import java.util.TreeMap;
    1515
     16import org.greenstone.gsdlas.Constants;
    1617import org.greenstone.gsdlas.database.DatabaseException;
    1718
     
    9293    private static SubstringMatchPredicate createSubstringMatchPredicate(String key, String value) {
    9394        SubstringMatchPredicate predicate = null;
    94         if (key.equals("collection_query")) {
     95        if (key.equals(Constants.COLLECTION_QUERY_FIELD)) {
    9596            if (collectionNameMatchPredicates.containsKey(value)) {
    9697                predicate = (SubstringMatchPredicate) collectionNameMatchPredicates.get(value);
    9798            } else {
    98                 predicate = new SubstringMatchPredicate("collectionID", value);
     99                predicate = new SubstringMatchPredicate(Constants.COLLECTION_ID_FIELD, value);
    99100                collectionNameMatchPredicates.put(value, predicate);
    100101            }
    101         } else if (key.equals("host_query")) {
     102        } else if (key.equals(Constants.HOST_QUERY_FIELD)) {
    102103            if (hostNameMatchPredicates.containsKey(value)) {
    103104                predicate = (SubstringMatchPredicate) hostNameMatchPredicates.get(value);
    104105            } else {
    105                 predicate = new SubstringMatchPredicate("hostID", value);
     106                predicate = new SubstringMatchPredicate(Constants.HOST_ID_FIELD, value);
    106107                hostNameMatchPredicates.put(value, predicate);
    107108            }
     
    132133            }
    133134
    134             if (key.equals("hostID") && !(value.startsWith("http://"))) {
     135            if (key.equals(Constants.HOST_ID_FIELD) && !(value.startsWith("http://"))) {
    135136                value = "http://" + value + ":8080/soap/servlet/rpcrouter";
    136137            }
     
    156157            String query) {
    157158        QueryPredicate predicate = null;
    158         if (field.equals("document_content")) {
     159        if (field.equals(Constants.DOCUMENT_CONTENT_FIELD)) {
    159160            if (!documentContentQueryPredicates.containsKey(query)) {
    160161                predicate = new QueryPredicate(field, query);
     
    162163            }
    163164            return (QueryPredicate) documentContentQueryPredicates.get(query);
    164         } else if (field.equals("document_title")) {
     165        } else if (field.equals(Constants.DOCUMENT_TITLE_FIELD)) {
    165166            if (!documentTitleQueryPredicates.containsKey(query)) {
    166167                predicate = new QueryPredicate(field, query);
     
    181182    public static Collection getQueryPredicates(String field) {
    182183        Set result = new TreeSet();
    183         if (field.equals("document_title")) {
     184        if (field.equals(Constants.DOCUMENT_TITLE_FIELD)) {
    184185            result.addAll(documentTitleQueryPredicates.values());
    185         } else if (field.equals("document_content")) {
     186        } else if (field.equals(Constants.DOCUMENT_CONTENT_FIELD)) {
    186187            result.addAll(documentContentQueryPredicates.values());
    187188        }
     
    222223            }
    223224        } else if (predicate instanceof QueryPredicate) {
    224             if (field.equals("document_title")) {
     225            if (field.equals(Constants.DOCUMENT_TITLE_FIELD)) {
    225226                documentTitleQueryPredicates.remove(value);
    226             } else if (field.equals("document_content")) {
     227            } else if (field.equals(Constants.DOCUMENT_CONTENT_FIELD)) {
    227228                documentContentQueryPredicates.remove(value);
    228229            } else {
     
    230231            }
    231232        } else if (predicate instanceof SubstringMatchPredicate) {
    232             if (field.equals("hostID")) {
     233            if (field.equals(Constants.HOST_ID_FIELD)) {
    233234                hostNameMatchPredicates.remove(value);
    234             } else if (field.equals("collectionID")) {
     235            } else if (field.equals(Constants.COLLECTION_ID_FIELD)) {
    235236                collectionNameMatchPredicates.remove(value);
    236237            } else {
  • trunk/greenstone3-extensions/gsdl-as/test-src/org/greenstone/gsdlas/AlertingServiceTest.java

    r8722 r8872  
    3939           
    4040            Map arguments = new TreeMap();
    41             arguments.put("type", "new_document");
    42             arguments.put("collectionID", "testing");
    43             arguments.put("document_content", "albatros");
     41            arguments.put(Constants.TYPE_FIELD, "new_document");
     42            arguments.put(Constants.COLLECTION_ID_FIELD, "testing");
     43            arguments.put(Constants.DOCUMENT_CONTENT_FIELD, "albatros");
    4444           
    4545            String template = as.createSubscription(arguments, context);
     
    104104           
    105105            Map arguments = new TreeMap();
    106             arguments.put("collectionID", "testing");
    107             arguments.put("type", "new_document");
    108             arguments.put("documentID", "20041124:1");
    109             arguments.put("document_title", "keine albatrosse in sicht");
    110             arguments.put("host_url", "http://localhost:8080/soap/servlet/rpcrouter");
     106            arguments.put(Constants.COLLECTION_ID_FIELD, "testing");
     107            arguments.put(Constants.TYPE_FIELD, "new_document");
     108            arguments.put(Constants.DOCUMENT_ID_FIELD, "20041124:1");
     109            arguments.put(Constants.DOCUMENT_TITLE_FIELD, "keine albatrosse in sicht");
     110            arguments.put(Constants.HOST_ID_FIELD, "http://localhost:8080/soap/servlet/rpcrouter");
    111111           
    112112            as.receiveEvent(arguments);
  • trunk/greenstone3-extensions/gsdl-as/test-src/org/greenstone/gsdlas/ProfileStoreTest.java

    r8798 r8872  
    4444            Map event = new TreeMap();
    4545           
    46             event.put("documentID", "20041118:5");
    47             event.put("collectionID", "gs3mgdemo");
    48             event.put("hostID", "http://localhost:8080/soap/servlet/rpcrouter");
     46            event.put(Constants.DOCUMENT_ID_FIELD, "20041118:5");
     47            event.put(Constants.COLLECTION_ID_FIELD, "gs3mgdemo");
     48            event.put(Constants.HOST_ID_FIELD, "http://localhost:8080/soap/servlet/rpcrouter");
    4949           
    5050            Set result = ProfileStore.getInstance().filter(event, gsComm);
     
    6161        Map valueMap = new TreeMap();
    6262       
    63         valueMap.put("collectionID", "gs3mgdemo");
    64         valueMap.put("document_content", "Tomatensalat");
     63        valueMap.put(Constants.COLLECTION_ID_FIELD, "gs3mgdemo");
     64        valueMap.put(Constants.DOCUMENT_CONTENT_FIELD, "Tomatensalat");
    6565       
    6666        addSubscription(valueMap);
     
    6868        valueMap.clear();
    6969       
    70         valueMap.put("collectionID", "gs3mgdemo");
    71         valueMap.put("document_content", "Water+Buffalo");
     70        valueMap.put(Constants.COLLECTION_ID_FIELD, "gs3mgdemo");
     71        valueMap.put(Constants.DOCUMENT_CONTENT_FIELD, "Water+Buffalo");
    7272       
    7373        addSubscription(valueMap);
     
    7575        valueMap.clear();
    7676       
    77         valueMap.put("collectionID", "gs3mgdemo");
    78         valueMap.put("document_content", "gender+equality");
     77        valueMap.put(Constants.COLLECTION_ID_FIELD, "gs3mgdemo");
     78        valueMap.put(Constants.DOCUMENT_CONTENT_FIELD, "gender+equality");
    7979       
    8080        addSubscription(valueMap);
Note: See TracChangeset for help on using the changeset viewer.