001/*
002 *  Copyright 2017 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.cms.indexing.solr;
017
018import org.apache.solr.client.solrj.SolrClient;
019import org.apache.solr.client.solrj.SolrRequest;
020import org.apache.solr.client.solrj.request.CollectionRequiringSolrRequest;
021import org.apache.solr.client.solrj.response.SolrResponseBase;
022import org.apache.solr.common.params.ModifiableSolrParams;
023import org.apache.solr.common.params.SolrParams;
024
025/**
026 * {@link SolrRequest} to reload the ACL Solr cache
027 */
028public class ReloadAclCacheRequest extends CollectionRequiringSolrRequest<SolrResponseBase>
029{
030    /** If true, only the segments which are not already in cache are computed */
031    protected boolean _checkIfNecessary;
032
033    /**
034     * Default constructor
035     */
036    public ReloadAclCacheRequest()
037    {
038        this(false);
039    }
040    
041    /**
042     * Default constructor
043     * @param checkIfNecessary true to check if the reload is necessary for each segment (i.e. reload only the segments not already in cache)
044     */
045    public ReloadAclCacheRequest(boolean checkIfNecessary)
046    {
047        super(METHOD.GET, "/reloadAclCache");
048        _checkIfNecessary = checkIfNecessary;
049    }
050    
051    @Override
052    public SolrParams getParams()
053    {
054        ModifiableSolrParams params = new ModifiableSolrParams();
055        params.add("checkIfNecessary", String.valueOf(_checkIfNecessary));
056        return params;
057    }
058
059    @Override
060    protected SolrResponseBase createResponse(SolrClient client)
061    {
062        return new SolrResponseBase();
063    }
064    
065    @Override
066    public String getRequestType()
067    {
068        return SolrRequestType.ADMIN.toString();
069    }
070}