Example usage for org.springframework.data.solr.core.schema SolrJsonResponse getNode

List of usage examples for org.springframework.data.solr.core.schema SolrJsonResponse getNode

Introduction

In this page you can find the example usage for org.springframework.data.solr.core.schema SolrJsonResponse getNode.

Prototype

public JsonNode getNode(String name) 

Source Link

Usage

From source file:org.springframework.data.solr.core.schema.SolrSchemaWriter.java

Double retrieveSchemaVersion(String collectionName) {
    try {/*from www.ja  v a  2 s .  c om*/
        SolrJsonResponse response = SolrSchemaRequest.version().process(factory.getSolrServer(collectionName));
        JsonNode node = response.getNode("version");
        return node != null ? node.asDouble() : Double.NaN;
    } catch (SolrServerException e) {
        EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e));
    } catch (IOException e) {
        EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e));
    } catch (SolrException e) {
        EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e));
    }
    return Double.NaN;
}

From source file:org.springframework.data.solr.core.schema.SolrSchemaWriter.java

SchemaDefinition loadExistingSchema(String collectionName) {

    try {/*from   ww w. j  a  va 2s.  c  om*/
        SolrJsonResponse response = SolrSchemaRequest.schema().process(factory.getSolrServer(collectionName));
        if (response != null && response.getNode("schema") != null) {
            ObjectMapper mapper = new ObjectMapper();
            mapper.enable(MapperFeature.AUTO_DETECT_CREATORS);
            mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
            mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
            return mapper.readValue(response.getNode("schema").toString(), SchemaDefinition.class);
        }
        return null;
    } catch (SolrServerException e) {
        throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e));
    } catch (IOException e) {
        throw new InvalidDataAccessResourceUsageException("Failed to load schema definition.", e);
    } catch (SolrException e) {
        throw EXCEPTION_TRANSLATOR.translateExceptionIfPossible(new RuntimeException(e));
    }
}