Author: tchemit Date: 2012-09-16 15:56:31 +0200 (Sun, 16 Sep 2012) New Revision: 669 Url: http://forge.codelutin.com/repositories/revision/echobase/669 Log: refs #1437: Suppression des imports (continue testing and fixing stuff) Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceTest.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AcousticRemoveDataServiceTest.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CatchesRemoveDataServiceTest.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceTest.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceTest.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/OperationRemoveDataServiceTest.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultEsduRemoveDataServiceTest.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultMapRemoveDataServiceTest.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultRegionRemoveDataServiceTest.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultVoyageRemoveDataServiceTest.java Removed: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceIT.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceIT.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceIT.java Modified: trunk/echobase-domain/src/main/xmi/echobase.zargo trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportConfiguration.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/CommonImportConfiguration.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsImportConfiguration.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/AbstractRemoveDataStrategy.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/AcousticRemoveDataStrategy.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CatchesRemoveDataStrategy.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CommonAllRemoveDataStrategy.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CommonTransectRemoveDataStrategy.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/LegacyVoyageRemoveDataStrategy.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/OperationRemoveDataStrategy.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultEsduRemoveDataStrategy.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultMapRemoveDataStrategy.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultRegionRemoveDataStrategy.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultVoyageRemoveDataStrategy.java Modified: trunk/echobase-domain/src/main/xmi/echobase.zargo =================================================================== (Binary files differ) Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportConfiguration.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportConfiguration.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportConfiguration.java 2012-09-16 13:56:31 UTC (rev 669) @@ -94,6 +94,10 @@ return importType; } + public final void setImportType(ImportType importType) { + this.importType = importType; + } + public List<EchoBaseCsvFileImportResult> getImportResults() { return importResults; } Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/CommonImportConfiguration.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/CommonImportConfiguration.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/CommonImportConfiguration.java 2012-09-16 13:56:31 UTC (rev 669) @@ -23,7 +23,6 @@ */ package fr.ifremer.echobase.services.importdata; -import fr.ifremer.echobase.entities.ImportType; import fr.ifremer.echobase.io.InputFile; import java.util.Locale; @@ -82,10 +81,6 @@ l_(locale, "echobase.common.transectFile")); } - public void setImportType(ImportType importType) { - this.importType = importType; - } - public String getMissionId() { return missionId; } Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsImportConfiguration.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsImportConfiguration.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsImportConfiguration.java 2012-09-16 13:56:31 UTC (rev 669) @@ -23,7 +23,6 @@ */ package fr.ifremer.echobase.services.importdata; -import fr.ifremer.echobase.entities.ImportType; import fr.ifremer.echobase.io.InputFile; import java.util.Locale; @@ -123,10 +122,6 @@ this.dataProcessingId = dataProcessingId; } - public void setImportType(ImportType importType) { - this.importType = importType; - } - public String getResultLabel() { return resultLabel; } Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/AbstractRemoveDataStrategy.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/AbstractRemoveDataStrategy.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/AbstractRemoveDataStrategy.java 2012-09-16 13:56:31 UTC (rev 669) @@ -37,6 +37,8 @@ import fr.ifremer.echobase.entities.data.LengthAgeKeyDAO; import fr.ifremer.echobase.entities.data.LengthWeightKey; import fr.ifremer.echobase.entities.data.LengthWeightKeyDAO; +import fr.ifremer.echobase.entities.data.Result; +import fr.ifremer.echobase.entities.data.ResultDAO; import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.entities.data.VoyageDAO; import fr.ifremer.echobase.services.EchoBaseServiceContext; @@ -44,9 +46,16 @@ import fr.ifremer.echobase.services.removedata.RemoveDataConfiguration; import org.apache.commons.collections.CollectionUtils; import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaSQLQuery; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Set; @@ -77,6 +86,8 @@ protected LengthWeightKeyDAO lengthWeightKeyDAO; + protected ResultDAO resultDAO; + @Override public void setServiceContext(EchoBaseServiceContext serviceContext) { super.setServiceContext(serviceContext); @@ -87,6 +98,7 @@ lengthAgeKeyDAO = getDAO(LengthAgeKey.class, LengthAgeKeyDAO.class); lengthWeightKeyDAO = getDAO(LengthWeightKey.class, LengthWeightKeyDAO.class); categoryDAO = getDAO(Category.class, CategoryDAO.class); + resultDAO = getDAO(Result.class, ResultDAO.class); } protected abstract void removeImportData(Voyage voyage, @@ -98,7 +110,7 @@ Voyage voyage = voyageDao.findByTopiaId(importLog.getVoyageId()); - removeDataInVoyage(voyage); + removePreDataInVoyage(voyage); int currentIndex = 0; for (String importId : importLog.getImportId()) { @@ -117,11 +129,24 @@ } } -// flushTransaction("Could not flush transaction"); + flushTransaction("Could not flush transaction"); + + removePostDataInVoyage(voyage); + + + flushTransaction("Could not flush transaction"); } - protected abstract void removeDataInVoyage(Voyage voyage) throws TopiaException; + protected void removePreDataInVoyage(Voyage voyage) throws TopiaException { + // by default nothing to remove + } + + protected void removePostDataInVoyage(Voyage voyage) throws TopiaException { + + // by default nothing to remove + } + protected <E extends TopiaEntity> E removeEntity(TopiaDAO<E> dao, String id) throws TopiaException { @@ -170,27 +195,28 @@ List<Category> allByEchotype = categoryDAO.findAllByEchotype(echotype); categoryDAO.deleteAll(allByEchotype); +// if (entity != null) { +// +// // remove it from the voyage +// entity.removeEchotype(echotype); +// } + // delete echotype echotypeDAO.delete(echotype); - if (entity != null) { - - // remove it from the voyage - entity.removeEchotype(echotype); - } } protected void removePostCell(Voyage entity, Cell cell) throws TopiaException { - // delete postcell - cellDAO.delete(cell); - if (entity != null) { // remove it from the voyage entity.removePostCell(cell); } + + // delete postcell + cellDAO.delete(cell); } protected void removeVoyage(Voyage entity) throws TopiaException { @@ -227,4 +253,49 @@ "Could not flush transaction after removing postCells"); } } + + protected void removeVoyageCellResults(final Voyage voyage) throws TopiaException { + + // Get all cells of the voyage + TopiaSQLQuery<String> query = new TopiaSQLQuery<String>() { + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + String hql = "SELECT c.topiaid FROM Transit ta, " + + " Transect te, " + + " DataAcquisition da, " + + " DataProcessing dp, " + + " Cell c " + + "WHERE ta.voyage = ? " + + "AND ta.topiaId = te.transit " + + "AND te.topiaId = da.transect " + + "AND da.topiaId = dp.dataacquisition " + + "AND dp.topiaId = c.dataprocessing"; + PreparedStatement result = connection.prepareStatement(hql); + result.setString(1, voyage.getTopiaId()); + return result; + } + + @Override + protected String prepareResult(ResultSet set) throws SQLException { + return set.getString(1); + } + }; + + List<String> cellIds = query.findMultipleResult( + (TopiaContextImplementor) getTransaction()); + + // remove all result of cells + + for (String cellId : cellIds) { + Cell cell = cellDAO.findByTopiaId(cellId); + if (cell != null && !cell.isResultEmpty()) { + Collection<Result> cellResult = cell.getResult(); +// for (Result result : cellResult) { +// cell.removeResult(result); +// } + resultDAO.deleteAll(cellResult); + cell.clearResult(); + } + } + } } Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/AcousticRemoveDataStrategy.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/AcousticRemoveDataStrategy.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/AcousticRemoveDataStrategy.java 2012-09-16 13:56:31 UTC (rev 669) @@ -28,6 +28,10 @@ import fr.ifremer.echobase.entities.data.Cell; import fr.ifremer.echobase.entities.data.DataAcquisition; import fr.ifremer.echobase.entities.data.DataAcquisitionDAO; +import fr.ifremer.echobase.entities.data.DataProcessing; +import fr.ifremer.echobase.entities.data.DataProcessingDAO; +import fr.ifremer.echobase.entities.data.Transect; +import fr.ifremer.echobase.entities.data.TransectDAO; import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.services.EchoBaseServiceContext; import org.apache.commons.logging.Log; @@ -50,18 +54,27 @@ private static final Log log = LogFactory.getLog(AcousticRemoveDataStrategy.class); + protected DataProcessingDAO dataProcessingDAO; + protected DataAcquisitionDAO dataAcquisitionDAO; + protected TransectDAO transectDAO; + @Override public void setServiceContext(EchoBaseServiceContext serviceContext) { super.setServiceContext(serviceContext); dataAcquisitionDAO = getDAO(DataAcquisition.class, DataAcquisitionDAO.class); + dataProcessingDAO = getDAO(DataProcessing.class, DataProcessingDAO.class); + transectDAO = getDAO(Transect.class, TransectDAO.class); } @Override - protected void removeDataInVoyage(Voyage voyage) throws TopiaException { + protected void removePostDataInVoyage(Voyage voyage) throws TopiaException { + // remove all cell results + removeVoyageCellResults(voyage); + // remove post cell from top voyage removeVoyagePostCell(voyage); } @@ -71,17 +84,31 @@ if (id.startsWith(DataAcquisition.class.getName())) { + // get dataAcquisition + DataAcquisition dataAcquisition = dataAcquisitionDAO.findByTopiaId(id); + + // remove it from cell + Transect transect = transectDAO.findContainsDataAcquisition(dataAcquisition); + transect.removeDataAcquisition(dataAcquisition); + // remove dataAcquisition - DataAcquisition entity = removeEntity(dataAcquisitionDAO, id); + delete(dataAcquisitionDAO, dataAcquisition); if (log.isInfoEnabled()) { - log.info("DataAcquisition " + entity.getTopiaId() + " was removed"); + log.info("DataAcquisition " + dataAcquisition.getTopiaId() + " was removed"); } } else if (id.startsWith(Cell.class.getName())) { + // get cell + Cell cell = cellDAO.findByTopiaId(id); + + // remove it from the dataAcquisition + DataProcessing dataProcessing = dataProcessingDAO.findContainsCell(cell); + dataProcessing.removeCell(cell); + // remove cell - Cell entity = removeEntity(cellDAO, id); + delete(cellDAO, cell); if (log.isInfoEnabled()) { - log.info("Cell " + entity.getTopiaId() + " was removed"); + log.info("Cell " + cell.getTopiaId() + " was removed"); } } else { canNotDealWithId(id); @@ -90,7 +117,8 @@ @Override public Set<ImportType> getPossibleSubImportType() { - Set<ImportType> result = Sets.newHashSet(ImportType.RESULT_ESDU, + Set<ImportType> result = Sets.newHashSet(ImportType.RESULT_VOYAGE, + ImportType.RESULT_ESDU, ImportType.RESULT_MAP, ImportType.RESULT_REGION); return result; Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CatchesRemoveDataStrategy.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CatchesRemoveDataStrategy.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CatchesRemoveDataStrategy.java 2012-09-16 13:56:31 UTC (rev 669) @@ -24,6 +24,8 @@ */ import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Operation; +import fr.ifremer.echobase.entities.data.OperationDAO; import fr.ifremer.echobase.entities.data.Sample; import fr.ifremer.echobase.entities.data.SampleDAO; import fr.ifremer.echobase.entities.data.Voyage; @@ -51,26 +53,31 @@ protected SampleDAO sampleDAO; + protected OperationDAO operationDAO; + @Override public void setServiceContext(EchoBaseServiceContext serviceContext) { super.setServiceContext(serviceContext); sampleDAO = getDAO(Sample.class, SampleDAO.class); + operationDAO = getDAO(Operation.class, OperationDAO.class); } @Override - protected void removeDataInVoyage(Voyage voyage) throws TopiaException { - // nothing to do on voyage level - } - - @Override protected void removeImportData(Voyage voyage, String id) throws TopiaException { if (id.startsWith(Sample.class.getName())) { + // get sample + Sample sample = sampleDAO.findByTopiaId(id); + + // remove it from operation + Operation operation = operationDAO.findContainsSample(sample); + operation.removeSample(sample); + // remove sample - Sample entity = removeEntity(sampleDAO, id); + delete(sampleDAO, sample); if (log.isInfoEnabled()) { - log.info("Sample " + entity.getTopiaId() + " was removed"); + log.info("Sample " + sample.getTopiaId() + " was removed"); } } else { canNotDealWithId(id); Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CommonAllRemoveDataStrategy.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CommonAllRemoveDataStrategy.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CommonAllRemoveDataStrategy.java 2012-09-16 13:56:31 UTC (rev 669) @@ -47,16 +47,10 @@ LogFactory.getLog(CommonAllRemoveDataStrategy.class); @Override - protected void removeDataInVoyage(Voyage voyage) throws TopiaException { - // nothing to do on voyage level (done by voyage id)... - } - - @Override protected void removeImportData(Voyage voyage, String id) throws TopiaException { if (id.startsWith(Voyage.class.getName())) { - // remove voyage // get entity to delete Voyage entity = voyageDao.findByTopiaId(id); Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CommonTransectRemoveDataStrategy.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CommonTransectRemoveDataStrategy.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CommonTransectRemoveDataStrategy.java 2012-09-16 13:56:31 UTC (rev 669) @@ -64,7 +64,7 @@ } @Override - protected void removeDataInVoyage(Voyage voyage) throws TopiaException { + protected void removePreDataInVoyage(Voyage voyage) throws TopiaException { // remove postCell from voyage removeVoyagePostCell(voyage); Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/LegacyVoyageRemoveDataStrategy.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/LegacyVoyageRemoveDataStrategy.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/LegacyVoyageRemoveDataStrategy.java 2012-09-16 13:56:31 UTC (rev 669) @@ -47,11 +47,6 @@ LogFactory.getLog(LegacyVoyageRemoveDataStrategy.class); @Override - protected void removeDataInVoyage(Voyage voyage) throws TopiaException { - // nothing to do on voyage level - } - - @Override protected void removeImportData(Voyage voyage, String id) throws TopiaException { if (id.startsWith(Voyage.class.getName())) { Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/OperationRemoveDataStrategy.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/OperationRemoveDataStrategy.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/OperationRemoveDataStrategy.java 2012-09-16 13:56:31 UTC (rev 669) @@ -27,6 +27,8 @@ import fr.ifremer.echobase.entities.ImportType; import fr.ifremer.echobase.entities.data.Operation; import fr.ifremer.echobase.entities.data.OperationDAO; +import fr.ifremer.echobase.entities.data.Transect; +import fr.ifremer.echobase.entities.data.TransectDAO; import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.services.EchoBaseServiceContext; import org.apache.commons.logging.Log; @@ -51,28 +53,33 @@ protected OperationDAO operationDAO; + protected TransectDAO transectDAO; + @Override public void setServiceContext(EchoBaseServiceContext serviceContext) { super.setServiceContext(serviceContext); operationDAO = getDAO(Operation.class, OperationDAO.class); + transectDAO = getDAO(Transect.class, TransectDAO.class); } @Override - protected void removeDataInVoyage(Voyage voyage) throws TopiaException { - // nothing to do on voyage level - } - - @Override protected void removeImportData(Voyage voyage, String id) throws TopiaException { if (id.startsWith(Operation.class.getName())) { - // remove operation - Operation entity = removeEntity(operationDAO, id); + // get operation + Operation operation = operationDAO.findByTopiaId(id); + + // remove it from transect + Transect transect = transectDAO.findContainsOperation(operation); + transect.removeOperation(operation); + + // remove it + delete(operationDAO, operation); if (log.isInfoEnabled()) { - log.info("Operation " + entity.getTopiaId() + " was removed"); + log.info("Operation " + operation.getTopiaId() + " was removed"); } } else { canNotDealWithId(id); Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultEsduRemoveDataStrategy.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultEsduRemoveDataStrategy.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultEsduRemoveDataStrategy.java 2012-09-16 13:56:31 UTC (rev 669) @@ -24,10 +24,9 @@ */ import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Cell; import fr.ifremer.echobase.entities.data.Result; -import fr.ifremer.echobase.entities.data.ResultDAO; import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.services.EchoBaseServiceContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaException; @@ -49,29 +48,22 @@ private static final Log log = LogFactory.getLog(ResultEsduRemoveDataStrategy.class); - protected ResultDAO resultDAO; - @Override - public void setServiceContext(EchoBaseServiceContext serviceContext) { - super.setServiceContext(serviceContext); - - resultDAO = getDAO(Result.class, ResultDAO.class); - } - - @Override - protected void removeDataInVoyage(Voyage voyage) throws TopiaException { - // nothing to do on voyage level - } - - @Override protected void removeImportData(Voyage voyage, String id) throws TopiaException { if (id.startsWith(Result.class.getName())) { + // get result + Result result = resultDAO.findByTopiaId(id); + + // remove it from cell + Cell cell = cellDAO.findContainsResult(result); + cell.removeResult(result); + // remove result - Result entity = removeEntity(resultDAO, id); + delete(resultDAO, result); if (log.isDebugEnabled()) { - log.debug("Result " + entity.getTopiaId() + " was removed"); + log.debug("Result " + result.getTopiaId() + " was removed"); } } else { canNotDealWithId(id); Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultMapRemoveDataStrategy.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultMapRemoveDataStrategy.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultMapRemoveDataStrategy.java 2012-09-16 13:56:31 UTC (rev 669) @@ -48,19 +48,23 @@ LogFactory.getLog(ResultMapRemoveDataStrategy.class); @Override - protected void removeDataInVoyage(Voyage voyage) throws TopiaException { - // nothing to do on voyage level - } - - @Override protected void removeImportData(Voyage voyage, String id) throws TopiaException { if (id.startsWith(Cell.class.getName())) { + // get cell + Cell cell = cellDAO.findByTopiaId(id); + + // dettach cell childs, we do not want to delete them from here ? + cell.clearChilds(); + + // remove it from voyage + voyage.removePostCell(cell); + // remove cell - Cell entity = removeEntity(cellDAO, id); + delete(cellDAO, cell); if (log.isInfoEnabled()) { - log.info("Cell " + entity.getTopiaId() + " was removed"); + log.info("Map Cell " + cell.getTopiaId() + " was removed"); } } else { canNotDealWithId(id); Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultRegionRemoveDataStrategy.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultRegionRemoveDataStrategy.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultRegionRemoveDataStrategy.java 2012-09-16 13:56:31 UTC (rev 669) @@ -25,9 +25,7 @@ import fr.ifremer.echobase.entities.ImportType; import fr.ifremer.echobase.entities.data.Cell; -import fr.ifremer.echobase.entities.data.CellDAO; import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.services.EchoBaseServiceContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaException; @@ -50,19 +48,23 @@ LogFactory.getLog(ResultRegionRemoveDataStrategy.class); @Override - protected void removeDataInVoyage(Voyage voyage) throws TopiaException { - // nothing to do on voyage level - } - - @Override protected void removeImportData(Voyage voyage, String id) throws TopiaException { if (id.startsWith(Cell.class.getName())) { - // remove post cell - Cell entity = removeEntity(cellDAO, id); + // get cell + Cell cell = cellDAO.findByTopiaId(id); + + // dettach cell childs, we do not want to delete them from here ? + cell.clearChilds(); + + // remove it from voyage + voyage.removePostCell(cell); + + // remove cell + delete(cellDAO, cell); if (log.isInfoEnabled()) { - log.info("Cell " + entity.getTopiaId() + " was removed"); + log.info("Region Cell " + cell.getTopiaId() + " was removed"); } } else { canNotDealWithId(id); Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultVoyageRemoveDataStrategy.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultVoyageRemoveDataStrategy.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultVoyageRemoveDataStrategy.java 2012-09-16 13:56:31 UTC (rev 669) @@ -25,26 +25,14 @@ import com.google.common.collect.Sets; import fr.ifremer.echobase.entities.ImportType; -import fr.ifremer.echobase.entities.data.Cell; import fr.ifremer.echobase.entities.data.Echotype; import fr.ifremer.echobase.entities.data.LengthAgeKey; import fr.ifremer.echobase.entities.data.LengthWeightKey; -import fr.ifremer.echobase.entities.data.Result; -import fr.ifremer.echobase.entities.data.ResultDAO; import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.services.EchoBaseServiceContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.framework.TopiaSQLQuery; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Collection; -import java.util.List; import java.util.Set; /** @@ -62,60 +50,13 @@ private static final Log log = LogFactory.getLog(ResultVoyageRemoveDataStrategy.class); - - protected ResultDAO resultDAO; - @Override - public void setServiceContext(EchoBaseServiceContext serviceContext) { - super.setServiceContext(serviceContext); + protected void removePreDataInVoyage(final Voyage voyage) throws TopiaException { - resultDAO = getDAO(Result.class, ResultDAO.class); - } - - @Override - protected void removeDataInVoyage(final Voyage voyage) throws TopiaException { - removeVoyagePostCell(voyage); - // Get all cells of the voyage - TopiaSQLQuery<String> query = new TopiaSQLQuery<String>() { - @Override - protected PreparedStatement prepareQuery(Connection connection) throws SQLException { - String hql = "SELECT c.topiaid FROM TransitImpl ta, " + - " TransectImpl te, " + - " DataAcquisitionImpl da, " + - " DataProcessingImpl dp, " + - " CellImpl c " + - "WHERE ta.voyage = ? " + - "AND ta.topiaId = te.transit " + - "AND te.topiaId = da.transect " + - "AND da.topiaId = dp.dataacquisition" + - "AND dp.topiaId = c.dataprocessing"; - PreparedStatement result = connection.prepareStatement(hql); - result.setString(1, voyage.getTopiaId()); - return result; - } + removeVoyageCellResults(voyage); - @Override - protected String prepareResult(ResultSet set) throws SQLException { - return set.getString(1); - } - }; - - List<String> cellIds = query.findMultipleResult( - (TopiaContextImplementor) getTransaction()); - - // remove all result of cells - - for (String cellId : cellIds) { - Cell cell = cellDAO.findByTopiaId(cellId); - Collection<Result> cellResult = cell.getResult(); - for (Result result : cellResult) { - cell.removeResult(result); - } - resultDAO.deleteAll(cellResult); - } - flushTransaction( "Could not flush transaction after deleting data from voyage"); } Deleted: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceIT.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceIT.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceIT.java 2012-09-16 13:56:31 UTC (rev 669) @@ -1,398 +0,0 @@ -package fr.ifremer.echobase.ui.actions.removedata; - -/* - * #%L - * EchoBase :: Services - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 - 2012 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.ImportLog; -import fr.ifremer.echobase.entities.ImportType; -import fr.ifremer.echobase.entities.data.Category; -import fr.ifremer.echobase.entities.data.CategoryDAO; -import fr.ifremer.echobase.entities.data.Cell; -import fr.ifremer.echobase.entities.data.CellDAO; -import fr.ifremer.echobase.entities.data.DataAcquisition; -import fr.ifremer.echobase.entities.data.DataAcquisitionDAO; -import fr.ifremer.echobase.entities.data.DataProcessing; -import fr.ifremer.echobase.entities.data.DataProcessingDAO; -import fr.ifremer.echobase.entities.data.Echotype; -import fr.ifremer.echobase.entities.data.EchotypeDAO; -import fr.ifremer.echobase.entities.data.LengthAgeKey; -import fr.ifremer.echobase.entities.data.LengthAgeKeyDAO; -import fr.ifremer.echobase.entities.data.LengthWeightKey; -import fr.ifremer.echobase.entities.data.LengthWeightKeyDAO; -import fr.ifremer.echobase.entities.data.Transect; -import fr.ifremer.echobase.entities.data.TransectDAO; -import fr.ifremer.echobase.entities.data.Transit; -import fr.ifremer.echobase.entities.data.TransitDAO; -import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.entities.data.VoyageDAO; -import fr.ifremer.echobase.entities.references.Mission; -import fr.ifremer.echobase.entities.references.Vessel; -import fr.ifremer.echobase.services.EchoBaseTestServiceSupport; -import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; -import fr.ifremer.echobase.services.importdata.CommonAllImportService; -import fr.ifremer.echobase.services.importdata.CommonImportConfiguration; -import fr.ifremer.echobase.services.removedata.RemoveDataConfiguration; -import fr.ifremer.echobase.services.removedata.RemoveDataService; -import junit.framework.Assert; -import org.apache.commons.collections.CollectionUtils; -import org.junit.Before; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; - -import java.util.List; - -/** - * Abstract it form remove data feature. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.2 - */ -public abstract class AbstractRemoveDataServiceIT extends EchoBaseTestServiceSupport { - - protected String importCommonAll1Id; - - protected String importCommonTransect1Id; - - protected static final String voyage1Id = "fr.ifremer.echobase.entities.data.Voyage#1#1"; - - protected static final String transit1Id = "fr.ifremer.echobase.entities.data.Transit#1#1"; - - protected static final String transect1Id = "fr.ifremer.echobase.entities.data.Transect#1#1"; - - protected static final String transect1_2Id = "fr.ifremer.echobase.entities.data.Transect#1#2"; - - protected String importCommonAll2Id; - - protected String importCommonTransect2Id; - - protected static final String voyage2Id = "fr.ifremer.echobase.entities.data.Voyage#2#1"; - - protected static final String transit2Id = "fr.ifremer.echobase.entities.data.Transit#2#1"; - - protected static final String transect2Id = "fr.ifremer.echobase.entities.data.Transect#2#1"; - - protected static final String transect2_2Id = "fr.ifremer.echobase.entities.data.Transect#2#2"; - - protected VoyageDAO voyageDao; - - protected TransectDAO transectDAO; - - protected TransitDAO transitDAO; - - protected DataAcquisitionDAO dataAcquisitionDAO; - - protected DataProcessingDAO dataProcessingDAO; - - protected CellDAO cellDAO; - - protected CategoryDAO categoryDAO; - - protected EchotypeDAO echotypeDAO; - - protected LengthAgeKeyDAO lengthAgeKeyDAO; - - protected LengthWeightKeyDAO lengthWeightKeyDAO; - - @Override - protected FakeEchoBaseServiceContext initContext() { - return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_NO_DATA()); - } - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - - voyageDao = getDAO(Voyage.class, VoyageDAO.class); - transectDAO = getDAO(Transect.class, TransectDAO.class); - transitDAO = getDAO(Transit.class, TransitDAO.class); - dataAcquisitionDAO = getDAO(DataAcquisition.class, DataAcquisitionDAO.class); - dataProcessingDAO = getDAO(DataProcessing.class, DataProcessingDAO.class); - - cellDAO = getDAO(Cell.class, CellDAO.class); - echotypeDAO = getDAO(Echotype.class, EchotypeDAO.class); - lengthAgeKeyDAO = getDAO(LengthAgeKey.class, LengthAgeKeyDAO.class); - lengthWeightKeyDAO = getDAO(LengthWeightKey.class, LengthWeightKeyDAO.class); - categoryDAO = getDAO(Category.class, CategoryDAO.class); - } - - protected void removeImport(String importId) { - RemoveDataConfiguration conf = new RemoveDataConfiguration(); - conf.setImportLogId(importId); - - RemoveDataService service = getService(RemoveDataService.class); - - EchoBaseUser fakeUser = createFakeUser(); - - service.removeImport(conf, fakeUser); - } - - - protected <E extends TopiaEntity> void assertEntityDeleted(Class<E> entityType, String... entityIds) throws TopiaException { - TopiaDAO<E> dao = getDAO(entityType); - for (String entityId : entityIds) { - E entity = dao.findByTopiaId(entityId); - Assert.assertNull("Entity with id " + entityId + " should have been deleted, but is still in db :(", entity); - } - } - - protected <E extends TopiaEntity> void assertEntityExists(Class<E> entityType, String... entityIds) throws TopiaException { - TopiaDAO<E> dao = getDAO(entityType); - for (String entityId : entityIds) { - E entity = dao.findByTopiaId(entityId); - Assert.assertNotNull("Entity with id " + entityId + " should have not been deleted, but is deleted in db :(", entity); - } - } - - protected <E extends TopiaEntity> E getFirstEntity(Class<E> entityType) { - List<E> entities = getEntities(entityType); - Assert.assertTrue(CollectionUtils.isNotEmpty(entities)); - return entities.get(0); - } - - protected void createCommonAllImportV1() { - - // create voyage - Voyage voyage1 = create(voyageDao, - TopiaEntity.TOPIA_ID, voyage1Id, - Voyage.PROPERTY_MISSION, getFirstEntity(Mission.class), - Voyage.PROPERTY_NAME, "voyage1", - Voyage.PROPERTY_START_DATE, newDate(), - Voyage.PROPERTY_END_DATE, newDate(), - Voyage.PROPERTY_START_PORT, "voyage1StartPort", - Voyage.PROPERTY_END_PORT, "voyage1EndPort", - Voyage.PROPERTY_DESCRIPTION, "voyage1Description", - Voyage.PROPERTY_DATUM, "voyage1Datum" - ); - - // create transit - Transit transit1 = create(transitDAO, - TopiaEntity.TOPIA_ID, transit1Id, - Transit.PROPERTY_START_TIME, newDate(), - Transit.PROPERTY_END_TIME, newDate(), - Transit.PROPERTY_START_LOCALITY, "transit1tartLocality", - Transit.PROPERTY_END_LOCALITY, "transit1EndLocality", - Transit.PROPERTY_DESCRIPTION, "transit1Description", - Transit.PROPERTY_RELATED_ACTIVITY, "transit1RelatedActivity" - ); - voyage1.addTransit(transit1); - - // create transect - Transect transect1 = create(transectDAO, - TopiaEntity.TOPIA_ID, transect1Id, - Transect.PROPERTY_TITLE, "transect1Title", - Transect.PROPERTY_VESSEL, getFirstEntity(Vessel.class), - Transect.PROPERTY_STRATUM, "transect1Stratum" - ); - transit1.addTransect(transect1); - - commitTransaction("ImportError!"); - - CommonImportConfiguration importConf = - new CommonImportConfiguration(getLocale()); - importConf.setImportType(ImportType.COMMON_ALL); - importConf.setImportNotes("Common/Voyage/Transit/Transect1"); - importConf.setVoyageId(voyage1.getTopiaId()); - - CommonAllImportService importService = - getService(CommonAllImportService.class); - - ImportLog importLog = importService.computeImportLogEntry( - importConf, createFakeUser()); - - importLog.addImportId(voyage1.getTopiaId()); - - commitTransaction("ImportLogError!"); - - importCommonAll1Id = importLog.getTopiaId(); - } - - protected void createCommonAllImportV2() { - - // create voyage - Voyage voyage1 = create(voyageDao, - TopiaEntity.TOPIA_ID, voyage2Id, - Voyage.PROPERTY_MISSION, getFirstEntity(Mission.class), - Voyage.PROPERTY_NAME, "voyage1", - Voyage.PROPERTY_START_DATE, newDate(), - Voyage.PROPERTY_END_DATE, newDate(), - Voyage.PROPERTY_START_PORT, "voyage1StartPort", - Voyage.PROPERTY_END_PORT, "voyage1EndPort", - Voyage.PROPERTY_DESCRIPTION, "voyage1Description", - Voyage.PROPERTY_DATUM, "voyage1Datum" - ); - - // create transit - Transit transit1 = create(transitDAO, - TopiaEntity.TOPIA_ID, transit2Id, - Transit.PROPERTY_START_TIME, newDate(), - Transit.PROPERTY_END_TIME, newDate(), - Transit.PROPERTY_START_LOCALITY, "transit1tartLocality", - Transit.PROPERTY_END_LOCALITY, "transit1EndLocality", - Transit.PROPERTY_DESCRIPTION, "transit1Description", - Transit.PROPERTY_RELATED_ACTIVITY, "transit1RelatedActivity" - ); - voyage1.addTransit(transit1); - - // create transect - Transect transect1 = create(transectDAO, - TopiaEntity.TOPIA_ID, transect2Id, - Transect.PROPERTY_TITLE, "transect1Title", - Transect.PROPERTY_VESSEL, getFirstEntity(Vessel.class), - Transect.PROPERTY_STRATUM, "transect1Stratum" - ); - transit1.addTransect(transect1); - - commitTransaction("ImportError!"); - - CommonImportConfiguration importConf = - new CommonImportConfiguration(getLocale()); - importConf.setImportType(ImportType.COMMON_ALL); - importConf.setImportNotes("Common/Voyage/Transit/Transect2"); - importConf.setVoyageId(voyage1.getTopiaId()); - - CommonAllImportService importService = - getService(CommonAllImportService.class); - - ImportLog importLog = importService.computeImportLogEntry( - importConf, createFakeUser()); - - importLog.addImportId(voyage1.getTopiaId()); - - commitTransaction("ImportLogError!"); - - importCommonAll2Id = importLog.getTopiaId(); - } - - protected void createCommonTransectImportV1() { - - Voyage voyage1 = getEntityById(Voyage.class, voyage1Id); - - // create transect - Transect transect2 = create(transectDAO, - TopiaEntity.TOPIA_ID, transect1_2Id, - Transect.PROPERTY_TITLE, "transect2Title", - Transect.PROPERTY_VESSEL, getFirstEntity(Vessel.class), - Transect.PROPERTY_STRATUM, "transect2Stratum" - ); - voyage1.getTransit().get(0).addTransect(transect2); - - commitTransaction("ImportError!"); - - CommonImportConfiguration importConf = - new CommonImportConfiguration(getLocale()); - importConf.setImportType(ImportType.COMMON_TRANSECT); - importConf.setImportNotes("Common/Transect1"); - importConf.setVoyageId(voyage1Id); - - CommonAllImportService importService = - getService(CommonAllImportService.class); - - ImportLog importLog = importService.computeImportLogEntry( - importConf, createFakeUser()); - - importLog.addImportId(transect2.getTopiaId()); - - commitTransaction("ImportLogError!"); - - importCommonTransect1Id = importLog.getTopiaId(); - } - - protected void createCommonTransectImportV2() { - - Voyage voyage1 = getEntityById(Voyage.class, voyage2Id); - - // create transect - Transect transect2 = create(transectDAO, - TopiaEntity.TOPIA_ID, transect2_2Id, - Transect.PROPERTY_TITLE, "transect2Title", - Transect.PROPERTY_VESSEL, getFirstEntity(Vessel.class), - Transect.PROPERTY_STRATUM, "transect2Stratum" - ); - voyage1.getTransit().get(0).addTransect(transect2); - - commitTransaction("ImportError!"); - - CommonImportConfiguration importConf = - new CommonImportConfiguration(getLocale()); - importConf.setImportType(ImportType.COMMON_TRANSECT); - importConf.setImportNotes("Common/Transect2"); - importConf.setVoyageId(voyage2Id); - - CommonAllImportService importService = - getService(CommonAllImportService.class); - - ImportLog importLog = importService.computeImportLogEntry( - importConf, createFakeUser()); - - importLog.addImportId(transect2.getTopiaId()); - - commitTransaction("ImportLogError!"); - - importCommonTransect2Id = importLog.getTopiaId(); - } - - protected void createOperationImport() { - - // create operation - // create operationMetadata - // create geartMetadata - } - - protected void createCatchesImport() { - - // create totalSample - // create subSample - // create biometrySample - } - - protected void createAcousticImport() { - - // create cell - } - - protected void createResultVoyageImport() { - - // create echotype - // create lengthAgeKey - // create lengthWeightKey - } - - protected void createResultEsduImport() { - - // create result (on ESDU) - } - - protected void createResultRegionImport() { - - // create region - // create result (on region) - } - - protected void createResultMapImport() { - - // create map - } -} Copied: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceTest.java (from rev 667, trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceIT.java) =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceTest.java (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceTest.java 2012-09-16 13:56:31 UTC (rev 669) @@ -0,0 +1,772 @@ +package fr.ifremer.echobase.ui.actions.removedata; + +/* + * #%L + * EchoBase :: Services + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.entities.ImportLog; +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Category; +import fr.ifremer.echobase.entities.data.CategoryDAO; +import fr.ifremer.echobase.entities.data.Cell; +import fr.ifremer.echobase.entities.data.CellDAO; +import fr.ifremer.echobase.entities.data.Data; +import fr.ifremer.echobase.entities.data.DataAcquisition; +import fr.ifremer.echobase.entities.data.DataAcquisitionDAO; +import fr.ifremer.echobase.entities.data.DataDAO; +import fr.ifremer.echobase.entities.data.DataProcessing; +import fr.ifremer.echobase.entities.data.DataProcessingDAO; +import fr.ifremer.echobase.entities.data.Echotype; +import fr.ifremer.echobase.entities.data.EchotypeDAO; +import fr.ifremer.echobase.entities.data.GearMetadataValue; +import fr.ifremer.echobase.entities.data.GearMetadataValueDAO; +import fr.ifremer.echobase.entities.data.LengthAgeKey; +import fr.ifremer.echobase.entities.data.LengthAgeKeyDAO; +import fr.ifremer.echobase.entities.data.LengthWeightKey; +import fr.ifremer.echobase.entities.data.LengthWeightKeyDAO; +import fr.ifremer.echobase.entities.data.Operation; +import fr.ifremer.echobase.entities.data.OperationDAO; +import fr.ifremer.echobase.entities.data.OperationMetadataValue; +import fr.ifremer.echobase.entities.data.OperationMetadataValueDAO; +import fr.ifremer.echobase.entities.data.Result; +import fr.ifremer.echobase.entities.data.ResultDAO; +import fr.ifremer.echobase.entities.data.Sample; +import fr.ifremer.echobase.entities.data.SampleDAO; +import fr.ifremer.echobase.entities.data.SampleData; +import fr.ifremer.echobase.entities.data.SampleDataDAO; +import fr.ifremer.echobase.entities.data.Transect; +import fr.ifremer.echobase.entities.data.TransectDAO; +import fr.ifremer.echobase.entities.data.Transit; +import fr.ifremer.echobase.entities.data.TransitDAO; +import fr.ifremer.echobase.entities.data.Voyage; +import fr.ifremer.echobase.entities.data.VoyageDAO; +import fr.ifremer.echobase.entities.references.AcousticInstrument; +import fr.ifremer.echobase.entities.references.CellType; +import fr.ifremer.echobase.entities.references.DataMetadata; +import fr.ifremer.echobase.entities.references.Gear; +import fr.ifremer.echobase.entities.references.GearMetadata; +import fr.ifremer.echobase.entities.references.Mission; +import fr.ifremer.echobase.entities.references.OperationMetadata; +import fr.ifremer.echobase.entities.references.SampleDataType; +import fr.ifremer.echobase.entities.references.SampleType; +import fr.ifremer.echobase.entities.references.Species; +import fr.ifremer.echobase.entities.references.SpeciesCategory; +import fr.ifremer.echobase.entities.references.Strata; +import fr.ifremer.echobase.entities.references.Vessel; +import fr.ifremer.echobase.services.EchoBaseTestServiceSupport; +import fr.ifremer.echobase.services.FakeEchoBaseServiceContext; +import fr.ifremer.echobase.services.importdata.AbstractImportConfiguration; +import fr.ifremer.echobase.services.importdata.AbstractImportDataService; +import fr.ifremer.echobase.services.importdata.AcousticImportConfiguration; +import fr.ifremer.echobase.services.importdata.AcousticImportService; +import fr.ifremer.echobase.services.importdata.CatchesImportConfiguration; +import fr.ifremer.echobase.services.importdata.CatchesImportService; +import fr.ifremer.echobase.services.importdata.CommonAllImportService; +import fr.ifremer.echobase.services.importdata.CommonImportConfiguration; +import fr.ifremer.echobase.services.importdata.OperationImportConfiguration; +import fr.ifremer.echobase.services.importdata.OperationImportService; +import fr.ifremer.echobase.services.importdata.ResultsEsduCellImportService; +import fr.ifremer.echobase.services.importdata.ResultsImportConfiguration; +import fr.ifremer.echobase.services.importdata.ResultsMapCellImportService; +import fr.ifremer.echobase.services.importdata.ResultsRegionCellImportService; +import fr.ifremer.echobase.services.importdata.ResultsVoyageImportService; +import fr.ifremer.echobase.services.removedata.RemoveDataConfiguration; +import fr.ifremer.echobase.services.removedata.RemoveDataService; +import junit.framework.Assert; +import org.apache.commons.collections.CollectionUtils; +import org.junit.Before; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaId; + +import java.util.List; + +/** + * Abstract test for remove data feature. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2 + */ +public abstract class AbstractRemoveDataServiceTest extends EchoBaseTestServiceSupport { + + protected String importCommonAll1Id; + + protected String importCommonTransect1Id; + + protected String importOperation1Id; + + protected String importCatches1Id; + + protected String importAcoustic1Id; + + protected String importResultVoyage1Id; + + protected String importResultEsdu1Id; + + protected String importResultRegion1Id; + + protected String importResultMap1Id; + + protected static final String voyage1Id = "fr.ifremer.echobase.entities.data.Voyage#1#1"; + + protected static final String transit1Id = "fr.ifremer.echobase.entities.data.Transit#1#1"; + + protected static final String transect1Id = "fr.ifremer.echobase.entities.data.Transect#1#1"; + + protected static final String transect1_2Id = "fr.ifremer.echobase.entities.data.Transect#1#2"; + + protected static final String operation1Id = "fr.ifremer.echobase.entities.data.Operation#1#1"; + + protected static final String totalSample1Id = "fr.ifremer.echobase.entities.data.Sample#1#total1"; + + protected static final String subSample1Id = "fr.ifremer.echobase.entities.data.Sample#1#sub1"; + + protected static final String biometrySample1Id = "fr.ifremer.echobase.entities.data.Sample#1#biometry1"; + + protected static final String dataAcquisition1Id = "fr.ifremer.echobase.entities.data.DataAcquisition#1"; + + protected static final String cellEsdu1Id = "fr.ifremer.echobase.entities.data.Cell#1#esdu1"; + + protected static final String cellMap1Id = "fr.ifremer.echobase.entities.data.Cell#1#map1"; + + protected static final String cellRegion1Id = "fr.ifremer.echobase.entities.data.Cell#1#region1"; + + protected static final String cellElementary1Id = "fr.ifremer.echobase.entities.data.Cell#1#elementary1"; + + protected static final String cellElementary1_2Id = "fr.ifremer.echobase.entities.data.Cell#1#elementary2"; + + protected static final String cellEsdu1_2Id = "fr.ifremer.echobase.entities.data.Cell#1#esdu2"; + + protected static final String resultEsdu1Id = "fr.ifremer.echobase.entities.data.Result#1#esdu1"; + + protected static final String resultMap1Id = "fr.ifremer.echobase.entities.data.Result#1#map1"; + + protected static final String resultRegion1Id = "fr.ifremer.echobase.entities.data.Result#1#region1"; + + protected static final String resultEsdu1_2Id = "fr.ifremer.echobase.entities.data.Result#1#esdu2"; + + protected static final String echotype1Id = "fr.ifremer.echobase.entities.data.Echotype#1#1"; + + protected static final String lengthAgeKey1Id = "fr.ifremer.echobase.entities.data.LengthAgeKey#1#1"; + + protected static final String lengthWeightKey1Id = "fr.ifremer.echobase.entities.data.LengthWeightKey#1#1"; + + protected String importCommonAll2Id; + + protected String importCommonTransect2Id; + + protected static final String voyage2Id = "fr.ifremer.echobase.entities.data.Voyage#2#1"; + + protected static final String transit2Id = "fr.ifremer.echobase.entities.data.Transit#2#1"; + + protected static final String transect2Id = "fr.ifremer.echobase.entities.data.Transect#2#1"; + + protected static final String transect2_2Id = "fr.ifremer.echobase.entities.data.Transect#2#2"; + + protected VoyageDAO voyageDao; + + protected TransectDAO transectDAO; + + protected TransitDAO transitDAO; + + protected DataAcquisitionDAO dataAcquisitionDAO; + + protected DataProcessingDAO dataProcessingDAO; + + protected CellDAO cellDAO; + + protected DataDAO dataDAO; + + protected OperationDAO operationDAO; + + protected OperationMetadataValueDAO operationMetadataValueDAO; + + protected GearMetadataValueDAO gearMetadataValueDAO; + + protected SampleDAO sampleDAO; + + protected SampleDataDAO sampleDataDAO; + + protected CategoryDAO categoryDAO; + + protected EchotypeDAO echotypeDAO; + + protected LengthAgeKeyDAO lengthAgeKeyDAO; + + protected LengthWeightKeyDAO lengthWeightKeyDAO; + + protected ResultDAO resultDAO; + + @Override + protected FakeEchoBaseServiceContext initContext() { + return new FakeEchoBaseServiceContext(fixtures.IMPORT_DATA_ECHOBASE_NO_DATA()); + } + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + + voyageDao = getDAO(Voyage.class, VoyageDAO.class); + transectDAO = getDAO(Transect.class, TransectDAO.class); + transitDAO = getDAO(Transit.class, TransitDAO.class); + dataAcquisitionDAO = getDAO(DataAcquisition.class, DataAcquisitionDAO.class); + dataProcessingDAO = getDAO(DataProcessing.class, DataProcessingDAO.class); + + cellDAO = getDAO(Cell.class, CellDAO.class); + dataDAO = getDAO(Data.class, DataDAO.class); + operationDAO = getDAO(Operation.class, OperationDAO.class); + operationMetadataValueDAO = getDAO(OperationMetadataValue.class, OperationMetadataValueDAO.class); + gearMetadataValueDAO = getDAO(GearMetadataValue.class, GearMetadataValueDAO.class); + sampleDAO = getDAO(Sample.class, SampleDAO.class); + sampleDataDAO = getDAO(SampleData.class, SampleDataDAO.class); + + echotypeDAO = getDAO(Echotype.class, EchotypeDAO.class); + lengthAgeKeyDAO = getDAO(LengthAgeKey.class, LengthAgeKeyDAO.class); + lengthWeightKeyDAO = getDAO(LengthWeightKey.class, LengthWeightKeyDAO.class); + categoryDAO = getDAO(Category.class, CategoryDAO.class); + resultDAO = getDAO(Result.class, ResultDAO.class); + + //create imports for voyage 1 + createCommonAllImportV1(); + createCommonTransectImportV1(); + createOperationImportV1(); + createCatchesImportV1(); + createAcousticImportV1(); + createResultVoyageImportV1(); + createResultEsduImportV1(); + createResultRegionImportV1(); + createResultMapImportV1(); + + // create imports for voyage 2 + createCommonAllImportV2(); + createCommonTransectImportV2(); +// createOperationImportV2(); +// createCatchesImportV2(); +// createAcousticImportV2(); +// createResultVoyageImportV2(); +// createResultEsduImportV2(); +// createResultRegionImportV2(); +// createResultMapImportv2(); + } + + protected void removeImport(String importId) { + RemoveDataConfiguration conf = new RemoveDataConfiguration(); + conf.setImportLogId(importId); + + RemoveDataService service = getService(RemoveDataService.class); + + EchoBaseUser fakeUser = createFakeUser(); + + service.removeImport(conf, fakeUser); + } + + + protected <E extends TopiaEntity> void assertEntityDeleted(String... entityIds) throws TopiaException { + for (String entityId : entityIds) { + if (entityId == null) continue; + E entity = getEntity(entityId); + Assert.assertNull("Entity with id " + entityId + " should have been deleted, but is still in db :(", entity); + } + } + + protected <E extends TopiaEntity> void assertEntityExists(String... entityIds) throws TopiaException { + for (String entityId : entityIds) { + if (entityId == null) continue; + E entity = getEntity(entityId); + Assert.assertNotNull("Entity with id " + entityId + " should have not been deleted, but is deleted in db :(", entity); + } + } + + private <E extends TopiaEntity> E getFirstEntity(Class<E> entityType) { + List<E> entities = getEntities(entityType); + Assert.assertTrue(CollectionUtils.isNotEmpty(entities)); + return entities.get(0); + } + + private <E extends TopiaEntity> E getEntity(String id) throws TopiaException { + Class entityType = TopiaId.getClassName(id); + TopiaDAO<E> dao = getDAO(entityType); + E entity = dao.findByTopiaId(id); + return entity; + } + + private void createCommonAllImportV1() { + + // create voyage + Voyage voyage = create(voyageDao, + TopiaEntity.TOPIA_ID, voyage1Id, + Voyage.PROPERTY_MISSION, getFirstEntity(Mission.class), + Voyage.PROPERTY_NAME, "voyage1", + Voyage.PROPERTY_START_DATE, newDate(), + Voyage.PROPERTY_END_DATE, newDate(), + Voyage.PROPERTY_START_PORT, "voyage1StartPort", + Voyage.PROPERTY_END_PORT, "voyage1EndPort", + Voyage.PROPERTY_DESCRIPTION, "voyage1Description", + Voyage.PROPERTY_DATUM, "voyage1Datum" + ); + + // create transit + Transit transit = create(transitDAO, + TopiaEntity.TOPIA_ID, transit1Id, + Transit.PROPERTY_START_TIME, newDate(), + Transit.PROPERTY_END_TIME, newDate(), + Transit.PROPERTY_START_LOCALITY, "transit1tartLocality", + Transit.PROPERTY_END_LOCALITY, "transit1EndLocality", + Transit.PROPERTY_DESCRIPTION, "transit1Description", + Transit.PROPERTY_RELATED_ACTIVITY, "transit1RelatedActivity" + ); + voyage.addTransit(transit); + + // create transect + Transect transect = create(transectDAO, + TopiaEntity.TOPIA_ID, transect1Id, + Transect.PROPERTY_TITLE, "transect1Title", + Transect.PROPERTY_VESSEL, getFirstEntity(Vessel.class), + Transect.PROPERTY_STRATUM, "transect1Stratum" + ); + transit.addTransect(transect); + + commitTransaction("ImportError!"); + + importCommonAll1Id = createImport( + CommonAllImportService.class, + new CommonImportConfiguration(getLocale()), + ImportType.COMMON_ALL, + "Common/Voyage/Transit/Transect1", + voyage1Id, + voyage); + } + + private void createCommonAllImportV2() { + + // create voyage + Voyage voyage = create(voyageDao, + TopiaEntity.TOPIA_ID, voyage2Id, + Voyage.PROPERTY_MISSION, getFirstEntity(Mission.class), + Voyage.PROPERTY_NAME, "voyage1", + Voyage.PROPERTY_START_DATE, newDate(), + Voyage.PROPERTY_END_DATE, newDate(), + Voyage.PROPERTY_START_PORT, "voyage1StartPort", + Voyage.PROPERTY_END_PORT, "voyage1EndPort", + Voyage.PROPERTY_DESCRIPTION, "voyage1Description", + Voyage.PROPERTY_DATUM, "voyage1Datum" + ); + + // create transit + Transit transit = create(transitDAO, + TopiaEntity.TOPIA_ID, transit2Id, + Transit.PROPERTY_START_TIME, newDate(), + Transit.PROPERTY_END_TIME, newDate(), + Transit.PROPERTY_START_LOCALITY, "transit1tartLocality", + Transit.PROPERTY_END_LOCALITY, "transit1EndLocality", + Transit.PROPERTY_DESCRIPTION, "transit1Description", + Transit.PROPERTY_RELATED_ACTIVITY, "transit1RelatedActivity" + ); + voyage.addTransit(transit); + + // create transect + Transect transect = create(transectDAO, + TopiaEntity.TOPIA_ID, transect2Id, + Transect.PROPERTY_TITLE, "transect1Title", + Transect.PROPERTY_VESSEL, getFirstEntity(Vessel.class), + Transect.PROPERTY_STRATUM, "transect1Stratum" + ); + transit.addTransect(transect); + + commitTransaction("ImportError!"); + + importCommonAll2Id = createImport( + CommonAllImportService.class, + new CommonImportConfiguration(getLocale()), + ImportType.COMMON_ALL, + "Common/Voyage/Transit/Transect2", + voyage2Id, + voyage); + } + + private void createCommonTransectImportV1() throws TopiaException { + + Voyage voyage = getEntity(voyage1Id); + + // create transect + Transect transect = create(transectDAO, + TopiaEntity.TOPIA_ID, transect1_2Id, + Transect.PROPERTY_TITLE, "transect2Title", + Transect.PROPERTY_VESSEL, getFirstEntity(Vessel.class), + Transect.PROPERTY_STRATUM, "transect2Stratum" + ); + voyage.getTransit().get(0).addTransect(transect); + + commitTransaction("ImportError!"); + + importCommonTransect1Id = createImport( + CommonAllImportService.class, + new CommonImportConfiguration(getLocale()), + ImportType.COMMON_TRANSECT, + "Common/Transect1", + voyage1Id, + transect); + } + + private void createCommonTransectImportV2() throws TopiaException { + + Voyage voyage = getEntity(voyage2Id); + + // create transect + Transect transect = create(transectDAO, + TopiaEntity.TOPIA_ID, transect2_2Id, + Transect.PROPERTY_TITLE, "transect2Title", + Transect.PROPERTY_VESSEL, getFirstEntity(Vessel.class), + Transect.PROPERTY_STRATUM, "transect2Stratum" + ); + voyage.getTransit().get(0).addTransect(transect); + + commitTransaction("ImportError!"); + + importCommonTransect2Id = createImport( + CommonAllImportService.class, + new CommonImportConfiguration(getLocale()), + ImportType.COMMON_TRANSECT, + "Common/Transect2", + voyage2Id, + transect); + } + + private void createOperationImportV1() throws TopiaException { + + Transect transect = getEntity(transect1Id); + + // create operation + Operation operation = create(operationDAO, + TopiaEntity.TOPIA_ID, operation1Id, + Operation.PROPERTY_ID, "operationId", + Operation.PROPERTY_GEAR, getFirstEntity(Gear.class) + ); + + transect.addOperation(operation); + + // create operationMetadata + OperationMetadataValue operationMetadataValue = create( + operationMetadataValueDAO, + OperationMetadataValue.PROPERTY_OPERATION_METADATA, getFirstEntity(OperationMetadata.class), + OperationMetadataValue.PROPERTY_DATA_VALUE, "dataValue" + ); + + operation.addOperationMetadataValue(operationMetadataValue); + + // create geartMetadata + GearMetadataValue gearMetadataValue = create( + gearMetadataValueDAO, + GearMetadataValue.PROPERTY_GEAR, operation.getGear(), + GearMetadataValue.PROPERTY_GEAR_METADATA, getFirstEntity(GearMetadata.class), + GearMetadataValue.PROPERTY_DATA_VALUE, "gearDataValue" + ); + + operation.addGearMetadataValue(gearMetadataValue); + + importOperation1Id = createImport( + OperationImportService.class, + new OperationImportConfiguration(getLocale()), + ImportType.OPERATION, + "Operation1", + voyage1Id, + operation); + + } + + private void createCatchesImportV1() throws TopiaException { + + Operation operation = getEntity(operation1Id); + + // create totalSample + Sample totalSample = create(sampleDAO, + TopiaEntity.TOPIA_ID, totalSample1Id, + Sample.PROPERTY_SAMPLE_TYPE, getFirstEntity(SampleType.class), + Sample.PROPERTY_SPECIES_CATEGORY, getFirstEntity(SpeciesCategory.class), + Sample.PROPERTY_NUMBER_SAMPLED, 10, + Sample.PROPERTY_SAMPLE_WEIGHT, 2.4f + ); + operation.addSample(totalSample); + + // add a data + SampleData totalSampleData = create(sampleDataDAO, + SampleData.PROPERTY_DATA_VALUE, 24.5f, + SampleData.PROPERTY_SAMPLE_DATA_TYPE, getFirstEntity(SampleDataType.class) + ); + totalSample.addSampleData(totalSampleData); + + // create subSample + Sample subSample = create(sampleDAO, + TopiaEntity.TOPIA_ID, subSample1Id, + Sample.PROPERTY_SAMPLE_TYPE, getFirstEntity(SampleType.class), + Sample.PROPERTY_SPECIES_CATEGORY, getFirstEntity(SpeciesCategory.class), + Sample.PROPERTY_NUMBER_SAMPLED, 10, + Sample.PROPERTY_SAMPLE_WEIGHT, 2.5f + ); + operation.addSample(subSample); + // add a data + SampleData subSampleData = create(sampleDataDAO, + SampleData.PROPERTY_DATA_VALUE, 25.4f, + SampleData.PROPERTY_SAMPLE_DATA_TYPE, getFirstEntity(SampleDataType.class) + ); + subSample.addSampleData(subSampleData); + + // create biometrySample + Sample biometrySample = create(sampleDAO, + TopiaEntity.TOPIA_ID, biometrySample1Id, + Sample.PROPERTY_SAMPLE_TYPE, getFirstEntity(SampleType.class), + Sample.PROPERTY_SPECIES_CATEGORY, getFirstEntity(SpeciesCategory.class), + Sample.PROPERTY_NUMBER_SAMPLED, 10, + Sample.PROPERTY_SAMPLE_WEIGHT, 2.6f + ); + operation.addSample(biometrySample); + + // add a data + SampleData biometrySampleData = create(sampleDataDAO, + SampleData.PROPERTY_DATA_VALUE, 26.4f, + SampleData.PROPERTY_SAMPLE_DATA_TYPE, getFirstEntity(SampleDataType.class) + ); + biometrySample.addSampleData(biometrySampleData); + + importCatches1Id = createImport( + CatchesImportService.class, + new CatchesImportConfiguration(getLocale()), + ImportType.CATCHES, + "Catches1", + voyage1Id, + totalSample, subSample, biometrySample); + } + + private void createAcousticImportV1() throws TopiaException { + + Transect transect = getEntity(transect1Id); + + // create data acquisition + DataAcquisition dataAcquisition = create(dataAcquisitionDAO, + TopiaEntity.TOPIA_ID, dataAcquisition1Id, + DataAcquisition.PROPERTY_ACOUSTIC_INSTRUMENT, getFirstEntity(AcousticInstrument.class)); + transect.addDataAcquisition(dataAcquisition); + + // create dataProcessing + DataProcessing dataProcessing = create(dataProcessingDAO, + DataProcessing.PROPERTY_ID, "id1", + DataProcessing.PROPERTY_PROCESSING_TEMPLATE, "processingTemplate"); + dataAcquisition.addDataProcessing(dataProcessing); + + // create esdu cell + Cell esduCell = create(cellDAO, + TopiaEntity.TOPIA_ID, cellEsdu1Id, + Cell.PROPERTY_CELL_TYPE, getFirstEntity(CellType.class), + Cell.PROPERTY_NAME, "cellEsdu1"); + dataProcessing.addCell(esduCell); + + // create cell data + Data esduData = create(dataDAO, + Data.PROPERTY_DATA_METADATA, getFirstEntity(DataMetadata.class), + Data.PROPERTY_DATA_VALUE, "esdu1Data"); + esduCell.addData(esduData); + + // create elementary cell + Cell elementaryCell = create(cellDAO, + TopiaEntity.TOPIA_ID, cellElementary1Id, + Cell.PROPERTY_CELL_TYPE, getFirstEntity(CellType.class), + Cell.PROPERTY_NAME, "cellElementary1"); + esduCell.addChilds(elementaryCell); + + // create cell data + Data elementaryData = create(dataDAO, + Data.PROPERTY_DATA_METADATA, getFirstEntity(DataMetadata.class), + Data.PROPERTY_DATA_VALUE, "elementary1Data"); + elementaryCell.addData(elementaryData); + + importAcoustic1Id = createImport( + AcousticImportService.class, + new AcousticImportConfiguration(getLocale()), + ImportType.ACOUSTIC, + "Acoustic1", + voyage1Id, + dataAcquisition); + } + + private void createResultVoyageImportV1() throws TopiaException { + + Voyage voyage = getEntity(voyage1Id); + + // create echotype + Echotype echotype = create(echotypeDAO, + TopiaEntity.TOPIA_ID, echotype1Id, + Echotype.PROPERTY_NAME, "echotype1Name"); + voyage.addEchotype(echotype); + + // create lengthAgeKey + LengthAgeKey lengthAgeKey = create(lengthAgeKeyDAO, + TopiaEntity.TOPIA_ID, lengthAgeKey1Id, + LengthAgeKey.PROPERTY_AGE, 12, + LengthAgeKey.PROPERTY_LENGTH, 12.5f, + LengthAgeKey.PROPERTY_METADATA, "lengthAgeKeyMetadata1", + LengthAgeKey.PROPERTY_SPECIES, getFirstEntity(Species.class), + LengthAgeKey.PROPERTY_STRATA, getFirstEntity(Strata.class) + ); + voyage.addLengthAgeKey(lengthAgeKey); + + // create lengthWeightKey + + LengthWeightKey lengthWeightKey = create(lengthWeightKeyDAO, + TopiaEntity.TOPIA_ID, lengthWeightKey1Id, + LengthWeightKey.PROPERTY_APARAMETER, 12.5f, + LengthWeightKey.PROPERTY_BPARAMETER, 0.2f, + LengthWeightKey.PROPERTY_METADATA, "lengthWeightMetadata1", + LengthWeightKey.PROPERTY_SPECIES_CATEGORY, getFirstEntity(SpeciesCategory.class), + LengthWeightKey.PROPERTY_STRATA, getFirstEntity(Strata.class) + ); + voyage.addLengthWeightKey(lengthWeightKey); + + importResultVoyage1Id = createImport( + ResultsVoyageImportService.class, + new ResultsImportConfiguration(getLocale()), + ImportType.RESULT_VOYAGE, + "ResultsVoyage1", + voyage1Id, + echotype, lengthAgeKey, lengthWeightKey); + } + + private void createResultEsduImportV1() throws TopiaException { + + // create result (on ESDU) + + Category category = create(categoryDAO); + + Result result = create(resultDAO, + TopiaEntity.TOPIA_ID, resultEsdu1Id, + Result.PROPERTY_CATEGORY, category, + Result.PROPERTY_DATA_METADATA, getFirstEntity(DataMetadata.class), + Result.PROPERTY_RESULT_VALUE, "resultValueEdsu1", + Result.PROPERTY_RESULT_LABEL, "resultLabelEdsu1" + ); + + Cell cell = getEntity(cellEsdu1Id); + cell.addResult(result); + + importResultEsdu1Id = createImport( + ResultsEsduCellImportService.class, + new ResultsImportConfiguration(getLocale()), + ImportType.RESULT_ESDU, + "ResultsEsdu1", + voyage1Id, + result); + } + + private void createResultRegionImportV1() throws TopiaException { + + // create region + Cell region = create(cellDAO, + TopiaEntity.TOPIA_ID, cellRegion1Id, + Cell.PROPERTY_CELL_TYPE, getFirstEntity(CellType.class), + Cell.PROPERTY_NAME, "cellRegion1"); + + Voyage voyage = getEntity(voyage1Id); + voyage.addPostCell(region); + + // add esdu cell on it + Cell esduCell = getEntity(cellEsdu1Id); + region.addChilds(esduCell); + + // create result (on region) + Category category = create(categoryDAO); + Result result = create(resultDAO, + TopiaEntity.TOPIA_ID, resultRegion1Id, + Result.PROPERTY_CATEGORY, category, + Result.PROPERTY_DATA_METADATA, getFirstEntity(DataMetadata.class), + Result.PROPERTY_RESULT_VALUE, "resultValueRegion1", + Result.PROPERTY_RESULT_LABEL, "resultLabelRegion1" + ); + region.addResult(result); + + importResultRegion1Id = createImport( + ResultsRegionCellImportService.class, + new ResultsImportConfiguration(getLocale()), + ImportType.RESULT_REGION, + "ResultsRegion1", + voyage1Id, + region); + } + + private void createResultMapImportV1() throws TopiaException { + + // create map + Cell map = create(cellDAO, + TopiaEntity.TOPIA_ID, cellMap1Id, + Cell.PROPERTY_CELL_TYPE, getFirstEntity(CellType.class), + Cell.PROPERTY_NAME, "cellMap1"); + + Voyage voyage = getEntity(voyage1Id); + voyage.addPostCell(map); + + // create result (on map) + Category category = create(categoryDAO); + Result result = create(resultDAO, + TopiaEntity.TOPIA_ID, resultMap1Id, + Result.PROPERTY_CATEGORY, category, + Result.PROPERTY_DATA_METADATA, getFirstEntity(DataMetadata.class), + Result.PROPERTY_RESULT_VALUE, "resultValueMap1", + Result.PROPERTY_RESULT_LABEL, "resultLabelMap1" + ); + map.addResult(result); + + importResultMap1Id = createImport( + ResultsMapCellImportService.class, + new ResultsImportConfiguration(getLocale()), + ImportType.RESULT_MAP, + "ResultsMap1", + voyage1Id, + map); + } + + private <C extends AbstractImportConfiguration, S extends AbstractImportDataService<C>> String createImport( + Class<S> serviceType, + C importConf, + ImportType importType, + String importNote, + String voyageId, + TopiaEntity... importIds) { + importConf.setImportType(importType); + importConf.setImportNotes(importNote); + importConf.setVoyageId(voyageId); + + S importService = getService(serviceType); + + ImportLog importLog = importService.computeImportLogEntry( + importConf, createFakeUser()); + + for (TopiaEntity importId : importIds) { + importLog.addImportId(importId.getTopiaId()); + } + + commitTransaction("ImportLogError!"); + + String importId = importLog.getTopiaId(); + return importId; + } +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AcousticRemoveDataServiceTest.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AcousticRemoveDataServiceTest.java (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AcousticRemoveDataServiceTest.java 2012-09-16 13:56:31 UTC (rev 669) @@ -0,0 +1,66 @@ +package fr.ifremer.echobase.ui.actions.removedata; + +/* + * #%L + * EchoBase :: Services + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.services.removedata.RemoveDataService; +import fr.ifremer.echobase.services.removedata.strategy.AcousticRemoveDataStrategy; +import org.junit.Test; +import org.nuiton.topia.TopiaException; + +/** + * Test{@link RemoveDataService} with {@link AcousticRemoveDataStrategy}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class AcousticRemoveDataServiceTest extends AbstractRemoveDataServiceTest { + + @Test + public void removeImport() throws TopiaException { + + removeImport(importAcoustic1Id); + + // dataAquisition 1 is deleted + assertEntityDeleted(dataAcquisition1Id, cellEsdu1Id, cellElementary1Id, + cellRegion1Id, cellMap1Id, + resultEsdu1Id, resultRegion1Id, resultMap1Id); + + // and all his imports + assertEntityDeleted(importAcoustic1Id, + importResultVoyage1Id, + importResultEsdu1Id, + importResultRegion1Id, + importResultMap1Id); + + // voyage 1 other imports stay + assertEntityExists(voyage1Id, transect1Id, operation1Id, + totalSample1Id, subSample1Id, biometrySample1Id); + + // and all his imports + assertEntityExists(importCommonAll1Id, + importCommonTransect1Id, + importOperation1Id, + importCatches1Id); + } +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AcousticRemoveDataServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CatchesRemoveDataServiceTest.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CatchesRemoveDataServiceTest.java (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CatchesRemoveDataServiceTest.java 2012-09-16 13:56:31 UTC (rev 669) @@ -0,0 +1,64 @@ +package fr.ifremer.echobase.ui.actions.removedata; + +/* + * #%L + * EchoBase :: Services + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.services.removedata.RemoveDataService; +import fr.ifremer.echobase.services.removedata.strategy.CatchesRemoveDataStrategy; +import org.junit.Test; +import org.nuiton.topia.TopiaException; + +/** + * Test{@link RemoveDataService} with {@link CatchesRemoveDataStrategy}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class CatchesRemoveDataServiceTest extends AbstractRemoveDataServiceTest { + + @Test + public void removeImport() throws TopiaException { + + removeImport(importCatches1Id); + + // sample1 are deleted + assertEntityDeleted(totalSample1Id, subSample1Id, biometrySample1Id); + + // and all his imports + assertEntityDeleted(importCatches1Id); + + // voyage 1 other imports stay + assertEntityExists(voyage1Id, transect1Id, operation1Id, + cellEsdu1Id, cellElementary1Id); + + // and all his imports + assertEntityExists(importCommonAll1Id, + importCommonTransect1Id, + importOperation1Id, + importAcoustic1Id, + importResultVoyage1Id, + importResultEsdu1Id, + importResultRegion1Id, + importResultMap1Id); + } +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CatchesRemoveDataServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceIT.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceIT.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceIT.java 2012-09-16 13:56:31 UTC (rev 669) @@ -1,100 +0,0 @@ -package fr.ifremer.echobase.ui.actions.removedata; - -/* - * #%L - * EchoBase :: Services - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 - 2012 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import fr.ifremer.echobase.entities.ImportLog; -import fr.ifremer.echobase.entities.data.Transect; -import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.services.removedata.RemoveDataService; -import fr.ifremer.echobase.services.removedata.strategy.CommonAllRemoveDataStrategy; -import org.junit.Test; -import org.nuiton.topia.TopiaException; - -/** - * Test{@link RemoveDataService} with {@link CommonAllRemoveDataStrategy}. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class CommonAllRemoveDataServiceIT extends AbstractRemoveDataServiceIT { - - @Test - public void removeImport1() throws TopiaException { - - createCommonAllImportV1(); - createCommonTransectImportV1(); - - createCommonAllImportV2(); - createCommonTransectImportV2(); - - removeImport(importCommonAll1Id); - - // voyage 1 is deleted - assertEntityDeleted(Voyage.class, voyage1Id); - - // and all his imports - assertEntityDeleted(ImportLog.class, - importCommonAll1Id, - importCommonTransect1Id); - - // voyage 2 still in db - assertEntityExists(Voyage.class, voyage2Id); - assertEntityExists(Transect.class, transect2Id); - - // and all his imports - assertEntityExists(ImportLog.class, - importCommonAll2Id, - importCommonTransect2Id); - - } - - @Test - public void removeImport2() throws TopiaException { - - createCommonAllImportV1(); - createCommonTransectImportV1(); - - createCommonAllImportV2(); - createCommonTransectImportV2(); - - removeImport(importCommonAll2Id); - - // voyage 2 is deleted - assertEntityDeleted(Voyage.class, voyage2Id); - - // and all his imports - assertEntityDeleted(ImportLog.class, - importCommonAll2Id, - importCommonTransect2Id); - - // voyage 1 still in db - assertEntityExists(Voyage.class, voyage1Id); - assertEntityExists(Transect.class, transect1Id); - - // and all his imports - assertEntityExists(ImportLog.class, - importCommonAll1Id, - importCommonTransect1Id); - } -} Copied: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceTest.java (from rev 667, trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceIT.java) =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceTest.java (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceTest.java 2012-09-16 13:56:31 UTC (rev 669) @@ -0,0 +1,99 @@ +package fr.ifremer.echobase.ui.actions.removedata; + +/* + * #%L + * EchoBase :: Services + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.services.removedata.RemoveDataService; +import fr.ifremer.echobase.services.removedata.strategy.CommonAllRemoveDataStrategy; +import org.junit.Test; +import org.nuiton.topia.TopiaException; + +/** + * Test{@link RemoveDataService} with {@link CommonAllRemoveDataStrategy}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class CommonAllRemoveDataServiceTest extends AbstractRemoveDataServiceTest { + + @Test + public void removeImport1() throws TopiaException { + + removeImport(importCommonAll1Id); + + // voyage 1 is deleted + assertEntityDeleted(voyage1Id, transect1Id, operation1Id, + totalSample1Id, subSample1Id, biometrySample1Id, + cellEsdu1Id, cellElementary1Id, resultEsdu1Id, + echotype1Id, lengthAgeKey1Id, lengthWeightKey1Id); + + // and all his imports + assertEntityDeleted(importCommonAll1Id, + importCommonTransect1Id, + importOperation1Id, + importCatches1Id, + importAcoustic1Id, + importResultVoyage1Id, + importResultEsdu1Id, + importResultRegion1Id, + importResultMap1Id); + + // voyage 2 still in db + assertEntityExists(voyage2Id, transect2Id); + + // and all his imports + assertEntityExists(importCommonAll2Id, + importCommonTransect2Id); + + } + + @Test + public void removeImport2() throws TopiaException { + + removeImport(importCommonAll2Id); + + // voyage 2 is deleted + assertEntityDeleted(voyage2Id); + + // and all his imports + assertEntityDeleted(importCommonAll2Id, + importCommonTransect2Id); + + // voyage 1 still in db + assertEntityExists(voyage1Id, transect1Id, operation1Id, + totalSample1Id, subSample1Id, biometrySample1Id, + cellEsdu1Id, cellElementary1Id, resultEsdu1Id, + echotype1Id, lengthAgeKey1Id, lengthWeightKey1Id); + + // and all his imports + assertEntityExists(importCommonAll1Id, + importCommonTransect1Id, + importOperation1Id, + importCatches1Id, + importAcoustic1Id, + importResultVoyage1Id, + importResultEsdu1Id, + importResultRegion1Id, + importResultMap1Id); + } +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Deleted: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceIT.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceIT.java 2012-09-16 09:39:45 UTC (rev 668) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceIT.java 2012-09-16 13:56:31 UTC (rev 669) @@ -1,117 +0,0 @@ -package fr.ifremer.echobase.ui.actions.removedata; - -/* - * #%L - * EchoBase :: Services - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 - 2012 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import fr.ifremer.echobase.entities.ImportLog; -import fr.ifremer.echobase.entities.data.Transect; -import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.services.removedata.RemoveDataService; -import fr.ifremer.echobase.services.removedata.strategy.CommonTransectRemoveDataStrategy; -import org.junit.Test; -import org.nuiton.topia.TopiaException; - -/** - * Test{@link RemoveDataService} with {@link CommonTransectRemoveDataStrategy}. - * - * @author tchemit <chemit@codelutin.com> - * @since 1.3 - */ -public class CommonTransectRemoveDataServiceIT extends AbstractRemoveDataServiceIT { - - @Test - public void removeImport1() throws TopiaException { - - createCommonAllImportV1(); - createCommonTransectImportV1(); - - createCommonAllImportV2(); - createCommonTransectImportV2(); - - removeImport(importCommonTransect1Id); - - // transect 1 is deleted - assertEntityDeleted(Transect.class, transect1_2Id); - - // and all his imports - assertEntityDeleted(ImportLog.class, - importCommonTransect1Id); - - // voyage 1 is still here - assertEntityExists(Voyage.class, voyage1Id); - assertEntityExists(Transect.class, transect1Id); - - // and all his imports - assertEntityExists(ImportLog.class, - importCommonAll1Id); - - - // voyage 2 still in db - assertEntityExists(Voyage.class, voyage2Id); - assertEntityExists(Transect.class, transect2Id); - - // and all his imports - assertEntityExists(ImportLog.class, - importCommonAll2Id, - importCommonTransect2Id); - } - - @Test - public void removeImport2() throws TopiaException { - - - createCommonAllImportV1(); - createCommonTransectImportV1(); - - createCommonAllImportV2(); - createCommonTransectImportV2(); - - removeImport(importCommonTransect2Id); - - // transect 2 is deleted - assertEntityDeleted(Transect.class, transect2_2Id); - - // and all his imports - assertEntityDeleted(ImportLog.class, - importCommonTransect2Id); - - - // voyage 2 is still here - assertEntityExists(Voyage.class, voyage2Id); - assertEntityExists(Transect.class, transect2Id); - - // and all his imports - assertEntityExists(ImportLog.class, - importCommonAll2Id); - - - // voyage 1 still in db - assertEntityExists(Voyage.class, voyage1Id); - assertEntityExists(Transect.class, transect1Id); - - // and all his imports - assertEntityExists(ImportLog.class, - importCommonAll1Id, - importCommonTransect1Id); - } -} Copied: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceTest.java (from rev 667, trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceIT.java) =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceTest.java (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceTest.java 2012-09-16 13:56:31 UTC (rev 669) @@ -0,0 +1,110 @@ +package fr.ifremer.echobase.ui.actions.removedata; + +/* + * #%L + * EchoBase :: Services + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.services.removedata.RemoveDataService; +import fr.ifremer.echobase.services.removedata.strategy.CommonTransectRemoveDataStrategy; +import org.junit.Test; +import org.nuiton.topia.TopiaException; + +/** + * Test{@link RemoveDataService} with {@link CommonTransectRemoveDataStrategy}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class CommonTransectRemoveDataServiceTest extends AbstractRemoveDataServiceTest { + + @Test + public void removeImport1() throws TopiaException { + + removeImport(importCommonTransect1Id); + + // transect 1 is deleted + assertEntityDeleted(transect1_2Id); + + // and all his imports + assertEntityDeleted(importCommonTransect1Id); + + // voyage 1 is still here + assertEntityExists(voyage1Id, transect1Id, operation1Id, + totalSample1Id, subSample1Id, biometrySample1Id, + cellEsdu1Id, cellElementary1Id, resultEsdu1Id); + + // and all his imports (exception transect1 one) + assertEntityExists(importCommonAll1Id, + importOperation1Id, + importCatches1Id, + importAcoustic1Id, + importResultVoyage1Id, + importResultEsdu1Id, + importResultRegion1Id, + importResultMap1Id); + + + // voyage 2 still in db + assertEntityExists(voyage2Id, transect2Id); + + // and all his imports + assertEntityExists(importCommonAll2Id, + importCommonTransect2Id); + } + + @Test + public void removeImport2() throws TopiaException { + + removeImport(importCommonTransect2Id); + + // transect 2 is deleted + assertEntityDeleted(transect2_2Id); + + // and all his imports + assertEntityDeleted(importCommonTransect2Id); + + + // voyage 2 is still here + assertEntityExists(voyage2Id, transect2Id); + + // and all his imports + assertEntityExists(importCommonAll2Id); + + + // voyage 1 still in db + assertEntityExists(voyage1Id, transect1Id, operation1Id, + totalSample1Id, subSample1Id, biometrySample1Id, + cellEsdu1Id, cellElementary1Id, resultEsdu1Id, + echotype1Id, lengthAgeKey1Id,lengthWeightKey1Id); + + // and all his imports + assertEntityExists(importCommonAll1Id, + importCommonTransect1Id, + importOperation1Id, + importCatches1Id, + importAcoustic1Id, + importResultVoyage1Id, + importResultEsdu1Id, + importResultRegion1Id, + importResultMap1Id); + } +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/OperationRemoveDataServiceTest.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/OperationRemoveDataServiceTest.java (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/OperationRemoveDataServiceTest.java 2012-09-16 13:56:31 UTC (rev 669) @@ -0,0 +1,64 @@ +package fr.ifremer.echobase.ui.actions.removedata; + +/* + * #%L + * EchoBase :: Services + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.services.removedata.RemoveDataService; +import fr.ifremer.echobase.services.removedata.strategy.OperationRemoveDataStrategy; +import org.junit.Test; +import org.nuiton.topia.TopiaException; + +/** + * Test{@link RemoveDataService} with {@link OperationRemoveDataStrategy}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class OperationRemoveDataServiceTest extends AbstractRemoveDataServiceTest { + + @Test + public void removeImport() throws TopiaException { + + removeImport(importOperation1Id); + + // operation 1 is deleted + assertEntityDeleted(operation1Id); + + // and all his imports + assertEntityDeleted(importOperation1Id); + + // voyage 1 other imports stay + assertEntityExists(voyage1Id, transect1Id, + cellEsdu1Id, cellElementary1Id, resultEsdu1Id, + echotype1Id, lengthAgeKey1Id, lengthWeightKey1Id); + + // and all his imports + assertEntityExists(importCommonAll1Id, + importCommonTransect1Id, + importAcoustic1Id, + importResultVoyage1Id, + importResultEsdu1Id, + importResultRegion1Id, + importResultMap1Id); + } +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/OperationRemoveDataServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultEsduRemoveDataServiceTest.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultEsduRemoveDataServiceTest.java (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultEsduRemoveDataServiceTest.java 2012-09-16 13:56:31 UTC (rev 669) @@ -0,0 +1,67 @@ +package fr.ifremer.echobase.ui.actions.removedata; + +/* + * #%L + * EchoBase :: Services + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.services.removedata.RemoveDataService; +import fr.ifremer.echobase.services.removedata.strategy.ResultEsduRemoveDataStrategy; +import org.junit.Test; +import org.nuiton.topia.TopiaException; + +/** + * Test{@link RemoveDataService} with {@link ResultEsduRemoveDataStrategy}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class ResultEsduRemoveDataServiceTest extends AbstractRemoveDataServiceTest { + + @Test + public void removeImport() throws TopiaException { + + removeImport(importResultEsdu1Id); + + // esdu cell result are deleted + assertEntityDeleted(resultEsdu1Id); + + // and all his imports + assertEntityDeleted(importResultEsdu1Id); + + // voyage 1 other imports stay + assertEntityExists(voyage1Id, transect1Id, operation1Id, + totalSample1Id, subSample1Id, biometrySample1Id, + dataAcquisition1Id, cellEsdu1Id, cellElementary1Id, + echotype1Id, lengthAgeKey1Id, lengthWeightKey1Id); + + // and all his imports + assertEntityExists(importCommonAll1Id, + importCommonTransect1Id, + importOperation1Id, + importCatches1Id, + importAcoustic1Id, + importResultVoyage1Id, + importResultRegion1Id, + importResultMap1Id); + } + +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultEsduRemoveDataServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultMapRemoveDataServiceTest.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultMapRemoveDataServiceTest.java (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultMapRemoveDataServiceTest.java 2012-09-16 13:56:31 UTC (rev 669) @@ -0,0 +1,45 @@ +package fr.ifremer.echobase.ui.actions.removedata; + +/* + * #%L + * EchoBase :: Services + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.services.removedata.RemoveDataService; +import fr.ifremer.echobase.services.removedata.strategy.ResultMapRemoveDataStrategy; +import org.junit.Test; +import org.nuiton.topia.TopiaException; + +/** + * Test{@link RemoveDataService} with {@link ResultMapRemoveDataStrategy}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class ResultMapRemoveDataServiceTest extends AbstractRemoveDataServiceTest { + + @Test + public void removeImport() throws TopiaException { + + removeImport(importResultMap1Id); + + } +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultMapRemoveDataServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultRegionRemoveDataServiceTest.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultRegionRemoveDataServiceTest.java (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultRegionRemoveDataServiceTest.java 2012-09-16 13:56:31 UTC (rev 669) @@ -0,0 +1,65 @@ +package fr.ifremer.echobase.ui.actions.removedata; + +/* + * #%L + * EchoBase :: Services + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.services.removedata.RemoveDataService; +import fr.ifremer.echobase.services.removedata.strategy.ResultRegionRemoveDataStrategy; +import org.junit.Test; +import org.nuiton.topia.TopiaException; + +/** + * Test{@link RemoveDataService} with {@link ResultRegionRemoveDataStrategy}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class ResultRegionRemoveDataServiceTest extends AbstractRemoveDataServiceTest { + + @Test + public void removeImport() throws TopiaException { + + removeImport(importResultRegion1Id); + + // esdu cell result are deleted + assertEntityDeleted(cellRegion1Id, resultRegion1Id); + + // and all his imports + assertEntityDeleted(importResultEsdu1Id); + + // voyage 1 other imports stay + assertEntityExists(voyage1Id, transect1Id, operation1Id, + totalSample1Id, subSample1Id, biometrySample1Id, + dataAcquisition1Id, cellEsdu1Id, cellElementary1Id, resultEsdu1Id, + echotype1Id, lengthAgeKey1Id, lengthWeightKey1Id); + + // and all his imports + assertEntityExists(importCommonAll1Id, + importCommonTransect1Id, + importOperation1Id, + importCatches1Id, + importAcoustic1Id, + importResultVoyage1Id, + importResultMap1Id); + } +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultRegionRemoveDataServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultVoyageRemoveDataServiceTest.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultVoyageRemoveDataServiceTest.java (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultVoyageRemoveDataServiceTest.java 2012-09-16 13:56:31 UTC (rev 669) @@ -0,0 +1,67 @@ +package fr.ifremer.echobase.ui.actions.removedata; + +/* + * #%L + * EchoBase :: Services + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.services.removedata.RemoveDataService; +import fr.ifremer.echobase.services.removedata.strategy.ResultVoyageRemoveDataStrategy; +import org.junit.Test; +import org.nuiton.topia.TopiaException; + +/** + * Test{@link RemoveDataService} with {@link ResultVoyageRemoveDataStrategy}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.3 + */ +public class ResultVoyageRemoveDataServiceTest extends AbstractRemoveDataServiceTest { + + @Test + public void removeImport() throws TopiaException { + + removeImport(importResultVoyage1Id); + + // voyage "results" are deleted + assertEntityDeleted(echotype1Id, lengthAgeKey1Id, lengthWeightKey1Id, + cellRegion1Id, cellMap1Id, + resultEsdu1Id, resultRegion1Id, resultMap1Id); + + // and all his imports + assertEntityDeleted(importResultVoyage1Id, + importResultEsdu1Id, + importResultRegion1Id, + importResultMap1Id); + + // voyage 1 other imports stay + assertEntityExists(voyage1Id, transect1Id, operation1Id, + totalSample1Id, subSample1Id, biometrySample1Id, + dataAcquisition1Id, cellEsdu1Id, cellElementary1Id); + + // and all his imports + assertEntityExists(importCommonAll1Id, + importCommonTransect1Id, + importOperation1Id, + importCatches1Id, + importAcoustic1Id); + } +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ResultVoyageRemoveDataServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native