Changeset 695


Ignore:
Timestamp:
03/07/10 15:19:30 (6 months ago)
Author:
fabman
Message:

Downloaded files are deleted once the download finishes
TEST_SUITE updated explaining how to backup (export to zip) a workspace's content

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/TEST_SUITE

    r631 r695  
    1 Calenco V2 Test Suite (Last updated 2009-12-29) 
     1Calenco V2 Test Suite (Last updated 2010-03-07) 
    22 
    33This file describes some basic test procedures to excercise the V2 core. The 
     
    154154- Try to get backup of a non-existing workspace, as sysadmin: MUST FAIL with 404 
    155155curl -uadmin@calenco.com:admin -i http://localhost:9000/workspaces/Non%20Existing 
    156  
     156- Backup content of w1 (should get a zip file with a folder named 'content' with all content for w1 in it) 
     157curl -uadminw1@calenco.com:very_secret -HAccept:application/zip http://localhost:9000/workspaces/Workspace%201/content > W1.zip 
    157158 
    15815911. List files 
  • trunk/src/com/calenco/resource/workspace/ContentResource.java

    r692 r695  
    7676import org.apache.commons.io.input.AutoCloseInputStream; 
    7777import org.json.JSONObject; 
     78import org.restlet.Request; 
     79import org.restlet.Response; 
     80import org.restlet.Uniform; 
    7881import org.restlet.data.CharacterSet; 
    7982import org.restlet.data.Disposition; 
     
    121124    String path = null; 
    122125    String fileName = null; 
     126    File tempFile = null; 
    123127 
    124128    @Override 
     
    169173        } 
    170174        path = String.format("%s/content%s", workspace.href, "".equals(fileName) ? fileName : "/" + fileName); 
     175        setOnSent(new CleanupTempFile()); 
    171176    } 
    172177 
     
    460465                    ContentDAO dao = new ContentDAO(session, workspace); 
    461466                    if (MediaType.APPLICATION_ZIP.equals(mt)) { // Export 
    462                         File exportFile = dao.export(); 
    463                         FileUtils.forceDeleteOnExit(exportFile); 
    464                         Representation rep = new FileRepresentation(exportFile, mt); 
     467                        tempFile = dao.export(); 
     468                        Representation rep = new FileRepresentation(tempFile, mt); 
    465469                        Disposition disposition = new Disposition(Disposition.TYPE_ATTACHMENT); 
    466                         disposition.setFilename(exportFile.getName()); 
    467                         disposition.setSize(exportFile.length()); 
     470                        disposition.setFilename(tempFile.getName()); 
     471                        disposition.setSize(tempFile.length()); 
    468472                        rep.setDisposition(disposition); 
    469473                        return rep; 
     
    533537                            Set<Association> deps = adao.findByKindFrom(Association.HAS_DEP_CALLED, content.href); 
    534538                            storeDeps(session, deps, Language.INTL, tempFolder); 
    535                             File zipFile = new File(Constants.IO_TMPDIR, String.format("%s-EXPORT-%d.zip", langOrFile, rstart)); 
    536                             new Packer().zip(tempFolder, zipFile); 
    537                             FileRepresentation rep = new FileRepresentation(zipFile, MediaType.APPLICATION_ZIP); 
     539                            tempFile = new File(Constants.IO_TMPDIR, String.format("%s-EXPORT-%d.zip", langOrFile, rstart)); 
     540                            new Packer().zip(tempFolder, tempFile); 
     541                            FileRepresentation rep = new FileRepresentation(tempFile, MediaType.APPLICATION_ZIP); 
    538542                            return rep; 
    539543                        } else { // Stream file back 
     
    551555                                return new EmptyRepresentation(); // No entity body allowed with http 304 responses 
    552556                            } 
    553                             File tempFile = File.createTempFile("cco", null); // NOI18N 
    554                             FileUtils.forceDeleteOnExit(tempFile); 
     557                            tempFile = File.createTempFile("cco", null); // NOI18N 
    555558                            FileOutputStream fos = FileUtils.openOutputStream(tempFile); 
    556559                            IOUtils.copy(new AutoCloseInputStream(content.getFstream()), fos); 
     
    654657                            Set<Association> deps = adao.findByKindFrom(Association.HAS_DEP_CALLED, content.href); 
    655658                            storeDeps(session, deps, lang, tempFolder); 
    656                             File zipFile = new File(Constants.IO_TMPDIR, String.format("%s-EXPORT-%d.zip", file, rstart)); 
    657                             new Packer().zip(tempFolder, zipFile); 
    658                             FileRepresentation rep = new FileRepresentation(zipFile, MediaType.APPLICATION_ZIP); 
     659                            tempFile = new File(Constants.IO_TMPDIR, String.format("%s-EXPORT-%d.zip", file, rstart)); 
     660                            new Packer().zip(tempFolder, tempFile); 
     661                            FileRepresentation rep = new FileRepresentation(tempFile, MediaType.APPLICATION_ZIP); 
    659662                            return rep; 
    660663                        } else { // Stream back 
     
    672675                                return new EmptyRepresentation(); // No entity body allowed with http 304 responses 
    673676                            } 
    674                             File tempFile = File.createTempFile("cco", null); 
    675                             FileUtils.forceDeleteOnExit(tempFile); 
     677                            tempFile = File.createTempFile("cco", null); 
    676678                            FileOutputStream fos = FileUtils.openOutputStream(tempFile); 
    677679                            IOUtils.copy(new AutoCloseInputStream(content.getFstream()), fos); 
     
    12351237        new AssociationDAO(session, workspace).add(hasAuthor); 
    12361238    } 
    1237      
     1239 
     1240 
     1241    /** 
     1242     * Delete temporary file, if any. This is used to delete files after they 
     1243     *  have been downloaded by the client. 
     1244     */ 
     1245    class CleanupTempFile implements Uniform { 
     1246        @Override 
     1247        public void handle(Request rqst, Response rspns) { 
     1248            if (Method.GET.equals(rqst.getMethod()) && tempFile != null) { 
     1249                FileUtils.deleteQuietly(tempFile); 
     1250            } 
     1251        } 
     1252    } 
     1253 
    12381254} 
Note: See TracChangeset for help on using the changeset viewer.