Class JobFactory<T extends Job>

  • Type Parameters:
    T - the concrete type of the Job implementation
    All Implemented Interfaces:
    com.inet.plugin.NamedExtension

    public abstract class JobFactory<T extends Job>
    extends SeriesDependentFactory<T,​JobDefinition,​JobInfo,​JobSummaryInfo>
    Base class for factories producing Job components.

               JobDefinition ----> JobFactory ----> Job
     
    See documentation of AbstractFactory for more information about the life cycle.

    When a factory is implemented, use ServerPluginManager.register(Class, Object) with JobFactory.class as first argument:

    spm.register(JobFactory.class, new MouseJobFactory());

    Implementations sample: because the extensionName must be unique and must be used when a JobDefinition is created by API, it is recommended to set up a public constant with the extensionName:

    
     public class MouseJobFactory extends JobFactory<MouseJob> {
          public static final String EXTENSION_NAME = "job.mouse";
    
          public MouseJobFactory(){
              super(EXTENSION_NAME);
          }
    
    
          @Override
          protected MouseJob createInstanceFrom( JobDefinition definition, GUID taskID ) {
              MouseJob job = new MouseJob();
              //put values from definition to job impl
              ...
    
              return job;
          }
    
          ...
          //somewhere using public API
          JobDefinition mouseJob = new JobDefinition(MouseJobFactory.EXTENSION_NAME);
          //configure it
          ...
    
     
    Since:
    taskplanner 3.0
    • Constructor Detail

      • JobFactory

        public JobFactory​(java.lang.String extensionName)
        Creates a new JobFactory instance.
        Parameters:
        extensionName - the unique extensionName for this Job.
        Since:
        taskplanner 3.0
    • Method Detail

      • getResultFlavors

        public abstract java.util.List<ResultFlavor> getResultFlavors​(JobDefinition definition)
        Returns the list of supported flavors.
        Parameters:
        definition - the definition with the settings made by a user
        Returns:
        the list of supported flavors.
        Since:
        taskplanner 3.0
      • validateCondition

        public final void validateCondition​(@Nonnull
                                            JobDefinition definition,
                                            @Nullable
                                            SeriesDefinition seriesDefinition,
                                            @Nullable
                                            com.inet.id.GUID taskID)
                                     throws ValidationException
        Validate the given condition.

        The given definition is guaranteed to belong to this factory

        Parameters:
        definition - definition of the job to validate
        seriesDefinition - the series which the user have configured, if any
        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 configured condition is not valid
        Since:
        taskplanner 3.0
      • patchDefinitionProperties

        protected final JobDefinition patchDefinitionProperties​(JobDefinition baseDefinition,
                                                                java.util.Map<java.lang.String,​java.lang.String> seriesProperties,
                                                                @Nullable
                                                                com.inet.id.GUID taskID)
        Patch the properties of the given baseDefinition with properties from the seriesProperties.

        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. Sth like {path} will be replaced with the value of a property 'path'. If no property 'path' exists then the placeholder is replaced with empty string.

        Overrides:
        patchDefinitionProperties in class SeriesDependentFactory<T extends Job,​JobDefinition,​JobInfo,​JobSummaryInfo>
        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
      • validateCondition

        protected abstract void validateCondition​(@Nonnull
                                                  JobDefinition definition)
                                           throws ValidationException
        Validate the condition. This is only called if a condition is set.
        Parameters:
        definition - definition of the job to validate. This already has patched properties from series if any.
        Throws:
        ValidationException - if the configured condition is not valid
        Since:
        taskplanner 3.0