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 java.io.Serializable;
22  import java.util.Comparator;
23  
24  import org.apache.commons.lang.builder.CompareToBuilder;
25  import org.apache.commons.lang.builder.ToStringBuilder;
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  	/**
36  	 * 
37  	 */
38  	private static final long serialVersionUID = 1L;
39  
40  	/**
41  	 * The Project for which the script must be executed.
42  	 */
43  	private Project project;
44  
45  	/**
46  	 * The ID of the built-in or custom field for which the script must be
47  	 * executed.
48  	 * 
49  	 * <p>
50  	 * If the ID represents a CustomField, then the CustomField should be
51  	 * configured for the Project or the script will never be executed.
52  	 * </p>
53  	 */
54  	private Integer fieldId;
55  
56  	/** The Beanshell script to execute. */
57  	private WorkflowScript script;
58  
59  	private int priority;
60  
61  	/**
62  	 * Default constructor (required by Hibernate).
63  	 * 
64  	 * <p>
65  	 * PENDING: should be <code>private</code> so that it can only be used by
66  	 * Hibernate, to ensure that the fields which form an instance's identity
67  	 * are always initialized/never <tt>null</tt>.
68  	 * </p>
69  	 */
70  	public ProjectScript() {
71  	}
72  
73  	public Project getProject() {
74  		return project;
75  	}
76  
77  	public void setProject(Project project) {
78  		this.project = project;
79  	}
80  
81  	public WorkflowScript getScript() {
82  		return script;
83  	}
84  
85  	public void setScript(WorkflowScript script) {
86  		this.script = script;
87  	}
88  
89  	public Integer getFieldId() {
90  		return fieldId;
91  	}
92  
93  	public void setFieldId(Integer fieldId) {
94  		this.fieldId = fieldId;
95  	}
96  
97  	public int getPriority() {
98  		return priority;
99  	}
100 
101 	public void setPriority(int priority) {
102 		this.priority = priority;
103 	}
104 
105 	public static class FieldPriorityComparator implements
106 			Comparator<ProjectScript>, Serializable {
107 		/**
108 		 * 
109 		 */
110 		private static final long serialVersionUID = 1L;
111 
112 		public int compare(ProjectScript a, ProjectScript b) {
113 			
114 			return new CompareToBuilder().append(a.getFieldId(), b.getFieldId()).append(a.getPriority(), b.getPriority()).toComparison();
115 		}
116 
117 	}
118 
119 	@Override
120 	public String toString() {
121 		return new ToStringBuilder(this).append("id", getId()).append("script", getScript()).append(
122 				"fieldId", getFieldId()).append("priority", getPriority()).append(
123 				"project", getProject()).toString();
124 	}
125 
126 }