ProjectScript.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.CompareToBuilder;
  20. import org.apache.commons.lang.builder.ToStringBuilder;

  21. import java.io.Serializable;
  22. import java.util.Comparator;

  23. /**
  24.  * A Beanshell script configured to be executed for a specific Project field.
  25.  *
  26.  * @author ready
  27.  */
  28. public class ProjectScript extends AbstractEntity {

  29.     public static final FieldPriorityComparator FIELD_PRIORITY_COMPARATOR = new FieldPriorityComparator();
  30.     public static final FieldPriorityComparator PRIORITY_COMPARATOR = new FieldPriorityComparator();
  31.     /**
  32.      *
  33.      */
  34.     private static final long serialVersionUID = 1L;

  35.     /**
  36.      * The Project for which the script must be executed.
  37.      */
  38.     private Project project;

  39.     /**
  40.      * The ID of the built-in or custom field for which the script must be
  41.      * executed.
  42.      * <p/>
  43.      * <p>
  44.      * If the ID represents a CustomField, then the CustomField should be
  45.      * configured for the Project or the script will never be executed.
  46.      * </p>
  47.      */
  48.     private Integer fieldId;
  49.     private Configuration.Type fieldType;

  50.     /**
  51.      * The Beanshell script to execute.
  52.      */
  53.     private WorkflowScript script;

  54.     private int priority;

  55.     /**
  56.      * Default constructor (required by Hibernate).
  57.      * <p/>
  58.      * <p>
  59.      * PENDING: should be <code>private</code> so that it can only be used by
  60.      * Hibernate, to ensure that the fields which form an instance's identity
  61.      * are always initialized/never <tt>null</tt>.
  62.      * </p>
  63.      */
  64.     public ProjectScript() {
  65.     }

  66.     public Project getProject() {
  67.         return project;
  68.     }

  69.     public void setProject(Project project) {
  70.         this.project = project;
  71.     }

  72.     public WorkflowScript getScript() {
  73.         return script;
  74.     }

  75.     public void setScript(WorkflowScript script) {
  76.         this.script = script;
  77.     }

  78.     public Integer getFieldId() {
  79.         return fieldId;
  80.     }

  81.     public void setFieldId(Integer fieldId) {
  82.         this.fieldId = fieldId;
  83.     }

  84.     public int getPriority() {
  85.         return priority;
  86.     }

  87.     public void setPriority(int priority) {
  88.         this.priority = priority;
  89.     }

  90.     public Configuration.Type getFieldType() {
  91.         return fieldType;
  92.     }

  93.     public void setFieldType(Configuration.Type fieldType) {
  94.         this.fieldType = fieldType;
  95.     }

  96.     public static class FieldPriorityComparator implements
  97.             Comparator<ProjectScript>, Serializable {
  98.         /**
  99.          *
  100.          */
  101.         private static final long serialVersionUID = 1L;

  102.         public int compare(ProjectScript a, ProjectScript b) {

  103.             return new CompareToBuilder().append(a.getFieldId(), b.getFieldId()).append(a.getPriority(), b.getPriority()).toComparison();
  104.         }

  105.     }
  106.     public static class ScriptPriorityComparator implements
  107.                 Comparator<ProjectScript>, Serializable {
  108.             /**
  109.              *
  110.              */
  111.             private static final long serialVersionUID = 1L;

  112.             public int compare(ProjectScript a, ProjectScript b) {

  113.                 return new CompareToBuilder().append(a.getPriority(), b.getPriority()).toComparison();
  114.             }

  115.         }


  116.     @Override
  117.     public String toString() {
  118.         return new ToStringBuilder(this).append("id", getId()).append("script", getScript()).append(
  119.                 "fieldId", getFieldId()).append("priority", getPriority()).append(
  120.                 "project", getProject()).toString();
  121.     }

  122. }