Project

General

Profile

« Previous | Next » 

Revision 7707

Added by Jing Tao about 11 years ago

Move the code to generate the QueryResponseWriter to the metacat-common module. So it can be shared with the metacat-index module.

View differences:

MetacatSolrIndex.java
82 82

  
83 83
import edu.ucsb.nceas.metacat.DBTransform;
84 84
import edu.ucsb.nceas.metacat.MetaCatServlet;
85
import edu.ucsb.nceas.metacat.common.SolrQueryResponseWriterFactory;
85 86
import edu.ucsb.nceas.metacat.common.SolrServerFactory;
86 87
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
87 88

  
......
100 101
    public static final String SOLR_COLLECTION_NAME_PROPERTY_NAME = "solr.collectionName";
101 102
    public static final String SOLR_SERVER_CLASSNAME_PROPERTY_NAME = "solr.server.classname";
102 103
    private static final String WT = "wt";//the property name to specify the return type
103
    private static final String XML = "xml";
104
    private static final String JSON = "json";
105
    private static final String PYTHON = "python";
106
    private static final String RUBY = "ruby";
107
    private static final String PHP = "php";
108
    private static final String PHPS = "phps";
109
    private static final String VELOCITY = "velocity";
110
    private static final String CSV ="csv";
104
    
111 105
    private static List<String> supportedWriterTypes = null;
112 106
    private static final String VERSION = "3.4";
113 107
    private static final String SOLRCONFDIR = "/conf";
......
146 140
    private MetacatSolrIndex() throws Exception {
147 141
    	// these are handled directly by solr
148 142
    	supportedWriterTypes = new ArrayList<String>();
149
    	supportedWriterTypes.add(CSV);
150
    	supportedWriterTypes.add(JSON);
151
    	supportedWriterTypes.add(PHP);
152
    	supportedWriterTypes.add(PHPS);
153
    	supportedWriterTypes.add(RUBY);
154
    	supportedWriterTypes.add(VELOCITY);
155
    	supportedWriterTypes.add(PYTHON);
156
    	supportedWriterTypes.add(XML);
143
    	supportedWriterTypes.add(SolrQueryResponseWriterFactory.CSV);
144
    	supportedWriterTypes.add(SolrQueryResponseWriterFactory.JSON);
145
    	supportedWriterTypes.add(SolrQueryResponseWriterFactory.PHP);
146
    	supportedWriterTypes.add(SolrQueryResponseWriterFactory.PHPS);
147
    	supportedWriterTypes.add(SolrQueryResponseWriterFactory.RUBY);
148
    	supportedWriterTypes.add(SolrQueryResponseWriterFactory.VELOCITY);
149
    	supportedWriterTypes.add(SolrQueryResponseWriterFactory.PYTHON);
150
    	supportedWriterTypes.add(SolrQueryResponseWriterFactory.XML);
157 151

  
158 152
        generateSolrServer();
159 153
    }
......
230 224
        	String qformat = wt;
231 225
        	
232 226
        	// perform the solr query using wt=XML
233
        	wt = XML;
227
        	wt = SolrQueryResponseWriterFactory.XML;
234 228
        	ModifiableSolrParams msp = new ModifiableSolrParams(solrParams);
235 229
        	msp.set(WT, wt);
236 230
        	QueryResponse response = solrServer.query(msp);
......
336 330
     */
337 331
    private InputStream transformResults(SolrParams request, QueryResponse response, String wt) throws SolrServerException, IOException {
338 332
        //InputStream stream = null;
339
        QueryResponseWriter writer = generateResponseWriter(wt);
333
        QueryResponseWriter writer = SolrQueryResponseWriterFactory.generateResponseWriter(wt);
340 334
        Writer results = new StringWriter();
341 335
        SolrQueryResponse sResponse = new SolrQueryResponse();
342 336
        sResponse.setAllValues(response.getResponse());
......
345 339
        return new ByteArrayInputStream(results.toString().getBytes(MetaCatServlet.DEFAULT_ENCODING));
346 340
    }
347 341
    
348
    
349
    /* Here is the list of the handler class to handle different format.
350
     * <queryResponseWriter name="xml" default="true" class="solr.XMLResponseWriter" />
351
     * <queryResponseWriter name="json" class="solr.JSONResponseWriter"/>
352
     * <queryResponseWriter name="python" class="solr.PythonResponseWriter"/>
353
     * <queryResponseWriter name="ruby" class="solr.RubyResponseWriter"/>
354
     * <queryResponseWriter name="php" class="solr.PHPResponseWriter"/>
355
     * <queryResponseWriter name="phps" class="solr.PHPSerializedResponseWriter"/>
356
     * <queryResponseWriter name="velocity" class="solr.VelocityResponseWriter"/>
357
     * <queryResponseWriter name="csv" class="solr.CSVResponseWriter"/>
358
     */
359
    private QueryResponseWriter generateResponseWriter(String wt) throws SolrServerException {
360
        QueryResponseWriter writer = null;
361
        if(wt == null || wt.trim().equals("") || wt.equals(XML)) {
362
            writer = new XMLResponseWriter();
363
        } else if(wt.equals(JSON)) {
364
            writer = new JSONResponseWriter();
365
        } else if(wt.equals(PYTHON)) {
366
            writer = new PythonResponseWriter();
367
        } else if(wt.equals(RUBY)) {
368
            writer = new RubyResponseWriter();
369
        } else if(wt.equals(PHP)) {
370
            writer = new PHPResponseWriter();
371
        } else if(wt.equals(PHPS)) {
372
            writer = new PHPSerializedResponseWriter();
373
        } else if(wt.equals(VELOCITY)) {
374
            writer = new VelocityResponseWriter();
375
        } else if(wt.equals(CSV)) {
376
            writer = new CSVResponseWriter();
377
        } else {
378
            throw new SolrServerException("Metacat doesn't support this response format "+wt);
379
        }
380
        return writer;
381
    }
382 342
  
383 343
}

Also available in: Unified diff