001 /*
002
003 $Id: InternalCommandManager.java,v 1.15 2003/05/15 12:05:55 culdesac Exp $
004
005 */
006
007 package sharpster.daemon.commandmanagement;
008
009 import sharpster.daemon.filemanagement.FileManager;
010 import sharpster.daemon.sharemanagement.ShareManager;
011 import sharpster.daemon.usermanagement.UserManager;
012 import sharpster.daemon.externalcommunication.ExternalCommunication;
013 import sharpster.daemon.groupmanagement.GroupController;
014 import sharpster.common.*;
015 import java.util.LinkedList;
016 import java.util.ListIterator;
017 import net.jxta.id.*;
018
019 /**
020 * Interface of the Command Management Module. It is used by the Client
021 * Communication Module to invoke the execution of commands, requested
022 * by the user of the client.
023 */
024
025 public class InternalCommandManager {
026
027 private FileManager fileManager;
028 private ShareManager shareManager;
029 private UserManager userManager;
030 private GroupController groupController;
031 private ExternalCommunication externalCommunication;
032
033 /**
034 * Constructs an object
035 */
036 public void initialize(FileManager fmi,
037 ShareManager smi,
038 UserManager umi,
039 ExternalCommunication eci,
040 Mutex globalMutex,
041 GroupController gci) {
042 fileManager = fmi;
043 shareManager = smi;
044 userManager = umi;
045 externalCommunication = eci;
046 groupController = gci;
047 }
048
049 /**
050 * Executes a shareFiles call received from the client.
051 */
052 public ResponseCollection shareFiles(FileCollection files,
053 String workingDirectory) {
054 ResponseCollection resp, responses;
055
056 responses = new ResponseCollection();
057
058 resp = fileManager.translateLocalPaths(files,
059 workingDirectory,
060 true);
061
062 responses.appendCollection(resp);
063 if(resp.hasError()) {
064 return responses;
065 }
066
067 resp = shareManager.shareFiles(files, false);
068
069 responses.appendCollection(resp);
070
071 return responses;
072 }
073
074 /**
075 * Executes a unshareFiles call received from the client.
076 */
077 public ResponseCollection unshareFiles(FileCollection files,
078 String workingDirectory) {
079 ResponseCollection resp, responses;
080
081 responses = new ResponseCollection();
082
083 resp = fileManager.translateLocalPaths(files,
084 workingDirectory,
085 true);
086
087 responses.appendCollection(resp);
088 if(resp.hasError()) return responses;
089
090 resp = shareManager.unshareFiles(files, false);
091
092 responses.appendCollection(resp);
093 if(resp.hasError()) return responses;
094
095 return responses;
096 }
097
098 /**
099 * Excecutes a localDoCVS call received from the client.
100 */
101 public ResponseCollection localDoCVS(String command,
102 String workingDirectory) {
103 ResponseCollection resp = fileManager.localDoCVS(command, workingDirectory);
104
105 shareManager.synchronizeShares();
106 shareManager.saveToFile(null);
107
108 return resp;
109 }
110
111 /**
112 * Excecutes a remoteCheckoutFiles call received from the client.
113 */
114 public ResponseCollection remoteCheckoutFiles(FileCollection files,
115 String fromUser,
116 String workingDirectory,
117 String role) {
118 ResponseCollection responses, respCol;
119
120 responses = externalCommunication.checkoutFiles(files, fromUser, role);
121 if(responses.hasError()) return responses;
122
123 for(int i=0;i<responses.getResponseCount();i++) {
124 Response resp = responses.getResponse(i);
125 if(resp.getType() == ResponseType.FILE) {
126 FileResponse fileResp = (FileResponse)resp;
127 respCol = fileManager.localSaveFiles(fileResp.getFiles(),workingDirectory);
128 responses.appendCollection(respCol);
129 }
130 }
131
132 return responses;
133 }
134
135 /**
136 * Excecutes a remoteUpdateFiles call received from the client.
137 */
138 public ResponseCollection remoteUpdateFiles(FileCollection files,
139 String fromUser,
140 String workingDirectory) {
141 ResponseCollection responses = new ResponseCollection();
142 ResponseCollection resp, respCol;
143
144 resp = fileManager.localLoadFiles(files,workingDirectory);
145 responses.appendCollection(resp);
146 if(responses.hasError()) return responses;
147
148 resp = fileManager.translateLocalPaths(files,
149 workingDirectory,
150 false);
151 responses.appendCollection(resp);
152 if(responses.hasError()) return responses;
153
154 resp = externalCommunication.updateFiles(files, fromUser);
155 responses.appendCollection(resp);
156
157 for(int i=0;i<responses.getResponseCount();i++) {
158 Response resp2 = responses.getResponse(i);
159 if(resp2.getType() == ResponseType.FILE) {
160 FileResponse fileResp = (FileResponse)resp2;
161 respCol = fileManager.localSaveFiles(fileResp.getFiles(),workingDirectory);
162 responses.appendCollection(respCol);
163 }
164 }
165
166 return responses;
167 }
168
169 /**
170 * Excecutes a remoteCommitFiles call received from the client.
171 */
172 public ResponseCollection remoteCommitFiles(FileCollection files,
173 String fromUser,
174 String workingDirectory,
175 String role) {
176
177 ResponseCollection responses = new ResponseCollection();
178 ResponseCollection resp, respCol;
179
180 resp = fileManager.localLoadFiles(files,workingDirectory);
181 responses.appendCollection(resp);
182 if(responses.hasError()) return responses;
183
184 resp = fileManager.translateLocalPaths(files,
185 workingDirectory,
186 false);
187 responses.appendCollection(resp);
188 if(responses.hasError()) return responses;
189
190 resp = externalCommunication.commitFiles(files, fromUser, role);
191 responses.appendCollection(resp);
192
193 for(int i=0;i<responses.getResponseCount();i++) {
194 Response resp2 = responses.getResponse(i);
195 if(resp2.getType() == ResponseType.FILE) {
196 FileResponse fileResp = (FileResponse)resp2;
197 respCol = fileManager.localSaveFiles(fileResp.getFiles(),workingDirectory);
198 responses.appendCollection(respCol);
199 }
200 }
201
202 return responses;
203 }
204
205 public ResponseCollection groupCommand(GroupCommand command) {
206 ResponseCollection responses;
207 responses = groupController.groupCommand(command);
208 return responses;
209 }
210
211 /**
212 * Excecutes a remoteAddFiles call received from the client.
213 */
214 public ResponseCollection remoteAddFiles(FileCollection files,
215 String fromUser,
216 String workingDirectory) {
217 ResponseCollection responses;
218 responses = externalCommunication.addFiles(files, fromUser);
219 if(responses.hasError()) return responses;
220
221 return responses;
222 }
223
224 /**
225 * Excecutes a remoteRemoveFiles call received from the client.
226 */
227 public ResponseCollection remoteRemoveFiles(FileCollection files,
228 String fromUser,
229 String workingDirectory) {
230 ResponseCollection responses;
231 responses = externalCommunication.removeFiles(files, fromUser);
232 if(responses.hasError()) return responses;
233
234 return responses;
235 }
236
237 /**
238 * Excecutes a viewFileSharing call received from the client.
239 */
240 public ResponseCollection viewFileSharing() {
241 return shareManager.viewFileSharing();
242 }
243
244 /**
245 * Excecutes a viewUsers call received from the client.
246 */
247 public ResponseCollection viewUsers() {
248 return userManager.viewUsers();
249 }
250
251 /**
252 * Excecutes a viewFileAccess call received from the client.
253 */
254 public ResponseCollection viewFileAccess() {
255 return userManager.viewFileAccess();
256 }
257
258 /**
259 * Excecutes a synchronizeCVS call received from the client.
260 */
261 public ResponseCollection synchronizeCVS(String workingDirectory) {
262 ResponseCollection resp = fileManager.synchronizeCVS(workingDirectory);
263
264 shareManager.synchronizeShares();
265 shareManager.saveToFile(null);
266
267 return resp;
268 }
269 }
270
271
272
273