Author: tchemit Date: 2014-04-22 17:45:06 +0200 (Tue, 22 Apr 2014) New Revision: 1016 Url: http://forge.codelutin.com/projects/echobase/repository/revisions/1016 Log: fixes #4985 (+ use NA constant) Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/csv/EchoBaseCsvUtil.java trunk/echobase-domain/src/main/java/fr/ifremer/echobase/csv/ResultValueParser.java trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/EchoBaseEntityHelper.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/exportCoser/RawDataSizeExportModel.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AbstractImportDataService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AcousticImportConfiguration.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsRegionCellImportService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/RegionCellResultImportModel.java Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/csv/EchoBaseCsvUtil.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/csv/EchoBaseCsvUtil.java 2014-04-22 14:51:05 UTC (rev 1015) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/csv/EchoBaseCsvUtil.java 2014-04-22 15:45:06 UTC (rev 1016) @@ -69,13 +69,13 @@ @Override public String format(Float value) { - return value == null ? "NA" : super.format(value); + return value == null ? NA : super.format(value); } @Override protected Float parseNoneEmptyValue(String value) { Float result = null; - if (!"NA".equals(value)) { + if (!NA.equals(value)) { result = super.parseNoneEmptyValue(value); } return result; @@ -88,7 +88,7 @@ @Override protected Float parseNoneEmptyValue(String value) { Float result; - if (!"NA".equals(value)) { + if (!NA.equals(value)) { result = super.parseNoneEmptyValue(value); } else { result = defaultValue; @@ -102,13 +102,13 @@ @Override public String format(Integer value) { - return value == null ? "NA" : super.format(value); + return value == null ? NA : super.format(value); } @Override protected Integer parseNoneEmptyValue(String value) { Integer result = null; - if (!"NA".equals(value)) { + if (!NA.equals(value)) { result = super.parseNoneEmptyValue(value); } return result; @@ -132,6 +132,8 @@ public static final String DEPTH_STRATUM_ID = "depthStratumId"; + public static final String NA = "NA"; + protected EchoBaseCsvUtil() { // avoid instanciation on helper class } Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/csv/ResultValueParser.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/csv/ResultValueParser.java 2014-04-22 14:51:05 UTC (rev 1015) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/csv/ResultValueParser.java 2014-04-22 15:45:06 UTC (rev 1016) @@ -50,7 +50,7 @@ Result result = new ResultImpl(); result.setDataMetadata(metadata); result.setResultValue(value); - if ("NA".equals(value) && useFillValue) { + if (EchoBaseCsvUtil.NA.equals(value) && useFillValue) { // use metadata fillValue result.setResultValue(String.valueOf(metadata.getFillValue())); Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/EchoBaseEntityHelper.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/EchoBaseEntityHelper.java 2014-04-22 14:51:05 UTC (rev 1015) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/EchoBaseEntityHelper.java 2014-04-22 15:45:06 UTC (rev 1016) @@ -51,12 +51,6 @@ /** Logger. */ private static final Log log = LogFactory.getLog(EchoBaseEntityHelper.class); -// public static TopiaContext newTransactionFromRootContext(TopiaContext otherTx) throws TopiaException { -// TopiaContextImplementor rootContext = ((TopiaContextImplementor) otherTx).getRootContext(); -// TopiaContext tx = rootContext.beginTransaction(); -// return tx; -// } - public static void releaseApplicationContext(TopiaApplicationContext context) { if (log.isInfoEnabled()) { Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java 2014-04-22 14:51:05 UTC (rev 1015) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java 2014-04-22 15:45:06 UTC (rev 1016) @@ -27,6 +27,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import fr.ifremer.echobase.EchoBaseTechnicalException; import fr.ifremer.echobase.entities.EchoBaseUserPersistenceContext; import fr.ifremer.echobase.entities.EntityModificationLog; @@ -225,9 +226,9 @@ //--- CellType -----------------------------------------------------------// //------------------------------------------------------------------------// - public List<CellType> getAllCellTypes() { + public Set<CellType> getRegionCellTypes() { List<CellType> cellTypes = persistenceContext.getCellTypeDao().findAll(); - return cellTypes; + return Sets.newHashSet(Iterables.filter(cellTypes, fr.ifremer.echobase.EchoBasePredicates.IS_REGION_CELL_TYPE)); } public CellType getCellType(String id) { Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/exportCoser/RawDataSizeExportModel.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/exportCoser/RawDataSizeExportModel.java 2014-04-22 14:51:05 UTC (rev 1015) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/exportCoser/RawDataSizeExportModel.java 2014-04-22 15:45:06 UTC (rev 1016) @@ -110,7 +110,7 @@ public String format(SexCategory value) { String result; if (value == null || "N".equals(value.getName())) { - result = "NA"; + result = EchoBaseCsvUtil.NA; } else { result = value.getName(); } @@ -187,7 +187,7 @@ row.setOperation(operation); row.setSpecies(species); row.setSexCategory(numberWeight.sexCategory); - row.setMaturite("NA"); + row.setMaturite(EchoBaseCsvUtil.NA); row.setLengthStep(lengthStep); row.setNumber((int) numberWeight.number); row.setWeight(numberWeight.weight); Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AbstractImportDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AbstractImportDataService.java 2014-04-22 14:51:05 UTC (rev 1015) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AbstractImportDataService.java 2014-04-22 15:45:06 UTC (rev 1016) @@ -42,7 +42,6 @@ import fr.ifremer.echobase.entities.references.SpeciesCategory; import fr.ifremer.echobase.io.InputFile; import fr.ifremer.echobase.services.EchoBaseServiceSupport; -import fr.ifremer.echobase.services.service.DecoratorService; import fr.ifremer.echobase.services.service.UserDbPersistenceService; import fr.ifremer.echobase.services.service.spatial.SpatialService; import org.apache.commons.lang3.StringUtils; @@ -230,13 +229,14 @@ } catch (IOException e) { throw new EchoBaseTechnicalException( "Could not close reader on file " + - inputFile.getFile(), e); + inputFile.getFile(), e + ); } } protected String getImportMessage(M configuration, InputFile inputFile) { String message = l(getLocale(), "echobase.importLabel.withFile", - getImportLabel(configuration), inputFile.getFileName()); + getImportLabel(configuration), inputFile.getFileName()); return message; } @@ -380,8 +380,9 @@ if (dataMetadata == null) { throw new ImportRuntimeException( l(locale, "echobase.importError.dataMetadata.notFound", - metadataName, - dataMetadataMap.keySet())); + metadataName, + dataMetadataMap.keySet()) + ); } result.add(dataMetadata); } @@ -407,10 +408,31 @@ String resultLabel, EchoBaseCsvFileImportResult importResult, boolean collecIds) { + addResults(row, + cell, + category, + resultLabel, + importResult, + collecIds, + true); + } + + protected void addResults(EchoBaseCsvUtil.ResultAble row, + Cell cell, + Category category, + String resultLabel, + EchoBaseCsvFileImportResult importResult, + boolean collecIds, + boolean importNAResults) { List<Result> results = row.getResult(); for (Result result : results) { + if (!importNAResults && EchoBaseCsvUtil.NA.equals(result.getResultValue())) { + + // Do not import NA results + continue; + } result.setDataQuality(row.getDataQuality()); result.setCategory(category); result.setResultLabel(resultLabel); Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AcousticImportConfiguration.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AcousticImportConfiguration.java 2014-04-22 14:51:05 UTC (rev 1015) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/AcousticImportConfiguration.java 2014-04-22 15:45:06 UTC (rev 1016) @@ -20,6 +20,7 @@ */ package fr.ifremer.echobase.services.service.importdata; +import fr.ifremer.echobase.csv.EchoBaseCsvUtil; import fr.ifremer.echobase.entities.ImportType; import fr.ifremer.echobase.io.InputFile; @@ -68,7 +69,7 @@ protected String soundSpeedCalculationsME70 = "(i) Equation: Mackenzie (1980), (ii) Hull-mounted thermosalinometer, (iii) surface absorption value recomputed every 30s and applied to the entire data set"; /** Manual sounderConstant. */ - protected String sounderConstant = "NA"; + protected String sounderConstant = EchoBaseCsvUtil.NA; /** Manual processingTemplate. */ protected String processingTemplate; Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsRegionCellImportService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsRegionCellImportService.java 2014-04-22 14:51:05 UTC (rev 1015) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsRegionCellImportService.java 2014-04-22 15:45:06 UTC (rev 1016) @@ -29,7 +29,6 @@ import fr.ifremer.echobase.entities.data.Echotype; import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.entities.references.CellType; -import fr.ifremer.echobase.entities.references.CellTypeImpl; import fr.ifremer.echobase.entities.references.DataMetadata; import fr.ifremer.echobase.entities.references.DataMetadataImpl; import fr.ifremer.echobase.entities.references.DataQuality; @@ -50,7 +49,6 @@ import java.io.Reader; import java.util.Arrays; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -97,14 +95,8 @@ InputFile inputFile = configuration.getRegionsFile(); - Set<CellType> allCellTypes = new HashSet<CellType>(persistenceService.getAllCellTypes()); + Set<CellType> allCellTypes = persistenceService.getRegionCellTypes(); - // remove some cell types (esdu, elementary, shoal) - allCellTypes.remove(persistenceService.getCellTypeById(CellTypeImpl.ELEMENTARY)); - allCellTypes.remove(persistenceService.getCellTypeById(CellTypeImpl.ESDU)); - allCellTypes.remove(persistenceService.getCellTypeById(CellTypeImpl.MAP)); - allCellTypes.remove(persistenceService.getCellTypeById(CellTypeImpl.SHOAL)); - DataMetadata dataCoordinateMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.REGION_ENV_COORDINATES); DataMetadata dataSurfaceMeta = persistenceService.getDataMetadataByName(DataMetadataImpl.SURFACE); @@ -303,7 +295,7 @@ null, importResult); - addResults(row, cell, category, resultLabel, importResult, false); + addResults(row, cell, category, resultLabel, importResult, false, false); } return importResult; Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/RegionCellResultImportModel.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/RegionCellResultImportModel.java 2014-04-22 14:51:05 UTC (rev 1015) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/RegionCellResultImportModel.java 2014-04-22 15:45:06 UTC (rev 1016) @@ -72,7 +72,7 @@ for (DataMetadata metadata : dataMetadatas) { newMandatoryColumn( metadata.getName(), - EchoBaseCsvUtil.newResultValueParser(metadata, true), + EchoBaseCsvUtil.newResultValueParser(metadata, false), EchoBaseCsvUtil.<RegionCellResultImportRow>newResultValueSetter()); } }