Revision e5c822f8 src/gr/ebs/gss/server/webdav/milton/GssFolderResource.java
b/src/gr/ebs/gss/server/webdav/milton/GssFolderResource.java | ||
---|---|---|
23 | 23 |
import gr.ebs.gss.client.exceptions.InsufficientPermissionsException; |
24 | 24 |
import gr.ebs.gss.client.exceptions.ObjectNotFoundException; |
25 | 25 |
import gr.ebs.gss.client.exceptions.RpcException; |
26 |
import gr.ebs.gss.server.domain.User; |
|
27 | 26 |
import gr.ebs.gss.server.domain.dto.FileHeaderDTO; |
28 | 27 |
import gr.ebs.gss.server.domain.dto.FolderDTO; |
29 |
import gr.ebs.gss.server.domain.dto.UserDTO; |
|
30 | 28 |
import gr.ebs.gss.server.ejb.TransactionHelper; |
31 | 29 |
|
32 | 30 |
import java.io.File; |
... | ... | |
47 | 45 |
import com.bradmcevoy.http.CopyableResource; |
48 | 46 |
import com.bradmcevoy.http.DeletableResource; |
49 | 47 |
import com.bradmcevoy.http.GetableResource; |
50 |
import com.bradmcevoy.http.HttpManager; |
|
51 | 48 |
import com.bradmcevoy.http.LockInfo; |
49 |
import com.bradmcevoy.http.LockResult; |
|
52 | 50 |
import com.bradmcevoy.http.LockTimeout; |
53 | 51 |
import com.bradmcevoy.http.LockToken; |
54 | 52 |
import com.bradmcevoy.http.LockingCollectionResource; |
... | ... | |
319 | 317 |
} |
320 | 318 |
final File uf = uploadedFile; |
321 | 319 |
try { |
322 |
FileHeaderDTO kmfileDTO = new TransactionHelper<FileHeaderDTO>().tryExecute(new Callable<FileHeaderDTO>() { |
|
320 |
String pathFolder = folder.getPath(); |
|
321 |
if(!pathFolder.endsWith("/")) |
|
322 |
pathFolder=pathFolder+"/"; |
|
323 |
String fname = pathFolder+name; |
|
324 |
Object ff2; |
|
325 |
try{ |
|
326 |
ff2 = factory.getService().getResourceAtPath(folder.getOwner().getId(), fname, true); |
|
327 |
} |
|
328 |
catch(ObjectNotFoundException ex){ |
|
329 |
ff2=null; |
|
330 |
} |
|
331 |
final Object ff = ff2; |
|
332 |
log.info("**************FOUND FILE:"+ff); |
|
333 |
FileHeaderDTO kmfileDTO=null; |
|
334 |
if(ff!=null && ff instanceof FileHeaderDTO){ |
|
335 |
kmfileDTO = new TransactionHelper<FileHeaderDTO>().tryExecute(new Callable<FileHeaderDTO>() { |
|
323 | 336 |
@Override |
324 | 337 |
public FileHeaderDTO call() throws Exception { |
338 |
log.info("**************UPDATING:"+ff); |
|
339 |
return factory.getService().updateFileContents(getCurrentUser().getId(), ((FileHeaderDTO)ff).getId(), contentType, uf.length(), uf.getAbsolutePath()); |
|
340 |
} |
|
341 |
}); |
|
342 |
} |
|
343 |
else |
|
344 |
kmfileDTO = new TransactionHelper<FileHeaderDTO>().tryExecute(new Callable<FileHeaderDTO>() { |
|
345 |
@Override |
|
346 |
public FileHeaderDTO call() throws Exception { |
|
347 |
log.info("**************CREATING:"+ff); |
|
325 | 348 |
return factory.getService().createFile(getCurrentUser().getId(), folder.getId(), name, contentType, uf.length(), uf.getAbsolutePath()); |
326 | 349 |
} |
327 | 350 |
}); |
... | ... | |
354 | 377 |
return null; |
355 | 378 |
} |
356 | 379 |
@Override |
357 |
public LockToken createAndLock( String name, LockTimeout timeout, LockInfo lockInfo ) throws NotAuthorizedException { |
|
380 |
public LockToken createAndLock(final String name, LockTimeout timeout, LockInfo lockInfo ) throws NotAuthorizedException { |
|
381 |
final File tmp = new File("/home/kman/"+new java.util.Random().nextInt()); |
|
382 |
FileHeaderDTO kmfileDTO=null; |
|
383 |
try { |
|
384 |
kmfileDTO = new TransactionHelper<FileHeaderDTO>().tryExecute(new Callable<FileHeaderDTO>() { |
|
385 |
@Override |
|
386 |
public FileHeaderDTO call() throws Exception { |
|
387 |
return factory.getService().createFile(getCurrentUser().getId(), folder.getId(), name, "text/html", tmp.length(), tmp.getAbsolutePath()); |
|
388 |
} |
|
389 |
}); |
|
390 |
} catch (Exception e) { |
|
391 |
// TODO Auto-generated catch block |
|
392 |
e.printStackTrace(); |
|
393 |
} |
|
358 | 394 |
//File dest = new File( this.getFile(), name ); |
359 | 395 |
//createEmptyFile( ); |
360 |
//FsFileResource newRes = new FsFileResource( host, factory, dest );
|
|
361 |
//LockResult res = newRes.lock( timeout, lockInfo );
|
|
362 |
//return res.getLockToken();
|
|
363 |
return null; |
|
396 |
GssFileResource newRes = new GssFileResource( host, factory, kmfileDTO );
|
|
397 |
LockResult res = newRes.lock( timeout, lockInfo ); |
|
398 |
return res.getLockToken(); |
|
399 |
|
|
364 | 400 |
} |
365 | 401 |
@Override |
366 | 402 |
public Long getContentLength() { |
Also available in: Unified diff