View Javadoc

1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.businessobjects.commons;
16  
17  import org.figure8.join.core.SortableEntityObject;
18  /**
19   * This is an entity representing an Integration process step.
20   * <br/>
21   * Steps and their position helps defining the integration process and thus
22   * the lifecycle of managed artifacts and environments.
23   * <br/>
24   * Steps may also help defining business and transition rules. e.g :
25   * an artifact may have to be deployed on an environment corresponding
26   * to step one "acceptance tests" before being deployed on another environment
27   * corresponding to step two "non regression tests".
28   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
29   * @version $Revision: 1.5 $
30   *
31   * @hibernate.class table="join_steps" lazy="false"
32   * @hibernate.cache usage="read-write"
33   *
34   * @hibernate.query name="join.step_findByLabel" query="from Step st where st.label = :stepLabel"
35   * @hibernate.query name="join.step_findByPosition" query="from Step st where st.position = :position"
36   */
37  public class Step extends SortableEntityObject{
38  
39     // Attributes ---------------------------------------------------------------
40  
41     /** The label of this step */
42     private String label;
43     /** The position of this step into the integration cycle */
44     private int position;
45  
46     /** The following step into the integration cycle (if any) */
47     private Step nextStep;
48     /** The previous step into the integration cycle (if any) */
49     private Step previousStep;
50  
51  
52     // Constructors -------------------------------------------------------------
53  
54     /** Creates a new instance of Step */
55     public Step(){
56     }
57  
58     /**
59      * Creates a new instance of Step with mandatory params.
60      * @param label This step label
61      * @param position This step position within integration cycle.
62      */
63     public Step(String label, int position){
64        this.label = label;
65        this.position = position;
66     }
67  
68  
69     // Public -------------------------------------------------------------------
70  
71     /**
72      * @hibernate.property column="s_label"
73      *    not-null="true" unique="true"
74      *    length="40"
75      * @return This release label
76      */
77     public String getLabel(){
78        return label;
79     }
80     /** @param label This step label */
81     public void setLabel(String label){
82        this.label = label;
83     }
84  
85     /**
86      * @hibernate.property column="n_position"
87      *    not-null="true"
88      * @return This position within cycle
89      */
90     public int getPosition(){
91        return position;
92     }
93     /** @param position The position in this step within integration cycle */
94     public void setPosition(int position){
95        this.position = position;
96     }
97  
98     /**
99      * @hibernate.many-to-one column="n_nextstep_fk"
100     *    cascade="save-update" unique="true"
101     * @return The next step within integration cycle
102     */
103    public Step getNextStep(){
104       return nextStep;
105    }
106    /** @param nextStep The next step within integration cycle */
107    public void setNextStep(Step nextStep){
108       this.nextStep = nextStep;
109    }
110 
111    /**
112     * @hibernate.many-to-one column="n_prevstep_fk"
113     *    cascade="save-update" unique="true"
114     * @return The previous step within integration cycle
115     */
116    public Step getPreviousStep(){
117       return previousStep;
118    }
119    /** @param previousStep The previous step within integration cycle */
120    public void setPreviousStep(Step previousStep){
121       Step old = this.previousStep;
122       this.previousStep = previousStep;
123       // Prevent infinite loops between setNext() and setPrevious().
124       if (previousStep != null && (old == null || previousStep.getPosition() != old.getPosition()))
125          previousStep.setNextStep(this);
126    }
127 
128    /** Shift the position of this step and its followers into integration process. */
129    public void shiftPosition(){
130       setPosition(position + 1);
131       if (getNextStep() != null)
132          getNextStep().shiftPosition();
133    }
134 
135 
136    // Implementation of Sortable -----------------------------------------------
137 
138    /**
139     * Get the comparision criterion as a string. Step position here.
140     * @return The string representation of comparison and sort cirterion
141     */
142    public String getStringForComparison(){
143       return String.valueOf(getPosition());
144    }
145 }