From: <de...@us...> - 2016-02-24 12:21:00
|
Revision: 9290 http://sourceforge.net/p/fudaa/svn/9290 Author: deniger Date: 2016-02-24 12:20:58 +0000 (Wed, 24 Feb 2016) Log Message: ----------- CRUE-667 Modified Paths: -------------- trunk/soft/fudaa-crue/ui-modelling/src/main/java/org/fudaa/fudaa/crue/modelling/calcul/ModellingListCLimMsProgressRunnable.java trunk/soft/fudaa-crue/ui-modelling/src/main/resources/org/fudaa/fudaa/crue/modelling/calcul/importer/Bundle.properties Added Paths: ----------- trunk/soft/fudaa-crue/ui-modelling/src/test/java/org/fudaa/fudaa/crue/modelling/calcul/ModellingListCLimMsProgressRunnableTest.java trunk/soft/fudaa-crue/ui-modelling/src/test/resources/ trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/ trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/ trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/ trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/ trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/modelling/ trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/modelling/calcul/ trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/modelling/calcul/example.csv trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/modelling/calcul/example.xlsx Property Changed: ---------------- trunk/soft/fudaa-crue/ui-modelling/ Index: trunk/soft/fudaa-crue/ui-modelling =================================================================== --- trunk/soft/fudaa-crue/ui-modelling 2016-02-24 11:06:45 UTC (rev 9289) +++ trunk/soft/fudaa-crue/ui-modelling 2016-02-24 12:20:58 UTC (rev 9290) Property changes on: trunk/soft/fudaa-crue/ui-modelling ___________________________________________________________________ Modified: svn:ignore ## -3,3 +3,4 ## .settings nbactions.xml target +nbproject Modified: trunk/soft/fudaa-crue/ui-modelling/src/main/java/org/fudaa/fudaa/crue/modelling/calcul/ModellingListCLimMsProgressRunnable.java =================================================================== --- trunk/soft/fudaa-crue/ui-modelling/src/main/java/org/fudaa/fudaa/crue/modelling/calcul/ModellingListCLimMsProgressRunnable.java 2016-02-24 11:06:45 UTC (rev 9289) +++ trunk/soft/fudaa-crue/ui-modelling/src/main/java/org/fudaa/fudaa/crue/modelling/calcul/ModellingListCLimMsProgressRunnable.java 2016-02-24 12:20:58 UTC (rev 9290) @@ -57,7 +57,7 @@ } values = CSVParser.parse(initValues, sep); } else if (file != null) { - values = readFile(values); + values = readFile(); } if (values == null) { return null; @@ -71,6 +71,8 @@ protected String getValue(Cell cell) { switch (cell.getCellType()) { + case Cell.CELL_TYPE_BLANK: + return ""; case Cell.CELL_TYPE_NUMERIC: return Double.toString(cell.getNumericCellValue()); case Cell.CELL_TYPE_STRING: @@ -91,7 +93,7 @@ return StringUtils.EMPTY; } - protected String[][] readFile(String[][] values) { + protected String[][] readFile() { final String nameToLowerCase = file.getName().toLowerCase(); if (nameToLowerCase.endsWith("xlsx") || nameToLowerCase.endsWith("xls")) { List<String[]> rows = new ArrayList<String[]>(); @@ -100,10 +102,14 @@ is = new FileInputStream(file); Workbook wb = WorkbookFactory.create(is); Sheet sheetAt = wb.getSheetAt(0); + int maxCol = 0; for (Row row : sheetAt) { + maxCol = Math.max(maxCol, row.getLastCellNum()); + } + for (Row row : sheetAt) { List<String> cols = new ArrayList<String>(); - for (Cell cell : row) { - cols.add(getValue(cell)); + for (int i = 0; i < maxCol; i++) { + cols.add(getValue(row.getCell(i, Row.CREATE_NULL_AS_BLANK))); } rows.add(cols.toArray(new String[cols.size()])); } @@ -116,12 +122,13 @@ return toArray; } else { - return readCsv(values); + return readCsv(); } } - protected String[][] readCsv(String[][] values) { + protected String[][] readCsv() { Reader reader = null; + String[][] values = null; try { reader = new FileReader(file); values = new CSVParser(new BufferedReader(reader), ';').getAllValues(); Modified: trunk/soft/fudaa-crue/ui-modelling/src/main/resources/org/fudaa/fudaa/crue/modelling/calcul/importer/Bundle.properties =================================================================== --- trunk/soft/fudaa-crue/ui-modelling/src/main/resources/org/fudaa/fudaa/crue/modelling/calcul/importer/Bundle.properties 2016-02-24 11:06:45 UTC (rev 9289) +++ trunk/soft/fudaa-crue/ui-modelling/src/main/resources/org/fudaa/fudaa/crue/modelling/calcul/importer/Bundle.properties 2016-02-24 12:20:58 UTC (rev 9290) @@ -2,9 +2,9 @@ import.cini.wrongValue=La ligne n\u00b0{0} a \u00e9t\u00e9 ignor\u00e9 car la valeur n''est pas lisible. Le format attendu est <nom EMH>;<Type>;<Valeur> import.cini.doublons=Le couple {0} est d\u00e9fini plusieurs fois. La derni\u00e8re valeur est prise en compte. import.cini.nbModifiedValue={0} valeurs modifi\u00e9es -climImport.wrongColumnsNumber=Le nombre de colonnes du fichier d'import doit \u00eatre impair. Ent\u00eate attendue: colonne 1=nom calcul; colonne 2=emh 1 (type);emh 1 (valeur) -climImport.wrongColumnsOrganization=Dans la ligne d'ent\u00eate, il doit y avoir 2 colonnes par EMH: type et valeur. Ent\u00eate attendue: colonne 1=nom calcul; colonne 2=emh 1 (type);emh 1 (valeur) -climImport.ligneWithWrongColumnsNumber=La ligne {0} doit contenir au maximum {1} colonnes +climImport.wrongColumnsNumber=Le tableau import\u00e9 doit avoir la structure suivante : Colonne 1 = Nom du Calcul ; Puis 2 colonnes pour chaque EMH (i) portant une Clim : Colonne i1 = emh i (type); colonne i2 = emh i (valeur);\nValeur attendue dans la colonne i2 : valeur num\u00e9rique pour un calcul permanent, nom de loi existante pour un calcul transitoire +climImport.wrongColumnsOrganization=Le tableau import\u00e9 doit avoir la structure suivante : Colonne 1 = Nom du Calcul ; Puis 2 colonnes pour chaque EMH (i) portant une Clim : Colonne i1 = emh i (type); colonne i2 = emh i (valeur);\nValeur attendue dans la colonne i2 : valeur num\u00e9rique pour un calcul permanent, nom de loi existante pour un calcul transitoire +climImport.ligneWithWrongColumnsNumber=Le tableau import\u00e9 doit avoir la structure suivante : Colonne 1 = Nom du Calcul ; Puis 2 colonnes pour chaque EMH (i) portant une Clim : Colonne i1 = emh i (type); colonne i2 = emh i (valeur);\nValeur attendue dans la colonne i2 : valeur num\u00e9rique pour un calcul permanent, nom de loi existante pour un calcul transitoire climImport.doublonCalcul=Le calcul {0} est d\u00e9fini plusieurs fois climImport.doublonEMH=L''EMH {0} est d\u00e9finie plusieurs fois dans les DCLM importCLimMs.bilan=Import des CLimMs @@ -14,6 +14,6 @@ importClimMs.skipLine=La ligne {0} du fichier d''import a \u00e9t\u00e9 ignor\u00e9e climImport.unknownEMH=L''EMH {0} n''existe pas climImport.nameCalculUnknown=Le calcul {0} ne suit pas la convention de nommage: le pr\u00e9fixe doit \u00eatre CC_P pour pseudo-permanent et CC_T pour transitoire. -climImport.NonConsistentDclimValue=Les valeurs du calcul {0} ne sont pas consistentes ( permanentes et transitoire) +climImport.NonConsistentDclimValue=Les valeurs du calcul {0} ne sont pas consistentes ( permanentes et transitoires) climImport.calculPermanentNoPermanentValue=Le calcul {0} de type pseudo-permanent contient une valeur non coh\u00e9rente pour l''EMH {0} climImport.calculTransitoireNoTransitoireValue=Le calcul {0} de type transitoire contient une valeur non coh\u00e9rente pour l''EMH {0} Added: trunk/soft/fudaa-crue/ui-modelling/src/test/java/org/fudaa/fudaa/crue/modelling/calcul/ModellingListCLimMsProgressRunnableTest.java =================================================================== --- trunk/soft/fudaa-crue/ui-modelling/src/test/java/org/fudaa/fudaa/crue/modelling/calcul/ModellingListCLimMsProgressRunnableTest.java (rev 0) +++ trunk/soft/fudaa-crue/ui-modelling/src/test/java/org/fudaa/fudaa/crue/modelling/calcul/ModellingListCLimMsProgressRunnableTest.java 2016-02-24 12:20:58 UTC (rev 9290) @@ -0,0 +1,45 @@ +/* +GPL 2 + */ +package org.fudaa.fudaa.crue.modelling.calcul; + +import java.io.File; +import java.io.IOException; +import org.fudaa.ctulu.CtuluLibFile; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author Frederic Deniger + */ +public class ModellingListCLimMsProgressRunnableTest { + + public ModellingListCLimMsProgressRunnableTest() { + } + + @Test + public void testReadXls() throws IOException { + File f = CtuluLibFile.getFileFromJar("/org/fudaa/fudaa/crue/modelling/calcul/example.xlsx", File.createTempFile("example", ".xlsx")); + testContent(f); + + } + + protected void testContent(File f) { + assertNotNull(f); + ModellingListCLimMsProgressRunnable runnable = new ModellingListCLimMsProgressRunnable(f, null); + String[][] values = runnable.readFile(); + assertEquals(2, values.length); + assertEquals(5, values[0].length); + assertArrayEquals(new String[]{"A", "", "B", "C", "D"}, values[0]); + assertEquals(5, values[1].length); + assertArrayEquals(new String[]{"E", "F", "", "G", "H"}, values[1]); + } + @Test + public void testReadCsv() throws IOException { + File f = CtuluLibFile.getFileFromJar("/org/fudaa/fudaa/crue/modelling/calcul/example.csv", File.createTempFile("example", ".csv")); + testContent(f); + + } + +} Added: trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/modelling/calcul/example.csv =================================================================== --- trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/modelling/calcul/example.csv (rev 0) +++ trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/modelling/calcul/example.csv 2016-02-24 12:20:58 UTC (rev 9290) @@ -0,0 +1,2 @@ +A;;B;C;D +E;F;;G;H Added: trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/modelling/calcul/example.xlsx =================================================================== (Binary files differ) Index: trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/modelling/calcul/example.xlsx =================================================================== --- trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/modelling/calcul/example.xlsx 2016-02-24 11:06:45 UTC (rev 9289) +++ trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/modelling/calcul/example.xlsx 2016-02-24 12:20:58 UTC (rev 9290) Property changes on: trunk/soft/fudaa-crue/ui-modelling/src/test/resources/org/fudaa/fudaa/crue/modelling/calcul/example.xlsx ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |