Class SeriesDependentFactory<COMPONENT, DEFINITION extends AbstractDefinition<DEFINITION>, INFO extends AbstractInfo, SUMMARY extends SummaryInfo>

java.lang.Object
com.inet.taskplanner.server.api.common.AbstractFactory<COMPONENT, DEFINITION, INFO, SUMMARY>
com.inet.taskplanner.server.api.common.SeriesDependentFactory<COMPONENT, DEFINITION, INFO, SUMMARY>
All Implemented Interfaces:
com.inet.plugin.NamedExtension
Direct Known Subclasses:
JobFactory, ResultActionFactory

public abstract class SeriesDependentFactory<COMPONENT, DEFINITION extends AbstractDefinition<DEFINITION>, INFO extends AbstractInfo, SUMMARY extends SummaryInfo> extends AbstractFactory<COMPONENT, DEFINITION, INFO, SUMMARY>
Factory for components whose properties depend on a Series that the user may have configured. These are jobs and result actions. This factory changes or updates the properties of the definition before being passed to implementation methods.

For validation, the possibly configured SeriesDefinition is also required. Validation then validates the component's patched properties with the first set of the series properties.

For component instantiation, the current property set from the series is required. The implementation's AbstractFactory.createInstanceFrom(AbstractDefinition, GUID) method then receives a definition with already patched or updated properties.

Since:
taskplanner 3.0
  • Field Details

    • PLACEHOLDER_START_CHARACTER

      public static final String PLACEHOLDER_START_CHARACTER
      The official start character of placeholder
      See Also:
    • PLACEHOLDER_END_CHARACTER

      public static final String PLACEHOLDER_END_CHARACTER
      The official end character of placeholder
      See Also:
  • Constructor Details

    • SeriesDependentFactory

      public SeriesDependentFactory(String extensionName)
      Creates a new SeriesDependentFactory instance.
      Parameters:
      extensionName - unique name for this kind of components
      Since:
      taskplanner 3.0
  • Method Details

    • validate

      public final void validate(@Nonnull DEFINITION definition, @Nullable SeriesDefinition seriesDefinition, @Nullable com.inet.id.GUID taskID) throws ValidationException
      Validates the given definition. This takes the first set from the series, patches the definition's properties, and validates the patched definition.

      Patch and Replacement:
      Placeholders in the properties will be replaced. For example, {path} will be replaced with the value of a property 'path'. If no property 'path' exists then the placeholder is not replaced. This replacement is only done for properties having a field in AbstractFactory.getInformation(GUID).

      The original definition object is not changed.

      Parameters:
      definition - the definition to validate
      seriesDefinition - the series definition if one exists. If null, then no properties are added and no placeholders are replaced (also not with empty string).
      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
      Since:
      taskplanner 3.0
    • updateValues

      public final @Nullable Map<String,String> updateValues(@Nonnull DEFINITION definition, @Nullable SeriesDefinition seriesDefinition, com.inet.id.GUID taskID)
      Updates values according to the given definition. This takes the first set from the series, patches the definition's properties, and then updates the values.

      Patch and Replacement:
      Placeholders in the properties will be replaced. For example, {path} will be replaced with the value of a property 'path'. If no property 'path' exists then the placeholder is not replaced. This replacement is only done for properties having a field in AbstractFactory.getInformation(GUID).

      The original definition object is not changed.

      The given definition is guaranteed to belong to this factory.

      Parameters:
      definition - the definition with the current properties
      seriesDefinition - the series definition if one exists. If null, then no placeholders are replaced.
      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
      Since:
      taskplanner 3.0
    • updateValues

      public @Nullable Map<String,String> updateValues(@Nonnull DEFINITION patchedDefinition, @Nullable DEFINITION unpatchedDefinition, @Nullable SeriesDefinition seriesDefinition, @Nonnull com.inet.id.GUID taskID)
      Updates values according to the given definition. This makes it possible to change values that are updated in the client, for example to perform time calculations and show the next executions.
      This method returns a map containing only changed values. Other values do not need to be added. If nothing should be changed, null can be returned. If values that are not patched by a series are required, the unpatchedDefinition can be used.

      The given definition is guaranteed to belong to this factory.

      Parameters:
      patchedDefinition - the definition with the current properties, patched with the first data set from the series, if available
      unpatchedDefinition - the original definition with the current properties, null if no series is available.
      seriesDefinition - the series definition if one exists. If null, then no properties are added and no placeholders are replaced (including with an empty string).
      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
      Since:
      taskplanner 3.0
    • createFrom

      public @Nonnull COMPONENT createFrom(@Nonnull DEFINITION definition, @Nullable Map<String,String> seriesProperties, @Nullable com.inet.id.GUID taskID)
      Creates a concrete object to be used by TaskPlanner from the given definition.
      See validate(AbstractDefinition, SeriesDefinition, GUID) for what is patched and replaced.
      Parameters:
      definition - holds information about the component to create
      seriesProperties - set of properties for the current series, if there is one. Properties of the definition will be patched with this. If null, then nothing is replaced or patched.
      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:
      the created component
      Throws:
      IllegalArgumentException - if definition is null or the definition's extension name does not match this factory's extension name.
      Since:
      taskplanner 3.0
      See Also:
    • getFirstValueFromSeries

      protected @Nonnull Map<String,String> getFirstValueFromSeries(@Nonnull SeriesDefinition series, @Nullable com.inet.id.GUID taskID) throws IllegalStateException
      Get the first set of properties from the given series
      Parameters:
      series - the configured series
      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:
      the first set of properties from the series, not null. Can be empty if the series does not have any data or the first set has no properties.
      Throws:
      IllegalStateException - if the series definition is not valid
      Since:
      taskplanner 3.0
    • patchDefinitionProperties

      protected DEFINITION patchDefinitionProperties(@Nonnull DEFINITION baseDefinition, @Nonnull Map<String,String> seriesProperties, @Nullable com.inet.id.GUID taskID)
      Patches the properties of the given base definition with properties from the series properties.

      Patch and Replacement:
      Properties from seriesProperties will overwrite properties with the same name from the definition. Other new properties are added.
      Placeholders in the properties will be replaced. For example, {path} will be replaced with the value of a property 'path'. If no property 'path' exists then the placeholder is replaced with empty string.

      Parameters:
      baseDefinition - original definition from the model; this one will not be changed
      seriesProperties - properties from the current series set
      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 definition with patched properties
      Since:
      taskplanner 3.0