r667 - in trunk/echobase-services/src: main/java/fr/ifremer/echobase/services/importdata main/java/fr/ifremer/echobase/services/removedata main/java/fr/ifremer/echobase/services/removedata/strategy test/java/fr/ifremer/echobase/services test/java/fr/ifremer/echobase/ui/actions test/java/fr/ifremer/echobase/ui/actions/removedata test/resources/import-data
Author: tchemit Date: 2012-09-15 13:50:06 +0200 (Sat, 15 Sep 2012) New Revision: 667 Url: http://forge.codelutin.com/repositories/revision/echobase/667 Log: refs #1437: Suppression des imports (debut des tests) Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/ 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 Removed: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removeData/ Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportDataService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/RemoveDataService.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/CommonTransectRemoveDataStrategy.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EchoBaseServiceFixtures.java trunk/echobase-services/src/test/resources/import-data/echobase-1.2-nodata.h2.db.gz Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportDataService.java 2012-09-14 20:16:18 UTC (rev 666) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportDataService.java 2012-09-15 11:50:06 UTC (rev 667) @@ -130,20 +130,36 @@ return new EchoBaseCsvFileImportResult(inputFile.getFileName()); } - protected String computeResultAndLogBookEntry(M configuration, - EchoBaseUser user) { - + public ImportLog computeImportLogEntry(M configuration, + EchoBaseUser user) { Date importDate = newDate(); String importUser = user.getEmail(); - ImportLog importLog = create(getDAO(ImportLog.class), ImportLog.PROPERTY_VOYAGE_ID, configuration.getVoyageId(), ImportLog.PROPERTY_IMPORT_TYPE, configuration.getImportType(), ImportLog.PROPERTY_IMPORT_USER, importUser, ImportLog.PROPERTY_IMPORT_DATE, importDate, ImportLog.PROPERTY_IMPORT_TEXT, configuration.getImportNotes()); + return importLog; + } + protected String computeResultAndLogBookEntry(M configuration, + EchoBaseUser user) { + + Date importDate = newDate(); + String importUser = user.getEmail(); + + ImportLog importLog = computeImportLogEntry(configuration, user); +// +// ImportLog importLog = create(getDAO(ImportLog.class), +// ImportLog.PROPERTY_VOYAGE_ID, configuration.getVoyageId(), +// ImportLog.PROPERTY_IMPORT_TYPE, configuration.getImportType(), +// ImportLog.PROPERTY_IMPORT_USER, importUser, +// ImportLog.PROPERTY_IMPORT_DATE, importDate, +// ImportLog.PROPERTY_IMPORT_TEXT, configuration.getImportNotes()); +// + String importType = getImportLabel(configuration); StringBuilder buffer = new StringBuilder(); Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/RemoveDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/RemoveDataService.java 2012-09-14 20:16:18 UTC (rev 666) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/RemoveDataService.java 2012-09-15 11:50:06 UTC (rev 667) @@ -158,11 +158,17 @@ continue; } + if (!importLog.getVoyageId().equals(logEntry.getVoyageId())) { + + // not on same voyage, this importLog can not be obsoleted + continue; + } + if (possibleSubImportType.contains(logEntry.getImportType())) { // ok can try to remove this import log // try to find out if first id is still exists - String firstId = importLog.getImportId().iterator().next(); + String firstId = logEntry.getImportId().iterator().next(); if (!isIdExists(firstId)) { 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-14 20:16:18 UTC (rev 666) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/AbstractRemoveDataStrategy.java 2012-09-15 11:50:06 UTC (rev 667) @@ -42,10 +42,12 @@ import fr.ifremer.echobase.services.EchoBaseServiceContext; import fr.ifremer.echobase.services.EchoBaseServiceSupport; import fr.ifremer.echobase.services.removedata.RemoveDataConfiguration; +import org.apache.commons.collections.CollectionUtils; import org.nuiton.topia.TopiaException; import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.TopiaEntity; +import java.util.Collections; import java.util.List; import java.util.Set; @@ -94,7 +96,7 @@ public void doRemove(RemoveDataConfiguration model, ImportLog importLog) throws TopiaException { - Voyage voyage = voyageDao.findByTopiaId(importLog.getTopiaId()); + Voyage voyage = voyageDao.findByTopiaId(importLog.getVoyageId()); removeDataInVoyage(voyage); @@ -114,6 +116,8 @@ throw new EchoBaseTechnicalException(e); } } + +// flushTransaction("Could not flush transaction"); } protected abstract void removeDataInVoyage(Voyage voyage) throws TopiaException; @@ -191,7 +195,9 @@ protected void removeVoyage(Voyage entity) throws TopiaException { - Set<Echotype> echotypes = Sets.newHashSet(entity.getEchotype()); + Set<Echotype> echotypes = CollectionUtils.isEmpty(entity.getEchotype()) ? + Collections.<Echotype>emptySet() : + Sets.newHashSet(entity.getEchotype()); // clean this data entity.clearEchotype(); @@ -209,13 +215,16 @@ protected void removeVoyagePostCell(Voyage entity) throws TopiaException { - for (Cell postCell : entity.getPostCell()) { - removePostCell(null, postCell); - } + if (CollectionUtils.isNotEmpty(entity.getPostCell())) { + for (Cell postCell : entity.getPostCell()) { + removePostCell(null, postCell); + } - // clean this data - entity.clearPostCell(); + // clean this data + entity.clearPostCell(); - flushTransaction("Could not flush transaction after removing postCells"); + flushTransaction( + "Could not flush transaction after removing postCells"); + } } } 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-14 20:16:18 UTC (rev 666) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/CommonTransectRemoveDataStrategy.java 2012-09-15 11:50:06 UTC (rev 667) @@ -27,6 +27,8 @@ import fr.ifremer.echobase.entities.ImportType; 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.services.EchoBaseServiceContext; import org.apache.commons.logging.Log; @@ -51,11 +53,14 @@ protected TransectDAO transectDAO; + protected TransitDAO transitDAO; + @Override public void setServiceContext(EchoBaseServiceContext serviceContext) { super.setServiceContext(serviceContext); transectDAO = getDAO(Transect.class, TransectDAO.class); + transitDAO = getDAO(Transit.class, TransitDAO.class); } @Override @@ -71,19 +76,24 @@ if (id.startsWith(Transect.class.getName())) { // remove transect - removeTransect(id); + Transect transect = transectDAO.findByTopiaId(id); + + // remove it from transit + Transit transit = transitDAO.findContainsTransect(transect); + transit.removeTransect(transect); + + // delete it + delete(transectDAO, transect); + + if (log.isInfoEnabled()) { + log.info("Transect " + transect.getTopiaId() + " was removed"); + } + } else { canNotDealWithId(id); } } - protected void removeTransect(String id) throws TopiaException { - Transect entity = removeEntity(transectDAO, id); - if (log.isInfoEnabled()) { - log.info("Transect " + entity.getTopiaId() + " was removed"); - } - } - @Override public Set<ImportType> getPossibleSubImportType() { Set<ImportType> result = Sets.newHashSet(ImportType.OPERATION, Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EchoBaseServiceFixtures.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EchoBaseServiceFixtures.java 2012-09-14 20:16:18 UTC (rev 666) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EchoBaseServiceFixtures.java 2012-09-15 11:50:06 UTC (rev 667) @@ -31,10 +31,6 @@ */ public class EchoBaseServiceFixtures { - public String completeDb2011() { - return "/import-data/echobase-pelgas-2011.h2.db.gz"; - } - public String IMPORT_DATA_ECHOBASE_NO_DATA() { return "/import-data/echobase-" + dbVersion() + "-nodata.h2.db.gz"; } Copied: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceIT.java (from rev 666, 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 (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceIT.java 2012-09-15 11:50:06 UTC (rev 667) @@ -0,0 +1,398 @@ +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 + } +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/AbstractRemoveDataServiceIT.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/CommonAllRemoveDataServiceIT.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceIT.java (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceIT.java 2012-09-15 11:50:06 UTC (rev 667) @@ -0,0 +1,100 @@ +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); + } +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonAllRemoveDataServiceIT.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/CommonTransectRemoveDataServiceIT.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceIT.java (rev 0) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceIT.java 2012-09-15 11:50:06 UTC (rev 667) @@ -0,0 +1,117 @@ +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); + } +} Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/ui/actions/removedata/CommonTransectRemoveDataServiceIT.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-services/src/test/resources/import-data/echobase-1.2-nodata.h2.db.gz =================================================================== (Binary files differ)
participants (1)
-
tchemit@users.forge.codelutin.com