Changeset 8847


Ignore:
Timestamp:
2004-12-17T15:21:07+13:00 (19 years ago)
Author:
schweer
Message:

substring match for host/collection works

Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/greenstone3-extensions/gsdl-as/lib/templates/sub_collection.vm

    r8798 r8847  
    4343                            <option>$collection</option>
    4444                            #end
    45                             <option selected="selected">any collection on host $host</option>
     45                            <option selected="selected" value="">any collection on host $host</option>
    4646                        </optgroup>
    4747                    #end
  • trunk/greenstone3-extensions/gsdl-as/lib/templates/sub_host.vm

    r8798 r8847  
    4242                    <option #if($firstoption) selected="selected" #set($firstoption = false) #end>$host</option>
    4343                    #end
    44                     <option value="any">any host</option>
     44                    <option value="">any host</option>
    4545                    </select></li>
    4646                    <li>You can enter a query in the field below. Only events coming from a host whose name matches this query will be sent to you.<br/>
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java

    r8798 r8847  
    305305        String direction = (String) arguments.get("next_page");
    306306       
     307        if (arguments.containsKey("host_query")) {
     308            String hostQuery = (String) arguments.get("host_query");
     309            if (hostQuery != null && hostQuery.length() != 0)
     310                arguments.remove("hostID");
     311        }
     312        if (arguments.containsKey("collection_query")) {
     313            String collQuery = (String) arguments.get("collection_query");
     314            if (collQuery != null && collQuery.length() != 0)
     315                arguments.remove("collectionID");
     316        }
     317       
    307318        // save page arguments
    308319        savePageArgsToSession(currentPage, arguments, session);
     
    318329        // get page-specific stuff
    319330        if (nextPage.equals("host")) {
    320             GreenstoneCommunicator gsComm = null;
    321331            String[] hostNames;
    322332            try {
    323                 gsComm = new GreenstoneCommunicator();
     333                GreenstoneCommunicator gsComm = new GreenstoneCommunicator();
    324334                hostNames = gsComm.getHostNames();
    325335            } catch (Exception e) {
     
    327337            }
    328338            context.put("hostnames", hostNames);
     339            session.setAttribute("hostnames", hostNames);
    329340        } else if (nextPage.equals("collection")) {
    330341            // TODO might be query instead of just name
    331342            List hostNames = (List) arguments.get("hostID");
    332             GreenstoneCommunicator gsComm = null;
     343            if (hostNames == null || hostNames.isEmpty()) {
     344                hostNames = new Vector();
     345                // no host names -> use host query
     346                String[] hostsFromSession = (String[]) session.getAttribute("hostnames");
     347                if (hostsFromSession == null || hostsFromSession.length == 0) {
     348                    try {
     349                        GreenstoneCommunicator gsComm = new GreenstoneCommunicator();
     350                        hostsFromSession = gsComm.getHostNames();
     351                    } catch (Exception e) {
     352                        hostsFromSession = new String[] { "localhost" };
     353                    }
     354                }
     355                String hostQuery = (String) arguments.get("host_query");
     356                for (int i = 0; i < hostsFromSession.length; i++) {
     357                    if (hostsFromSession[i] != null && hostsFromSession[i].indexOf(hostQuery) >= 0) {
     358                        hostNames.add(hostsFromSession[i]);
     359                    }
     360                }
     361            }
     362           
    333363            Map collNames = new TreeMap();
    334364            for (Iterator iter = hostNames.iterator(); iter.hasNext();) {
     
    336366                Set collNamesForHost = new TreeSet();   
    337367                try {
    338                     gsComm = new GreenstoneCommunicator(new URL("http://" + host + ":8080/soap/servlet/rpcrouter"));
     368                    URL url = new URL("http://" + host + ":8080/soap/servlet/rpcrouter");
     369                    GreenstoneCommunicator gsComm = new GreenstoneCommunicator(url);
    339370                    collNamesForHost.addAll(Arrays.asList(gsComm.getCollectionNames()));
    340371                } catch (Exception e) {
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/GreenstoneCommunicator.java

    r8798 r8847  
    5353
    5454    public String[] getHostNames() {
     55        // TODO method implementation
    5556        return new String[] {"localhost"};
    5657    }
  • trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java

    r8798 r8847  
    3131    // substring for collection_name -> SubstringMatchPredicates referring to it
    3232    private static Map collectionNameMatchPredicates = new TreeMap();
     33    private static Map hostNameMatchPredicates = new TreeMap();
    3334   
    3435    // query -> QueryPredicates referring to it
     
    6263        } else if (key.startsWith("document")) {
    6364            result = createQueryPredicate(key, value);
    64         } else if (key.endsWith("_name")) {
     65        } else if (key.endsWith("_query")) {
    6566            result = createSubstringMatchPredicate(key, value);
    6667        } else {
     
    9192    private static SubstringMatchPredicate createSubstringMatchPredicate(String key, String value) {
    9293        SubstringMatchPredicate predicate = null;
    93         if (key.equals("collection_name")) {
     94        if (key.equals("collection_query")) {
    9495            if (collectionNameMatchPredicates.containsKey(value)) {
    9596                predicate = (SubstringMatchPredicate) collectionNameMatchPredicates.get(value);
    9697            } else {
    97                 predicate = new SubstringMatchPredicate(key, value);
     98                predicate = new SubstringMatchPredicate("collectionID", value);
    9899                collectionNameMatchPredicates.put(value, predicate);
    99100            }
    100         } // TODO other fields than collection_name
     101        } else if (key.equals("host_query")) {
     102            if (hostNameMatchPredicates.containsKey(value)) {
     103                predicate = (SubstringMatchPredicate) hostNameMatchPredicates.get(value);
     104            } else {
     105                predicate = new SubstringMatchPredicate("hostID", value);
     106                hostNameMatchPredicates.put(value, predicate);
     107            }
     108        }
     109        // TODO other fields?
    101110        return predicate;
    102111    }
     
    119128        for (Iterator iter = values.iterator(); iter.hasNext();) {
    120129            String value = (String) iter.next();
     130            if (value == null || value.length() == 0) {
     131                continue;
     132            }
    121133
    122134            if (key.equals("hostID") && !(value.startsWith("http://"))) {
     
    143155    private static QueryPredicate createQueryPredicate(String field,
    144156            String query) {
    145         QueryPredicate predicate = new QueryPredicate(field, query);
     157        QueryPredicate predicate = null;
    146158        if (field.equals("document_content")) {
    147             documentContentQueryPredicates.put(query, predicate);
     159            if (!documentContentQueryPredicates.containsKey(query)) {
     160                predicate = new QueryPredicate(field, query);
     161                documentContentQueryPredicates.put(query, predicate);
     162            }
     163            return (QueryPredicate) documentContentQueryPredicates.get(query);
    148164        } else if (field.equals("document_title")) {
    149             documentTitleQueryPredicates.put(query, predicate);
     165            if (!documentTitleQueryPredicates.containsKey(query)) {
     166                predicate = new QueryPredicate(field, query);
     167                documentTitleQueryPredicates.put(query, predicate);
     168            }
     169            return (QueryPredicate) documentTitleQueryPredicates.get(query);
    150170        }
    151171        return predicate;
     
    170190   
    171191    public static Collection getAllSubstringMatchPredicates() {
    172         return Collections.unmodifiableCollection(collectionNameMatchPredicates.values());
     192        Collection result = new Vector();
     193        result.addAll(hostNameMatchPredicates.values());
     194        result.addAll(collectionNameMatchPredicates.values());
     195        return Collections.unmodifiableCollection(result);
    173196    }
    174197
  • trunk/gsdl3/extensions/gsdl-as/lib/templates/sub_collection.vm

    r8798 r8847  
    4343                            <option>$collection</option>
    4444                            #end
    45                             <option selected="selected">any collection on host $host</option>
     45                            <option selected="selected" value="">any collection on host $host</option>
    4646                        </optgroup>
    4747                    #end
  • trunk/gsdl3/extensions/gsdl-as/lib/templates/sub_host.vm

    r8798 r8847  
    4242                    <option #if($firstoption) selected="selected" #set($firstoption = false) #end>$host</option>
    4343                    #end
    44                     <option value="any">any host</option>
     44                    <option value="">any host</option>
    4545                    </select></li>
    4646                    <li>You can enter a query in the field below. Only events coming from a host whose name matches this query will be sent to you.<br/>
  • trunk/gsdl3/extensions/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java

    r8798 r8847  
    305305        String direction = (String) arguments.get("next_page");
    306306       
     307        if (arguments.containsKey("host_query")) {
     308            String hostQuery = (String) arguments.get("host_query");
     309            if (hostQuery != null && hostQuery.length() != 0)
     310                arguments.remove("hostID");
     311        }
     312        if (arguments.containsKey("collection_query")) {
     313            String collQuery = (String) arguments.get("collection_query");
     314            if (collQuery != null && collQuery.length() != 0)
     315                arguments.remove("collectionID");
     316        }
     317       
    307318        // save page arguments
    308319        savePageArgsToSession(currentPage, arguments, session);
     
    318329        // get page-specific stuff
    319330        if (nextPage.equals("host")) {
    320             GreenstoneCommunicator gsComm = null;
    321331            String[] hostNames;
    322332            try {
    323                 gsComm = new GreenstoneCommunicator();
     333                GreenstoneCommunicator gsComm = new GreenstoneCommunicator();
    324334                hostNames = gsComm.getHostNames();
    325335            } catch (Exception e) {
     
    327337            }
    328338            context.put("hostnames", hostNames);
     339            session.setAttribute("hostnames", hostNames);
    329340        } else if (nextPage.equals("collection")) {
    330341            // TODO might be query instead of just name
    331342            List hostNames = (List) arguments.get("hostID");
    332             GreenstoneCommunicator gsComm = null;
     343            if (hostNames == null || hostNames.isEmpty()) {
     344                hostNames = new Vector();
     345                // no host names -> use host query
     346                String[] hostsFromSession = (String[]) session.getAttribute("hostnames");
     347                if (hostsFromSession == null || hostsFromSession.length == 0) {
     348                    try {
     349                        GreenstoneCommunicator gsComm = new GreenstoneCommunicator();
     350                        hostsFromSession = gsComm.getHostNames();
     351                    } catch (Exception e) {
     352                        hostsFromSession = new String[] { "localhost" };
     353                    }
     354                }
     355                String hostQuery = (String) arguments.get("host_query");
     356                for (int i = 0; i < hostsFromSession.length; i++) {
     357                    if (hostsFromSession[i] != null && hostsFromSession[i].indexOf(hostQuery) >= 0) {
     358                        hostNames.add(hostsFromSession[i]);
     359                    }
     360                }
     361            }
     362           
    333363            Map collNames = new TreeMap();
    334364            for (Iterator iter = hostNames.iterator(); iter.hasNext();) {
     
    336366                Set collNamesForHost = new TreeSet();   
    337367                try {
    338                     gsComm = new GreenstoneCommunicator(new URL("http://" + host + ":8080/soap/servlet/rpcrouter"));
     368                    URL url = new URL("http://" + host + ":8080/soap/servlet/rpcrouter");
     369                    GreenstoneCommunicator gsComm = new GreenstoneCommunicator(url);
    339370                    collNamesForHost.addAll(Arrays.asList(gsComm.getCollectionNames()));
    340371                } catch (Exception e) {
  • trunk/gsdl3/extensions/gsdl-as/src/org/greenstone/gsdlas/GreenstoneCommunicator.java

    r8798 r8847  
    5353
    5454    public String[] getHostNames() {
     55        // TODO method implementation
    5556        return new String[] {"localhost"};
    5657    }
  • trunk/gsdl3/extensions/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java

    r8798 r8847  
    3131    // substring for collection_name -> SubstringMatchPredicates referring to it
    3232    private static Map collectionNameMatchPredicates = new TreeMap();
     33    private static Map hostNameMatchPredicates = new TreeMap();
    3334   
    3435    // query -> QueryPredicates referring to it
     
    6263        } else if (key.startsWith("document")) {
    6364            result = createQueryPredicate(key, value);
    64         } else if (key.endsWith("_name")) {
     65        } else if (key.endsWith("_query")) {
    6566            result = createSubstringMatchPredicate(key, value);
    6667        } else {
     
    9192    private static SubstringMatchPredicate createSubstringMatchPredicate(String key, String value) {
    9293        SubstringMatchPredicate predicate = null;
    93         if (key.equals("collection_name")) {
     94        if (key.equals("collection_query")) {
    9495            if (collectionNameMatchPredicates.containsKey(value)) {
    9596                predicate = (SubstringMatchPredicate) collectionNameMatchPredicates.get(value);
    9697            } else {
    97                 predicate = new SubstringMatchPredicate(key, value);
     98                predicate = new SubstringMatchPredicate("collectionID", value);
    9899                collectionNameMatchPredicates.put(value, predicate);
    99100            }
    100         } // TODO other fields than collection_name
     101        } else if (key.equals("host_query")) {
     102            if (hostNameMatchPredicates.containsKey(value)) {
     103                predicate = (SubstringMatchPredicate) hostNameMatchPredicates.get(value);
     104            } else {
     105                predicate = new SubstringMatchPredicate("hostID", value);
     106                hostNameMatchPredicates.put(value, predicate);
     107            }
     108        }
     109        // TODO other fields?
    101110        return predicate;
    102111    }
     
    119128        for (Iterator iter = values.iterator(); iter.hasNext();) {
    120129            String value = (String) iter.next();
     130            if (value == null || value.length() == 0) {
     131                continue;
     132            }
    121133
    122134            if (key.equals("hostID") && !(value.startsWith("http://"))) {
     
    143155    private static QueryPredicate createQueryPredicate(String field,
    144156            String query) {
    145         QueryPredicate predicate = new QueryPredicate(field, query);
     157        QueryPredicate predicate = null;
    146158        if (field.equals("document_content")) {
    147             documentContentQueryPredicates.put(query, predicate);
     159            if (!documentContentQueryPredicates.containsKey(query)) {
     160                predicate = new QueryPredicate(field, query);
     161                documentContentQueryPredicates.put(query, predicate);
     162            }
     163            return (QueryPredicate) documentContentQueryPredicates.get(query);
    148164        } else if (field.equals("document_title")) {
    149             documentTitleQueryPredicates.put(query, predicate);
     165            if (!documentTitleQueryPredicates.containsKey(query)) {
     166                predicate = new QueryPredicate(field, query);
     167                documentTitleQueryPredicates.put(query, predicate);
     168            }
     169            return (QueryPredicate) documentTitleQueryPredicates.get(query);
    150170        }
    151171        return predicate;
     
    170190   
    171191    public static Collection getAllSubstringMatchPredicates() {
    172         return Collections.unmodifiableCollection(collectionNameMatchPredicates.values());
     192        Collection result = new Vector();
     193        result.addAll(hostNameMatchPredicates.values());
     194        result.addAll(collectionNameMatchPredicates.values());
     195        return Collections.unmodifiableCollection(result);
    173196    }
    174197
  • trunk/gsdl3/packages/gsdl-as/lib/templates/sub_collection.vm

    r8798 r8847  
    4343                            <option>$collection</option>
    4444                            #end
    45                             <option selected="selected">any collection on host $host</option>
     45                            <option selected="selected" value="">any collection on host $host</option>
    4646                        </optgroup>
    4747                    #end
  • trunk/gsdl3/packages/gsdl-as/lib/templates/sub_host.vm

    r8798 r8847  
    4242                    <option #if($firstoption) selected="selected" #set($firstoption = false) #end>$host</option>
    4343                    #end
    44                     <option value="any">any host</option>
     44                    <option value="">any host</option>
    4545                    </select></li>
    4646                    <li>You can enter a query in the field below. Only events coming from a host whose name matches this query will be sent to you.<br/>
  • trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java

    r8798 r8847  
    305305        String direction = (String) arguments.get("next_page");
    306306       
     307        if (arguments.containsKey("host_query")) {
     308            String hostQuery = (String) arguments.get("host_query");
     309            if (hostQuery != null && hostQuery.length() != 0)
     310                arguments.remove("hostID");
     311        }
     312        if (arguments.containsKey("collection_query")) {
     313            String collQuery = (String) arguments.get("collection_query");
     314            if (collQuery != null && collQuery.length() != 0)
     315                arguments.remove("collectionID");
     316        }
     317       
    307318        // save page arguments
    308319        savePageArgsToSession(currentPage, arguments, session);
     
    318329        // get page-specific stuff
    319330        if (nextPage.equals("host")) {
    320             GreenstoneCommunicator gsComm = null;
    321331            String[] hostNames;
    322332            try {
    323                 gsComm = new GreenstoneCommunicator();
     333                GreenstoneCommunicator gsComm = new GreenstoneCommunicator();
    324334                hostNames = gsComm.getHostNames();
    325335            } catch (Exception e) {
     
    327337            }
    328338            context.put("hostnames", hostNames);
     339            session.setAttribute("hostnames", hostNames);
    329340        } else if (nextPage.equals("collection")) {
    330341            // TODO might be query instead of just name
    331342            List hostNames = (List) arguments.get("hostID");
    332             GreenstoneCommunicator gsComm = null;
     343            if (hostNames == null || hostNames.isEmpty()) {
     344                hostNames = new Vector();
     345                // no host names -> use host query
     346                String[] hostsFromSession = (String[]) session.getAttribute("hostnames");
     347                if (hostsFromSession == null || hostsFromSession.length == 0) {
     348                    try {
     349                        GreenstoneCommunicator gsComm = new GreenstoneCommunicator();
     350                        hostsFromSession = gsComm.getHostNames();
     351                    } catch (Exception e) {
     352                        hostsFromSession = new String[] { "localhost" };
     353                    }
     354                }
     355                String hostQuery = (String) arguments.get("host_query");
     356                for (int i = 0; i < hostsFromSession.length; i++) {
     357                    if (hostsFromSession[i] != null && hostsFromSession[i].indexOf(hostQuery) >= 0) {
     358                        hostNames.add(hostsFromSession[i]);
     359                    }
     360                }
     361            }
     362           
    333363            Map collNames = new TreeMap();
    334364            for (Iterator iter = hostNames.iterator(); iter.hasNext();) {
     
    336366                Set collNamesForHost = new TreeSet();   
    337367                try {
    338                     gsComm = new GreenstoneCommunicator(new URL("http://" + host + ":8080/soap/servlet/rpcrouter"));
     368                    URL url = new URL("http://" + host + ":8080/soap/servlet/rpcrouter");
     369                    GreenstoneCommunicator gsComm = new GreenstoneCommunicator(url);
    339370                    collNamesForHost.addAll(Arrays.asList(gsComm.getCollectionNames()));
    340371                } catch (Exception e) {
  • trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/GreenstoneCommunicator.java

    r8798 r8847  
    5353
    5454    public String[] getHostNames() {
     55        // TODO method implementation
    5556        return new String[] {"localhost"};
    5657    }
  • trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/profiles/PredicateFactory.java

    r8798 r8847  
    3131    // substring for collection_name -> SubstringMatchPredicates referring to it
    3232    private static Map collectionNameMatchPredicates = new TreeMap();
     33    private static Map hostNameMatchPredicates = new TreeMap();
    3334   
    3435    // query -> QueryPredicates referring to it
     
    6263        } else if (key.startsWith("document")) {
    6364            result = createQueryPredicate(key, value);
    64         } else if (key.endsWith("_name")) {
     65        } else if (key.endsWith("_query")) {
    6566            result = createSubstringMatchPredicate(key, value);
    6667        } else {
     
    9192    private static SubstringMatchPredicate createSubstringMatchPredicate(String key, String value) {
    9293        SubstringMatchPredicate predicate = null;
    93         if (key.equals("collection_name")) {
     94        if (key.equals("collection_query")) {
    9495            if (collectionNameMatchPredicates.containsKey(value)) {
    9596                predicate = (SubstringMatchPredicate) collectionNameMatchPredicates.get(value);
    9697            } else {
    97                 predicate = new SubstringMatchPredicate(key, value);
     98                predicate = new SubstringMatchPredicate("collectionID", value);
    9899                collectionNameMatchPredicates.put(value, predicate);
    99100            }
    100         } // TODO other fields than collection_name
     101        } else if (key.equals("host_query")) {
     102            if (hostNameMatchPredicates.containsKey(value)) {
     103                predicate = (SubstringMatchPredicate) hostNameMatchPredicates.get(value);
     104            } else {
     105                predicate = new SubstringMatchPredicate("hostID", value);
     106                hostNameMatchPredicates.put(value, predicate);
     107            }
     108        }
     109        // TODO other fields?
    101110        return predicate;
    102111    }
     
    119128        for (Iterator iter = values.iterator(); iter.hasNext();) {
    120129            String value = (String) iter.next();
     130            if (value == null || value.length() == 0) {
     131                continue;
     132            }
    121133
    122134            if (key.equals("hostID") && !(value.startsWith("http://"))) {
     
    143155    private static QueryPredicate createQueryPredicate(String field,
    144156            String query) {
    145         QueryPredicate predicate = new QueryPredicate(field, query);
     157        QueryPredicate predicate = null;
    146158        if (field.equals("document_content")) {
    147             documentContentQueryPredicates.put(query, predicate);
     159            if (!documentContentQueryPredicates.containsKey(query)) {
     160                predicate = new QueryPredicate(field, query);
     161                documentContentQueryPredicates.put(query, predicate);
     162            }
     163            return (QueryPredicate) documentContentQueryPredicates.get(query);
    148164        } else if (field.equals("document_title")) {
    149             documentTitleQueryPredicates.put(query, predicate);
     165            if (!documentTitleQueryPredicates.containsKey(query)) {
     166                predicate = new QueryPredicate(field, query);
     167                documentTitleQueryPredicates.put(query, predicate);
     168            }
     169            return (QueryPredicate) documentTitleQueryPredicates.get(query);
    150170        }
    151171        return predicate;
     
    170190   
    171191    public static Collection getAllSubstringMatchPredicates() {
    172         return Collections.unmodifiableCollection(collectionNameMatchPredicates.values());
     192        Collection result = new Vector();
     193        result.addAll(hostNameMatchPredicates.values());
     194        result.addAll(collectionNameMatchPredicates.values());
     195        return Collections.unmodifiableCollection(result);
    173196    }
    174197
Note: See TracChangeset for help on using the changeset viewer.