r801 - trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy
Author: tchemit Date: 2013-03-19 09:49:36 +0100 (Tue, 19 Mar 2013) New Revision: 801 Url: http://forge.codelutin.com/projects/echobase/repository/revisions/801 Log: fixes #2154: Probl?\195?\168me ?\195?\160 la suppression d'import de r?\195?\169sultats de voyage 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/ResultVoyageRemoveDataStrategy.java 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 2013-03-19 08:02:37 UTC (rev 800) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/AbstractRemoveDataStrategy.java 2013-03-19 08:49:36 UTC (rev 801) @@ -23,6 +23,7 @@ * #L% */ +import com.google.common.collect.Sets; import fr.ifremer.echobase.EchoBaseTechnicalException; import fr.ifremer.echobase.entities.ImportLog; import fr.ifremer.echobase.entities.ImportType; @@ -45,7 +46,6 @@ import fr.ifremer.echobase.services.EchoBaseServiceContext; import fr.ifremer.echobase.services.EchoBaseServiceSupport; import fr.ifremer.echobase.services.ProgressModel; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaException; @@ -181,70 +181,19 @@ } } - protected void removeLengthWeightKey(Voyage entity, - LengthWeightKey lengthWeightKey) throws TopiaException { + protected void removeVoyagePostCell(Voyage entity) throws TopiaException { - lengthWeightKeyDAO.delete(lengthWeightKey); + if (!entity.isPostCellEmpty()) { + for (Cell cell : Sets.newHashSet(entity.getPostCell())) { - if (entity != null) { + // remove it from the voyage + entity.removePostCell(cell); - // remove it from the voyage - entity.removeLengthWeightKey(lengthWeightKey); - } - incrementOp("Remove lengthWeightKey " + lengthWeightKey.getTopiaId()); - } + // delete postcell + cellDAO.delete(cell); - protected void removeLengthAgeKey(Voyage entity, - LengthAgeKey lengthAgeKey) throws TopiaException { - - lengthAgeKeyDAO.delete(lengthAgeKey); - - if (entity != null) { - - // remove it from the voyage - entity.removeLengthAgeKey(lengthAgeKey); - } - incrementOp("Remove lengthAgeKey " + lengthAgeKey.getTopiaId()); - } - - protected void removeEchotype(Voyage entity, - Echotype echotype) throws TopiaException { - - // delete all categories using this echotype - 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); - - incrementOp("Remove echotype " + echotype.getTopiaId()); - } - - protected void removePostCell(Voyage entity, - Cell cell) throws TopiaException { - if (entity != null) { - - // remove it from the voyage - entity.removePostCell(cell); - } - - // delete postcell - cellDAO.delete(cell); - - incrementOp("Remove postCell " + cell.getTopiaId()); - } - - protected void removeVoyagePostCell(Voyage entity) throws TopiaException { - - if (CollectionUtils.isNotEmpty(entity.getPostCell())) { - for (Cell postCell : entity.getPostCell()) { - removePostCell(null, postCell); + // increments operation + incrementOp("Remove postCell " + cell.getTopiaId()); } // clean this data 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 2013-03-19 08:02:37 UTC (rev 800) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/strategy/ResultVoyageRemoveDataStrategy.java 2013-03-19 08:49:36 UTC (rev 801) @@ -26,6 +26,7 @@ import com.google.common.collect.Sets; 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.Echotype; import fr.ifremer.echobase.entities.data.LengthAgeKey; import fr.ifremer.echobase.entities.data.LengthWeightKey; @@ -34,6 +35,7 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaException; +import java.util.List; import java.util.Set; /** @@ -78,32 +80,59 @@ if (id.startsWith(Echotype.class.getName())) { // remove echotype - Echotype entity = echotypeDAO.findByTopiaId(id); + Echotype echotype = echotypeDAO.findByTopiaId(id); - removeEchotype(voyage, entity); + // delete all categories using this echotype + List<Category> allByEchotype = categoryDAO.findAllByEchotype(echotype); + categoryDAO.deleteAll(allByEchotype); + if (voyage != null) { + + // remove it from the voyage + voyage.removeEchotype(echotype); + } + + // delete echotype + echotypeDAO.delete(echotype); + + incrementOp("Remove echotype " + echotype.getTopiaId()); + if (log.isDebugEnabled()) { - log.debug(entity.getTopiaId() + " was removed"); + log.debug(echotype.getTopiaId() + " was removed"); } } else if (id.startsWith(LengthAgeKey.class.getName())) { // remove lengthAgeKey - LengthAgeKey entity = lengthAgeKeyDAO.findByTopiaId(id); + LengthAgeKey lengthAgeKey = lengthAgeKeyDAO.findByTopiaId(id); - removeLengthAgeKey(voyage, entity); + lengthAgeKeyDAO.delete(lengthAgeKey); + if (voyage != null) { + + // remove it from the voyage + voyage.removeLengthAgeKey(lengthAgeKey); + } + incrementOp("Remove lengthAgeKey " + lengthAgeKey.getTopiaId()); + if (log.isDebugEnabled()) { - log.debug(entity.getTopiaId() + " was removed"); + log.debug(lengthAgeKey.getTopiaId() + " was removed"); } } else if (id.startsWith(LengthWeightKey.class.getName())) { - // remove lengthAgeKey - LengthWeightKey entity = lengthWeightKeyDAO.findByTopiaId(id); + // remove lengthWeightKey + LengthWeightKey lengthWeightKey = lengthWeightKeyDAO.findByTopiaId(id); - removeLengthWeightKey(voyage, entity); + lengthWeightKeyDAO.delete(lengthWeightKey); + if (voyage != null) { + + // remove it from the voyage + voyage.removeLengthWeightKey(lengthWeightKey); + } + incrementOp("Remove lengthWeightKey " + lengthWeightKey.getTopiaId()); + if (log.isDebugEnabled()) { - log.debug(entity.getTopiaId() + " was removed"); + log.debug(lengthWeightKey.getTopiaId() + " was removed"); } } else { canNotDealWithId(id);
participants (1)
-
tchemit@users.forge.codelutin.com