// Path: aemsolrsearch-services/src/main/java/com/headwire/aemsolrsearch/exception/AEMSolrSearchException.java
// public class AEMSolrSearchException extends Throwable {
//     public AEMSolrSearchException(String message) {
//         super(message);
//     }
// }


import com.headwire.aemsolrsearch.exception.AEMSolrSearchException;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.*;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.LBHttpSolrClient;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.request.LukeRequest;
import org.apache.solr.client.solrj.request.schema.SchemaRequest;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.client.solrj.response.CoreAdminResponse;
import org.apache.solr.client.solrj.response.LukeResponse;
import org.apache.solr.client.solrj.response.schema.SchemaResponse;
import org.apache.solr.common.luke.FieldFlag;
import org.apache.solr.common.params.CoreAdminParams;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

        CloudSolrClient client =  new CloudSolrClient(solrZKHost);
        client.setParser(new XMLResponseParser());

        return client;
    }

    private SolrClient getStandaloneQuerySolrClient() {

        LBHttpSolrClient lbHttpSolrClient = null;

        try {
            if (StringUtils.isEmpty(solrSlaves) && StringUtils.isNotEmpty(solrMaster)) {

                LOG.debug("Creating LBHttpSolrClient using solrMaster {}", solrMaster);
                lbHttpSolrClient = new LBHttpSolrClient(solrMaster);

            } else if (StringUtils.isNotEmpty(solrSlaves)) {

                LOG.debug("Creating LBHttpSolrClient using solrSlaves {}", solrSlaves);
                lbHttpSolrClient = new LBHttpSolrClient(solrSlaves);

                if (solrAllowMasterQueriesEnabled && StringUtils.isNotEmpty(solrMaster)) {

                    LOG.debug("Adding solrMaster {} to the LBHttpSolrClient", solrSlaves);
                    lbHttpSolrClient.addSolrServer(solrMaster);
                }

            } else if (StringUtils.isEmpty(solrSlaves) && StringUtils.isEmpty(solrMaster)) {
                // unexpected
// Path: aemsolrsearch-services/src/main/java/com/headwire/aemsolrsearch/exception/AEMSolrSearchException.java
// public class AEMSolrSearchException extends Throwable {
//     public AEMSolrSearchException(String message) {
//         super(message);
//     }
// }


// Path: aemsolrsearch-services/src/main/java/com/headwire/aemsolrsearch/services/SolrConfigurationService.java
import com.headwire.aemsolrsearch.exception.AEMSolrSearchException;
import org.apache.commons.lang.StringUtils;
import org.apache.felix.scr.annotations.*;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.LBHttpSolrClient;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.apache.solr.client.solrj.request.LukeRequest;
import org.apache.solr.client.solrj.request.schema.SchemaRequest;
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.client.solrj.response.CoreAdminResponse;
import org.apache.solr.client.solrj.response.LukeResponse;
import org.apache.solr.client.solrj.response.schema.SchemaResponse;
import org.apache.solr.common.luke.FieldFlag;
import org.apache.solr.common.params.CoreAdminParams;
import org.osgi.framework.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;


        CloudSolrClient client =  new CloudSolrClient(solrZKHost);
        client.setParser(new XMLResponseParser());

        return client;
    }

    private SolrClient getStandaloneQuerySolrClient() {

        LBHttpSolrClient lbHttpSolrClient = null;

        try {
            if (StringUtils.isEmpty(solrSlaves) && StringUtils.isNotEmpty(solrMaster)) {

                LOG.debug("Creating LBHttpSolrClient using solrMaster {}", solrMaster);
                lbHttpSolrClient = new LBHttpSolrClient(solrMaster);

            } else if (StringUtils.isNotEmpty(solrSlaves)) {

                LOG.debug("Creating LBHttpSolrClient using solrSlaves {}", solrSlaves);
                lbHttpSolrClient = new LBHttpSolrClient(solrSlaves);

                if (solrAllowMasterQueriesEnabled && StringUtils.isNotEmpty(solrMaster)) {

                    LOG.debug("Adding solrMaster {} to the LBHttpSolrClient", solrSlaves);
                    lbHttpSolrClient.addSolrServer(solrMaster);
                }

            } else if (StringUtils.isEmpty(solrSlaves) && StringUtils.isEmpty(solrMaster)) {
                // unexpected
                throw new AEMSolrSearchException("Initialization failed. "