Author: chatellier Date: 2011-01-19 10:10:46 +0000 (Wed, 19 Jan 2011) New Revision: 528 Log: Les sources doivent contenir l'export rsufi et non les donn?\195?\169es brutes de s?\195?\169lection. Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java trunk/coser-business/src/test/java/fr/ifremer/coser/services/CoserTestAbstract.java trunk/coser-business/src/test/java/fr/ifremer/coser/services/WebServiceTest.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2011-01-19 09:43:05 UTC (rev 527) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2011-01-19 10:10:46 UTC (rev 528) @@ -691,7 +691,7 @@ return project; } - + /** * Load selection data in an initialized project. * @@ -701,8 +701,20 @@ * @throws CoserBusinessException */ public Project loadSelectionData(Project project, Selection selection) throws CoserBusinessException { + return loadSelectionData(config.getProjectsDirectory(), project, selection); + } - File projectsDirectory = config.getProjectsDirectory(); + /** + * Load selection data in an initialized project form specific directory. + * + * @param projectsDirectory directory containing projects + * @param project project + * @param selection selection to fill + * @return project with data + * @throws CoserBusinessException + */ + public Project loadSelectionData(File projectsDirectory, Project project, Selection selection) throws CoserBusinessException { + File projectDirectory = new File(projectsDirectory, project.getName()); // first free memory, clear all data @@ -2561,9 +2573,10 @@ * @param project project * @param selection selection * @param directory directory to extract file to + * @return extracted directory * @throws CoserBusinessException */ - public void extractRSUfiData(Project project, Selection selection, File directory) throws CoserBusinessException { + public File extractRSUfiData(Project project, Selection selection, File directory) throws CoserBusinessException { File projectDirectory = new File(directory, project.getName()); projectDirectory.mkdirs(); @@ -2602,6 +2615,8 @@ finally { IOUtils.closeQuietly(out); } + + return projectDirectory; } /** @@ -2674,6 +2689,23 @@ } /** + * Look for project survey name in container data. + * + * @param container data container + * @return survey name + */ + public String getProjectSurveyName(AbstractDataContainer container) { + String result = null; + + Iterator<String[]> itCatchData = container.getCatch().iterator(true); + while (StringUtils.isEmpty(result) && itCatchData.hasNext()) { + result = itCatchData.next()[Catch.INDEX_SURVEY]; + } + + return result; + } + + /** * Look for project survey name in rsufi result. * Read estcomind file to known that. * Used in webservice to know map file names. Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2011-01-19 09:43:05 UTC (rev 527) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2011-01-19 10:10:46 UTC (rev 528) @@ -1557,10 +1557,14 @@ // extraction des especes pour le résultat demandé if (rsufiResult.getZone() != null && rsufiResult.getZone().equals(zone)) { - // load project (without data to get original file names) + // load project (with data to get original file names) Project project = projectService.openProject(projectFile.getName(), projectsDirectory); + + // load selection data (to do data export rsufi) + Selection selection = project.getSelections().get(selectionFile.getName()); + projectService.loadSelectionData(projectsDirectory,project, selection); - result = generateSourceZip(project, selectionFile, resultFile, rsufiResult); + result = generateSourceZip(project, selection); } } } @@ -1579,41 +1583,23 @@ * Generate zip for selection. * * @param project project - * @param selectionDirectory selection directory - * @param rsufiResultDirectory rsufi result directory (to get survey name) - * @param rsufiResult rsufi result (to get survey name) + * @param selection selection with loaded data * @return generated zip file * @throws CoserBusinessException */ - protected File generateSourceZip(Project project, File selectionDirectory, File rsufiResultDirectory, RSufiResult rsufiResult) throws CoserBusinessException { + protected File generateSourceZip(Project project, Selection selection) throws CoserBusinessException { File resultZip = null; try { File tempDir = FileUtil.createTempDirectory("coser-", ".tmp"); - // pour que l'archive contiennent ce dossier - File archiveDir = new File(tempDir, project.getName()); + // il ne faut pas les fichiers de selection, mais leurs + // export rsufi (sans les lignes, et les quotes) + File archiveDir = projectService.extractRSUfiData(project, selection, tempDir); - // recupere les noms originaux des fichiers - // de selection et de nom de fichier dans le zip - String catchSeFileName = projectService.getDataStorageFileName(project, Category.CATCH, CoserConstants.STORAGE_SELECTION_SUFFIX); - String haulSeFileName = projectService.getDataStorageFileName(project, Category.HAUL, CoserConstants.STORAGE_SELECTION_SUFFIX); - String lengthSeFileName = projectService.getDataStorageFileName(project, Category.LENGTH, CoserConstants.STORAGE_SELECTION_SUFFIX); - String strataSeFileName = projectService.getDataStorageFileName(project, Category.STRATA, CoserConstants.STORAGE_SELECTION_SUFFIX); - String catchFileName = projectService.getDataStorageFileName(project, Category.CATCH, null); - String haulFileName = projectService.getDataStorageFileName(project, Category.HAUL, null); - String lengthFileName = projectService.getDataStorageFileName(project, Category.LENGTH, null); - String strataFileName = projectService.getDataStorageFileName(project, Category.STRATA, null); - - // copy to temp directory - FileUtils.copyFile(new File(selectionDirectory, catchSeFileName), new File(archiveDir, catchFileName)); - FileUtils.copyFile(new File(selectionDirectory, haulSeFileName), new File(archiveDir, haulFileName)); - FileUtils.copyFile(new File(selectionDirectory, lengthSeFileName), new File(archiveDir, lengthFileName)); - FileUtils.copyFile(new File(selectionDirectory, strataSeFileName), new File(archiveDir, strataFileName)); - // add decharge file - File dechargePDF = generateDechargePDF(rsufiResultDirectory, rsufiResult); + File dechargePDF = generateDechargePDF(selection); FileUtils.copyFile(dechargePDF, new File(archiveDir, "DechargeDonnees.pdf")); // make zip @@ -1632,12 +1618,11 @@ /** * Genere le PDF dynamique de decharge à partir du template freemarker. * - * @param rsufiResultDirectory rsufi result directory (to get survey name) - * @param rsufiResult rsufi result (to get survey name) + * @param selection selection with loaded data * @return le fichier généré * @throws CoserBusinessException */ - protected File generateDechargePDF(File rsufiResultDirectory, RSufiResult rsufiResult) throws CoserBusinessException { + protected File generateDechargePDF(Selection selection) throws CoserBusinessException { File result = null; @@ -1645,7 +1630,7 @@ // get some info to put into pdf Date updateDate = getLastDataUpdateDate(); - String surveyName = projectService.getProjectSurveyName(rsufiResultDirectory, rsufiResult); + String surveyName = projectService.getProjectSurveyName(selection); // render freemarker template Template mapTemplate = freemarkerConfiguration.getTemplate("decharge.ftl"); Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/services/CoserTestAbstract.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/services/CoserTestAbstract.java 2011-01-19 09:43:05 UTC (rev 527) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/CoserTestAbstract.java 2011-01-19 10:10:46 UTC (rev 528) @@ -104,7 +104,7 @@ @AfterClass public static void cleanDirectory() throws IOException { - FileUtils.deleteDirectory(testDirectory); + //FileUtils.deleteDirectory(testDirectory); } /** Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/services/WebServiceTest.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/services/WebServiceTest.java 2011-01-19 09:43:05 UTC (rev 527) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/WebServiceTest.java 2011-01-19 10:10:46 UTC (rev 528) @@ -129,17 +129,20 @@ /** * Test du contenu du zip de téléchargement des sources. * + * Generation du zip, freemarker, et pdf. + * * @throws CoserBusinessException * @throws IOException */ @Test public void testSourceZip() throws CoserBusinessException, IOException { - registerUploadedResult("/web/upload1.zip"); + registerUploadedResult("/web/upload2.zip"); File zip = webService.getSourceZip("testzone1", "en"); File tempDir = FileUtil.createTempDirectory("coser", ".tmp"); ZipUtil.uncompress(zip, tempDir); - Assert.assertTrue(new File(tempDir, "coser-sources" + File.separator + "testcatch.csv").isFile()); + Assert.assertTrue(new File(tempDir, "projet1" + File.separator + "testcatch.csv").isFile()); + Assert.assertTrue(new File(tempDir, "projet1" + File.separator + "DechargeDonnees.pdf").isFile()); FileUtils.deleteDirectory(tempDir); } @@ -166,18 +169,4 @@ File file = webService.getMapFileAsPDF("Medits", "SPECIES1"); Assert.assertNotNull(file); } - - /** - * Test la simulation d'un téléchargement de données sources d'un projet. - * - * Generation du zip, freemarker, et pdf. - * - * @throws CoserBusinessException - */ - @Test - public void testGetSourceZip() throws CoserBusinessException { - registerUploadedResult("/web/upload2.zip"); - File file = webService.getSourceZip("testzone1", "fr"); - Assert.assertNotNull(file); - } }