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.environment;
16
17 import org.figure8.join.core.EntityObject;
18 import org.figure8.join.businessobjects.commons.Step;
19 import org.figure8.join.businessobjects.commons.Release;
20
21 import java.util.List;
22 import java.util.ArrayList;
23 /**
24 * This is an entity representing a logical (or business/functional) view of an
25 * environment. A LogicalEnvironment is a place dedicated to the realization
26 * of a particular step of the integration process for a specific release.
27 * <br/>
28 * Such an environment will be bind/unbind by integration team members to a
29 * pool of managed physical environment (this one is a concrete one, composed
30 * of resources, gateway, machines, etc ...).
31 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
32 * @version $Revision: 1.2 $
33 *
34 * @see org.figure8.join.businessobjects.commons.Step
35 * @see org.figure8.join.businessobjects.commons.Release
36 *
37 * @hibernate.class table="join_logicalenvs"
38 * @hibernate.cache usage="read-write"
39 *
40 * @hibernate.query name="join.logicalenv_findByKey"
41 * query="from LogicalEnvironment env where env.key = :envKey"
42 */
43 public class LogicalEnvironment extends EntityObject{
44
45
46
47 /** This environment unique business key */
48 private String key;
49 /** This environment label */
50 private String label;
51 /** This environment description */
52 private String description;
53 /** This environment manager identifier */
54 private String managerId;
55 /** Is this environment active ? default is true */
56 private boolean active = true;
57 /** The list of active environment mappings (should be only one) */
58 private List activeMappings = new ArrayList();
59
60 /** The integration process step this environment is dedicated to */
61 private Step step;
62 /** The project release this environment is dedicated to */
63 private Release release;
64
65
66
67
68 /** Creates a new LogicalEnvironment */
69 public LogicalEnvironment(){
70 }
71
72 /**
73 * Creates a new LogicalEnvironment with mandatory attribute
74 * @param key This environment unique key
75 * @param label This environment label
76 * @param description This environment description
77 * @param managerId The unique identifier environment manager
78 * @param step The integration cycle step this environment is dedicated to
79 * @param release The project release this environment is dedicated to
80 */
81 public LogicalEnvironment(String key, String label, String description,
82 String managerId, Step step, Release release){
83 this.key = key;
84 this.label = label;
85 this.description = description;
86 this.managerId = managerId;
87
88 this.step = step;
89 this.release = release;
90 }
91
92
93
94
95 /**
96 * @hibernate.property column="s_key"
97 * not-null="true" unique="true"
98 * update="false" length="10"
99 * @return This environment business key
100 */
101 public String getKey(){
102 return key;
103 }
104 /** @param key This environment business key (should be uique) */
105 public void setKey(String key){
106 this.key = key;
107 }
108
109 /**
110 * @hibernate.property column="s_label"
111 * not-null="true" unique="true"
112 * length="40"
113 * @return This environment label
114 */
115 public String getLabel(){
116 return label;
117 }
118 /** @param label This environment label */
119 public void setLabel(String label){
120 this.label = label;
121 }
122
123 /**
124 * @hibernate.property column="s_description"
125 * not-null="true" length="200"
126 * @return This environment description
127 */
128 public String getDescription(){
129 return description;
130 }
131 /** @param description This environment description */
132 public void setDescription(String description){
133 this.description = description;
134 }
135
136 /**
137 * @hibernate.property column="s_managerid"
138 * length="20" not-null="true"
139 * @return The identifier of user managing this environment
140 */
141 public String getManagerId(){
142 return managerId;
143 }
144 /** @param managerId The identifier of user managin this environment */
145 public void setManagerId(String managerId){
146 this.managerId = managerId;
147 }
148
149 /**
150 * @hibernate.property column="b_active" not-null="true"
151 * @return Is this environment active ?
152 */
153 public boolean isActive(){
154 return active;
155 }
156 /** @param active The active flag for this environment */
157 public void setActive(boolean active){
158 this.active = active;
159 }
160 /** @return Is this environment active ? */
161 public boolean getActive(){
162 return active;
163 }
164
165 /**
166 * @hibernate.many-to-one column="n_step_fk"
167 * not-null="true" foreign-key="n_id"
168 * @return The integration process step this environment is dedicated to
169 */
170 public Step getStep(){
171 return step;
172 }
173 /** @param step The integration process step for this environment */
174 public void setStep(Step step){
175 this.step = step;
176 }
177
178 /**
179 * @hibernate.many-to-one column="n_release_fk"
180 * not-null="true" foreign-key="n_id"
181 * @return The project release this environment is dedicated to
182 */
183 public Release getRelease(){
184 return release;
185 }
186 /** @param release The project release this environment is dedicated to */
187 public void setRelease(Release release){
188 this.release = release;
189 }
190
191 /**
192 * @hibernate.bag cascade="save-update" lazy="true" inverse="true"
193 * where="d_end is null" order-by="d_start desc"
194 * @hibernate.collection-key column="n_logicalenv_fk"
195 * @hibernate.collection-one-to-many class="org.figure8.join.businessobjects.environment.EnvironmentMapping"
196 * @return A set of {@code EnvironmentMapping}s that are active now
197 */
198 public List getActiveEnvironmentMappings(){
199 return activeMappings;
200 }
201 /** @param mappings The set of {@code EnvironmentMapping}s that are active now */
202 public void setActiveEnvironmentMappings(List mappings){
203 this.activeMappings = mappings;
204 }
205
206 /**
207 * Get the most recent active EnvironmentMapping for this environment
208 * @return The last mapping that has been created
209 */
210 public EnvironmentMapping getActiveEnvironmentMapping(){
211
212 List actives = getActiveEnvironmentMappings();
213 if (actives.isEmpty()) return null;
214
215 return (EnvironmentMapping)actives.get(0);
216 }
217 /** @param mapping The EnvironmentMapping to use as current active mapping */
218 public void setActiveEnvironmentMapping(EnvironmentMapping mapping){
219 closeActiveEnvironmentMappings();
220 activeMappings.add(mapping);
221 }
222
223
224
225
226 /** Close the current active environment mappings */
227 private void closeActiveEnvironmentMappings(){
228
229 for (int i=0; i<activeMappings.size(); i++){
230 EnvironmentMapping mapping = (EnvironmentMapping)activeMappings.get(i);
231 mapping.close();
232 }
233 }
234 }