WorkflowScript.java

  1. /*
  2.  * This software was designed and created by Jason Carroll.
  3.  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
  4.  * The author can be reached at jcarroll@cowsultants.com
  5.  * ITracker website: http://www.cowsultants.com
  6.  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it only under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  */

  18. package org.itracker.model;

  19. import org.apache.commons.lang.builder.ToStringBuilder;

  20. /**
  21.  * A BeanShell script to execute on a particular event.
  22.  * <p> The script is interpreted on it's event fired<br />
  23.  * in the environment there is available:</p>
  24.  * <ul> <li>event (event type-id)
  25.  * </li><li>fieldId (is a field id associated with event)
  26.  * </li><li>currentValue (is a set of current values)
  27.  * </li><li>currentErrors (is a container for occurred errors)
  28.  * </li><li>currentForm (is a form instance, holding values)
  29.  * </li> </ul>
  30.  * <p>
  31.  * currentValue will be applied to the currentForm, property field</p>
  32.  * </p>
  33.  * <p>
  34.  * This allows to dynamically customize the system by executing custom actions
  35.  * at given extension points where an event is generated.
  36.  * </p>
  37.  * <p>
  38.  * A WorkflowScript needs to be configured to be executed for a particular field
  39.  * of a Project. This configuration is represented as a ProjectScript. <br>
  40.  * WorkflowScript - ProjectScript is a 1-N relationship.
  41.  * </p>
  42.  *
  43.  * @author ready
  44.  * @see ProjectScript
  45.  */
  46. public class WorkflowScript extends AbstractEntity {

  47.     /**
  48.      *
  49.      */
  50.     private static final long serialVersionUID = 1L;

  51.     public enum ScriptLanguage {
  52.         BeanShell,
  53.         Groovy
  54.     }
  55.     private String name;

  56.     private String script;

  57.     private int event;

  58.     // TODO: what's the expected type here?
  59.     // private Collection projectFields;
  60.     private int numUses;

  61.     private ScriptLanguage language;
  62.     /*
  63.       * This class used to have a <code>projectFields</code> attribute, which
  64.       * was a Collection<ProjectScript>. This has been removed because the
  65.       * association WorkflowScript - ProjectScript doesn't need to be navigatable
  66.       * in this direction.
  67.       */

  68.     public int getEvent() {
  69.         return event;
  70.     }

  71.     public void setEvent(int event) {
  72.         this.event = event;
  73.     }

  74.     public String getName() {
  75.         return name;
  76.     }

  77.     public void setName(String name) {
  78.         this.name = name;
  79.     }

  80.     /*
  81.       * public Collection getProjectFields() { return projectFields; }
  82.       *
  83.       * public void setProjectFields(Collection projectFields) {
  84.       * this.projectFields = projectFields; }
  85.       */
  86.     public String getScript() {
  87.         return script;
  88.     }

  89.     public void setScript(String script) {
  90.         this.script = script;
  91.     }


  92.     public ScriptLanguage getLanguage() {
  93.         return language;
  94.     }

  95.     public void setLanguage(ScriptLanguage language) {
  96.         this.language = language;
  97.     }

  98.     @Override
  99.     public String toString() {
  100.         return new ToStringBuilder(this).append("id", getId()).append("name", getName())
  101.                 .append("event", getEvent()).append("language", getLanguage()).append(
  102.                         "script", getScript()).toString();
  103.     }

  104. }