Source code: com/flexstor/common/gateway/CheckInGateway.java
1 /*
2 * CheckInGateway.java
3 *
4 * Copyright $Date: 2003/08/26 15:28:25 $ 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 * Contributors:
10 * David Cardozo dcardozo@flexstornet.com
11 */
12 package com.flexstor.common.gateway;
13
14 import java.util.List;
15 import java.util.Map;
16
17 import com.flexstor.common.data.ActionData;
18 import com.flexstor.common.exceptions.ejb.NotFoundException;
19 import com.flexstor.common.gateway.debug.GatewayDebugOutput;
20 import com.flexstor.common.gateway.exceptions.TransactionFailedException;
21 import com.flexstor.ejb.EjbObject;
22 import com.flexstor.ejb.versioncontrol.checkin.CheckIn;
23 import com.flexstor.ejb.versioncontrol.checkin.CheckInHome;
24
25 /**
26 * Gateway to interact with the CheckInBean
27 */
28 public class CheckInGateway extends Gateway
29 {
30 private CheckIn ci;
31
32 /**
33 * @return
34 * @see com.flexstor.common.gateway.Gateway#getHomeName()
35 */
36 protected String getHomeName()
37 {
38 return CHECKIN_HOME;
39 }
40
41 /**
42 * @return
43 * @see com.flexstor.common.gateway.Gateway#getBeanObject()
44 */
45 protected EjbObject getBeanObject()
46 {
47 return ci;
48 }
49
50 public void connect ()
51 throws TransactionFailedException
52 {
53 try
54 {
55 if ( canLoadObject() )
56 return;
57
58 CheckInHome home = (CheckInHome)getHome ( );
59
60 GatewayDebugOutput.println ( 3, "Getting CheckIn object" );
61 ci = home.create ();
62 }
63 catch ( NotFoundException nfe )
64 {
65 throw new TransactionFailedException ( nfe );
66 }
67 catch ( Throwable e )
68 {
69 throw buildException(e, "Connecting to CheckIn", IDENTIFIER );
70 }
71 }
72
73 /**
74 * Checks records to determine whether it has been copied to more than a single bucket or not
75 *
76 * @return A Map where the key is the asset id and the value is a Boolean object indicating
77 * TRUE for assets which has multiple copies or FALSE for assets that has a single copy
78 * in the database
79 * @throws TransactionFailedException
80 */
81 public Map hasMultipleUsages( List assetIds )
82 throws TransactionFailedException
83 {
84 try
85 {
86 GatewayDebugOutput.println ( 3, "Checking for multiple usages" );
87
88 if ( canLoadObject() )
89 return (Map) retrieveObject( "CheckIn_hasMultipleUsages" );
90
91 Map mMultUsages = ci.hasMultipleUsages(assetIds);
92
93 if ( canSaveObject() )
94 storeObject( "CheckIn_hasMultipleUsages", mMultUsages );
95
96 return mMultUsages;
97 }
98 catch ( Throwable e )
99 {
100 throw buildException(e, "Checking for multiple usages", IDENTIFIER );
101 }
102 }
103
104 /**
105 * Updates asset records after the user has performed some modifications to them. The records
106 * have their status changed to checkin. The changes apply to all instances of the asset in the
107 * repository.
108 *
109 * @param data An ActionData object containing a list of AssetRecordData objects; one for each
110 * asset to be updated
111 * @return A List of assets that could not be updated
112 * @throws EjbException
113 * @throws RemoteException
114 */
115 public List checkInApplyToAllUses( ActionData data )
116 throws TransactionFailedException
117 {
118 try
119 {
120 GatewayDebugOutput.println ( 3, "Checking in assets; apply to all uses" );
121
122 if ( canLoadObject() )
123 return (List) retrieveObject( "CheckIn_checkInApplyToAllUses" );
124
125 List badRecords = ci.checkInApplyToAllUses(data);
126
127 if ( canSaveObject() )
128 storeObject( "CheckIn_checkInApplyToAllUses", badRecords );
129
130 return badRecords;
131 }
132 catch ( Throwable e )
133 {
134 throw buildException(e, "Checking in assets; apply to all uses", IDENTIFIER );
135 }
136 }
137
138 /**
139 * Updates asset records after the user has performed some modifications to them. The records
140 * have their status changed to checkin. The changes apply to a single instance of the asset
141 * in the repository. This process is also known as braching, in which from that point onward,
142 * the asset will have its own history, independent of the other instances of the same asset
143 * in the repository.
144 *
145 * @param data An ActionData object containing a list of AssetRecordData objects; one for each
146 * asset to be updated
147 * @return A List of assets that could not be updated
148 * @throws EjbException
149 * @throws RemoteException
150 */
151 public List checkInApplyToSingleUse( ActionData data )
152 throws TransactionFailedException
153 {
154 try
155 {
156 GatewayDebugOutput.println ( 3, "Checking in assets; apply to single use only" );
157
158 if ( canLoadObject() )
159 return (List) retrieveObject( "CheckIn_checkInApplyToSingleUse" );
160
161 List badRecords = ci.checkInApplyToSingleUse(data);
162
163 if ( canSaveObject() )
164 storeObject( "CheckIn_checkInApplyToSingleUse", badRecords );
165
166 return badRecords;
167 }
168 catch ( Throwable e )
169 {
170 throw buildException(e, "Checking in assets; apply to single use only", IDENTIFIER );
171 }
172 }
173 }