Author: tchemit Date: 2014-04-22 16:15:39 +0200 (Tue, 22 Apr 2014) New Revision: 1011 Url: http://forge.codelutin.com/projects/echobase/repository/revisions/1011 Log: fixes Anomalie #4888: Pas possible d'importer une cellule de type r?\195?\169gion avec un cellType=='Region' (alors qu'il faudrait pouvoir le faire pour le grand polygone du survey) Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/EchoBasePredicates.java trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/CellTypeImpl.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/importdata/ResultsRegionCellImportService.java Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/EchoBasePredicates.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/EchoBasePredicates.java 2014-04-17 09:38:52 UTC (rev 1010) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/EchoBasePredicates.java 2014-04-22 14:15:39 UTC (rev 1011) @@ -29,6 +29,7 @@ import fr.ifremer.echobase.entities.data.Sample; import fr.ifremer.echobase.entities.references.AcousticInstrument; import fr.ifremer.echobase.entities.references.CellType; +import fr.ifremer.echobase.entities.references.CellTypeImpl; import fr.ifremer.echobase.entities.references.SampleTypeImpl; import fr.ifremer.echobase.entities.references.SizeCategory; import org.apache.commons.collections4.CollectionUtils; @@ -58,41 +59,41 @@ } }; - public static final Predicate<CellType> IS_REGION_CELL_TYPE = new Predicate<CellType>() { + public static final Predicate<CellType> IS_ESDU_CELL_TYPE = new Predicate<CellType>() { - public final Set<String> acceptedNames = Sets.newHashSet( - "RegionCLAS", "RegionSURF" - ); - @Override public boolean apply(CellType input) { - boolean result = acceptedNames.contains(input.getId()); + boolean result = CellTypeImpl.ESDU.equals(input.getId().toLowerCase()); return result; } }; - public static final Predicate<CellType> IS_ESDU_CELL_TYPE = new Predicate<CellType>() { + public static final Predicate<CellType> IS_ELEMENTARY_CELL_TYPE = new Predicate<CellType>() { @Override public boolean apply(CellType input) { - boolean result = "esdu".equals(input.getId().toLowerCase()); + boolean result = CellTypeImpl.ELEMENTARY.equals(input.getId().toLowerCase()); return result; } }; - public static final Predicate<CellType> IS_ELEMENTARY_CELL_TYPE = new Predicate<CellType>() { + public static final Predicate<CellType> IS_MAP_CELL_TYPE = new Predicate<CellType>() { + public final Set<String> acceptedNames = Sets.newHashSet( + CellTypeImpl.MAP + ); + @Override public boolean apply(CellType input) { - boolean result = "elementary".equals(input.getId().toLowerCase()); + boolean result = acceptedNames.contains(input.getId()); return result; } }; - public static final Predicate<CellType> IS_MAP_CELL_TYPE = new Predicate<CellType>() { + public static final Predicate<CellType> IS_SHOAL_CELL_TYPE = new Predicate<CellType>() { public final Set<String> acceptedNames = Sets.newHashSet( - "Map" + CellTypeImpl.SHOAL ); @Override @@ -102,6 +103,12 @@ } }; + public static final Predicate<CellType> IS_REGION_CELL_TYPE = Predicates.not(Predicates.and( + IS_ESDU_CELL_TYPE, + IS_ELEMENTARY_CELL_TYPE, + IS_SHOAL_CELL_TYPE, + IS_MAP_CELL_TYPE)); + public static final Predicate<Cell> IS_REGION_CELL = new Predicate<Cell>() { @Override public boolean apply(Cell input) { Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/CellTypeImpl.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/CellTypeImpl.java 2014-04-17 09:38:52 UTC (rev 1010) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/CellTypeImpl.java 2014-04-22 14:15:39 UTC (rev 1011) @@ -25,6 +25,8 @@ public static final String MAP = "Map"; + public static final String REGION = "Region"; + public static final String REGION_SURF = "RegionSURF"; public static final String REGION_CLAS = "RegionCLAS"; @@ -33,5 +35,7 @@ public static final String ESDU = "Esdu"; + public static final String SHOAL = "Shoal"; + private static final long serialVersionUID = 3631136258339910497L; } //CellTypeImpl 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-17 09:38:52 UTC (rev 1010) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java 2014-04-22 14:15:39 UTC (rev 1011) @@ -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,6 +226,11 @@ //--- CellType -----------------------------------------------------------// //------------------------------------------------------------------------// + public List<CellType> getAllCellTypes() { + List<CellType> cellTypes = persistenceContext.getCellTypeDao().findAll(); + return cellTypes; + } + public CellType getCellType(String id) { CellType cellType = persistenceContext.getCellTypeDao().findByTopiaId(id); return cellType; 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-17 09:38:52 UTC (rev 1010) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/ResultsRegionCellImportService.java 2014-04-22 14:15:39 UTC (rev 1011) @@ -50,8 +50,10 @@ import java.io.Reader; import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; /** * To import regions results attached to a voyage. @@ -95,9 +97,13 @@ InputFile inputFile = configuration.getRegionsFile(); - CellType cellSurfaceType = persistenceService.getCellTypeById(CellTypeImpl.REGION_SURF); + Set<CellType> allCellTypes = new HashSet<CellType>(persistenceService.getAllCellTypes()); - CellType cellBottomType = persistenceService.getCellTypeById(CellTypeImpl.REGION_CLAS); + // 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); @@ -109,7 +115,7 @@ // authorize only to use region* cell types Map<String, CellType> cellTypeMap = Maps.uniqueIndex( - Arrays.asList(cellSurfaceType, cellBottomType), + allCellTypes, EchoBaseFunctions.CELL_TYPE_ID); RegionCellImportModel csvModel = new RegionCellImportModel(