Source code: com/flexstor/common/gateway/CheckOutCheckInGateway.java
1 /*
2 * CheckOutCheckInGateway.java
3 *
4 * Copyright $Date: 2003/08/11 02:22:29 $ FLEXSTOR.net Inc.
5 *
6 * This work is licensed for use and distribution under license terms found at
7 * http://www.flexstor.org/license.html
8 *
9 */
10
11 package com.flexstor.common.gateway;
12
13 import com.flexstor.common.data.ActionData;
14 import com.flexstor.common.data.AssetRecordData;
15 import com.flexstor.common.gateway.debug.GatewayDebugOutput;
16 import com.flexstor.common.gateway.exceptions.TransactionFailedException;
17 import com.flexstor.ejb.EjbObject;
18 import com.flexstor.ejb.checkincheckout.persist.CheckInCheckOut;
19 import com.flexstor.ejb.checkincheckout.persist.CheckInCheckOutHome;
20
21
22 public class CheckOutCheckInGateway
23 extends Gateway
24 {
25 // MKS macro expander
26 public final static String IDENTIFIER = "$Id: CheckOutCheckInGateway.java,v 1.3 2003/08/11 02:22:29 aleric Exp $";
27
28 private CheckInCheckOut bean;
29
30 protected String getHomeName ( )
31 {
32 return CHECK_IN_CHECK_OUT_HOME;
33 }
34
35 protected EjbObject getBeanObject ( )
36 {
37 return bean;
38 }
39
40 public void connect ( )
41 throws TransactionFailedException
42 {
43 try
44 {
45 if ( canLoadObject() )
46 return;
47
48 CheckInCheckOutHome home = (CheckInCheckOutHome)getHome ( );
49
50 GatewayDebugOutput.println ( 3, "Getting CheckInCheckOutPersist object" );
51 bean = home.create();
52 }
53 catch ( Throwable e )
54 {
55 throw buildException(e, "Connecting to CheckInCheckOut", IDENTIFIER );
56 }
57 }
58
59 /**
60 * Checks out assets.
61 * @param data the check out data.
62 */
63 public void checkOutAssets ( ActionData data )
64 throws TransactionFailedException
65 {
66 try
67 {
68 if ( canLoadObject() )
69 return;
70
71 GatewayDebugOutput.println ( 3, "Checking out assets." );
72 bean.checkOutAssets ( data );
73 }
74 catch ( Throwable e )
75 {
76 throw buildException(e, "Checking Out Assets", IDENTIFIER );
77 }
78 }
79
80 /**
81 * Checks in assets. This call will create the necessary rows to ALL_ASSET_RECORD
82 * and the [ROLE] tables for the new version asset to insert; it will not change
83 * the status of the asset to checked in
84 * @param data the check in data.
85 * @see updateCheckInStatus
86 */
87 public void checkInAssets ( ActionData data )
88 throws TransactionFailedException
89 {
90 try
91 {
92 if ( canLoadObject() )
93 return;
94
95 GatewayDebugOutput.println ( 3, "Checking in assets." );
96 bean.checkInAssets ( data );
97 }
98 catch ( Throwable e )
99 {
100 throw buildException(e, "Checking In Assets", IDENTIFIER );
101 }
102 }
103
104 /**
105 * Update the status of the asset to checked in.
106 * A call to checkInAssets must be done before this call.
107 * @param data the check in data.
108 * @see checkInAssets
109 */
110 public void updateCheckInStatus ( ActionData data )
111 throws TransactionFailedException
112 {
113 try
114 {
115 if ( canLoadObject() )
116 return;
117
118 GatewayDebugOutput.println ( 3, "Updating assets to checked-in status." );
119 bean.updateCheckInStatus ( data );
120 }
121 catch ( Throwable e )
122 {
123 throw buildException(e, "Updating Check In Status", IDENTIFIER );
124 }
125 }
126
127 /**
128 * Cancels a check out assets (undo checkout).
129 * @param ids an array of asset ids.
130 */
131 public void cancelCheckOutAssets ( ActionData data )
132 throws TransactionFailedException
133 {
134 try
135 {
136 if ( canLoadObject() )
137 return;
138
139 GatewayDebugOutput.println ( 3, "Canceling check out assets." );
140 bean.cancelCheckOutAssets ( data );
141 }
142 catch ( Throwable e )
143 {
144 throw buildException(e, "Canceling Check Out Assets", IDENTIFIER );
145 }
146 }
147
148 public AssetRecordData getDefaultViewAsset( AssetRecordData record )
149 throws TransactionFailedException
150 {
151 try
152 {
153 GatewayDebugOutput.println ( 3, "Getting default view asset" );
154
155 if ( canLoadObject() )
156 return (AssetRecordData) retrieveObject( "CheckInCheckOut_getDefaultViewAsset" );
157
158 AssetRecordData defaultViewAsset = bean.getDefaultViewAsset ( record );
159
160 if ( canSaveObject() )
161 storeObject( "CheckInCheckOut_getDefaultViewAsset", defaultViewAsset );
162
163 return defaultViewAsset;
164 }
165 catch ( Throwable e )
166 {
167 throw buildException(e, "Getting Default View Asset", IDENTIFIER );
168 }
169 }
170
171 /**
172 * This will get all children assets based upon an RecordId passed
173 * in to the method. This will populate a ActionData class
174 * with vars from the database.
175 *
176 * @return ActionData - A list of ChildrenRecordData objects
177 */
178 public ActionData getChildrenByAssetRole( int roleId, AssetRecordData record )
179 throws TransactionFailedException
180 {
181 try
182 {
183 GatewayDebugOutput.println ( 3, "Getting children by asset role" );
184
185 if ( canLoadObject() )
186 return (ActionData) retrieveObject( "CheckInCheckOut_getChildrenByAssetRole" );
187
188 ActionData data = bean.getChildrenByAssetRole ( roleId, record );
189
190 if ( canSaveObject() )
191 storeObject( "CheckInCheckOut_getChildrenByAssetRole", data );
192
193 return data;
194 }
195 catch ( Throwable e )
196 {
197 throw buildException(e, "Getting Children by Asset Role", IDENTIFIER );
198 }
199 }
200
201 /**
202 * Update assets status to In Process Check Out.
203 *
204 * @param naAssetIds ids of assets to change status for.
205 * @return ids of assets that could not be updated.
206 */
207 //public long[] updateToInProcessCheckOut( long[] naAssetIds )
208 public long[] updateToInProcessCheckOut( ActionData naAssetIds )
209 throws TransactionFailedException
210 {
211 try
212 {
213 if ( canLoadObject() )
214 return null;
215
216 GatewayDebugOutput.println ( 3, "Updating to In Process Check Out." );
217
218 return bean.updateToInProcessCheckOut( naAssetIds );
219 }
220 catch ( Throwable e )
221 {
222 throw buildException( e, "Updating to In Process Check Out", IDENTIFIER );
223 }
224 }
225
226 /**
227 * Rollback In Process Check Out status.
228 *
229 * @param naAssetIds ids of assets to rollback status for.
230 * @return ids of assets that could not be updated.
231 */
232 //public long[] rollbackInProcessCheckOut( long[] naAssetIds )
233 public long[] rollbackInProcessCheckOut( ActionData naAssetIds )
234 throws TransactionFailedException
235 {
236 try
237 {
238 if ( canLoadObject() )
239 return null;
240
241 GatewayDebugOutput.println ( 3, "Rolling back In Process Check Out." );
242
243 return bean.rollbackInProcessCheckOut( naAssetIds );
244 }
245 catch ( Throwable e )
246 {
247 throw buildException( e, "Rolling back In Process Check Out", IDENTIFIER );
248 }
249 }
250
251 /**
252 * Update assets status to In Process Check In.
253 *
254 * @param naAssetIds ids of assets to change status for.
255 * @return ids of assets that could not be updated.
256 */
257 //public long[] updateToInProcessCheckIn( long[] naAssetIds )
258 public long[] updateToInProcessCheckIn( ActionData naAssetIds )
259 throws TransactionFailedException
260 {
261 try
262 {
263 if ( canLoadObject() )
264 return null;
265
266 GatewayDebugOutput.println ( 3, "Updating to In Process Check In." );
267
268 return bean.updateToInProcessCheckIn( naAssetIds );
269 }
270 catch ( Throwable e )
271 {
272 throw buildException( e, "Updating To In Process Check In", IDENTIFIER );
273 }
274 }
275
276 /**
277 * Rollback In Process Check In status.
278 *
279 * @param naAssetIds ids of assets to rollback status for.
280 * @return ids of assets that could not be updated.
281 */
282 public long[] rollbackInProcessCheckIn( ActionData naAssetIds, boolean bDeleteNewVersion )
283 throws TransactionFailedException
284 {
285 try
286 {
287 if ( canLoadObject() )
288 return null;
289
290 GatewayDebugOutput.println ( 3, "Rolling back In Process Check In." );
291
292 return bean.rollbackInProcessCheckIn( naAssetIds, bDeleteNewVersion );
293 }
294 catch ( Throwable e )
295 {
296 throw buildException( e, "Rolling back In Process Check In", IDENTIFIER );
297 }
298 }
299
300
301 } // end of class