001/*
002 *  Copyright 2021 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.search.solr;
017
018import java.nio.file.Files;
019import java.nio.file.Path;
020import java.util.HashMap;
021import java.util.Map;
022
023import org.apache.avalon.framework.parameters.Parameters;
024import org.apache.cocoon.acting.ServiceableAction;
025import org.apache.cocoon.environment.Redirector;
026import org.apache.cocoon.environment.SourceResolver;
027
028import org.ametys.cms.scripts.ReportLocationAction;
029
030/**
031 * Get the path where the async solr exports are stored.
032 */
033public class AsyncExportLocationAction extends ServiceableAction
034{
035    
036    @Override
037    public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception
038    {
039        Path exportPath = ReportLocationAction.getScriptReportDirectory();
040        if (Files.isDirectory(exportPath))
041        {
042            HashMap<String, Object> result = new HashMap<>();
043            result.put("location", exportPath.toUri().toString());
044            return result;
045        }
046        return EMPTY_MAP;
047    }
048
049}
050