Class TaskDefinition


  • @JsonData
    public class TaskDefinition
    extends java.lang.Object
    This represents the settings of a task. It contains triggers, jobs and actions.

    A TaskDefinition can easily be instantiated and modified. Use TaskPlanner.addTask(TaskDefinition, GUID) to save new Tasks.

    It is recommended to use Builder classes to construct new Definitions for triggers, jobs and actions, but you can also construct them manually by using the properties described in the corresponding factory.

    Example:

    
          TaskDefinition task = new TaskDefinition( "Send Reports every Week" );
            task.setDescription( "Send the request report every two weeks to steve" );
    
            TriggerDefinition triggerDefinition = new TimeTriggerBuilder().withHourAndMinute( 10, 00 ).withRepeating( RepeatInterval.WEEKLY ).create();
            task.addTrigger( triggerDefinition );
    
            //manually
            JobDefinition job = new JobDefinition( ReportJobFactory.EXTENSION );
            job.setProperty( UrlConstants.REPORTS, "file:C:/report/request.rpt" );
            job.setProperty( UrlConstants.EXPORT_FMT, Engine.EXPORT_HTML );
            task.addJob( job );
    
            ResultActionDefinition emailAction = new EmailResultActionBuilder( "Request Report", "This is the weekly request report. --- CompanyName Inc.---", "steve@companyname.com", "david@companyname.com" ).create();
            task.addResultAction( emailAction );
    
            TaskPlanner.getInstance().addTask( task, "CompanyName Inc." );
     
     

    Changes in existing task's definition must be saved using TaskPlanner.updateTask(com.inet.id.GUID, TaskDefinition).

    Since:
    taskplanner 3.0
    See Also:
    TriggerDefinition, JobDefinition, ResultActionDefinition
    • Constructor Detail

      • TaskDefinition

        public TaskDefinition​(@Nonnull
                              java.lang.String name)
        Creates a new TaskModel instance.
        Parameters:
        name - the display name for this task
        Throws:
        java.lang.IllegalArgumentException - if the given name is null
        Since:
        taskplanner 3.0
    • Method Detail

      • isActivated

        public boolean isActivated()
        Returns whether this task is activated. This means it's trigger are active.
        Returns:
        true if this task is activated
        Since:
        taskplanner 3.0
      • setActivated

        public void setActivated​(boolean activated)
        Mark this task as activated. Keep in mind that this method does not save the task in TaskPlanner.
        Parameters:
        activated - the activated state to be set
        Since:
        taskplanner 3.0
      • getName

        public java.lang.String getName()
        Get the display name of this task.
        Returns:
        the display name of this task
        Since:
        taskplanner 3.0
      • setName

        public void setName​(@Nonnull
                            java.lang.String name)
        Set the display name of this task.
        Parameters:
        name - the display name
        Throws:
        java.lang.IllegalArgumentException - if the given name is null
        Since:
        taskplanner 3.0
      • 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.
        Since:
        taskplanner 3.0
        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.
        Throws:
        java.lang.IllegalArgumentException - if the description is null.
        Since:
        taskplanner 3.0
        See Also:
        getDescription()
      • getSeries

        @Nullable
        public SeriesDefinition getSeries()
        Get the optional series of this task.
        Returns:
        the series definition
        Since:
        taskplanner 3.0
      • setSeries

        public void setSeries​(@Nullable
                              SeriesDefinition series)
        Set the optional series definition of this task.
        Parameters:
        series - the series
        Since:
        taskplanner 3.0
      • addTrigger

        @Nonnull
        public TaskDefinition addTrigger​(@Nullable
                                         TriggerDefinition definition)
        Adds a trigger to this task by its definition. Please refer to TriggerDefinition on how to create a valid trigger definition.
        Parameters:
        definition - the definition for the new trigger
        Returns:
        this instance to allow chaining
        Since:
        taskplanner 3.0
      • removeTrigger

        public boolean removeTrigger​(@Nullable
                                     TriggerDefinition definition)
        Removes a trigger from this task. This requires the passed trigger to be equal to a trigger in the task to have any effect.
        Parameters:
        definition - the definition of the trigger to remove
        Returns:
        true if the trigger was actually removed
        Since:
        taskplanner 3.0
      • addJob

        @Nonnull
        public TaskDefinition addJob​(@Nullable
                                     JobDefinition definition)
        Adds a job to this task by its definition. Please refer to JobDefinition on how to create a valid job definition.
        Parameters:
        definition - the definition for the new job
        Returns:
        this instance to allow chaining
        Since:
        taskplanner 3.0
      • removeJob

        public boolean removeJob​(@Nullable
                                 JobDefinition definition)
        Removes a job from this task. This requires the passed job to be equal to a job in the task to have any effect.
        Parameters:
        definition - the definition of the job to remove
        Returns:
        true if the job was actually removed
        Since:
        taskplanner 3.0
      • addResultAction

        @Nonnull
        public TaskDefinition addResultAction​(@Nullable
                                              ResultActionDefinition definition)
        Adds a result action to this task by its definition. Please refer to ResultActionDefinition on how to create a valid result action definition.
        Parameters:
        definition - the definition for the new result action
        Returns:
        this instance to allow chaining
        Since:
        taskplanner 3.0
      • removeResultAction

        public boolean removeResultAction​(@Nullable
                                          ResultActionDefinition definition)
        Removes a result action from this task. This requires the passed result action to be equal to a result action in the task to have any effect.
        Parameters:
        definition - the definition of the result action to remove
        Returns:
        true if the result action was actually removed
        Since:
        taskplanner 3.0
      • copyTaskModel

        public TaskDefinition copyTaskModel()
        Create a deep copy of this model.
        Returns:
        the copy of this model
        Since:
        taskplanner 3.0
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • validate

        public void validate()
                      throws ValidationException
        Validate all settings from this task.
        This includes jobs with conditions, triggers, actions, series.
        Throws:
        ValidationException - if some problems are found. The Exception contains all found errors.
        Since:
        taskplanner 3.0
      • validate

        public void validate​(com.inet.id.GUID taskID)
                      throws ValidationException
        Validate all settings from this task.
        This includes jobs with conditions, triggers, actions, series.
        Parameters:
        taskID - the ID of the task this model belongs to. Can be null. In most of the cases it does not make any difference whether passing the taskID or not. Only in special constellations where the components (trigger, job, resultAction) somehow reference other tasks you may get a more precise validation result with a taskID. E.g. the NextTaskResultAction may not reference the own task.
        Throws:
        ValidationException - if some problems are found. The Exception contains all found errors.
        Since:
        taskplanner 3.0