Github user srdo commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2108#discussion_r132811049
  
    --- Diff: 
external/storm-solr/src/main/java/org/apache/storm/solr/schema/builder/SolrClientSchemaBuilder.java
 ---
    @@ -0,0 +1,95 @@
    +/*
    + * SolrClientSchemaBuilder.java
    + * Copyright 2017 Qunhe Tech, all rights reserved.
    + * Qunhe PROPRIETARY/CONFIDENTIAL, any form of usage is subject to 
approval.
    + */
    +
    +package org.apache.storm.solr.schema.builder;
    +
    +import org.apache.solr.client.solrj.SolrServerException;
    +import org.apache.solr.client.solrj.request.schema.FieldTypeDefinition;
    +import org.apache.solr.client.solrj.request.schema.SchemaRequest;
    +import org.apache.solr.client.solrj.response.schema.SchemaRepresentation;
    +import org.apache.solr.client.solrj.response.schema.SchemaResponse;
    +import org.apache.storm.solr.client.SolrClientFactory;
    +import org.apache.storm.solr.schema.CopyField;
    +import org.apache.storm.solr.schema.FieldType;
    +import org.apache.storm.solr.schema.Schema;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.Map;
    +
    +/**
    + * <p>this Class build the {@link Schema} by Solr Schema API.</p>
    + *
    + * @see <a 
href="https://cwiki.apache.org/confluence/display/solr/Schema+API";>Solr Schema 
API</a>
    + * @author alei
    + */
    +public class SolrClientSchemaBuilder implements SchemaBuilder {
    +
    +    private static final Logger LOG = 
LoggerFactory.getLogger(SolrClientSchemaBuilder.class);
    +
    +    private Schema schema;
    +
    +    public SolrClientSchemaBuilder(String collection, SolrClientFactory 
factory) throws IOException, SolrServerException {
    +        SchemaRequest request = new SchemaRequest();
    +        SchemaResponse response = request.process(factory.getSolrClient(), 
collection);
    +        SchemaRepresentation representation = 
response.getSchemaRepresentation();
    +        schema = convert(representation);
    +    }
    +
    +    @Override
    +    public Schema getSchema() {
    +        return schema;
    +    }
    +
    +    private Schema convert(final SchemaRepresentation representation) {
    +        Schema converted = new Schema();
    +        converted.setUniqueKey(representation.getUniqueKey());
    +        converted.setName(representation.getName());
    +        converted.setVersion(String.valueOf(representation.getVersion()));
    +        List<FieldType> fieldTypeList = new 
ArrayList<>(representation.getFieldTypes().size());
    +        for (FieldTypeDefinition type : representation.getFieldTypes()) {
    +            FieldType fieldType = new FieldType();
    +            
fieldType.setClazz(type.getAttributes().get("class").toString());
    +            if (type.getAttributes().get("multiValued") != null) {
    +                
fieldType.setMultiValued(Boolean.valueOf(type.getAttributes().get("multiValued").toString()));
    --- End diff --
    
    Is this attribute already a boolean? If so I don't think there's a reason 
to toString and then Boolean.valueOf it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to