Source code: com/flexstor/common/gateway/WorkspaceGateway.java
1 /*
2 * WorkspaceGateway.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 */
10
11 package com.flexstor.common.gateway;
12
13 import java.util.List;
14 import java.util.Map;
15
16 import com.flexstor.common.data.ActionData;
17 import com.flexstor.common.data.AssetRecordData;
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.workspace.Workspace;
23 import com.flexstor.ejb.versioncontrol.workspace.WorkspaceHome;
24
25 /**
26 * Gateway to interact with the WorkspaceBean
27 */
28 public class WorkspaceGateway extends Gateway
29 {
30 private Workspace ws;
31 /**
32 * @return
33 * @see com.flexstor.common.gateway.Gateway#getHomeName()
34 */
35 protected String getHomeName()
36 {
37 return WORKSPACE_HOME;
38 }
39
40 /**
41 * @return
42 * @see com.flexstor.common.gateway.Gateway#getBeanObject()
43 */
44 protected EjbObject getBeanObject()
45 {
46 return ws;
47 }
48
49 public void connect ()
50 throws TransactionFailedException
51 {
52 try
53 {
54 if ( canLoadObject() )
55 return;
56
57 WorkspaceHome home = (WorkspaceHome)getHome ( );
58
59 GatewayDebugOutput.println ( 3, "Getting Workspace object" );
60 ws = home.create ();
61 }
62 catch ( NotFoundException e )
63 {
64 throw new TransactionFailedException ( e );
65 }
66 catch ( Throwable e )
67 {
68 throw buildException(e, "Connecting to Workspace", IDENTIFIER );
69 }
70 }
71
72 /**
73 * Updates the workspace by adding the records after copying the files to the workspace in
74 * the filesystem.
75 *
76 * @param data an ActionData object holding a collection of EditData objects, one for each
77 * record to be udpated
78 * @throws TransactionFailedException
79 */
80 public void addRecords( ActionData data )
81 throws TransactionFailedException
82 {
83 try
84 {
85 if ( canLoadObject() )
86 return;
87
88 GatewayDebugOutput.println ( 3, "Adding workspace records" );
89 ws.addRecords(data);
90 return;
91 }
92 catch ( Throwable e )
93 {
94 throw buildException( e, "Adding workspace records", IDENTIFIER );
95 }
96 }
97
98 /**
99 * Updates the records in the workspace to reflect the new state of the asset (synchronized
100 * with the repository)
101 *
102 * @param data an ActionData object hoding a collection of EditData objects, one for each
103 * record to be updated.
104 * @throws TransactionFailedException
105 */
106 public void updateRecords( ActionData data )
107 throws TransactionFailedException
108 {
109 try
110 {
111 if ( canLoadObject() )
112 return;
113
114 GatewayDebugOutput.println ( 3, "Updating workspace records" );
115 ws.updateRecords(data);
116 return;
117 }
118 catch ( Throwable e )
119 {
120 throw buildException( e, "Updating workspace records", IDENTIFIER );
121 }
122 }
123
124 public AssetRecordData getDefaultViewAsset( AssetRecordData record )
125 throws TransactionFailedException
126 {
127 try
128 {
129 GatewayDebugOutput.println ( 3, "Getting default view asset" );
130
131 if ( canLoadObject() )
132 return (AssetRecordData) retrieveObject( "Workspace_getDefaultViewAsset" );
133
134 AssetRecordData defaultViewAsset = ws.getDefaultViewAsset ( record );
135
136 if ( canSaveObject() )
137 storeObject( "Workspace_getDefaultViewAsset", defaultViewAsset );
138
139 return defaultViewAsset;
140 }
141 catch ( Throwable e )
142 {
143 throw buildException(e, "Getting Default View Asset", IDENTIFIER );
144 }
145 }
146
147 /**
148 * Checks records to determine whether its version in the workspace is synchronized with the
149 * most current version in the repository.
150 *
151 * @param records a List of Long values representing the record ids of assets in the workspace
152 * @return A Map where the key is the asset id and the value is a Boolean object indicating
153 * TRUE for assets which version is up-to-date or FALSE for assets that are of an
154 * older version in the workspace
155 * @throws TransactionFailedException
156 */
157 public Map areVersionsCurrent( List recordIds )
158 throws TransactionFailedException
159 {
160 try
161 {
162 GatewayDebugOutput.println ( 3, "Checking for current versions" );
163
164 if ( canLoadObject() )
165 return (Map) retrieveObject( "Workspace_areVersionsCurrent" );
166
167 Map mVerCurrent = ws.areVersionsCurrent(recordIds);
168
169 if ( canSaveObject() )
170 storeObject( "Workspace_areVersionsCurrent", mVerCurrent );
171
172 return mVerCurrent;
173 }
174 catch ( Throwable e )
175 {
176 throw buildException(e, "Checking for current versions", IDENTIFIER );
177 }
178 }
179
180 /**
181 * Returns an AssetRecordData object for each asset id specified in the argument.
182 *
183 * @param recordIds a List of asset record ids
184 * @return a Map where the key is the asset id and the value is the AssetRecordData object
185 * for such id
186 * @throws TransactionFailedException
187 */
188 public Map getCurrentVersions( List assetIds )
189 throws TransactionFailedException
190 {
191 try
192 {
193 GatewayDebugOutput.println ( 3, "Getting current versions" );
194
195 if ( canLoadObject() )
196 return (Map) retrieveObject( "Workspace_getCurrentVersions" );
197
198 Map mCurVers = ws.getCurrentVersions(assetIds);
199
200 if ( canSaveObject() )
201 storeObject( "Workspace_getCurrentVersions", mCurVers );
202
203 return mCurVers;
204 }
205 catch ( Throwable e )
206 {
207 throw buildException(e, "Getting current versions", IDENTIFIER );
208 }
209 }
210 }