Class CronTriggerFactory

java.lang.Object
com.inet.taskplanner.server.api.common.AbstractFactory<com.inet.taskplanner.server.api.trigger.cron.CronTrigger, TriggerDefinition, TriggerInfo, SummaryInfo>
com.inet.taskplanner.server.api.common.SeriesIndependentFactory<com.inet.taskplanner.server.api.trigger.cron.CronTrigger, TriggerDefinition, TriggerInfo, SummaryInfo>
com.inet.taskplanner.server.api.trigger.TriggerFactory<com.inet.taskplanner.server.api.trigger.cron.CronTrigger>
com.inet.taskplanner.server.api.trigger.cron.CronTriggerFactory
All Implemented Interfaces:
com.inet.plugin.NamedExtension

public class CronTriggerFactory extends TriggerFactory<com.inet.taskplanner.server.api.trigger.cron.CronTrigger>
Factory that produces CronTrigger components.
Since:
taskplanner 3.0
See Also:
  • CronTrigger
  • Field Details

    • EXTENSION_NAME

      public static final String EXTENSION_NAME
      Name of the Cron trigger to use as extension name in the TriggerDefinition
      See Also:
    • PROP_CRON_EXPRESSION

      public static final String PROP_CRON_EXPRESSION
      The cron expression which determines the time when this trigger will start the task.

      Format:
      [minute] [hour] [dayOfMonth] [month] [dayOfWeek] [year]
      One of dayOfMonth and dayOfWeek must be '?' and year can be omitted.

      Example:

      
           TriggerDefinition cron = new TriggerDefinition(CronTriggerFactory.EXTENSION_NAME);
           cron.setProperty(CronTriggerFactory.PROP_CRON_EXPRESSION, "30 10 ? * 2"); //at 10:30 on each Monday
      
      
      See Also:
  • Constructor Details

    • CronTriggerFactory

      public CronTriggerFactory()
      Creates a new CronTriggerFactory instance.
      Since:
      taskplanner 3.0
  • Method Details

    • getInformation

      public TriggerInfo getInformation(com.inet.id.GUID taskID)
      Returns an information object about components which can be produced with this factory.

      The returned info contains information about how such a component is to be presented in the Task Planner web GUI. This includes display information and available configuration options. The returned information contains fields that describe the values a user can specify in the web GUI. The fields are also responsible for replacing placeholders for the corresponding property in a serial task. That means properties without a field definition will not get any series placeholder replaced.

      If you implement a factory for a component used only through the API, you can return null here.

      Specified by:
      getInformation in class AbstractFactory<com.inet.taskplanner.server.api.trigger.cron.CronTrigger, TriggerDefinition, TriggerInfo, SummaryInfo>
      Parameters:
      taskID - the ID of the task the definition belongs or will belong to, for optional use. Can be null if the operation is done for a non-saved task.
      Returns:
      an information object for components this factory can produce
    • updateValues

      public Map<String,String> updateValues(TriggerDefinition definition, com.inet.id.GUID taskID)
      Updates values according to the given definition.

      The given definition is guaranteed to belong to this factory.

      Overrides:
      updateValues in class SeriesIndependentFactory<com.inet.taskplanner.server.api.trigger.cron.CronTrigger, TriggerDefinition, TriggerInfo, SummaryInfo>
      Parameters:
      definition - the definition with the current properties
      taskID - the ID of the task the definition belongs or will belong to, for optional use
      Returns:
      a map of property keys and their changed values
    • getNextExecutionsSummaryText

      public static String getNextExecutionsSummaryText(List<ZonedDateTime> nextExecutionDates)
      FOR INTERNAL USE ONLY.
      Generates the text of the next executions
      Parameters:
      nextExecutionDates - list of next execution dates to get the summary text for
      Returns:
      the next executions text
    • validate

      public void validate(TriggerDefinition definition, com.inet.id.GUID taskID) throws ValidationException
      Validate the given definition.

      The given definition is guaranteed to belong to this factory

      Specified by:
      validate in class SeriesIndependentFactory<com.inet.taskplanner.server.api.trigger.cron.CronTrigger, TriggerDefinition, TriggerInfo, SummaryInfo>
      Parameters:
      definition - the definition to validate
      taskID - the ID of the task the definition belongs or will belong to, for optional use. Can be null if the operation is done for a non-saved task.
      Throws:
      ValidationException - if the component has some errors
    • validateCronExpression

      public static String validateCronExpression(@Nullable String cronExpression)
      FOR INTERNAL USE ONLY. Validate the given cron expression and returns the error message.
      Parameters:
      cronExpression - the expression to validate
      Returns:
      Message describing the error in the expression. Null if expression is ok. Message may also say that expression is null.
    • createInstanceFrom

      protected com.inet.taskplanner.server.api.trigger.cron.CronTrigger createInstanceFrom(TriggerDefinition definition, com.inet.id.GUID taskID)
      Constructs a component (PRODUCT) from the given definition.
      Overrides:
      createInstanceFrom in class AbstractFactory<com.inet.taskplanner.server.api.trigger.cron.CronTrigger, TriggerDefinition, TriggerInfo, SummaryInfo>
      Parameters:
      definition - the definition holding information for the PRODUCT
      taskID - the ID of the task the definition belongs or will belong to, for optional use. Can be null if the operation is done for a non-saved task.
      Returns:
      a new PRODUCT
    • getSummary

      public SummaryInfo getSummary(TriggerDefinition definition)
      Constructs summary information for the component represented by the given definition.

      The summary information is used when the web GUI displays the component.

      When implementing a factory for a component to be used only through the API, you can return null here.

      Specified by:
      getSummary in class AbstractFactory<com.inet.taskplanner.server.api.trigger.cron.CronTrigger, TriggerDefinition, TriggerInfo, SummaryInfo>
      Parameters:
      definition - the definition with the settings made by a user
      Returns:
      summary information containing text lines to be displayed in the web GUI for this component.
    • getNextExecutionTimes

      public List<ZonedDateTime> getNextExecutionTimes(TriggerDefinition definition)
      Returns the calculated times of the next executions. If the trigger is, for example, event-based and does not provide a time, null is returned. If a time-based trigger is configured incorrectly or has no future executions, an empty list is returned.
      Overrides:
      getNextExecutionTimes in class TriggerFactory<com.inet.taskplanner.server.api.trigger.cron.CronTrigger>
      Parameters:
      definition - the current definition where to get the next executions for
      Returns:
      the calculated times of the next executions. Normally three future executions are returned, or fewer if there are not three more from now.
    • getNextExecutionsAsSummary

      public static List<SummaryEntry> getNextExecutionsAsSummary(List<ZonedDateTime> nextExecutions)
      FOR INTERNAL USE ONLY. Creates a list of summary entries for the supplied next-execution dates.
      Parameters:
      nextExecutions - list of next execution dates to get the summary text for
      Returns:
      a list of summary entries; it is empty when the supplied list is empty
      See Also:
    • getNextExecutionsForCronExpression

      public static List<ZonedDateTime> getNextExecutionsForCronExpression(String cronExpression)
      FOR INTERNAL USE ONLY. Get the date of the next executions for the given cron expression from now.
      Parameters:
      cronExpression - the expression to analyse
      Returns:
      a list of future executions; can be empty if there are no future executions or the expression is invalid or null.
    • getNextExecutionsForCronExpression

      public static List<ZonedDateTime> getNextExecutionsForCronExpression(String cronExpression, ZonedDateTime startDate, @Nullable Predicate<ZonedDateTime> acceptDate)
      FOR INTERNAL USE ONLY. Gets the dates of the next executions for the given cron expression, starting from the given date.
      Parameters:
      cronExpression - the expression to analyse
      startDate - date from which to find the next executions
      acceptDate - optional filter which will be applied on next execution date. Each next execution will be checked with this, and if the filter declines a date, that date will not be used as a next execution date. It continues until enough next dates have passed the filter. BEWARE of possible endless loops!
      Returns:
      a list of future executions; can be empty if there are no future executions or the expression is invalid or null.