i-net Clear Reports

com.inet.report.schedule
Class ScheduleTask

java.lang.Object
  extended by com.inet.report.schedule.ScheduleTask

public class ScheduleTask
extends java.lang.Object

An object of this class defines a task - running a report on a specific date or on multiple dates and performing a certain action if the rendering process of the report has been finished successfully.

Example 1

We wish to create a task called "My First Task", which, starting on April 15th, 2005, executes the report "myReport.rpt" as well as exporting it to PS format and and send the exported PostScript file per email to myself@nosuchhost.com. It is to do this every 4 days at 1:12 p.m.
Here is the code for accomplishing this:

 // We start by getting a scheduler object:
 Scheduler scheduler = Scheduler.getInstance();
 // We then create a task by the name "My First Task" and add it to the scheduler:
 ScheduleTask task = scheduler.addTask( "My First Task" );
 
 //Now we define a report to be executed with this task
 //To do this, we create a properties object for the report we want to add
 Properties properties=new Properties();
 //each report defined for a task at least needs the property "report"
 properties.put("report","myReport.rpt");
 //Now we add a new report to our task with the properties we set
 ScheduleReport report=task.addReport("My First Report",properties);
 //Now we specify that we want the report to be rendered with export format "ps"
 report.addProperty("export_fmt","ps"); //use property "export_fmt" to specify export format
 
 //We now define the action which should be executed after the task has finished
 EmailAction emailAction = new EmailAction();
 emailAction.setTo("myself@nosuchhost.com");
 emailAction.setSubject("Some kind of subject line.");
 emailAction.setMessage("This is the body text of the email which will be sent at report creation.");
 emailAction.setAttachReport(true);
 //...then add the action to the task
 task.addAction(emailAction);
      
 // We now set the execution time details of the task - starting on April 15th, every 4 days, at 1:12p.m.
 task.setExecutionTime(ScheduleExecutionFactory.createDaily(new Date(2005,4,15),4,13,12);
 
 // Now we tell the scheduler to start its service.
 scheduler.start();
 

Example 2

We wish to create a task called "My Second Task", which, starting on April 8th, 2005, executes the report "myReport.rpt" as well as exporting it to PDF format and emailing the exported PDF file to myself@nosuchhost.com. It is to do this every Monday and Friday at 8 a.m. and 6 p.m.
Here is the code for accomplishing this:

 // We start by getting a scheduler object:
 Scheduler scheduler = Scheduler.getInstance();
 // We then create a task by the name "My Second Task" and add it to the scheduler:
 ScheduleTask task = scheduler.addTask( "My Second Task" );
 
 //Now we define a report to be executed with this task
 //To do this, we create a properties object for the report we want to add
 Properties properties=new Properties();
 //each report defined for a task at least needs the property "report"
 properties.put("report","myReport.rpt");
 //Now we add a new report to our task with the properties we set
 ScheduleReport report=task.addReport("My Second Report",properties);
 //Now we specify that we want the report to be rendered with export format "pdf"
 report.addProperty("export_fmt","pdf"); //use property "export_fmt" to specify export format
 
 //We now define the action which should be executed after the task has finished
 EmailAction emailAction = new EmailAction();
 emailAction.setTo("myself@nosuchhost.com");
 emailAction.setSubject("Some kind of subject line.");
 emailAction.setMessage("This is the body text of the email which will be sent at report creation.");
 emailAction.setAttachReport(true);
 //...then add the action to the task
 task.addAction(emailAction);
      
 // We now set the task's execution time details - starting on April 8th, 2005, every 2 weeks, on
 // Monday and Wednesday, from 8am to 6pm every 10 hours.  
 task.setExecutionTime(ScheduleExecutionFactory.createWeekly(new Date(2005,4,8),2,
     new int[] {ScheduleExecution.MONDAY, ScheduleExecution.WEDNESDAY},8,18,10,0));
 
 // Now we tell the scheduler to start its service.
 scheduler.start();
 

Example 3


We wish to create a task called "My Third Task", which, starting on April 8th, 2005, executes the report "myReport.rpt" as well as exporting it to Excel format and and emailing the exported Excel file to myself@nosuchhost.com.. It is to do this on every 8th and 23rd day of every month, at 2, 4, 6, and 8 p.m.
Here is the code for accomplishing this:

 // We start by getting a scheduler object:
 Scheduler scheduler = Scheduler.getInstance();
 // We then create a task by the name "My Third Task" and add it to the scheduler:
 ScheduleTask task = scheduler.addTask( "My Third Task" );
 
 //Now we define a report to be executed with this task
 //To do this, we create a properties object for the report we want to add
 Properties properties=new Properties();
 //each report defined for a task at least needs the property "report"
 properties.put("report","myReport.rpt");
 //Now we add a new report to our task with the properties we set
 ScheduleReport report=task.addReport("My Third Report",properties);
 //Now we specify that we want the report to be rendered with export format "xls"
 report.addProperty("export_fmt","xls"); //use property "export_fmt" to specify export format
 
 //We now define the action which should be executed after the task has finished
 EmailAction emailAction = new EmailAction();
 emailAction.setTo("myself@nosuchhost.com");
 emailAction.setSubject("Some kind of subject line.");
 emailAction.setMessage("This is the body text of the email which will be sent at report creation.");
 emailAction.setAttachReport(true);
 //...then add the action to the task
 task.addAction(emailAction);
      
 // We now set the task's execution time details - starting on April 8th, 2005, every month, on
 // the 8th and 23rd day, at 2, 4, 6, and 8pm.  
 task.setExecutionTime(ScheduleExecutionFactory.createMonthly(new Date(2005,4,8), new int[]{0,1,2,3,4,5,6,7,8,9,10,11},
     new int[] {8,23},14,20,2,0));
 
 // Now we tell the scheduler to start its service.
 scheduler.start();
 

Example 4

We wish to create a task called "My Fourth Task", which, on May 31st, 2005, executes the report "myReport.rpt" as well as exporting it to plain text format and and emailing the exported text file to myself@nosuchhost.com.. It is to do this only on this one day, at 2:12, 3:12, 4:12, and 5:12 p.m.
Here is the code for accomplishing this:

 // We start by getting a scheduler object:
 Scheduler scheduler = Scheduler.getInstance();
 // We then create a task by the name "My Fourth Task" and add it to the scheduler:
 ScheduleTask task = scheduler.addTask( "My Fourth Task" );
 
 //Now we define a report to be executed with this task
 //To do this, we create a properties object for the report we want to add
 Properties properties=new Properties();
 //each report defined for a task at least needs the property "report"
 properties.put("report","myReport.rpt");
 //Now we add a new report to our task with the properties we set
 ScheduleReport report=task.addReport("My Fourth Report",properties);
 //Now we specify that we want the report to be rendered with export format "txt"
 report.addProperty("export_fmt","txt"); //use property "export_fmt" to specify export format
 
 //We now define the action which should be executed after the task has finished
 EmailAction emailAction = new EmailAction();
 emailAction.setTo("myself@nosuchhost.com");
 emailAction.setSubject("Some kind of subject line.");
 emailAction.setMessage("This is the body text of the email which will be sent at report creation.");
 emailAction.setAttachReport(true);
 //...then add the action to the task
 task.addAction(emailAction);
 
 // We now set the task's execution time details - only on May 31st, 2005, at 2:12,3:12,4:12, and 5:12 p.m.
 task.setExecutionTime(ScheduleExecutionFactory.createOneDayExecution(new Date(2005,5,31),14,17,1,12));// Now, we can set the task's start date - May 31st, 2005
 
 // Now we tell the scheduler to start its service.
 scheduler.start();
 

Since:
6.0

Nested Class Summary
static class ScheduleTask.LastGeneratedReportInstance
          Contains information about a report that has been rendered and it's files.
 
Field Summary
static int STATUS_EXECUTING
          This status means that this task is in execution.
static int STATUS_SCHEDULED
          This status means that the execution of this task has already been scheduled.
static int STATUS_UNSCHEDULED
          This status means that this task has not been scheduled for execution.
static int STATUS_WAITING_FOR_EXECUTION
          This status means that this task should have been executed now but that there are currently too much other tasks in execution.
 
Method Summary
 void addAction(ScheduleAction action)
          Adds this action to the task.
 void addExecutionError(java.lang.String source, java.lang.String message)
          Adds an error message for the current execution of this task.
 ScheduleReport addReport(java.lang.String scheduleName, java.util.Properties properties)
          Returns a report that is associated with this task using the name supplied and initialized using the supplied properties.
 boolean containsReport(java.lang.String scheduleName)
          Returns whether a report by that name is associated with this task.
 ScheduleAction getAction(int index)
          Returns the ScheduleAction associated with the specified index.
 ScheduleAction getAction(java.lang.String className)
          Returns the ScheduleAction with the specified class name.
 int getActionCount()
          Returns the number of ScheduleAction associated with this task.
 java.lang.String getDescription()
          Returns the description for this task.
 java.lang.String[] getErrorMessage()
          Returns an error message if start and end date are in an illegal configuration.
 java.lang.String[] getExecutionErrors()
          Returns an array of messages of the last execution of this task.
 ExecutionTimeProvider getExecutionTime()
          Returns this task's ScheduleExecution object, which contains start date, interval type, etc. information
 java.lang.Integer getId()
          Returns the unique id identifying this task.
 java.util.Date getLastRun()
          Returns the date of the last run.
 java.lang.String getName()
          Returns the name identifying this task uniquely.
 java.util.Date getNextStart()
          Returns the date of the next execution of this task, depending on the date of the last run.
 ScheduleReport getReport(int index)
          Returns the report at a certain index.
 ScheduleReport getReport(java.lang.String scheduleName)
          Allows you to retrieve a report using the name that was supplied when creating/adding the report.
 int getReportCount()
          Tells you how many reports are associated with this task.
 int getStatus()
          Returns STATUS_UNSCHEDULED, STATUS_SCHEDULED, STATUS_WAITING_FOR_EXECUTION or STATUS_EXECUTING as status of this task.
 boolean isDeleteIfExpired()
          Returns if the task will be removed from the i-net Scheduler if it is expired, which means that there are no more execution dates for this task.
 boolean isEnabled()
          Checks if this task is currently enabled.
 boolean isManualExecution()
          Check whether this task has been manually marked for execution.
 boolean isValid()
          Checks whether this task is valid.
 void markForExecution()
          This will mark this task to be executed shortly.
 ScheduleAction removeAction(int idx)
          Removes the ScheduleAction with the specified index from this task.
 ScheduleAction removeAction(ScheduleAction action)
          Removes the specified ScheduleAction from this task.
 void removeReport(java.lang.String scheduleName)
          Removes the report by the specified name from this task.
 void setDeleteIfExpired(boolean deleteIfExpired)
          Sets whether the task should be removed from the i-net Scheduler if it is expired or not.
 void setDescription(java.lang.String description)
          Use this method to set the description of the task.
 void setEnabled(boolean enabled)
          Enables or disables this task.
 void setExecutionTime(ExecutionTimeProvider executionTime)
          Sets this task's ScheduleExecution object - to create a ScheduleExecution, please use ScheduleExecutionFactory's factory methods.
 void setName(java.lang.String taskName)
          Sets the name of this task.
 java.lang.String toString()
          Returns a string representation of this ScheduleTask containing its name and description if available.
 

Field Detail

STATUS_EXECUTING

public static final int STATUS_EXECUTING
This status means that this task is in execution. The actions of this task will be done now.

See Also:
Constant Field Values

STATUS_WAITING_FOR_EXECUTION

public static final int STATUS_WAITING_FOR_EXECUTION
This status means that this task should have been executed now but that there are currently too much other tasks in execution. This task will be executed as soon as the number of running tasks is lower than Scheduler.PROPERTY_MAX_WORKER.

See Also:
Constant Field Values

STATUS_SCHEDULED

public static final int STATUS_SCHEDULED
This status means that the execution of this task has already been scheduled.

See Also:
Constant Field Values

STATUS_UNSCHEDULED

public static final int STATUS_UNSCHEDULED
This status means that this task has not been scheduled for execution. A reason could be that the task is disabled.

See Also:
Constant Field Values
Method Detail

getDescription

public java.lang.String getDescription()
Returns the description for this task. Can be null if no description was set.

Returns:
The task description. Can be null.
See Also:
setDescription(String)

setDescription

public void setDescription(java.lang.String description)
Use this method to set the description of the task.

Parameters:
description - A description of the task.
See Also:
getDescription()

getName

public java.lang.String getName()
Returns the name identifying this task uniquely.

Returns:
The name of this task.

getId

public java.lang.Integer getId()
Returns the unique id identifying this task.

Returns:
the id of this task
Since:
11.0

getErrorMessage

public java.lang.String[] getErrorMessage()
Returns an error message if start and end date are in an illegal configuration.

Returns:
error message An array with error messages.

isValid

public boolean isValid()
Checks whether this task is valid. The task is valid if it has an executionTime object which at least has a start date, and whose end date, if it has one, is AFTER its start date.

Returns:
true if the task is valid, otherwise false.

isEnabled

public boolean isEnabled()
Checks if this task is currently enabled. If not the task will not be executed if the configured time is reached.

Returns:
true if the task can be executed, false if the task is "sleeping".
See Also:
setEnabled(boolean)

setEnabled

public void setEnabled(boolean enabled)
Enables or disables this task.

Parameters:
enabled - If true this task will be enabled and executed at the configured time. If false this task will be disabled and will not be executed. The task is "sleeping".
See Also:
isEnabled()

getReportCount

public int getReportCount()
Tells you how many reports are associated with this task.

Returns:
an int indicating the number of reports associated with this task.
See Also:
getReport(int), getReport(String), containsReport(String), addReport(String, Properties), removeReport(String)

getReport

public ScheduleReport getReport(int index)
Returns the report at a certain index. There is no guarantee that a certain report is associated with a certain index. It is guaranteed that you will get a report if you supply a zero based index smaller than the number of reports associated with this task.

Parameters:
index - The index of the report you want to be returned from the list.
Returns:
A ScheduleReport instance.
See Also:
getReportCount(), getReport(String), addReport(String, Properties), containsReport(String), removeReport(String)

getReport

public ScheduleReport getReport(java.lang.String scheduleName)
Allows you to retrieve a report using the name that was supplied when creating/adding the report.

Parameters:
scheduleName - The name of the report which should be returned.
Returns:
if a report by the supplied name is found it is returned, otherwise null
See Also:
getReportCount(), getReport(int), containsReport(String), addReport(String, Properties), removeReport(String)

containsReport

public boolean containsReport(java.lang.String scheduleName)
Returns whether a report by that name is associated with this task.

Parameters:
scheduleName - The name of the report which should be find.
Returns:
True if there is a report defined for this task with the given scheduleName, otherwise false.
See Also:
addReport(String, Properties), getReport(int), getReport(String), getReportCount(), removeReport(String)

addReport

public ScheduleReport addReport(java.lang.String scheduleName,
                                java.util.Properties properties)
                         throws ScheduleException
Returns a report that is associated with this task using the name supplied and initialized using the supplied properties.

Parameters:
scheduleName - A name for the report which should be added to the task.
properties - A properties object containing at least the property "report".
Returns:
a new report The added report.
Throws:
ScheduleException -
  • If the name for the report scheduleName was null or empty. (SE0027)
  • If there is already a report defined for this task with name scheduleName. (SE0028)
  • If the properties passed were null. (SE0029)
  • If the properties passed did not contain the property "report". (SE0030,SE0031)
See Also:
getReport(int), getReport(String), getReportCount(), containsReport(String), removeReport(String)

removeReport

public void removeReport(java.lang.String scheduleName)
Removes the report by the specified name from this task. It will no longer be executed, counted, or returned when asked for.

Parameters:
scheduleName - The name of the report which should be removed.
See Also:
containsReport(String), getReportCount(), getReport(int), getReport(String), addReport(String, Properties)

removeAction

public ScheduleAction removeAction(int idx)
Removes the ScheduleAction with the specified index from this task.

Parameters:
idx - The index of the action which should be removed.
Returns:
The removed action object.
See Also:
removeAction(ScheduleAction), getActionCount(), getAction(int), getAction(String), addAction(ScheduleAction)

addAction

public void addAction(ScheduleAction action)
               throws ScheduleException
Adds this action to the task. The action will be executed whenever the task is being executed, after the reports have been executed. Note:If you're adding an own implementation of ScheduleAction and you did not register this custom action to the i-net Scheduler with Scheduler.addCustomAction(String, String, String) then you should be sure that this class is in class path when the i-net Scheduler is loaded. Otherwise the class can not be found.

Parameters:
action - The action object which should be added to this task.
Throws:
ScheduleException -
  • If you try to add null as action. (SE0024)
  • If you already added an instance of that action to the task. (SE0025)
See Also:
getAction(int), getAction(String), getActionCount(), removeAction(int), removeAction(ScheduleAction)

getActionCount

public int getActionCount()
Returns the number of ScheduleAction associated with this task.

Returns:
The number of actions defined for the task.
See Also:
getAction(int), getAction(String), addAction(ScheduleAction), removeAction(int), removeAction(ScheduleAction)

getAction

public ScheduleAction getAction(int index)
Returns the ScheduleAction associated with the specified index.

Parameters:
index - The index of the action to retrieve from the list-
Returns:
An action defined for this task.
See Also:
getActionCount(), getAction(String), addAction(ScheduleAction), removeAction(int), removeAction(ScheduleAction)

getAction

public ScheduleAction getAction(java.lang.String className)
Returns the ScheduleAction with the specified class name. There can only be one ScheduleAction per type per task.

Parameters:
className - The class name of the action which should be returned.
Returns:
A ScheduleAction object if an action with the given class name is defined for this task, otherwise null.
See Also:
getAction(int), getActionCount(), addAction(ScheduleAction), removeAction(int), removeAction(ScheduleAction)

removeAction

public ScheduleAction removeAction(ScheduleAction action)
Removes the specified ScheduleAction from this task.

Parameters:
action - The action which should be removed from the task.
Returns:
The removed action or null if the action was not defined for this task.
See Also:
removeAction(int), getActionCount(), getAction(int), getAction(String), addAction(ScheduleAction)

getNextStart

public java.util.Date getNextStart()
Returns the date of the next execution of this task, depending on the date of the last run. If the task is expired, this will return null

Returns:
The date of the next execution, or null if the task has expired.

getExecutionTime

public ExecutionTimeProvider getExecutionTime()
Returns this task's ScheduleExecution object, which contains start date, interval type, etc. information

Returns:
This task's ScheduleExecution object, which contains start date, interval type, etc. information

setExecutionTime

public final void setExecutionTime(ExecutionTimeProvider executionTime)
Sets this task's ScheduleExecution object - to create a ScheduleExecution, please use ScheduleExecutionFactory's factory methods.

Parameters:
executionTime - The ScheduleExecution object

getStatus

public int getStatus()
Returns STATUS_UNSCHEDULED, STATUS_SCHEDULED, STATUS_WAITING_FOR_EXECUTION or STATUS_EXECUTING as status of this task.

Returns:
One of the following constants: STATUS_UNSCHEDULED, STATUS_SCHEDULED, STATUS_WAITING_FOR_EXECUTION or STATUS_EXECUTING

setName

public void setName(java.lang.String taskName)
             throws ScheduleException
Sets the name of this task. Each task must have a different name.

Parameters:
taskName - the name of the task
Throws:
ScheduleException - if an other task with the given name already exists (SE0002).

toString

public java.lang.String toString()
Returns a string representation of this ScheduleTask containing its name and description if available.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of this ScheduleTask.

isDeleteIfExpired

public boolean isDeleteIfExpired()
Returns if the task will be removed from the i-net Scheduler if it is expired, which means that there are no more execution dates for this task.

Returns:
True if the task will be removed, otherwise false.
See Also:
setDeleteIfExpired(boolean)

setDeleteIfExpired

public void setDeleteIfExpired(boolean deleteIfExpired)
Sets whether the task should be removed from the i-net Scheduler if it is expired or not.

Parameters:
deleteIfExpired - True if the task should be removed, otherwise false.
See Also:
isDeleteIfExpired()

addExecutionError

public void addExecutionError(java.lang.String source,
                              java.lang.String message)
Adds an error message for the current execution of this task. This method should be used if you have a custom action class. If there occurs an error while doing this action you should call this method of the executed task. Then you will be able to see in the web configuration tool of the i-net Scheduler that the last execution of a task contained an error.

Parameters:
source - The name of the source where the error occurred. Here you should specify the name of your custom action class.
message - The message text of the error which occurred.
Since:
6.1

getLastRun

public java.util.Date getLastRun()
Returns the date of the last run.

Returns:
last run date, can be null

getExecutionErrors

public java.lang.String[] getExecutionErrors()
Returns an array of messages of the last execution of this task. If there has been no execution since the last start of the i-net Scheduler you will get an empty array. If the last execution was successful an array with length 1 will be returned containing the string of the last execution date. If there are more messages then these describe errors occurred during the last execution.

Returns:
An array containing the information about the last execution.
Since:
6.1

markForExecution

public void markForExecution()
This will mark this task to be executed shortly. That means that the status will be set to STATUS_WAITING_FOR_EXECUTION. Shortly means that the task will not be executed immediately. If there are not more than Scheduler.PROPERTY_MAX_WORKER task currently running this execution of this task will be started within the next 10 seconds. This call will have no effect if the task is currently executing or already in the queue of waiting tasks. (That means that the status of the task is either STATUS_EXECUTING or STATUS_WAITING_FOR_EXECUTION.

Since:
6.1

isManualExecution

public boolean isManualExecution()
Check whether this task has been manually marked for execution.

Returns:
true when markForExecution() has been called and this task is waiting for execution or is being executed, otherwise returns false.
Since:
11.3

i-net Clear Reports

Copyright © 1999-2015 by i-net software GmbH