Project

General

Profile

« Previous | Next » 

Revision 7733

Added by Jing Tao over 11 years ago

Use SolrQueryServiceController to get the ValidFieldList.

View differences:

metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/resourcemap/ResourceMapSubprocessor.java
32 32
import java.io.InputStream;
33 33
import java.io.StringWriter;
34 34
import java.io.Writer;
35
import java.net.MalformedURLException;
35 36
import java.util.ArrayList;
36 37
import java.util.Collections;
37 38
import java.util.Date;
......
70 71
import org.dataone.cn.indexer.resourcemap.ResourceMap;
71 72
import org.dataone.cn.indexer.solrhttp.SolrDoc;
72 73
import org.dataone.cn.indexer.solrhttp.SolrElementField;
74
import org.dataone.service.exceptions.NotFound;
75
import org.dataone.service.exceptions.NotImplemented;
76
import org.dataone.service.exceptions.UnsupportedType;
77
import org.dataone.service.types.v1.Subject;
73 78
import org.w3c.dom.Document;
74 79
import org.w3c.dom.Element;
75 80
import org.w3c.dom.NodeList;
......
77 82

  
78 83
import edu.ucsb.nceas.metacat.common.query.SolrQueryResponseTransformer;
79 84
import edu.ucsb.nceas.metacat.common.query.SolrQueryResponseWriterFactory;
85
import edu.ucsb.nceas.metacat.common.query.SolrQueryServiceController;
80 86
import edu.ucsb.nceas.metacat.common.SolrServerFactory;
81 87
import edu.ucsb.nceas.metacat.index.SolrIndex;
82 88

  
......
107 113
    @Override
108 114
    public Map<String, SolrDoc> processDocument(String identifier, Map<String, SolrDoc> docs,
109 115
    Document doc) throws IOException, EncoderException, SAXException,
110
    XPathExpressionException, ParserConfigurationException, SolrServerException {
116
    XPathExpressionException, ParserConfigurationException, SolrServerException, NotImplemented, NotFound, UnsupportedType {
111 117
        SolrDoc resourceMapDoc = docs.get(identifier);
112 118
        List<SolrDoc> processedDocs = processResourceMap(resourceMapDoc, doc);
113 119
        Map<String, SolrDoc> processedDocsMap = new HashMap<String, SolrDoc>();
......
118 124
    }
119 125

  
120 126
    private List<SolrDoc> processResourceMap(SolrDoc indexDocument, Document resourceMapDocument)
121
                    throws XPathExpressionException, IOException, SAXException, ParserConfigurationException, EncoderException, SolrServerException{
127
                    throws XPathExpressionException, IOException, SAXException, ParserConfigurationException, EncoderException, SolrServerException, NotImplemented, NotFound, UnsupportedType{
122 128
        ResourceMap resourceMap = new ResourceMap(resourceMapDocument);
123 129
        List<String> documentIds = resourceMap.getAllDocumentIDs();
124 130
        //List<SolrDoc> updateDocuments = getHttpService().getDocuments(getSolrQueryUri(), documentIds);
......
140 146
    /*
141 147
     * Get the SolrDoc list for the list of the ids.
142 148
     */
143
    public static List<SolrDoc> getSolrDocs(List<String> ids) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException {
149
    public static List<SolrDoc> getSolrDocs(List<String> ids) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException, NotImplemented, NotFound, UnsupportedType {
144 150
        List<SolrDoc> list = new ArrayList<SolrDoc>();
145 151
        if(ids != null) {
146 152
            for(String id : ids) {
......
156 162
    /*
157 163
     * Get the SolrDoc for the specified id 
158 164
     */
159
    private static SolrDoc getSolrDoc(String id) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException {
165
    private static SolrDoc getSolrDoc(String id) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException, NotImplemented, NotFound, UnsupportedType {
160 166
        SolrDoc solrDoc = null;
161 167
        if(solrServer != null) {
162 168
           String query = QUERY+"\""+id+"\"";
163 169
           SolrParams solrParams = SolrRequestParsers.parseQueryString(query);
164
           QueryResponse response = solrServer.query(solrParams);
170
           Set<Subject>subjects = null;//when subjects are null, there will not be any access rules.
171
           InputStream response = SolrQueryServiceController.getInstance().query(solrParams, subjects);
165 172
           solrDoc = transformQueryResponseToSolrDoc(solrParams, response);
166 173
           
167 174
           /*if(solrDoc != null) {
......
183 190
     * @param reponse
184 191
     * @return
185 192
     */
186
    private static SolrDoc transformQueryResponseToSolrDoc(SolrParams solrParams, QueryResponse response) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException {
193
    private static SolrDoc transformQueryResponseToSolrDoc(SolrParams solrParams, InputStream response) throws SolrServerException, IOException, ParserConfigurationException, SAXException, XPathExpressionException, UnsupportedType, NotFound {
187 194
        SolrDoc solrDoc = null;
188 195
        if(response != null) {
189
            SolrQueryResponseTransformer transformer = new SolrQueryResponseTransformer(solrCore);
190
            InputStream input = transformer.transformResults(solrParams, response, SolrQueryResponseWriterFactory.XML);
191 196
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
192 197
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
193
            Document doc = dBuilder.parse(input);
198
            Document doc = dBuilder.parse(response);
194 199
            solrDoc = parseResults(doc);
195 200
        }
196 201
        return solrDoc;
......
201 206
    /*
202 207
     * Parse the query result document. This method only choose the first one from a list.
203 208
     */
204
    private static SolrDoc parseResults(Document document) throws XPathExpressionException {
209
    private static SolrDoc parseResults(Document document) throws XPathExpressionException, MalformedURLException, UnsupportedType, NotFound, ParserConfigurationException, IOException, SAXException {
205 210
        SolrDoc solrDoc = null;
206 211
        NodeList nodeList = (NodeList) XPathFactory.newInstance().newXPath()
207 212
                .evaluate("/response/result/doc", document, XPathConstants.NODESET);
......
216 221
    /*
217 222
     * Parse an element
218 223
     */
219
    private static SolrDoc parseDoc(Element docElement) {
220
        List<String> validSolrFieldNames = getValidSchemaField();
224
    private static SolrDoc parseDoc(Element docElement) throws MalformedURLException, UnsupportedType, NotFound, ParserConfigurationException, IOException, SAXException {
225
        List<String> validSolrFieldNames = SolrQueryServiceController.getInstance().getValidSchemaFields();
221 226
        SolrDoc doc = new SolrDoc();
222 227
        doc.LoadFromElement(docElement, validSolrFieldNames);
223 228
        return doc;
......
228 233
     * Get the valid schema fields from the solr server.
229 234
     * @return
230 235
     */
231
    private static List<String> getValidSchemaField() {
236
    /*private static List<String> getValidSchemaField() {
232 237
        List<String> validSolrFieldNames = new ArrayList<String>();
233 238
        IndexSchema schema = solrCore.getSchema();
234 239
        Map<String, SchemaField> fieldMap = schema.getFields();
......
242 247
        }
243 248
        //System.out.println("the valid file name is\n"+validSolrFieldNames);
244 249
        return validSolrFieldNames;
245
    }
250
    }*/
246 251

  
247 252
}
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SolrIndex.java
61 61
import org.dataone.cn.indexer.parser.SolrField;
62 62
import org.dataone.cn.indexer.solrhttp.SolrDoc;
63 63
import org.dataone.cn.indexer.solrhttp.SolrElementField;
64
import org.dataone.service.exceptions.NotFound;
65
import org.dataone.service.exceptions.NotImplemented;
66
import org.dataone.service.exceptions.UnsupportedType;
64 67
import org.dataone.service.types.v1.Identifier;
65 68
import org.dataone.service.types.v1.SystemMetadata;
66 69
import org.dataone.service.util.TypeMarshaller;
......
161 164
     * @throws JiBXException 
162 165
     * @throws SolrServerException 
163 166
     * @throws EncoderException
167
     * @throws UnsupportedType 
168
     * @throws NotFound 
169
     * @throws NotImplemented 
164 170
     */
165 171
    private Map<String, SolrDoc> process(String id, SystemMetadata systemMetadata, InputStream dataStream)
166 172
                    throws IOException, SAXException, ParserConfigurationException,
167
                    XPathExpressionException, JiBXException, EncoderException, SolrServerException{
173
                    XPathExpressionException, JiBXException, EncoderException, SolrServerException, NotImplemented, NotFound, UnsupportedType{
168 174

  
169 175
        // Load the System Metadata document
170 176
        ByteArrayOutputStream systemMetadataOutputStream = new ByteArrayOutputStream();
......
239 245
     * @throws SAXException 
240 246
     * @throws ParserConfigurationException 
241 247
     * @throws SolrServerException 
248
     * @throws UnsupportedType 
249
     * @throws NotFound 
250
     * @throws NotImplemented 
242 251
     */
243 252
    // TODO:combine merge function with resourcemap merge function
244 253

  
245 254
    private SolrDoc mergeWithIndexedDocument(SolrDoc indexDocument) throws IOException,
246
            EncoderException, XPathExpressionException, SolrServerException, ParserConfigurationException, SAXException {
255
            EncoderException, XPathExpressionException, SolrServerException, ParserConfigurationException, SAXException, NotImplemented, NotFound, UnsupportedType {
247 256
        List<String> ids = new ArrayList<String>();
248 257
        ids.add(indexDocument.getIdentifier());
249 258
        List<SolrDoc> indexedDocuments = ResourceMapSubprocessor.getSolrDocs(ids);
......
330 339
     * @throws SolrServerException 
331 340
     * @throws JiBXException 
332 341
     * @throws EncoderException 
342
     * @throws UnsupportedType 
343
     * @throws NotFound 
344
     * @throws NotImplemented 
333 345
     */
334 346
    private synchronized void insert(String pid, SystemMetadata systemMetadata, InputStream data) 
335 347
                    throws IOException, SAXException, ParserConfigurationException,
336
                    XPathExpressionException, SolrServerException, JiBXException, EncoderException {
348
                    XPathExpressionException, SolrServerException, JiBXException, EncoderException, NotImplemented, NotFound, UnsupportedType {
337 349
        checkParams(pid, systemMetadata, data);
338 350
        Map<String, SolrDoc> docs = process(pid, systemMetadata, data);
339 351
        
......
385 397
     * @throws SolrServerException 
386 398
     * @throws JiBXException 
387 399
     * @throws EncoderException 
400
     * @throws UnsupportedType 
401
     * @throws NotFound 
402
     * @throws NotImplemented 
388 403
     */
389 404
    public void update(String pid, List<String> obsoleteIds, SystemMetadata systemMetadata, InputStream data) 
390 405
                    throws IOException, SAXException, ParserConfigurationException,
391
                    XPathExpressionException, SolrServerException, JiBXException, EncoderException {
406
                    XPathExpressionException, SolrServerException, JiBXException, EncoderException, NotImplemented, NotFound, UnsupportedType {
392 407
        checkParams(pid, systemMetadata, data);
393 408
        boolean isArchive = systemMetadata.getArchived();
394 409
        if(isArchive) {

Also available in: Unified diff