Search in sources :

Example 1 with JSONAPIResult

use of org.alfresco.repo.search.impl.lucene.JSONAPIResult in project alfresco-repository by Alfresco.

the class SOLRAdminClient method executeCommand.

/* (non-Javadoc)
     * @see org.alfresco.repo.search.impl.solr.SolrAdminClient#executeCommand(java.lang.String, org.alfresco.repo.search.impl.solr.SolrAdminClient.HANDLER, org.alfresco.repo.search.impl.solr.SolrAdminClient.COMMAND, java.util.Map)
     */
@Override
public JSONAPIResult executeCommand(String core, JSONAPIResultFactory.HANDLER handler, JSONAPIResultFactory.COMMAND command, Map<String, String> parameters) {
    StoreRef store = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
    SolrStoreMappingWrapper mapping = SolrClientUtil.extractMapping(store, mappingLookup, shardRegistry, useDynamicShardRegistration, beanFactory);
    HttpClient httpClient = mapping.getHttpClientAndBaseUrl().getFirst();
    StringBuilder url = new StringBuilder();
    url.append(baseUrl);
    if (!url.toString().endsWith("/")) {
        url.append("/");
    }
    url.append(core + "/" + handler.toString().toLowerCase());
    URLCodec encoder = new URLCodec();
    url.append("?command=" + command.toString().toLowerCase());
    parameters.forEach((key, value) -> {
        try {
            url.append("&" + key + "=" + encoder.encode(value));
        } catch (EncoderException e) {
            throw new RuntimeException(e);
        }
    });
    url.append("&alfresco.shards=");
    if (mapping.isSharded()) {
        url.append(mapping.getShards());
    } else {
        String solrurl = httpClient.getHostConfiguration().getHostURL() + mapping.getHttpClientAndBaseUrl().getSecond();
        url.append(solrurl);
    }
    try {
        JSONAPIResult response = new SolrCommandBackupResult(getOperation(httpClient, url.toString()));
        if (response.getStatus() != 0) {
            solrTracker.setSolrActive(false);
        }
        return response;
    } catch (IOException e) {
        throw new LuceneQueryParserException("action", e);
    }
}
Also used : URLCodec(org.apache.commons.codec.net.URLCodec) StoreRef(org.alfresco.service.cmr.repository.StoreRef) EncoderException(org.apache.commons.codec.EncoderException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) SolrCommandBackupResult(org.alfresco.repo.search.impl.lucene.SolrCommandBackupResult) ExplicitSolrStoreMappingWrapper(org.alfresco.repo.search.impl.solr.ExplicitSolrStoreMappingWrapper) SolrStoreMappingWrapper(org.alfresco.repo.search.impl.solr.SolrStoreMappingWrapper) LuceneQueryParserException(org.alfresco.repo.search.impl.lucene.LuceneQueryParserException) HttpClient(org.apache.commons.httpclient.HttpClient) IOException(java.io.IOException) JSONAPIResult(org.alfresco.repo.search.impl.lucene.JSONAPIResult)

Aggregations

IOException (java.io.IOException)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 JSONAPIResult (org.alfresco.repo.search.impl.lucene.JSONAPIResult)1 LuceneQueryParserException (org.alfresco.repo.search.impl.lucene.LuceneQueryParserException)1 SolrCommandBackupResult (org.alfresco.repo.search.impl.lucene.SolrCommandBackupResult)1 ExplicitSolrStoreMappingWrapper (org.alfresco.repo.search.impl.solr.ExplicitSolrStoreMappingWrapper)1 SolrStoreMappingWrapper (org.alfresco.repo.search.impl.solr.SolrStoreMappingWrapper)1 StoreRef (org.alfresco.service.cmr.repository.StoreRef)1 EncoderException (org.apache.commons.codec.EncoderException)1 URLCodec (org.apache.commons.codec.net.URLCodec)1 HttpClient (org.apache.commons.httpclient.HttpClient)1