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 _format; 037 private String _xsltFile; 038 039 /** 040 * Constructor 041 * @param definitionFilePath The extraction definition file path 042 * @param variables clauses variables and optional columns 043 * @param recipient An email will be sent at this address when the extraction is complete 044 * @param format The format of the exatraction result. Can be xml or pdf. 045 * @param xsltFile A stylesheet to apply on extraction result 046 */ 047 public ExecuteExtractionRunnable(String definitionFilePath, String variables, String recipient, String format, String xsltFile) 048 { 049 this._definitionFilePath = definitionFilePath; 050 this._variables = variables; 051 this._recipient = recipient; 052 this._format = format; 053 this._xsltFile = xsltFile; 054 } 055 056 public String getId() 057 { 058 return this.getClass().getName() + "." + _definitionFilePath; 059 } 060 061 public I18nizableText getLabel() 062 { 063 return new I18nizableText(ExtractionConstants.PLUGIN_NAME, "PLUGINS_EXTRACTION_EXECUTE_EXTRACTION_SCHEDULABLE_LABEL", Collections.singletonList(this._definitionFilePath)); 064 } 065 066 public I18nizableText getDescription() 067 { 068 return new I18nizableText(ExtractionConstants.PLUGIN_NAME, "PLUGINS_EXTRACTION_EXECUTE_EXTRACTION_SCHEDULABLE_DESCRIPTION", Collections.singletonList(this._definitionFilePath)); 069 } 070 071 public FireProcess getFireProcess() 072 { 073 return FireProcess.NOW; 074 } 075 076 public String getCronExpression() 077 { 078 return null; 079 } 080 081 public String getSchedulableId() 082 { 083 return "org.ametys.plugins.extraction.execution.ExecuteExtractionSchedulable"; 084 } 085 086 public boolean isRemovable() 087 { 088 return false; 089 } 090 091 public boolean isModifiable() 092 { 093 return false; 094 } 095 096 public boolean isDeactivatable() 097 { 098 return false; 099 } 100 101 public MisfirePolicy getMisfirePolicy() 102 { 103 return null; 104 } 105 106 public boolean isVolatile() 107 { 108 return false; 109 } 110 111 public UserIdentity getUserIdentity() 112 { 113 return UserPopulationDAO.SYSTEM_USER_IDENTITY; 114 } 115 116 public Map<String, Object> getParameterValues() 117 { 118 Map<String, Object> values = new HashMap<>(); 119 values.put(ExecuteExtractionSchedulable.DEFINITION_FILE_PATH_KEY, _definitionFilePath); 120 values.put(ExecuteExtractionSchedulable.VARIABLES_KEY, _variables); 121 values.put(ExecuteExtractionSchedulable.RECIPIENT_KEY, _recipient); 122 values.put(ExecuteExtractionSchedulable.FORMAT_KEY, _format); 123 values.put(ExecuteExtractionSchedulable.XSLT_FILE_PATH_KEY, _xsltFile); 124 return values; 125 } 126 127}