Author: tchemit Date: 2012-09-07 22:58:54 +0200 (Fri, 07 Sep 2012) New Revision: 636 Url: http://forge.codelutin.com/repositories/revision/echobase/636 Log: refs #1437: Suppression des imports (add remove basic service) Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/AbstractRemoveDataService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/AcousticRemoveDataService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CatchesRemoveDataService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CommonAllRemoveDataService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CommonTransectRemoveDataService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/OperationRemoveDataService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultEsduRemoveDataService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultMapRemoveDataService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultRegionRemoveDataService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultVoyageRemoveDataService.java Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DecoratorService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportDataService.java Modified: trunk/echobase-domain/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java =================================================================== --- trunk/echobase-domain/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java 2012-09-07 16:34:49 UTC (rev 635) +++ trunk/echobase-domain/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java 2012-09-07 20:58:54 UTC (rev 636) @@ -157,6 +157,37 @@ } } + protected <E extends TopiaEntity> E create(TopiaDAO<E> dao, + Object... properties) { + try { + E result = dao.create(properties); + return result; + } catch (TopiaException e) { + throw new EchoBaseTechnicalException("Could not create entity", e); + } + } + + protected final <E extends TopiaEntity> void delete(TopiaDAO<E> dao, E entity) { + + try { + dao.delete(entity); + } catch (TopiaException e) { + + throw new EchoBaseTechnicalException("Could not delete entity " + entity, e); + } + } + + protected <E extends TopiaEntity> E findByProperties(TopiaDAO<E> dao, + String propertyName, + Object value, + Object... others) { + try { + E result = dao.findByProperties(propertyName, value, others); + return result; + } catch (TopiaException e) { + throw new EchoBaseTechnicalException("Could not obtain query db", e); + } + } protected final <E extends TopiaEntity, D extends TopiaDAO<E>> D getDAO(Class<E> entityType, Class<D> daoType) { TopiaDAO<E> dao = getDAO(entityType); Preconditions.checkState(daoType.isAssignableFrom(dao.getClass())); Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DecoratorService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DecoratorService.java 2012-09-07 16:34:49 UTC (rev 635) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DecoratorService.java 2012-09-07 20:58:54 UTC (rev 636) @@ -28,6 +28,7 @@ import com.google.common.collect.Maps; import fr.ifremer.echobase.entities.EchoBaseUser; import fr.ifremer.echobase.entities.ExportQuery; +import fr.ifremer.echobase.entities.ImportLog; import fr.ifremer.echobase.entities.WorkingDbConfiguration; import fr.ifremer.echobase.entities.data.Category; import fr.ifremer.echobase.entities.data.Cell; @@ -179,6 +180,10 @@ // ExportQuery decorator registerJXPathDecorator(locale, ExportQuery.class, "${name}$s - ${description}$s"); + // ImportLog decorator + registerJXPathDecorator(locale, ImportLog.class, "${importType}$s - ${importDate}$s - ${importText}$s"); + + // WorkingDbConfiguration decorator registerJXPathDecorator(locale, WorkingDbConfiguration.class, "${url}$s - ${login}$s (${description}$s)"); 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-07 16:34:49 UTC (rev 635) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportDataService.java 2012-09-07 20:58:54 UTC (rev 636) @@ -136,7 +136,6 @@ EchoBaseUser user, long time) { - Date importDate = newDate(); String importUser = user.getEmail(); @@ -261,16 +260,6 @@ } } - protected <E extends TopiaEntity> E create(TopiaDAO<E> dao, - Object... properties) { - try { - E result = dao.create(properties); - return result; - } catch (TopiaException e) { - throw new EchoBaseTechnicalException("Could not create entity", e); - } - } - protected <E extends TopiaEntity> E findByProperties(TopiaDAO<E> dao, String propertyName, Object value, Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/AbstractRemoveDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/AbstractRemoveDataService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/AbstractRemoveDataService.java 2012-09-07 20:58:54 UTC (rev 636) @@ -0,0 +1,239 @@ +package fr.ifremer.echobase.services.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 com.google.common.collect.Lists; +import fr.ifremer.echobase.EchoBaseTechnicalException; +import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.entities.EntityModificationLog; +import fr.ifremer.echobase.entities.ImportLog; +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.services.DecoratorService; +import fr.ifremer.echobase.services.EchoBaseServiceSupport; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaId; +import org.nuiton.util.StringUtil; +import org.nuiton.util.TimeLog; +import org.nuiton.util.decorator.Decorator; + +import java.util.List; +import java.util.Locale; +import java.util.Set; + +import static org.nuiton.i18n.I18n.l_; + +/** + * Abstract service to remove import data. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2 + */ +public abstract class AbstractRemoveDataService extends EchoBaseServiceSupport { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(AbstractRemoveDataService.class); + + public static final TimeLog TIME_LOG = + new TimeLog(AbstractRemoveDataService.class); + + protected static final String ID_REQUEST = + "SELECT COUNT(*) FROM %s WHERE topiaid = :id"; + + protected String importLabel; + + public String getImportLabel() { + return importLabel; + } + + protected abstract void removeData(String id); + + protected abstract Set<ImportType> getPossibleSubImportType(); + + public String doRemove(ImportLog importLog, EchoBaseUser user) { + + Locale locale = getLocale(); + importLabel = l_(locale, importLog.getImportType().getI18nKey()); + + long s0 = TimeLog.getTime(); + + for (String importId : importLog.getImportId()) { + + removeData(importId); + } + + s0 = TIME_LOG.log(s0, "removeData"); + + List<ImportLog> removedImortLog = removeObsoleteImportLogs(importLog); + + s0 = TIME_LOG.log(s0, "removeObsoleteImportLogs"); + + // add result in log book and compute resume to show in result + String result = computeLogBookEntry(importLog, + removedImortLog, + user, + TimeLog.getTime() - s0); + + // do commit + commitTransaction("Could not remove import " + getImportLabel()); + return result; + } + + protected List<ImportLog> removeObsoleteImportLogs(ImportLog importLog) { + + List<ImportLog> result = Lists.newArrayList(); + + Set<ImportType> possibleSubImportType = getPossibleSubImportType(); + + TopiaDAO<ImportLog> dao = getDAO(ImportLog.class); + + for (ImportLog logEntry : dao) { + + if (importLog.equals(logEntry)) { + + // for sure remove me + // but do not add to result + delete(dao, logEntry); + 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(); + + if (!isIdExists(firstId)) { + + // one of id does not exist, can safely remove importLog + + if (log.isInfoEnabled()) { + log.info("Will remove obsolete importLog " + + importLog.getTopiaId()); + } + + delete(dao, logEntry); + + // add it in result + result.add(logEntry); + } + } + } + return result; + } + + protected String computeLogBookEntry(ImportLog importLog, + List<ImportLog> obsoleteImportLogs, + EchoBaseUser user, + long time) { + + Decorator<ImportLog> decorator = getService(DecoratorService.class). + getDecorator(getLocale(), ImportLog.class, null); + + StringBuilder buffer = new StringBuilder(); + buffer.append("Suppression import "); + buffer.append(decorator.toString(importLog)); + buffer.append("\nOpération réalisée en "); + buffer.append(StringUtil.convertTime(time)); + + for (ImportLog obsoleteImportLog : obsoleteImportLogs) { + + buffer.append("\n- Suppression en cascade de l'import "); + buffer.append(decorator.toString(obsoleteImportLog)); + } + + String result = buffer.toString(); + + if (log.isDebugEnabled()) { + log.debug("Log text: " + result); + } + create(getDAO(EntityModificationLog.class), + EntityModificationLog.PROPERTY_ENTITY_TYPE, "Remove Import", + EntityModificationLog.PROPERTY_ENTITY_ID, importLog.getImportType(), + EntityModificationLog.PROPERTY_MODIFICATION_USER, user.getEmail(), + EntityModificationLog.PROPERTY_MODIFICATION_DATE, newDate(), + EntityModificationLog.PROPERTY_MODIFICATION_TEXT, result + ); + return result; + } + + protected boolean isIdExists(String id) { + + try { + + boolean result = getDAOFromId(id).existByTopiaId(id); + return result; + } catch (TopiaException e) { + throw new EchoBaseTechnicalException( + "Could not find out if id " + id + " exists.", e); + } + } + + protected <E extends TopiaEntity> E findById(TopiaDAO<E> dao, String id) { + + try { + E result = dao.findByTopiaId(id); + return result; + } catch (TopiaException e) { + throw new EchoBaseTechnicalException("Could not find entity with id " + id, e); + } + } + + protected <E extends TopiaEntity> TopiaDAO<E> getDAOFromId(String id) { + try { + return getDAO(TopiaId.getClassName(id)); + } catch (TopiaNotFoundException e) { + + throw new EchoBaseTechnicalException( + "Could not find class from id: " + id, e); + } + } + + protected <E extends TopiaEntity> E removeEntity(String id) { + + // get dao + TopiaDAO<E> dao = getDAOFromId(id); + + // get entity to delete + E entity = findById(dao, id); + + // delete it + delete(dao, entity); + + return entity; + } + + + protected void canNotDealWithId(String id) { + throw new IllegalStateException( + "Can not deal with this type of id " + id + + " from service " + this); + } + +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/AbstractRemoveDataService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/AcousticRemoveDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/AcousticRemoveDataService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/AcousticRemoveDataService.java 2012-09-07 20:58:54 UTC (rev 636) @@ -0,0 +1,90 @@ +package fr.ifremer.echobase.services.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 com.google.common.collect.Sets; +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Cell; +import fr.ifremer.echobase.entities.data.DataAcquisition; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.HashSet; +import java.util.Set; + +/** + * Remove a {@link ImportType#ACOUSTIC} import. + * <p/> + * Can remove only {@link DataAcquisition} or {@link Cell}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2 + */ +public class AcousticRemoveDataService extends AbstractRemoveDataService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(AcousticRemoveDataService.class); + + @Override + protected void removeData(String id) { + + if (id.startsWith(DataAcquisition.class.getName())) { + + // remove dataAcquisition + removeDataAcquisition(id); + } else if (id.startsWith(Cell.class.getName())) { + + // remove cell + removeCell(id); + } else { + canNotDealWithId(id); + } + } + + protected void removeDataAcquisition(String id) { + DataAcquisition entity = removeEntity(id); + if (log.isInfoEnabled()) { + log.info("DataAcquisition " + entity.getTopiaId() + " was removed"); + } + } + + protected void removeCell(String id) { + Cell entity = removeEntity(id); + if (log.isInfoEnabled()) { + log.info("Cell " + entity.getTopiaId() + " was removed"); + } + } + + @Override + protected Set<ImportType> getPossibleSubImportType() { + HashSet<ImportType> result = Sets.newHashSet(ImportType.values()); + result.remove(ImportType.COMMON_ALL); + result.remove(ImportType.COMMON_TRANSECT); + result.remove(ImportType.OPERATION); + result.remove(ImportType.CATCHES); + result.remove(ImportType.ACOUSTIC); + return result; + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/AcousticRemoveDataService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CatchesRemoveDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CatchesRemoveDataService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CatchesRemoveDataService.java 2012-09-07 20:58:54 UTC (rev 636) @@ -0,0 +1,77 @@ +package fr.ifremer.echobase.services.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 com.google.common.collect.Sets; +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Sample; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.HashSet; +import java.util.Set; + +/** + * Remove a {@link ImportType#CATCHES} import. + * <p/> + * Can remove only {@link Sample}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2 + */ +public class CatchesRemoveDataService extends AbstractRemoveDataService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(CatchesRemoveDataService.class); + + @Override + protected void removeData(String id) { + + if (id.startsWith(Sample.class.getName())) { + + // remove sample + removeSample(id); + } else { + canNotDealWithId(id); + } + } + + protected void removeSample(String id) { + Sample entity = removeEntity(id); + if (log.isInfoEnabled()) { + log.info("Sample " + entity.getTopiaId() + " was removed"); + } + } + + @Override + protected Set<ImportType> getPossibleSubImportType() { + HashSet<ImportType> result = Sets.newHashSet(ImportType.values()); + result.remove(ImportType.COMMON_ALL); + result.remove(ImportType.COMMON_TRANSECT); + result.remove(ImportType.OPERATION); + result.remove(ImportType.CATCHES); + return result; + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CatchesRemoveDataService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CommonAllRemoveDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CommonAllRemoveDataService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CommonAllRemoveDataService.java 2012-09-07 20:58:54 UTC (rev 636) @@ -0,0 +1,75 @@ +package fr.ifremer.echobase.services.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 com.google.common.collect.Sets; +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Voyage; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.HashSet; +import java.util.Set; + +/** + * Remove a {@link ImportType#COMMON_ALL} import. + * <p/> + * Can remove only {@link Voyage}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2 + */ +public class CommonAllRemoveDataService extends AbstractRemoveDataService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(CommonAllRemoveDataService.class); + + @Override + protected void removeData(String id) { + + if (id.startsWith(Voyage.class.getName())) { + + // remove voyage + removeVoyage(id); + } else { + canNotDealWithId(id); + } + } + + protected void removeVoyage(String id) { + Voyage entity = removeEntity(id); + if (log.isInfoEnabled()) { + log.info("Voyage " + entity.getTopiaId() + " was removed"); + } + } + + @Override + protected Set<ImportType> getPossibleSubImportType() { + HashSet<ImportType> result = Sets.newHashSet(ImportType.values()); + result.remove(ImportType.COMMON_ALL); + result.remove(ImportType.COMMON_TRANSECT); + return result; + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CommonAllRemoveDataService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CommonTransectRemoveDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CommonTransectRemoveDataService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CommonTransectRemoveDataService.java 2012-09-07 20:58:54 UTC (rev 636) @@ -0,0 +1,75 @@ +package fr.ifremer.echobase.services.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 com.google.common.collect.Sets; +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Transect; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.HashSet; +import java.util.Set; + +/** + * Remove a {@link ImportType#COMMON_TRANSECT} import. + * <p/> + * Can remove only {@link Transect}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2 + */ +public class CommonTransectRemoveDataService extends AbstractRemoveDataService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(CommonTransectRemoveDataService.class); + + @Override + protected void removeData(String id) { + + if (id.startsWith(Transect.class.getName())) { + + // remove transect + removeTransect(id); + } else { + canNotDealWithId(id); + } + } + + protected void removeTransect(String id) { + Transect entity = removeEntity(id); + if (log.isInfoEnabled()) { + log.info("Transect " + entity.getTopiaId() + " was removed"); + } + } + + @Override + protected Set<ImportType> getPossibleSubImportType() { + HashSet<ImportType> result = Sets.newHashSet(ImportType.values()); + result.remove(ImportType.COMMON_ALL); + result.remove(ImportType.COMMON_TRANSECT); + return result; + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/CommonTransectRemoveDataService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/OperationRemoveDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/OperationRemoveDataService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/OperationRemoveDataService.java 2012-09-07 20:58:54 UTC (rev 636) @@ -0,0 +1,76 @@ +package fr.ifremer.echobase.services.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 com.google.common.collect.Sets; +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Operation; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.HashSet; +import java.util.Set; + +/** + * Remove a {@link ImportType#OPERATION} import. + * <p/> + * Can remove only {@link Operation}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2 + */ +public class OperationRemoveDataService extends AbstractRemoveDataService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(OperationRemoveDataService.class); + + @Override + protected void removeData(String id) { + + if (id.startsWith(Operation.class.getName())) { + + // remove operation + removeOperation(id); + } else { + canNotDealWithId(id); + } + } + + protected void removeOperation(String id) { + Operation entity = removeEntity(id); + if (log.isInfoEnabled()) { + log.info("Operation " + entity.getTopiaId() + " was removed"); + } + } + + @Override + protected Set<ImportType> getPossibleSubImportType() { + HashSet<ImportType> result = Sets.newHashSet(ImportType.values()); + result.remove(ImportType.COMMON_ALL); + result.remove(ImportType.COMMON_TRANSECT); + result.remove(ImportType.OPERATION); + return result; + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/OperationRemoveDataService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultEsduRemoveDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultEsduRemoveDataService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultEsduRemoveDataService.java 2012-09-07 20:58:54 UTC (rev 636) @@ -0,0 +1,80 @@ +package fr.ifremer.echobase.services.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 com.google.common.collect.Sets; +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Result; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.HashSet; +import java.util.Set; + +/** + * Remove a {@link ImportType#RESULT_ESDU} import. + * <p/> + * Can remove only {@link Result}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2 + */ +public class ResultEsduRemoveDataService extends AbstractRemoveDataService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(ResultEsduRemoveDataService.class); + + @Override + protected void removeData(String id) { + + if (id.startsWith(Result.class.getName())) { + + // remove result + removeResult(id); + } else { + canNotDealWithId(id); + } + } + + protected void removeResult(String id) { + Result entity = removeEntity(id); + if (log.isInfoEnabled()) { + log.info("Result " + entity.getTopiaId() + " was removed"); + } + } + + @Override + protected Set<ImportType> getPossibleSubImportType() { + HashSet<ImportType> result = Sets.newHashSet(ImportType.values()); + result.remove(ImportType.COMMON_ALL); + result.remove(ImportType.COMMON_TRANSECT); + result.remove(ImportType.OPERATION); + result.remove(ImportType.CATCHES); + result.remove(ImportType.ACOUSTIC); + result.remove(ImportType.RESULT_VOYAGE); + result.remove(ImportType.RESULT_ESDU); + return result; + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultEsduRemoveDataService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultMapRemoveDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultMapRemoveDataService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultMapRemoveDataService.java 2012-09-07 20:58:54 UTC (rev 636) @@ -0,0 +1,73 @@ +package fr.ifremer.echobase.services.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 com.google.common.collect.Sets; +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Cell; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.HashSet; +import java.util.Set; + +/** + * Remove a {@link ImportType#RESULT_MAP} import. + * <p/> + * Can remove only {@link Cell}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2 + */ +public class ResultMapRemoveDataService extends AbstractRemoveDataService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(ResultMapRemoveDataService.class); + + @Override + protected void removeData(String id) { + + if (id.startsWith(Cell.class.getName())) { + + // remove cell + removeCell(id); + } else { + canNotDealWithId(id); + } + } + + protected void removeCell(String id) { + Cell entity = removeEntity(id); + if (log.isInfoEnabled()) { + log.info("Cell " + entity.getTopiaId() + " was removed"); + } + } + + @Override + protected Set<ImportType> getPossibleSubImportType() { + HashSet<ImportType> result = Sets.newHashSet(); + return result; + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultMapRemoveDataService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultRegionRemoveDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultRegionRemoveDataService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultRegionRemoveDataService.java 2012-09-07 20:58:54 UTC (rev 636) @@ -0,0 +1,81 @@ +package fr.ifremer.echobase.services.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 com.google.common.collect.Sets; +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Cell; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.HashSet; +import java.util.Set; + +/** + * Remove a {@link ImportType#RESULT_REGION} import. + * <p/> + * Can remove only {@link Cell}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2 + */ +public class ResultRegionRemoveDataService extends AbstractRemoveDataService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(ResultRegionRemoveDataService.class); + + @Override + protected void removeData(String id) { + + if (id.startsWith(Cell.class.getName())) { + + // remove echotype + removeCell(id); + } else { + canNotDealWithId(id); + } + } + + protected void removeCell(String id) { + Cell entity = removeEntity(id); + if (log.isInfoEnabled()) { + log.info("Cell " + entity.getTopiaId() + " was removed"); + } + } + + @Override + protected Set<ImportType> getPossibleSubImportType() { + HashSet<ImportType> result = Sets.newHashSet(ImportType.values()); + result.remove(ImportType.COMMON_ALL); + result.remove(ImportType.COMMON_TRANSECT); + result.remove(ImportType.OPERATION); + result.remove(ImportType.CATCHES); + result.remove(ImportType.ACOUSTIC); + result.remove(ImportType.RESULT_VOYAGE); + result.remove(ImportType.RESULT_ESDU); + result.remove(ImportType.RESULT_VOYAGE); + return result; + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultRegionRemoveDataService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultVoyageRemoveDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultVoyageRemoveDataService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultVoyageRemoveDataService.java 2012-09-07 20:58:54 UTC (rev 636) @@ -0,0 +1,104 @@ +package fr.ifremer.echobase.services.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 com.google.common.collect.Sets; +import fr.ifremer.echobase.entities.ImportType; +import fr.ifremer.echobase.entities.data.Echotype; +import fr.ifremer.echobase.entities.data.LengthAgeKey; +import fr.ifremer.echobase.entities.data.LengthWeightKey; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.HashSet; +import java.util.Set; + +/** + * remove a {@link ImportType#OPERATION} import. + * <p/> + * Can remove only {@link Echotype}, {@link LengthAgeKey} or + * {@link LengthWeightKey}. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.2 + */ +public class ResultVoyageRemoveDataService extends AbstractRemoveDataService { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(ResultVoyageRemoveDataService.class); + + @Override + protected void removeData(String id) { + + if (id.startsWith(Echotype.class.getName())) { + + // remove echotype + removeEchotype(id); + } else if (id.startsWith(LengthAgeKey.class.getName())) { + + // remove lengthAgeKey + removeLengthAgeKey(id); + } else if (id.startsWith(LengthWeightKey.class.getName())) { + + // remove lengthAgeKey + removeLengthWeightKey(id); + } else { + canNotDealWithId(id); + } + } + + protected void removeEchotype(String id) { + Echotype entity = removeEntity(id); + if (log.isInfoEnabled()) { + log.info("Echotype " + entity.getTopiaId() + " was removed"); + } + } + + protected void removeLengthAgeKey(String id) { + LengthAgeKey entity = removeEntity(id); + if (log.isInfoEnabled()) { + log.info("LengthAgeKey " + entity.getTopiaId() + " was removed"); + } + } + + protected void removeLengthWeightKey(String id) { + LengthWeightKey entity = removeEntity(id); + if (log.isInfoEnabled()) { + log.info("LengthWeightKey " + entity.getTopiaId() + " was removed"); + } + } + + @Override + protected Set<ImportType> getPossibleSubImportType() { + HashSet<ImportType> result = Sets.newHashSet(ImportType.values()); + result.remove(ImportType.COMMON_ALL); + result.remove(ImportType.COMMON_TRANSECT); + result.remove(ImportType.OPERATION); + result.remove(ImportType.CATCHES); + result.remove(ImportType.ACOUSTIC); + result.remove(ImportType.RESULT_VOYAGE); + return result; + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/removedata/ResultVoyageRemoveDataService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native