greenstone.org greenstone wiki greenstone trac planet greenstone

Changeset 15485

Show
Ignore:
Timestamp:
2008-05-15 13:32:29 (6 months ago)
Author:
ak19
Message:

Added in basicQuery method and merged query with protected queryProcess method

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • other-projects/trunk/gs3-webservices-democlient/src/GS3DemoClient/org/greenstone/gs3services/QBRSOAPServer.java

    r15222 r15485  
    3535import org.w3c.dom.Document; 
    3636import org.w3c.dom.Element; 
     37import org.w3c.dom.NodeList; 
    3738 
    3839import org.greenstone.gsdl3.core.MessageRouter; 
     
    288289                return this.processInternal(message); 
    289290        } 
    290  
     291         
    291292        /* (2) Process-type message, QUERY-TYPE SERVICES - p.45 */ 
    292293        /** For executing a (process-type message) query-type service. 
     
    320321                                        this.doc, name, value)); 
    321322                } 
    322                 return queryProcess(collection+"/"+service, lang, paramList); 
    323         } 
    324          
    325         /** Values for field Names given in the paramList must exist for the  
    326          * (Collection-)Service Query that this message is sent To (as given in the  
    327          * 'to' argument).  
    328          * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 45</a> 
    329          * @param to - the (Collection-)Service Query that this message is sent To  
    330          * @param lang - the language of the display items in the response  
    331          * @param paramList - XML Dom Element representing the list of field names,  
    332          * and associated values required for executing the query.  
    333          * For names of Greenstone-accepted arguments, 
    334          * @see <a href="http://wiki.greenstone.org/wiki/index.php/Actions_and_Arguments">Greenstone wiki - Actions and Arguments<a> 
    335         */ 
    336         protected String queryProcess(String to, String lang, Element paramList) { 
    337                 // must work with whatever Document was used to create the 
    338                 // <paramList>: other elements must be created using this  
    339                 // document object too 
    340                 Document ownerDoc = paramList.getOwnerDocument(); 
    341                 Element message = ownerDoc.createElement(GSXML.MESSAGE_ELEM); 
     323                 
     324                Element message = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    342325                Element request = GSXML.createBasicRequest( 
    343                                 ownerDoc, GSXML.REQUEST_TYPE_PROCESS, to, lang, ""); 
     326                                this.doc, GSXML.REQUEST_TYPE_PROCESS,  
     327                                collection+"/"+service, lang, ""); 
    344328                 
    345329                request.appendChild(paramList); 
     
    348332                // Send it off to the Message Router and return the response 
    349333                return this.processInternal(message); 
     334        } 
     335         
     336        /**  
     337         * This method is used to perform the most basic query of them: 
     338         * it assumes defaults for all other parameters and provides only 
     339         * the query string. It is built on top of a TextQuery. 
     340         * @param collection is the Greenstone collection to be searched 
     341         * @param lang is the preferred language of the display content in  
     342         * the response to be returned. 
     343         * @param query is the string to be sought in the Greenstone collection 
     344         * @return a Greenstone 3 XML response message for the query specifying  
     345         * the search results. 
     346         */ 
     347        public String basicQuery(String collection, String lang, String query) { 
     348                // The basicQuery is built on top of the TextQuery service 
     349                final String queryService = "TextQuery"; 
     350                 
     351                // (1) describe request on the TextQuery 
     352                String queryDescription = describeCollectionService( 
     353                                collection, queryService, "en", "paramList"); // just get paramList 
     354                //System.out.println(queryDescription); 
     355                 
     356                Document doc = this.converter.getDOM(queryDescription); 
     357                NodeList nl = doc.getElementsByTagName( 
     358                                GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 
     359                 
     360                Element paramList = null; 
     361                if(nl.getLength() <= 0) { // no paramList in textQuery description means 
     362                                // no query field either: that means we can't continue 
     363                        return this.error("BasicQuery is not available for this collection"  
     364                                + " as it provides no TextQuery service."); 
     365                } //else 
     366                 
     367                paramList = (Element)nl.item(0); 
     368                nl = paramList.getElementsByTagName(GSXML.PARAM_ELEM); 
     369                if(nl.getLength() <= 0) { // no params, means no query field, so return 
     370                        return this.error("BasicQuery is not available for this collection."); 
     371                } 
     372                 
     373                // (2) get the defaults for each parameter and use that to set 
     374                // the defaults 
     375                Map params = new HashMap(nl.getLength()); // field name to value map 
     376                for(int i = 0; i < nl.getLength(); i++) { 
     377                        Element param = (Element)nl.item(i); 
     378                        String paramName = param.getAttribute(GSXML.NAME_ATT); 
     379                        String def = param.getAttribute(GSXML.DEFAULT_ATT); 
     380                        if(def.equals("")) {  
     381                                // if there's no default, the field must want the query String 
     382                                params.put(paramName, query); 
     383                        } else { // there is a default, use the default for this param 
     384                                params.put(paramName, def); 
     385                        } 
     386                } 
     387                 
     388                // (3) Perform the query using defaults and return the response 
     389                return this.query(collection, queryService, lang, params); 
    350390        } 
    351391                 
     
    782822                System.out.println(ws.describeService("AddItem", "", "")); 
    783823                                 
    784                 // (2) try 3 query methods (simplerFieldQuery twice) + getFieldNameMappings() 
     824                // (2) try 2 query methods: query and basicQuery 
    785825                HashMap map = new HashMap(); 
    786826                map.put("maxDocs", "100"); 
     
    796836                System.out.println("Regular query: " + response); 
    797837                 
     838                // basicQuery 
     839                response = ws.basicQuery("gs2mgppdemo", "", "cat"); 
     840                System.out.println("Basic query on 'cat' over collection gs2mgppdemo:" 
     841                                + response); 
     842 
    798843                // (3) try 2 browse 
    799844                System.out.println("describe browse:\n"  
     
    854899                System.out.println(ws.helpWithMethod("helpWithMethod")); 
    855900 
     901                 
    856902                System.out.println("Finished executing"); 
    857903