Class ScriptPackage

java.lang.Object
overit.geocall.platform.Package
overit.geocall.platform.ScriptPackage
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
FsmAssetsScripts, FsmBundlerScripts, FsmExecutionScripts, FsmForecastCapacityScripts, FsmGPSTrackingScripts, FsmInventoryScripts, FsmLocationsScripts, FsmMaterialsScripts, FsmMobileFormsScripts, FsmOrganizationalStructuressScripts, FsmRoughPlanningScripts, FsmSchedulingScripts, FsmSkillScripts, FsmWorkOrdersScripts, WfmAiScripts, WfmCeeScripts, WfmProjectScripts

public class ScriptPackage extends Package
This class defines a script package, i.e. a package that containing the sql scripts, used for the definition of the data model that each layer/module contributes to enriching.
Each layer can contain a script package or, in case it is divided into application modules, it can contain as many script packages as modules.
Each layer/module does not necessarily must have a script package; in case the functionalities do not require to enrich the data model already available, the definition of a script package is not necessary.

When scripts are applied, they are executed in the order defined by the SQL file name; sql files must be named with the following format
<major>.<minor>.<patch>.<sequence>.sql
(the sequence is optional). This allows you to run scripts with lower versioning first.
However, the life cycle of the modules foresees a progressive advancement of the scripts, and therefore their application must take into account not only the versioning within a single package, but also any dependencies between modules.
For example, if the package A contains the following scripts
  • 1.0.0.sql
  • 1.1.0.sql
  • 1.1.1.sql
And module B, dependent on A, contains the following scripts
  • 1.0.0.sql
  • 1.0.1.sql
  • 1.1.0.sql
the overall execution order will be:
  • 1.0.0.sql - module A
  • 1.0.0.sql - module B
  • 1.0.1.sql - module B
  • 1.1.0.sql - module A
  • 1.1.0.sql - module B
  • 1.1.1.sql - module A
It is possible to define a script package by creating a ScriptPackage extension indicating a name that uniquely identify the package within the layer, a list of dependencies from other packages and eventually the position of the package. Remember to annotate the class with the @Provider annotation.

 package overit.geocallapp.wfm.core.scripts;

 {@literal @}Provider
 public class CoreScriptPackage extends ScriptPackage {
   public CoreScriptPackage() {
       super("core");
   }
 }
 
The example above shows how to define a package script, called core, whose sql files are placed within the package overit.geocallapp.wfm.core.scripts.

 package overit.geocallapp.wfm.cee.scripts;

 {@literal @}Provider
 public class CEEScriptPackage extends ScriptPackage {
   public CEEScriptPackage() {
       super("cee");
       addDependency(CoreScriptPackage.class);
   }
 }
 
The example above shows the definition of another script package, belonging to the CEE module of the same layer, which defines a dependency on the script package described in the previous example.

Or you can define a script package programmatically by creating a new instance of ScriptPackage and registering it by calling the Layer.addScriptPackage(ScriptPackage) method.

 ScriptPackage scriptPackage = new ScriptPackage("cee", "overit/geocallapp/wfm/cee/scripts/");
 scriptPackage.addDependency(CoreScriptPackage.class);
 layer.addScriptPackage(scriptPackage);
 
The association between ScriptPackage and Layer occurs automatically as long as the class that defines its implementation:
  • is positioned within the domain defined by the Layer
  • contains the annotation @Provider
See Also:
  • Field Details

    • owner

      protected Layer owner
  • Constructor Details

    • ScriptPackage

      protected ScriptPackage(String name)
      Create a new script package by specifying name. This constructor can be called from class extensions, instead of ScriptPackage(String, String), because it is easier to use since the package containing the scripts is automatically calculated according to the subclass package.
      Parameters:
      name - string that uniquely identifies the package. Null value is not allowed.
    • ScriptPackage

      public ScriptPackage(String name, String position)
      Create a new script package by specifying its name and position. The position directories must be separated with the / character, it must start without the / character and must end with.
      The following example shows the definition of a new script package, called core, whose sql file is positioned inside the overit.geocallapp.wfm.scripts package
      
       ScriptPackage scriptPackage = new ScriptPackage("core", "overit/geocallapp/wfm/scripts/");
       
      Parameters:
      name - string that uniquely identifies the package. Null value is not allowed.
      position - path that identifies the position of the script package, i.e. the directory that contains the sql script files. Null value is not allowed.
  • Method Details

    • getOwner

      public Layer getOwner()
      Returns:
      the layer that this package belongs to or null if the package has not yet been registered to any layer
    • setOwner

      protected void setOwner(Layer owner)
      Set the layer that this package belongs to.
      Parameters:
      owner - the owner layer
    • addDependency

      @SafeVarargs public final void addDependency(Class<? extends ScriptPackage>... dependency)
      Adds the dependency of the current package to the script package identified by the classes passed as a parameter. Any class for which there is no correspondence with any other registered script packages will not be taken into account.
      Parameters:
      dependency - classes of the script packages towards which to define a dependency
    • addDependency

      public final void addDependency(String... dependency)
      Adds the dependency of the current package to the script package identified by the names passed as a parameter. Any names for which there is no correspondence with any other registered script packages will not be taken into account.
      Parameters:
      dependency - names of the script packages towards which to define a dependency
    • getLayerName

      public String getLayerName()
      Returns the name of the layer that this package belongs to
      Returns:
      the name of the layer that this package belongs to. If the layer is the BasicLayer, returns "geocall"
    • getDependencies

      public Set<ScriptPackage> getDependencies()
      Get the ordered list of the script packages that this depends from
      Returns:
      the list of the script packages that this depends from, ordered according to the specified dependencies. If this package has no dependencies, empty set will be returned.
    • dependsBy

      public final boolean dependsBy(ScriptPackage other)
      Check if the current script package depends from the one passed as parameter
      Parameters:
      other - the instance of the package with which to check the dependency
      Returns:
      true if this package depends from the other; false otherwise
    • listContent

      public Set<String> listContent()
      Get the list with the sql file's name contained inside the current package
      Returns:
      the list with the sql file's name contained inside the current package, or an empty set if the folder doesn't contains any file.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Package
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Package