Project

General

Profile

« Previous | Next » 

Revision 7730

Added by Jing Tao over 11 years ago

Use the SolrQueryServiceController to get the spec version and index schema information.

View differences:

src/edu/ucsb/nceas/metacat/index/MetacatSolrEngineDescriptionHandler.java
34 34
import java.util.Properties;
35 35
import java.util.Set;
36 36

  
37
import javax.xml.parsers.ParserConfigurationException;
37 38

  
38 39

  
40

  
39 41
import org.apache.commons.io.FileUtils;
40 42
import org.apache.commons.logging.Log;
41 43
import org.apache.commons.logging.LogFactory;
......
44 46
import org.apache.solr.core.SolrCore;
45 47
import org.apache.solr.schema.IndexSchema;
46 48
import org.apache.solr.schema.SchemaField;
49
import org.dataone.service.exceptions.NotFound;
50
import org.dataone.service.exceptions.UnsupportedType;
47 51
import org.dataone.service.types.v1_1.QueryEngineDescription;
48 52
import org.dataone.service.types.v1_1.QueryField;
53
import org.xml.sax.SAXException;
49 54

  
50 55
import edu.ucsb.nceas.metacat.common.SolrServerFactory;
56
import edu.ucsb.nceas.metacat.common.query.SolrQueryServiceController;
51 57
import edu.ucsb.nceas.metacat.properties.PropertyService;
52 58
import edu.ucsb.nceas.utilities.FileUtil;
53 59

  
......
89 95
     * Constructor
90 96
     */
91 97
    private MetacatSolrEngineDescriptionHandler() throws Exception {
92
       CoreContainer container = SolrServerFactory.getCoreContainer();
98
       /*CoreContainer container = SolrServerFactory.getCoreContainer();
93 99
       if(container == null) {
94 100
           throw new Exception("MetacatSolrEngineDescriptionHandler - The Solr Server is not configured as an EmbeddedSolrServer and the EmbeddedSolrServer is the only SolrServer that the Metacat can provide the Query Engine Description.");
95 101
       }
......
100 106
       SolrCore core = container.getCore(coreName);
101 107
       if(core == null) {
102 108
           throw new Exception("MetacatSolrEngineDescriptionHandler - Metacat can't find the SolrCore for the given name - "+SolrServerFactory.getCollectionName());
103
       }
104
       init(core);
109
       }*/
110
       init();
105 111
    }
106 112
    
107 113
   
108 114
    
109
    private void init(SolrCore core) throws IOException {
115
    private void init() throws IOException, UnsupportedType, NotFound, ParserConfigurationException, SAXException {
110 116
        Map<String, String>fieldDescriptions = loadSchemaFieldDescriptions();
111 117
        qed = new QueryEngineDescription();
112 118
        qed.setName(MetacatSolrIndex.SOLRQUERY);
113 119
        //setSchemaVersionFromPropertiesFile(qed);
114 120
        setSolrVersion();
115 121

  
116
        IndexSchema schema = core.getSchema();
117
        Map<String, SchemaField> fieldMap = schema.getFields();
122
        //IndexSchema schema = core.getSchema();
123
        Map<String, SchemaField> fieldMap = SolrQueryServiceController.getInstance().getIndexSchemaFields();
118 124
        for (SchemaField schemaField : fieldMap.values()) {
119 125
            qed.addQueryField(createQueryFieldFromSchemaField(schemaField, fieldDescriptions));
120 126
        }
......
123 129
    
124 130
    /**
125 131
     * Based on org.apache.solr.handler.admin.SystemInfoHandler.getLuceneInfo()
132
     * @throws SAXException 
133
     * @throws IOException 
134
     * @throws ParserConfigurationException 
135
     * @throws NotFound 
136
     * @throws UnsupportedType 
126 137
     */
127
    private void setSolrVersion() {
128
        String solrSpecVersion = "";
129
        Package p = SolrCore.class.getPackage();
130
        StringWriter tmp = new StringWriter();
131
        solrSpecVersion = p.getSpecificationVersion();
132
        if (null != solrSpecVersion) {
133
            try {
134
                XML.escapeCharData(solrSpecVersion, tmp);
135
            } catch (IOException e) {
136
                e.printStackTrace();
137
            }
138
            solrSpecVersion = tmp.toString();
139
        }
140
        if (solrSpecVersion != null && !solrSpecVersion.trim().equals("")) {
141
            qed.setQueryEngineVersion(solrSpecVersion);
142
        } else {
143
            qed.setQueryEngineVersion(UNKNOWN);
144
        }
145
        
138
    private void setSolrVersion() throws UnsupportedType, NotFound, ParserConfigurationException, IOException, SAXException {
139
        qed.setQueryEngineVersion(SolrQueryServiceController.getInstance().getSolrSpecVersion());
146 140
    }
147 141
    
148 142

  

Also available in: Unified diff