View Javadoc
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  
19  package org.itracker.model;
20  
21  import org.apache.commons.lang.builder.CompareToBuilder;
22  import org.apache.commons.lang.builder.ToStringBuilder;
23  
24  import java.io.Serializable;
25  import java.util.Comparator;
26  
27  /**
28   * A Beanshell script configured to be executed for a specific Project field.
29   *
30   * @author ready
31   */
32  public class ProjectScript extends AbstractEntity {
33  
34      public static final FieldPriorityComparator FIELD_PRIORITY_COMPARATOR = new FieldPriorityComparator();
35      public static final FieldPriorityComparator PRIORITY_COMPARATOR = new FieldPriorityComparator();
36      /**
37       *
38       */
39      private static final long serialVersionUID = 1L;
40  
41      /**
42       * The Project for which the script must be executed.
43       */
44      private Project project;
45  
46      /**
47       * The ID of the built-in or custom field for which the script must be
48       * executed.
49       * <p/>
50       * <p>
51       * If the ID represents a CustomField, then the CustomField should be
52       * configured for the Project or the script will never be executed.
53       * </p>
54       */
55      private Integer fieldId;
56      private Configuration.Type fieldType;
57  
58      /**
59       * The Beanshell script to execute.
60       */
61      private WorkflowScript script;
62  
63      private int priority;
64  
65      /**
66       * Default constructor (required by Hibernate).
67       * <p/>
68       * <p>
69       * PENDING: should be <code>private</code> so that it can only be used by
70       * Hibernate, to ensure that the fields which form an instance's identity
71       * are always initialized/never <tt>null</tt>.
72       * </p>
73       */
74      public ProjectScript() {
75      }
76  
77      public Project getProject() {
78          return project;
79      }
80  
81      public void setProject(Project project) {
82          this.project = project;
83      }
84  
85      public WorkflowScript getScript() {
86          return script;
87      }
88  
89      public void setScript(WorkflowScript script) {
90          this.script = script;
91      }
92  
93      public Integer getFieldId() {
94          return fieldId;
95      }
96  
97      public void setFieldId(Integer fieldId) {
98          this.fieldId = fieldId;
99      }
100 
101     public int getPriority() {
102         return priority;
103     }
104 
105     public void setPriority(int priority) {
106         this.priority = priority;
107     }
108 
109     public Configuration.Type getFieldType() {
110         return fieldType;
111     }
112 
113     public void setFieldType(Configuration.Type fieldType) {
114         this.fieldType = fieldType;
115     }
116 
117     public static class FieldPriorityComparator implements
118             Comparator<ProjectScript>, Serializable {
119         /**
120          *
121          */
122         private static final long serialVersionUID = 1L;
123 
124         public int compare(ProjectScript../../../org/itracker/model/ProjectScript.html#ProjectScript">ProjectScript a, ProjectScript b) {
125 
126             return new CompareToBuilder().append(a.getFieldId(), b.getFieldId()).append(a.getPriority(), b.getPriority()).toComparison();
127         }
128 
129     }
130     public static class ScriptPriorityComparator implements
131                 Comparator<ProjectScript>, Serializable {
132             /**
133              *
134              */
135             private static final long serialVersionUID = 1L;
136 
137             public int compare(ProjectScript../../../org/itracker/model/ProjectScript.html#ProjectScript">ProjectScript a, ProjectScript b) {
138 
139                 return new CompareToBuilder().append(a.getPriority(), b.getPriority()).toComparison();
140             }
141 
142         }
143 
144 
145     @Override
146     public String toString() {
147         return new ToStringBuilder(this).append("id", getId()).append("script", getScript()).append(
148                 "fieldId", getFieldId()).append("priority", getPriority()).append(
149                 "project", getProject()).toString();
150     }
151 
152 }