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.plugins.extraction.execution;
017
018import java.util.Collections;
019import java.util.HashMap;
020import java.util.Map;
021
022import org.ametys.core.schedule.Runnable;
023import org.ametys.core.user.UserIdentity;
024import org.ametys.core.user.population.UserPopulationDAO;
025import org.ametys.plugins.extraction.ExtractionConstants;
026import org.ametys.runtime.i18n.I18nizableText;
027
028/**
029 * A {@link Runnable} which schedules a {@link ExecuteExtractionSchedulable} task for the given definition file.
030 */
031public class ExecuteExtractionRunnable implements Runnable
032{
033    private String _definitionFilePath;
034    private String _variables;
035    private String _recipient;
036    private String _pipeline;
037    
038    /**
039     * Constructor
040     * @param definitionFilePath The extraction definition file path
041     * @param variables clauses variables and optional columns
042     * @param recipient An email will be sent at this address when the extraction is complete
043     * @param pipeline The pipeline id
044     */
045    public ExecuteExtractionRunnable(String definitionFilePath, String variables, String recipient, String pipeline)
046    {
047        _definitionFilePath = definitionFilePath;
048        _variables = variables;
049        _recipient = recipient;
050        _pipeline = pipeline;
051    }
052
053    public String getId()
054    {
055        return getClass().getName() + "." + _definitionFilePath;
056    }
057
058    public I18nizableText getLabel()
059    {
060        return new I18nizableText(ExtractionConstants.PLUGIN_NAME, "PLUGINS_EXTRACTION_EXECUTE_EXTRACTION_SCHEDULABLE_LABEL", Collections.singletonList(_definitionFilePath));
061    }
062
063    public I18nizableText getDescription()
064    {
065        return new I18nizableText(ExtractionConstants.PLUGIN_NAME, "PLUGINS_EXTRACTION_EXECUTE_EXTRACTION_SCHEDULABLE_DESCRIPTION", Collections.singletonList(_definitionFilePath));
066    }
067
068    public FireProcess getFireProcess()
069    {
070        return FireProcess.NOW;
071    }
072
073    public String getCronExpression()
074    {
075        return null;
076    }
077
078    public String getSchedulableId()
079    {
080        return "org.ametys.plugins.extraction.execution.ExecuteExtractionSchedulable";
081    }
082
083    public boolean isRemovable()
084    {
085        return false;
086    }
087
088    public boolean isModifiable()
089    {
090        return false;
091    }
092
093    public boolean isDeactivatable()
094    {
095        return false;
096    }
097
098    public MisfirePolicy getMisfirePolicy()
099    {
100        return null;
101    }
102
103    public boolean isVolatile()
104    {
105        return false;
106    }
107
108    public UserIdentity getUserIdentity()
109    {
110        return UserPopulationDAO.SYSTEM_USER_IDENTITY;
111    }
112
113    public Map<String, Object> getParameterValues()
114    {
115        Map<String, Object> values = new HashMap<>();
116        values.put(ExecuteExtractionSchedulable.DEFINITION_FILE_PATH_KEY, _definitionFilePath);
117        values.put(ExecuteExtractionSchedulable.VARIABLES_KEY, _variables);
118        values.put(ExecuteExtractionSchedulable.RECIPIENT_KEY, _recipient);
119        values.put(ExecuteExtractionSchedulable.PIPELINE_KEY, _pipeline);
120        return values;
121    }
122
123}