...
 
# lutece-wf-module-workflow-directoryfile
\ No newline at end of file
![](http://dev.lutece.paris.fr/jenkins/buildStatus/icon?job=directory-module-workflow-directoryfile-deploy)
# Module workflow directory file
## Introduction
Ce module propose une tâche de workflow permettant de purger (vider) les fichiers associés à un record; soit instantanément, soit au bout d'un nombre de jours configuré
## Configuration
## Usage
[Maven documentation and reports](http://dev.lutece.paris.fr/plugins/module-workflow-directoryfile/)
*generated by [xdoc2md](https://github.com/lutece-platform/tools-maven-xdoc2md-plugin) - do not edit directly.*
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>lutece-global-pom</artifactId>
<groupId>fr.paris.lutece.tools</groupId>
<version>4.0.4</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>fr.paris.lutece.plugins</groupId>
<artifactId>module-workflow-directoryfile</artifactId>
<packaging>lutece-plugin</packaging>
<version>1.0.0</version>
<name>Lutece Workflow Directory File module</name>
<repositories>
<repository>
<id>lutece</id>
<name>luteceRepository</name>
<url>http://dev.lutece.paris.fr/maven_repository</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>fr.paris.lutece</groupId>
<artifactId>lutece-core</artifactId>
<version>[6.0.1,)</version>
<type>lutece-core</type>
</dependency>
<dependency>
<groupId>fr.paris.lutece.plugins</groupId>
<artifactId>plugin-workflow</artifactId>
<version>[4.3.5,)</version>
<type>lutece-plugin</type>
</dependency>
<dependency>
<groupId>fr.paris.lutece.plugins</groupId>
<artifactId>plugin-directory</artifactId>
<version>[4.0.12-SNAPSHOT,)</version>
<type>lutece-plugin</type>
</dependency>
</dependencies>
<properties>
<componentName>workflow-directoryfile</componentName>
<jiraProjectName>WDIRFILE</jiraProjectName>
<jiraComponentId />
</properties>
<scm>
<connection>scm:git:https://github.com/lutece-platform/lutece-wf-module-workflow-directoryfile.git</connection>
<developerConnection>scm:git:https://github.com/lutece-platform/lutece-wf-module-workflow-directoryfile.git</developerConnection>
<url>scm:git:https://github.com/lutece-platform/lutece-wf-module-workflow-directoryfile.git</url>
<tag>module-workflow-directoryfile-1.0.0</tag>
</scm>
</project>
/*
* Copyright (c) 2002-2018, Mairie de Paris
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright notice
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice
* and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* License 1.0
*/
package fr.paris.lutece.plugins.workflow.modules.directoryfile.business.task.config;
import fr.paris.lutece.plugins.workflowcore.business.config.TaskConfig;
public class TaskGlobalFilePurgeConfig extends TaskConfig
{
private boolean _bInstantPurge;
private int _nDaysBeforePurge;
/**
* Get the instantPurge boolean
*
* @return true if instant purge, false otherwise
*/
public boolean isInstantPurge( )
{
return _bInstantPurge;
}
/**
* Set the instant purge boolean
*
* @param bInstantPurge
* the instant purge boolean
*/
public void setInstantPurge( boolean bInstantPurge )
{
_bInstantPurge = bInstantPurge;
}
/**
* Get the nb days before purge
*
* @return the nb of days before purge
*/
public int getDaysBeforePurge( )
{
return _nDaysBeforePurge;
}
/**
* Set the nb days before purge
*
* @param nDaysBeforePurge
* the nb days before purge
*/
public void setDaysBeforePurge( int nDaysBeforePurge )
{
_nDaysBeforePurge = nDaysBeforePurge;
}
}
/*
* Copyright (c) 2002-2018, Mairie de Paris
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright notice
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice
* and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* License 1.0
*/
package fr.paris.lutece.plugins.workflow.modules.directoryfile.business.task.config;
import fr.paris.lutece.plugins.workflow.service.WorkflowPlugin;
import fr.paris.lutece.plugins.workflowcore.business.config.ITaskConfigDAO;
import fr.paris.lutece.portal.service.plugin.PluginService;
import fr.paris.lutece.util.sql.DAOUtil;
public class TaskGlobalFilePurgeConfigDAO implements ITaskConfigDAO<TaskGlobalFilePurgeConfig>
{
private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = " SELECT id_task, is_instant_purge, nb_days_before_purge FROM workflow_file_task_global_file_purge_config "
+ " WHERE id_task = ? ";
private static final String SQL_QUERY_INSERT = " INSERT INTO workflow_file_task_global_file_purge_config ( id_task, is_instant_purge, nb_days_before_purge ) "
+ " VALUES ( ?,?,? ) ";
private static final String SQL_QUERY_UPDATE = "UPDATE workflow_file_task_global_file_purge_config SET is_instant_purge = ?, nb_days_before_purge = ? "
+ " WHERE id_task = ? ";
private static final String SQL_QUERY_DELETE = " DELETE FROM workflow_file_task_global_file_purge_config WHERE id_task = ? ";
/**
* {@inheritDoc}
*/
@Override
public void insert( TaskGlobalFilePurgeConfig config )
{
DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, PluginService.getPlugin( WorkflowPlugin.PLUGIN_NAME ) );
int nIndex = 1;
daoUtil.setInt( nIndex++, config.getIdTask( ) );
daoUtil.setBoolean( nIndex++, config.isInstantPurge( ) );
daoUtil.setInt( nIndex++, config.getDaysBeforePurge( ) );
daoUtil.executeUpdate( );
daoUtil.free( );
}
/**
* {@inheritDoc}
*/
@Override
public void store( TaskGlobalFilePurgeConfig config )
{
DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, PluginService.getPlugin( WorkflowPlugin.PLUGIN_NAME ) );
int nIndex = 1;
daoUtil.setBoolean( nIndex++, config.isInstantPurge( ) );
daoUtil.setInt( nIndex++, config.getDaysBeforePurge( ) );
daoUtil.setInt( nIndex++, config.getIdTask( ) );
daoUtil.executeUpdate( );
daoUtil.free( );
}
/**
* {@inheritDoc}
*/
@Override
public TaskGlobalFilePurgeConfig load( int nIdTask )
{
TaskGlobalFilePurgeConfig config = null;
DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, PluginService.getPlugin( WorkflowPlugin.PLUGIN_NAME ) );
daoUtil.setInt( 1, nIdTask );
daoUtil.executeQuery( );
int nIndex = 1;
if ( daoUtil.next( ) )
{
config = new TaskGlobalFilePurgeConfig( );
config.setIdTask( daoUtil.getInt( nIndex++ ) );
config.setInstantPurge( daoUtil.getBoolean( nIndex++ ) );
config.setDaysBeforePurge( daoUtil.getInt( nIndex++ ) );
}
daoUtil.free( );
return config;
}
/**
* {@inheritDoc}
*/
@Override
public void delete( int nIdTask )
{
DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, PluginService.getPlugin( WorkflowPlugin.PLUGIN_NAME ) );
daoUtil.setInt( 1, nIdTask );
daoUtil.executeUpdate( );
daoUtil.free( );
}
}
# Plugin's keys
module.description=Workflow module for file
module.provider=City of Paris
# Tasks keys
task.globalFilePurge.task_title=(workflow-directoryfile) Purge of files
task.filePurge.title=Files purge task
configForm.instantPurge.label=Instant purge of files
configForm.instantPurge.help=Tick if you want to delete the files associated to given ressource when this task is executed.
configForm.nbDaysBeforePurge.label=days before files purge.
configForm.nbDaysBeforePurge.=Tick and enter a number of days if you want to delete the files after this number of days.
# Daemon
daemon.filePurge.name=File purge daemon
daemon.filePurge.description=File purge daemon
\ No newline at end of file
# Plugin's keys
module.description=Module de workflow pour la gestion des fichiers
module.provider=Mairie de Paris
# Tasks keys
task.globalFilePurge.task_title=(workflow-directoryfile) Purge de fichiers
task.filePurge.title=T\u00e2che de purge de fichiers
configForm.instantPurge.label=Purge instantan\u00e9e des fichiers
configForm.instantPurge.help=Cochez si vous souhaitez que les fichiers associ\u00e9s \u00e0 cette ressource soient imm\u00e9diatement supprim\u00e9 lors de l'execution de cette t\u00e2che.
configForm.nbDaysBeforePurge.label=jours avant la purge des fichiers
configForm.nbDaysBeforePurge.help=Cochez et saisissez un nombre de jours si vous souhaitez que les fichiers associ\u00e9s \u00e0 cette ressource soient supprim\u00e9s au bout d'un certain nombre de jours.
# Daemon
daemon.filePurge.name=Daemon de purge des fichiers
daemon.filePurge.description=Daemon de purge des fichiers
/*
* Copyright (c) 2002-2018, Mairie de Paris
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright notice
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice
* and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* License 1.0
*/
package fr.paris.lutece.plugins.workflow.modules.directoryfile.service;
import fr.paris.lutece.portal.service.plugin.Plugin;
import fr.paris.lutece.portal.service.plugin.PluginService;
/**
* Workflow file plugin class
*/
public class WorkflowDirectoryFilePlugin extends Plugin
{
/**
* Name of the Workflow Directory demands plugin
*/
public static final String PLUGIN_NAME = "workflow-directoryfile";
/**
* Name of the transaction manager bean for this plugin
*/
public static final String BEAN_TRANSACTION_MANAGER = PLUGIN_NAME + ".transactionManager";
/**
* {@inheritDoc}
*/
@Override
public void init( )
{
// Nothing to do
}
/**
* Gives this plugin
*
* @return This plugin
*/
public static Plugin getPlugin( )
{
return PluginService.getPlugin( PLUGIN_NAME );
}
}
/*
* Copyright (c) 2002-2018, Mairie de Paris
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright notice
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice
* and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* License 1.0
*/
package fr.paris.lutece.plugins.workflow.modules.directoryfile.service.daemon;
import fr.paris.lutece.plugins.directory.business.File;
import fr.paris.lutece.plugins.directory.service.file.DirectoryFileService;
import fr.paris.lutece.portal.service.daemon.Daemon;
import fr.paris.lutece.portal.service.spring.SpringContextService;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
public class FilePurgeDaemon extends Daemon
{
private static final String DIRECTORY_FILE_SERVICE_NAME = "directory.fileService";
/**
* Process the purge of the expired files
*/
@Override
public void run( )
{
DirectoryFileService directoryFileService = (DirectoryFileService) SpringContextService.getBean( DIRECTORY_FILE_SERVICE_NAME );
List<File> listFiles = directoryFileService.getFilesList( );
List<String> listPurgedFileTitle = new ArrayList<>( );
List<String> listErrorPurgedFileTitle = new ArrayList<>( );
for ( File file : listFiles )
{
if ( file.getDateExpiration( ) != null && file.getDateExpiration( ).before( new Timestamp( System.currentTimeMillis( ) ) ) && file.getSize( ) > 0 )
{
String strFileTitle = file.getTitle( );
try
{
directoryFileService.purge( file );
listPurgedFileTitle.add( strFileTitle );
}
catch( Exception e )
{
listErrorPurgedFileTitle.add( strFileTitle );
}
}
}
StringBuilder strBuilder = new StringBuilder( );
for ( String strFileTitle : listPurgedFileTitle )
{
strBuilder.append( " File " );
strBuilder.append( strFileTitle );
strBuilder.append( " correctly purged.\r\n" );
}
for ( String strFileTitle : listErrorPurgedFileTitle )
{
strBuilder.append( " Error when trying to purge " );
strBuilder.append( strFileTitle );
strBuilder.append( ".\r\n" );
}
setLastRunLogs( strBuilder.toString( ) );
}
}
/*
* Copyright (c) 2002-2018, Mairie de Paris
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright notice
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice
* and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* License 1.0
*/
package fr.paris.lutece.plugins.workflow.modules.directoryfile.service.task;
import fr.paris.lutece.plugins.directory.business.File;
import fr.paris.lutece.plugins.directory.service.file.DirectoryFileService;
import fr.paris.lutece.plugins.workflow.modules.directoryfile.business.task.config.TaskGlobalFilePurgeConfig;
import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceHistory;
import fr.paris.lutece.plugins.workflowcore.service.config.TaskConfigService;
import fr.paris.lutece.plugins.workflowcore.service.resource.ResourceHistoryService;
import fr.paris.lutece.plugins.workflowcore.service.task.SimpleTask;
import fr.paris.lutece.portal.service.i18n.I18nService;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import javax.annotation.Resource;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
/**
* Task for purging files associated to given ressource id
*/
public class TaskGlobalFilePurge extends SimpleTask
{
private static final String MESSAGE_TASK_FILE_PURGE_TITLE = "module.workflow.directoryfile.task.filePurge.title";
@Inject
private DirectoryFileService _directoryFileService;
@Inject
@Resource( name = "workflow-directoryfile.taskGlobalFilePurgeConfigService" )
private TaskConfigService _taskConfigService;
@Inject
private ResourceHistoryService _resourceHistoryService;
/**
* {@inheritDoc}
*/
@Override
public void processTask( int nIdResourceHistory, HttpServletRequest request, Locale locale )
{
ResourceHistory resourceHistory = _resourceHistoryService.findByPrimaryKey( nIdResourceHistory );
// Get all the file associated to given ressource id
List<File> listFiles = _directoryFileService.getAssociatedFiles( resourceHistory.getIdResource( ) );
TaskGlobalFilePurgeConfig config = _taskConfigService.findByPrimaryKey( getId( ) );
for ( File file : listFiles )
{
if ( config.isInstantPurge( ) )
{
_directoryFileService.purge( file );
}
else
if ( config.getDaysBeforePurge( ) > 0 )
{
Timestamp tNow = new Timestamp( System.currentTimeMillis( ) );
Calendar cal = Calendar.getInstance( );
cal.setTime( tNow );
cal.add( Calendar.DAY_OF_WEEK, config.getDaysBeforePurge( ) );
Timestamp tAfter = new Timestamp( cal.getTime( ).getTime( ) );
file.setDateExpiration( tAfter );
_directoryFileService.update( file );
}
}
}
/**
* {@inheritDoc}
*/
@Override
public String getTitle( Locale locale )
{
return I18nService.getLocalizedString( MESSAGE_TASK_FILE_PURGE_TITLE, locale );
}
}
/*
* Copyright (c) 2002-2014, Mairie de Paris
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright notice
* and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice
* and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* License 1.0
*/
package fr.paris.lutece.plugins.workflow.modules.directoryfile.web.task;
import fr.paris.lutece.plugins.workflow.modules.directoryfile.business.task.config.TaskGlobalFilePurgeConfig;
import fr.paris.lutece.plugins.workflowcore.business.config.ITaskConfig;
import fr.paris.lutece.plugins.workflowcore.service.task.ITask;
import fr.paris.lutece.plugins.workflowcore.web.task.TaskComponent;
import fr.paris.lutece.portal.service.template.AppTemplateService;
import fr.paris.lutece.util.beanvalidation.BeanValidationUtil;
import fr.paris.lutece.util.html.HtmlTemplate;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.validation.ConstraintViolation;
public class TaskGlobalFilePurgeComponent extends TaskComponent
{
private static final String TEMPLATE_CONFIG_GLOBAL_FILE_PURGE = "admin/plugins/workflow/modules/directoryfile/global_file_purge_task_config.html";
private static final String MARK_CONFIG = "config";
/**
* {@inheritDoc}
*/
@Override
public String getDisplayConfigForm( HttpServletRequest request, Locale locale, ITask task )
{
Map<String, Object> model = new HashMap<>( );
TaskGlobalFilePurgeConfig config = getTaskConfigService( ).findByPrimaryKey( task.getId( ) );
model.put( MARK_CONFIG, config );
HtmlTemplate page = AppTemplateService.getTemplate( TEMPLATE_CONFIG_GLOBAL_FILE_PURGE, locale, model );
return page.getHtml( );
}
/**
* {@inheritDoc}
*/
@Override
public String validateConfig( ITaskConfig config, HttpServletRequest hsr )
{
Set<ConstraintViolation<ITaskConfig>> errors = BeanValidationUtil.validate( config );
if ( !errors.isEmpty( ) )
{
for ( ConstraintViolation<ITaskConfig> constraint : errors )
{
return constraint.getMessage( );
}
}
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getDisplayTaskInformation( int i, HttpServletRequest hsr, Locale locale, ITask itask )
{
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getTaskInformationXml( int i, HttpServletRequest hsr, Locale locale, ITask itask )
{
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String getDisplayTaskForm( int i, String string, HttpServletRequest hsr, Locale locale, ITask itask )
{
return null;
}
/**
* {@inheritDoc}
*/
@Override
public String doValidateTask( int i, String string, HttpServletRequest hsr, Locale locale, ITask itask )
{
return null;
}
}
DROP TABLE IF EXISTS workflow_file_task_global_file_purge_config;
--
-- Table structure for table form_action
--
CREATE TABLE workflow_file_task_global_file_purge_config (
id_task INT NOT NULL,
is_instant_purge SMALLINT DEFAULT 0 NOT NULL,
nb_days_before_purge INT NULL DEFAULT NULL,
PRIMARY KEY (id_task)
);
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- Transaction Manager -->
<bean id="workflow-directoryfile.transactionManager" class="fr.paris.lutece.portal.service.database.DAOUtilTransactionManager"
p:pluginName="workflow-directoryfile" />
<!-- DAO -->
<bean id="workflow-directoryfile.globalFilePurgeConfigDAO" class="fr.paris.lutece.plugins.workflow.modules.directoryfile.business.task.config.TaskGlobalFilePurgeConfigDAO" />
<!-- Services -->
<bean id="workflow-directoryfile.taskGlobalFilePurgeConfigService"
class="fr.paris.lutece.plugins.workflowcore.service.config.TaskConfigService"
p:taskConfigDAO-ref="workflow-directoryfile.globalFilePurgeConfigDAO" />
<!-- Task config -->
<bean id="workflow-directoryfile.taskGlobalFilePurgeConfig"
class="fr.paris.lutece.plugins.workflow.modules.directoryfile.business.task.config.TaskGlobalFilePurgeConfig"
scope="prototype" />
<!-- Task -->
<bean id="workflow-directoryfile.taskTypeGlobalPurgeFile" class="fr.paris.lutece.plugins.workflowcore.business.task.TaskType"
p:key="taskGlobalPurgeFile"
p:titleI18nKey="module.workflow.directoryfile.task.globalFilePurge.task_title"
p:beanName="workflow-directoryfile.taskGlobalFilePurge"
p:configBeanName="workflow-directoryfile.taskGlobalFilePurgeConfig"
p:configRequired="true"
p:formTaskRequired="false"
p:taskForAutomaticAction="true"
/>
<bean id="workflow-directoryfile.taskGlobalFilePurge" class="fr.paris.lutece.plugins.workflow.modules.directoryfile.service.task.TaskGlobalFilePurge" scope="prototype" />
<bean id="workflow-directoryfile.taskGlobalPurgeFileComponent" class="fr.paris.lutece.plugins.workflow.modules.directoryfile.web.task.TaskGlobalFilePurgeComponent"
p:taskType-ref="workflow-directoryfile.taskTypeGlobalPurgeFile"
p:taskConfigService-ref="workflow-directoryfile.taskGlobalFilePurgeConfigService"
/>
<!-- Daemon -->
<bean id="filePurgeDaemon" class="fr.paris.lutece.plugins.workflow.modules.directoryfile.service.daemon.FilePurgeDaemon"/>
</beans>
<?xml version="1.0" encoding="UTF-8"?><plug-in>
<name>workflow-directoryfile</name>
<class>fr.paris.lutece.plugins.workflow.modules.directoryfile.service.WorkflowDirectoryFilePlugin</class>
<version>1.0.0</version>
<documentation/>
<installation/>
<changes/>
<user-guide/>
<description>module.workflow.directoryfile.module.description</description>
<provider>module.workflow.directoryfile.module.provider</provider>
<provider-url>http://dev.lutece.paris.fr</provider-url>
<icon-url>images/admin/skin/feature_default_icon.png</icon-url>
<copyright>Copyright (c) 2017 Mairie de Paris</copyright>
<!-- if the plugin must have a connection pool with parameter : 1 - yes, 0 - no -->
<db-pool-required>1</db-pool-required>
<core-version-dependency>
<min-core-version>5.1.1</min-core-version>
<max-core-version/>
</core-version-dependency>
<!-- Admin features parameters -->
<admin-features>
</admin-features>
<!-- Daemons -->
<daemons>
<daemon>
<daemon-id>filePurgeDaemon</daemon-id>
<daemon-name>module.workflow.directoryfile.daemon.filePurge.name</daemon-name>
<daemon-description>module.workflow.directoryfile.daemon.filePurge.description</daemon-description>
<daemon-class>fr.paris.lutece.plugins.workflow.modules.directoryfile.service.daemon.FilePurgeDaemon</daemon-class>
</daemon>
</daemons>
<!-- Xpage configuration -->
<applications>
</applications>
<!-- Portlet parameters -->
<portlets>
</portlets>
<!-- Servlets -->
<servlets>
</servlets>
<!-- Specific plugin Javascript files -->
<javascript-files>
</javascript-files>
<!-- Specific plugin CSS stylesheet -->
<admin-css-stylesheets>
<admin-css-stylesheet/>
</admin-css-stylesheets>
<css-stylesheets/>
</plug-in>
\ No newline at end of file
<@row>
<#if (config.isInstantPurge)??>
<#assign configInstantPurge = config.instantPurge />
<#else>
<#assign configInstantPurge = false />
</#if>
<#if (config.isInstantPurgeWithAction)??>
<#assign configInstantPurgeWithAction = config.instantPurgeWithAction />
<#else>
<#assign configInstantPurgeWithAction = false />
</#if>
<@fieldInputRadioBox i18nLabelKey="module.workflow.directoryfile.configForm.instantPurge.label" inputName="instantPurge" value="true" i18nHelpBlockKey='module.workflow.directoryfile.configForm.instantPurge.help' cssClass='' checked=configInstantPurge />
<div class="form-group">
<div class="col-xs-12 col-sm-offset-3 col-sm-6 col-md-offset-3 col-md-6 col-lg-offset-3 col-lg-6">
<div class="radio">
<label>
<input id="days_before_purge" name="instantPurge" type="radio" value="false" <#if config ?? && !config.instantPurge && config.daysBeforePurge gt 0>checked="checked"</#if>>
<input type="text" name="daysBeforePurge" value="<#if config?? && config.daysBeforePurge gt 0>${config.daysBeforePurge}<#else>0</#if>"/>
#i18n{module.workflow.directoryfile.configForm.nbDaysBeforePurge.label}
</label>
</div>
<p class="help-block">#i18n{module.workflow.directoryfile.configForm.nbDaysBeforePurge.help}</p>
</div>
</div>
</@row>