This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository tutti. See http://git.codelutin.com/tutti.git commit cab709a7a1ee1ca3bd90399f0577e04b744fd9cf Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Jan 9 09:43:38 2016 +0100 Suppression old code --- .../observe/services/AbstractObserveService.java | 514 ------------- .../ObserveServiceFactoryProviderTopia.java | 212 ----- .../observe/services/ReplicationServiceImpl.java | 445 ----------- .../observe/services/data/OpenableServiceImpl.java | 179 ----- .../ird/observe/services/data/TripServiceImpl.java | 233 ------ .../data/longline/ActivityLonglineServiceImpl.java | 167 ---- .../data/longline/BaitsCompositionServiceImpl.java | 98 --- .../BranchlinesCompositionServiceImpl.java | 94 --- .../data/longline/CatchLonglineServiceImpl.java | 267 ------- .../data/longline/EncounterServiceImpl.java | 94 --- .../longline/FloatlinesCompositionServiceImpl.java | 94 --- .../GearUseFeaturesLonglineServiceImpl.java | 236 ------ .../data/longline/HooksCompositionServiceImpl.java | 94 --- .../LonglineDetailCompositionServiceImpl.java | 213 ----- .../LonglineGlobalCompositionServiceImpl.java | 87 --- .../data/longline/SensorUsedServiceImpl.java | 129 ---- .../data/longline/SetLonglineServiceImpl.java | 201 ----- .../services/data/longline/TdrServiceImpl.java | 127 --- .../data/longline/TripLonglineServiceImpl.java | 158 ---- .../data/seine/ActivitySeineServiceImpl.java | 224 ------ .../data/seine/FloatingObjectServiceImpl.java | 216 ------ .../seine/GearUseFeaturesSeineServiceImpl.java | 233 ------ .../data/seine/NonTargetCatchServiceImpl.java | 136 ---- .../data/seine/NonTargetSampleServiceImpl.java | 267 ------- .../seine/ObjectObservedSpeciesServiceImpl.java | 88 --- .../seine/ObjectSchoolEstimateServiceImpl.java | 89 --- .../services/data/seine/RouteServiceImpl.java | 184 ----- .../data/seine/SchoolEstimateServiceImpl.java | 94 --- .../services/data/seine/SetSeineServiceImpl.java | 173 ----- .../data/seine/TargetCatchServiceImpl.java | 186 ----- .../data/seine/TargetSampleServiceImpl.java | 298 ------- .../services/data/seine/TripSeineServiceImpl.java | 158 ---- .../services/operation/ComputeDataServiceImpl.java | 854 --------------------- .../services/operation/GpsImportServiceImpl.java | 153 ---- .../services/operation/SynchronizeServiceImpl.java | 240 ------ .../services/operation/ValidationServiceImpl.java | 116 --- .../referential/ReferentialServiceImpl.java | 540 ------------- 37 files changed, 7891 deletions(-) diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/AbstractObserveService.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/AbstractObserveService.java deleted file mode 100644 index d744aec..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/AbstractObserveService.java +++ /dev/null @@ -1,514 +0,0 @@ -package fr.ird.observe.services; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import fr.ird.observe.BinderService; -import fr.ird.observe.IObserveConfig; -import fr.ird.observe.ObserveEntityEnum; -import fr.ird.observe.business.db.DataSource; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.EntityMap; -import fr.ird.observe.entities.constants.ReferenceLocale; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; -import org.nuiton.topia.TopiaContext; - -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.topia.persistence.util.TopiaEntityHelper; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * @author Sylvain Bavencoff - bavencoff@codelutin.com - * @since 4.0 - */ -public abstract class AbstractObserveService implements ObserveService { - - /** Logger. */ - private static final Log log = LogFactory.getLog(AbstractObserveService.class); - - String PARENT_BEAN = "parentBean"; - - String BEAN = "bean"; - - protected ObserveServiceContext serviceContext; - - @Override - public void setServiceContext(ObserveServiceContext serviceContext) { - this.serviceContext = serviceContext; - } - - @Override - public <E extends TopiaEntity> EntityMap findAllUsages(E entity) { - - Class<E> entityType = getEntityContractClass(entity); - - TopiaDAO<E> dao = getDao(entityType); - - // always get a fresh version of object - entity = dao.findByTopiaId(entity.getTopiaId()); - EntityMap result; - result = new EntityMap(dao.findAllUsages(entity)); - // on charge les entites - for (Class<? extends TopiaEntity> aClass : result.keySet()) { - - List topiaEntities = result.get(aClass); - decorate(aClass, topiaEntities); - - } - return result; - - } - - @Override - public <E extends TopiaEntity> List<E> getList(Class<E> klass) { - - List<E> list = getList(klass, null); - return list; - } - - @Override - public <E extends TopiaEntity> List<E> getList(Class<E> klass, Predicate<E> predicate) { - - if (Entities.isDataClass(klass)) { - // on verifie que l'on a le droit de lire la donnee - if (!getDataSource().canReadData()) { - if (log.isDebugEnabled()) { - log.debug("Can not read data, no read credential"); - } - return new ArrayList<E>(); - } - } - - if (Entities.isReferentielClass(klass)) { - // on verifie que l'on a le droit de lire la donnee - if (!getDataSource().canReadReferentiel()) { - if (log.isDebugEnabled()) { - log.debug("Can not read referentiel, no read credential"); - } - return new ArrayList<E>(); - } - } - - List<E> result = getList0(klass, predicate); - - //TC-20100208 : on peut modifier la liste (pour supprimer par - // exemple les entites non active), on doit donc toujours travailler - // sur une copie de la liste - return new ArrayList<E>(result); - - } - - public TopiaContext getTransaction() { - return serviceContext.getTransaction(); - } - - public IObserveConfig getConfig() { - return serviceContext.getConfig(); - } - - public ReferenceLocale getReferentielLocale() { - return serviceContext.getReferentielLocale(); - } - - public Date now() { - return serviceContext.now(); - } - - public BinderService getBinderService() { - return serviceContext.getBinderService(); - } - - public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target) { - getBinderService().copy(type, context, source, target); - } - - public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, String... propertyNames) { - getBinderService().copyExcluding(type, context, source, target, propertyNames); - } - - public <E extends TopiaEntity> void copyExcluding(Class<E> type, String context, E source, E target, boolean bindTechnical, String... propertyNames) { - getBinderService().copyExcluding(type, context, source, target, bindTechnical, propertyNames); - } - - public <E extends TopiaEntity> void copy(Class<E> type, String context, E source, E target, boolean bindTechnical) { - getBinderService().copy(type, context, source, target, bindTechnical); - } - - public <E extends TopiaEntity> Map<String, Object> obtainProperties(Class<E> type, String context, E source) { - return getBinder(type, context).obtainProperties(source); - } - - public <E extends TopiaEntity> TopiaEntityBinder<E> getBinder(Class<E> entityClass, String contextName) { - return getBinderService().getBinder(entityClass, contextName); - } - - protected <E extends TopiaEntity> TopiaDAO<E> getDao(E entity) { - Class<E> entityType = getEntityContractClass(entity); - return getDataSource().getDAO(getTransaction(), entityType); - } - - protected DataSource getDataSource() { - return serviceContext.getDataSource(); - } - - protected <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityType) { - return getDataSource().getDAO(getTransaction(), entityType); - } - - protected <E extends TopiaEntity> E findByTopiaId(Class<E> entityType, String topiaId) { - - TopiaDAO<E> dao = getDataSource().getDAO(getTransaction(), entityType); - return dao.findByTopiaId(topiaId); - - } - - protected <O> Decorator<O> getDecoratorByType(Class<O> entityType, String context) { - return serviceContext.getDecoratorService().getDecoratorByType(entityType, context); - } - - - protected <O> void decorate(Class<O> objectType, Collection<O> objects) { - - Decorator<O> decorator = getDecoratorByType(objectType, null); - for (Object object : objects) { - decorator.toString(object); - } - - } - - protected <O> void decorate(Class<O> objectType, O object) { - - Decorator<O> decorator = getDecoratorByType(objectType, null); - decorator.toString(object); - - } - - protected <E extends TopiaEntity> String decorateEntity(E entity) { - - Class<E> entityType = getEntityContractClass(entity); - Decorator<E> decorator = getDecoratorByType(entityType, null); - return decorator.toString(entity); - - } - - protected <E extends TopiaEntity> Class<E> getEntityContractClass(E entity) { - return (Class<E>) ObserveEntityEnum.valueOf(entity).getContract(); - } - - protected <E extends TopiaEntity> List<E> getList0(Class<E> klass, Predicate<E> predicate) { - - TopiaDAO<E> dao = getDao(klass); - List<E> result = dao.findAll(); - - if (predicate != null) { - - // use a filter - result = Lists.newArrayList(Iterables.filter(result, predicate)); - - } - - return result; - - } - - protected <P extends TopiaEntity, E extends TopiaEntity> String doSave(String parentId, E toSave, SaveAction<P, E> saveAction) { - E saved; - - saveAction.beforeSave(parentId, toSave); - - P parent = null; - - if (parentId != null) { - - parent = findByTopiaId(saveAction.parentClass, parentId); - - checkNotNullAndExistingEntity(PARENT_BEAN, parent); - } - - if (Entities.isNew(toSave)) { - - checkNotNullAndNoneExistingEntity(BEAN, toSave); - - saved = saveAction.onCreate(parent, toSave); - - } else { - - checkNotNullAndExistingEntity(BEAN, toSave); - - saved = saveAction.onUpdate(parent, toSave); - - checkNotNullAndExistingEntity(BEAN, saved); - - } - - if (parent == null) { - - // sauvegarde de l'entité - getDao(saveAction.entityClass).update(saved); - - } else { - - // sauvegarde du père de l'entité - getDao(saveAction.parentClass).update(parent); - - } - - return saved.getTopiaId(); - - - } - - protected abstract class SaveAction<P extends TopiaEntity, E extends TopiaEntity> { - - protected final Class<P> parentClass; - - protected final Class<E> entityClass; - - public SaveAction(Class<P> parentClass, Class<E> entityClass) { - this.parentClass = parentClass; - this.entityClass = entityClass; - } - - public void beforeSave(String parentId, E toSave) { - - } - - public abstract E onCreate(P parent, E toCreate); - - public E onUpdate(P parent, E toSave) { - - E saved = findByTopiaId(entityClass, toSave.getTopiaId()); - checkNotNullAndExistingEntity(BEAN, saved); - return saved; - - } - - } - - protected <P extends TopiaEntity, E extends TopiaEntity> void doDelete(String parentId, String idToDelete, DeleteAction<P, E> deleteAction) { - - P parent = null; - - if (parentId != null) { - - parent = findByTopiaId(deleteAction.parentClass, parentId); - - checkNotNullAndExistingEntity(PARENT_BEAN, parent); - - } - - E toDelete = findByTopiaId(deleteAction.entityClass, idToDelete); - - checkNotNullAndExistingEntity(BEAN, toDelete); - - deleteAction.onDelete(parent, toDelete); - - if (parentId != null) { - - getDao(deleteAction.parentClass).update(parent); - - } - - } - - protected class DeleteAction<P extends TopiaEntity, E extends TopiaEntity> { - - protected final Class<P> parentClass; - - protected final Class<E> entityClass; - - public DeleteAction(Class<P> parentClass, Class<E> entityClass) { - this.parentClass = parentClass; - this.entityClass = entityClass; - } - - public void onDelete(P parent, E toDelete) { - getDao(entityClass).delete(toDelete); - } - - } - - protected <P extends TopiaEntity, E extends TopiaEntity> void doSaveList(P parentToSave, SaveCollectionAction<P, E> saveCollectionAction) { - - Collection<E> childrenToSave = saveCollectionAction.listUpdator.getChilds(parentToSave); - - saveCollectionAction.prepareSave(parentToSave, childrenToSave); - - P parentSaved = saveCollectionAction.onUpdateParent(parentToSave); - - List<E> oldChilds = new ArrayList<E>(saveCollectionAction.listUpdator.getChilds(parentSaved)); - - saveCollectionAction.listUpdator.removeAll(parentSaved); - - for (E childToSave : childrenToSave) { - - E childSaved; - - if (Entities.isNew(childToSave)) { - - // creation du fils - childSaved = saveCollectionAction.onCreateChild(childToSave); - - } else { - - // mise a jour du fils - childSaved = saveCollectionAction.onUpdateChild(childToSave); - - } - - saveCollectionAction.listUpdator.addToList(parentSaved, childSaved); - - } - - for (E childNotSaved : Iterables.filter(oldChilds, Predicates.not(saveCollectionAction.childPredicate))) { - saveCollectionAction.listUpdator.addToList(parentSaved, childNotSaved); - } - - // on donne la main aux implantations pour faire des traitements supplémentaires - saveCollectionAction.onUpdateFinalize(parentSaved, oldChilds); - - } - - - protected class SaveCollectionAction<P extends TopiaEntity, E extends TopiaEntity> { - - protected final Class<P> parentClass; - - protected final Class<E> entityClass; - - protected final EntityListUpdator<P, E> listUpdator; - - protected final TopiaEntityBinder<P> parentBinder; - - protected final TopiaEntityBinder<E> childBinder; - - protected final Predicate<E> childPredicate; - - public SaveCollectionAction(Class<P> parentClass, - Class<E> entityClass, - EntityListUpdator<P, E> listUpdator, - TopiaEntityBinder<P> parentBinder, - TopiaEntityBinder<E> childBinder, - Predicate<E> childPredicate) { - this.parentClass = parentClass; - this.entityClass = entityClass; - this.listUpdator = listUpdator; - this.parentBinder = parentBinder; - this.childBinder = childBinder; - this.childPredicate = childPredicate; - } - - public SaveCollectionAction(Class<P> parentClass, - Class<E> entityClass, - EntityListUpdator<P, E> listUpdator, - TopiaEntityBinder<P> parentBinder, - TopiaEntityBinder<E> childBinder) { - this.parentClass = parentClass; - this.entityClass = entityClass; - this.listUpdator = listUpdator; - this.parentBinder = parentBinder; - this.childBinder = childBinder; - this.childPredicate = Predicates.alwaysTrue(); - } - - public void prepareSave(P parentToSave, Collection<E> toSaves) { - // par defaut, rien de specifique a faire avant de faire la sauvegarde - } - - public void onUpdateFinalize(P parentSaved, Collection<E> oldChilds) { - // par défaut, rien à faire après la sauvegarde de la liste - } - - public P onUpdateParent(P parentToSave) { - - TopiaDAO<P> dao = getDao(parentClass); - - P parentSaved = dao.findByTopiaId(parentToSave.getTopiaId()); - parentBinder.copyExcluding(parentToSave, parentSaved, listUpdator.getPropertyName()); - parentSaved = dao.update(parentSaved); - - return parentSaved; - - } - - public E onCreateChild(E childToCreate) { - - Map<String, Object> properties = childBinder.obtainProperties(childToCreate); - E childCreated = getDao(entityClass).create(properties); - - return childCreated; - - } - - public E onUpdateChild(E childToUpdate) { - - TopiaDAO<E> dao = getDao(entityClass); - - E childUpdated = dao.findByTopiaId(childToUpdate.getTopiaId()); - childBinder.load(childToUpdate, childUpdated, true); - childUpdated = dao.update(childUpdated); - - return childUpdated; - - } - - } - - protected <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(String variableName, E entity) { - TopiaEntityHelper.checkNotNullAndNoneExistingEntity(variableName, entity); - } - - - protected <E extends TopiaEntity> void checkNotNullAndExistingEntity(String variableName, E entity) { - TopiaEntityHelper.checkNotNullAndExistingEntity(variableName, entity); - } - - protected <S extends ObserveService> S newService(Class<S> serviceType) { - - S service = ObserveServiceFactoryTopia.newSimpleService(serviceType, serviceContext); - return service; - - } - - protected <S extends ObserveService> S newService(DataSource dataSource, Class<S> serviceType) { - - ObserveServiceContext serviceContext1 = new ObserveServiceContext(serviceContext.applicationContext, dataSource); - S service = new ObserveServiceFactoryTopia().newService(serviceType, serviceContext1); - return service; - - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java deleted file mode 100644 index 2efa703..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/ObserveServiceFactoryProviderTopia.java +++ /dev/null @@ -1,212 +0,0 @@ -package fr.ird.observe.services; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Preconditions; -import com.google.common.collect.Sets; -import fr.ird.observe.ObserveTechnicalException; -import fr.ird.observe.business.db.DataSource; -import fr.ird.observe.business.db.impl.H2DataSource; -import fr.ird.observe.business.db.impl.PGDataSource; -import org.apache.commons.lang3.reflect.ConstructorUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.Set; - -/** - * Created on 5/4/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class ObserveServiceFactoryProviderTopia implements ObserveServiceFactory { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ObserveServiceFactoryProviderTopia.class); - - @Override - public boolean acceptDataSource(DataSource dataSource) { - - boolean result = false; - if (dataSource instanceof H2DataSource) { - result = true; - } else if (dataSource instanceof PGDataSource) { - result = true; - } - return result; - - } - - @Override - public <S extends ObserveService> S newService(Class<S> serviceType, ObserveServiceContext serviceContext) { - - Preconditions.checkNotNull(serviceType, "serviceType can't be null"); - Preconditions.checkArgument(serviceType.isInterface(), "serviceType must be an interface"); - Preconditions.checkNotNull(serviceContext, "serviceContext can't be null"); - - S service = newSimpleService(serviceType, serviceContext); - S proxyService = addProxyService(serviceType, service, serviceContext); - return proxyService; - - } - - public static <S extends ObserveService> S newSimpleService(Class<S> serviceType, ObserveServiceContext serviceContext) { - - //FIXME Rename implementation to TopiaImpl - Class<S> serviceImpl; - try { - serviceImpl = (Class<S>) Class.forName(serviceType.getName() + "Impl"); - } catch (ClassNotFoundException e) { - throw new IllegalStateException("Could not find implementation class for " + serviceType); - } - - try { - - // Instanciate concrete service - S service = ConstructorUtils.invokeConstructor(serviceImpl); - service.setServiceContext(serviceContext); - - return service; - - } catch (Exception e) { - throw new ObserveTechnicalException("Could not create service: " + serviceType, e); - } - - } - - protected <S extends ObserveService> S addProxyService(Class<S> serviceType, S service, ObserveServiceContext serviceContext) { - - // Instanciate transactional proxied service - ServiceInvocationHandler invocationHandler = new ServiceInvocationHandler(serviceContext, service); - S proxyService = (S) Proxy.newProxyInstance(ObserveServiceFactoryProviderTopia.class.getClassLoader(), new Class[]{serviceType}, invocationHandler); - - return proxyService; - - } - - protected static class ServiceInvocationHandler implements InvocationHandler { - - private final ObserveServiceContext serviceContext; - - private final ObserveService target; - - private final Set<String> methodNamesToByPass; - - protected ServiceInvocationHandler(ObserveServiceContext serviceContext, ObserveService target) { - - this.serviceContext = serviceContext; - this.target = target; - this.methodNamesToByPass = Sets.newHashSet( - "equals", - "hashCode", - "finalize", - "toString", - "clone", - "getClass", - "close"); - - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - - Object result; - - if (methodNamesToByPass.contains(method.getName()) || method.isAnnotationPresent(NoTransaction.class)) { - - result = invokeMethod(method, args); - - } else { - - result = invokeMethodWithTransaction(method, args); - - } - - return result; - - } - - protected Object invokeMethod(Method method, Object... args) throws Throwable { - try { - Object result = method.invoke(target, args); - return result; - } catch (InvocationTargetException e) { - if (log.isErrorEnabled()) { - log.error("Error in method " + method.getName(), e); - } - throw e.getCause(); - } - } - - - protected Object invokeMethodWithTransaction(Method method, Object... args) throws Throwable { - - String methodName = method.getName(); - - DataSource source = serviceContext.getDataSource(); - - TopiaContext tx = source.beginTransaction(methodName); - - try { - - serviceContext.setTransaction(tx); - - Object invoke = invokeMethod(method, args); - - if (method.isAnnotationPresent(Commit.class)) { - - // do commit - source.commitTransaction(tx, methodName); - - } - - return invoke; - - } finally { - - try { - - // always rollback transaction to avoid dirty transactions - source.rollbackTransaction(tx, methodName); - - - } finally { - - serviceContext.setTransaction(null); - source.closeTransaction(tx, methodName); - - } - - } - - } - - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/ReplicationServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/ReplicationServiceImpl.java deleted file mode 100644 index 5148447..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/ReplicationServiceImpl.java +++ /dev/null @@ -1,445 +0,0 @@ -package fr.ird.observe.services; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.DecoratorService; -import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.ObserveEntityEnum; -import fr.ird.observe.SendMessageAble; -import fr.ird.observe.business.db.DataSource; -import fr.ird.observe.business.db.DataSourceException; -import fr.ird.observe.business.db.constants.DataSourceState; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.Trip; -import fr.ird.observe.entities.longline.TripLongline; -import fr.ird.observe.entities.longline.TripLonglines; -import fr.ird.observe.entities.seine.TripSeineDAO; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; - -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.framework.TopiaSQLQuery; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.replication.TopiaReplicationService; -import org.nuiton.topia.replication.model.ReplicationModel; -import org.nuiton.util.StringUtil; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import static org.nuiton.i18n.I18n.t; - -/** - * Created on 5/3/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class ReplicationServiceImpl extends AbstractObserveService implements ReplicationService { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ReplicationServiceImpl.class); - - @Override - public void replicateObsoletesEntities(List<TopiaEntity> obsoleteEntities, DataSource source, SendMessageAble messanger) throws DataSourceException { - - String txName = "replicateObsoletesEntities"; - TopiaContext sourceCtxt = source.beginTransaction(txName); - try { - - for (ObserveEntityEnum constant : Entities.REFERENCE_ENTITIES) { - - Class<? extends TopiaEntity> contractClass = constant.getContract(); - List<TopiaEntity> toReplicate = new ArrayList<TopiaEntity>(); - for (Iterator<TopiaEntity> itr = obsoleteEntities.iterator(); itr.hasNext(); ) { - - TopiaEntity e = itr.next(); - if (contractClass.isAssignableFrom(e.getClass())) { - if (log.isDebugEnabled()) { - log.debug("obsolete to inject : " + e.getTopiaId()); - } - itr.remove(); - - // cet objet doit etre replique - toReplicate.add(e); - - messanger.sendMessage(t("observe.message.synchro.obsolete.data.to.duplicate", e)); - } - } - - if (toReplicate.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("no obsolete entity " + constant); - } - continue; - } - - if (log.isDebugEnabled()) { - log.debug("inject obsolete entity " + constant + " (" + toReplicate.size() + ")"); - } - - sourceCtxt.replicateEntities(getTransaction(), toReplicate); - - getTransaction().commitTransaction(); - - } - - } finally { - - source.closeTransaction(sourceCtxt, txName); - - } - - if (!obsoleteEntities.isEmpty()) { - throw new IllegalStateException("there is still obsolete entities to inject in synchro db : " + obsoleteEntities); - } - - } - - /** - * Duplication du référentiel depuis la source donnée en paramètre vers la source de ce service. - * - * @param srcService le service source qui contient les référentiels à repliquer - * @throws DataSourceException if pb - */ - public void replicateReferentiel(DataSource srcService) throws DataSourceException { - - if (srcService == null) { - throw new NullPointerException("srcService can not be null"); - } - - srcService.checkState(DataSourceState.OPEN); - - if (srcService.equals(getDataSource())) { - throw new IllegalArgumentException("can not duplicate to the same service..."); - } - long t0 = System.nanoTime(); - - Date date = new Date(); - srcService.fireNewMessage(t("observe.storage.message.replicate.referentiel.starting", date)); - - try { - - TopiaReplicationService service = srcService.getTopiaService(TopiaReplicationService.class); - - ReplicationModel model = service.prepareForAll(Entities.REFERENCE_ENTITIES); - - service.doReplicate(model, getTransaction()); - - String delay = StringUtil.convertTime(t0, System.nanoTime()); - srcService.fireNewMessage( - t("observe.storage.message.replicate.referentiel.done", delay)); - } catch (Exception e) { - throw new DataSourceException(e, "replicateReferentiel"); - } - } - - @Override - public void replicateReferentiel(DataSource srcService, List<String> ids, SendMessageAble messanger) throws DataSourceException { - - for (String id : ids) { - - String txName = "replicateReferentiel::" + id; - TopiaContext tx = srcService.beginTransaction(txName); - - try { - - TopiaEntity entity = tx.findByTopiaId(id); - String message = t("observe.synchro.add.object", id); - messanger.sendMessage(message); - tx.replicateEntity(getTransaction(), entity); - - // On est obligé de commiter à chaque ajout sinon si - // une autre entité à ajouter depend de celle là, on - // ne la retrouve pas - getTransaction().commitTransaction(); - if (log.isDebugEnabled()) { - log.debug("add [" + id + "] : "); - } - - } finally { - - // rollback context since we do not want to keep any modification - try { - srcService.rollbackTransaction(tx, txName); - } finally { - srcService.closeTransaction(tx, txName); - } - - } - - } - - } - - /** - * Duplication de toutes les données depuis le service passé en paramètre. - * - * @param srcService le service source - * @throws DataSourceException if pb - */ - public void replicateAllData(DataSource srcService) throws DataSourceException { - - srcService.checkState(DataSourceState.OPEN); - - // le service peut-être en cours d'ouverture - getDataSource().checkState(DataSourceState.INIT, DataSourceState.OPEN); - - if (srcService.equals(getDataSource())) { - throw new IllegalArgumentException("can not replcate to the same service..."); - } - - // recuperation des marees a repliquer - - String[] topiaIds = null; - - TopiaContext srcCtxt = srcService.beginTransaction("replicateData"); - try { - - TripSeineDAO srcTripDAO = ObserveDAOHelper.getTripSeineDAO(srcCtxt); - List<String> allIds = srcTripDAO.findAllIds(); - - if (CollectionUtils.isEmpty(allIds)) { - - // aucune donnee a repliquer - srcService.fireNewMessage(t("observe.storage.message.replicate.data.no.data")); - return; - - } - - topiaIds = allIds.toArray(new String[allIds.size()]); - - } catch (TopiaException e) { - - throw new DataSourceException(e, "replicateData"); - - } finally { - - // rollback context since we do not want to keep any modification - try { - srcService.rollbackTransaction(srcCtxt, "replicateData"); - } finally { - srcService.closeTransaction(srcCtxt, "replicateData"); - } - - } - - // replication des marees - replicateData(srcService, topiaIds); - - } - - /** - * Duplication de données observateur depuis la source passée en paramètre. - * - * @param srcService le service source - * @param ids les ids des entités à répliquer - * @throws DataSourceException if pb - */ - public void replicateData(DataSource srcService, String... ids) throws DataSourceException { - - if (srcService == null) { - throw new NullPointerException("srcService can not be null"); - } - - srcService.checkState(DataSourceState.OPEN); - // le service peut-être en cours d'ouverture - getDataSource().checkState(DataSourceState.INIT, DataSourceState.OPEN); - - if (srcService.equals(getDataSource())) { - throw new IllegalArgumentException("can not replcate to the same service..."); - } - - long t0 = System.nanoTime(); - - srcService.fireNewMessage(t("observe.storage.message.replicate.entities.starting", now())); - - for (String id : ids) { - replicateOneData(srcService, id); - } - - String time = StringUtil.convertTime(t0, System.nanoTime()); - srcService.fireNewMessage(t("observe.storage.message.replicate.entities.done", time)); - - } - - /** - * Duplication de l'unique donnée observateur depuis ce service vers le service donné. - * - * La duplication utilise une transaction dédiée afin de ne pas saturer le serveur - * et aussi une meilleure maitrise du rollback en cas d'une erreur. - * - * Voir http://forge.codelutin.com/issues/4837 - * - * @param srcService le service source - * @param id les ids des entités à répliquer - * @throws DataSourceException if pb - */ - protected void replicateOneData(DataSource srcService, String id) throws DataSourceException { - - String dstLabel = getDataSource().getShortLabel(); - - TopiaReplicationService service = srcService.getTopiaService(TopiaReplicationService.class); - - ReplicationModel model; - try { - model = service.prepare(Entities.DATA_ENTITIES, false, id); - } catch (TopiaException e) { - throw new DataSourceException(e, "replicateData"); - } - - // To fix missing tdr associations (see https://forge.codelutin.com/issues/6611) - List<Pair<String, String>> tdrAssociation = null; - - TopiaContext srcCtxt = srcService.beginTransaction("replicateData"); - try { - - TopiaEntity e = srcCtxt.findByTopiaId(id); - String label = t(DecoratorService.getEntityLabel(e.getClass())) + " :: " + id; - srcService.fireNewMessage(t("observe.storage.message.replicate.data.entity", label, dstLabel)); - - if (e instanceof Trip && Entities.isLonglineId(id)) { - - // Grab tdr missing associations (see https://forge.codelutin.com/issues/6611) - if (log.isInfoEnabled()) { - log.info("Should keep SetLongline - Tdr association ids for: " + id); - } - - tdrAssociation = getTdrAssociationIds(srcCtxt, (TripLongline) e); - - } - } catch (TopiaException e) { - throw new DataSourceException(e, "replicateData"); - } finally { - srcService.closeTransaction(srcCtxt, "replicateData"); - } - - TopiaContext dstCtxt = getTransaction(); - try { - - // do the replicate - service.doReplicate(model, dstCtxt); - - // Apply back tdr missing associations (see https://forge.codelutin.com/issues/6611) - applyTdrAssociationFix(dstCtxt, tdrAssociation); - - // commit the result - getTransaction().commitTransaction(); - - } catch (Exception e) { - getTransaction().rollbackTransaction(); - throw new DataSourceException(e, "replicateData"); - } finally { - - getTransaction().rollbackTransaction(); - - } - - } - - private void applyTdrAssociationFix(TopiaContext dstCtxt, List<Pair<String, String>> tdrAssociation) { - - String request = "\nUPDATE OBSERVE_LONGLINE.TDR SET SET = '%s' WHERE topiaid = '%s';"; - - StringBuilder builder = new StringBuilder(); - - if (CollectionUtils.isNotEmpty(tdrAssociation)) { - for (Pair<String, String> entry : tdrAssociation) { - builder.append(String.format(request, entry.getKey(), entry.getValue())); - } - } - - dstCtxt.executeSQL(builder.toString()); - - } - - private List<Pair<String, String>> getTdrAssociationIds(TopiaContext srcCtxt, TripLongline e) { - - List<Pair<String, String>> result = new ArrayList<Pair<String, String>>(); - - Set<String> setIds = TripLonglines.getSetIdsWithTdr(e); - - GetTdrIdsQuery query = new GetTdrIdsQuery(); - - for (String setId : setIds) { - - List<Pair<String, String>> multipleResult = query.execute((TopiaContextImplementor) srcCtxt, setId); - - if (log.isDebugEnabled()) { - log.debug("Found TDR associations: " + multipleResult); - } - result.addAll(multipleResult); - - } - - return result; - } - - - private static class GetTdrIdsQuery extends TopiaSQLQuery<Pair<String, String>> { - - private String setId; - - public List<Pair<String, String>> execute(TopiaContextImplementor tx, String setId) { - try { - - this.setId = setId; - return findMultipleResult(tx); - - } finally { - - this.setId = null; - - } - } - - @Override - protected PreparedStatement prepareQuery(Connection connection) throws SQLException { - String sql = "SELECT t.SET, t.topiaId " + - "FROM OBSERVE_LONGLINE.TDR t " + - "WHERE t.SET = ?"; - PreparedStatement ps = connection.prepareStatement(sql); - ps.setString(1, setId); - return ps; - } - - @Override - protected Pair<String, String> prepareResult(ResultSet set) throws SQLException { - Pair<String, String> result = - Pair.of(set.getString(1), set.getString(2)); - return result; - } - - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/OpenableServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/OpenableServiceImpl.java deleted file mode 100644 index 6f1dc8f..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/OpenableServiceImpl.java +++ /dev/null @@ -1,179 +0,0 @@ -package fr.ird.observe.services.data; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.entities.OpenableEntity; -import fr.ird.observe.entities.OpenableEntityDAOImpl; -import fr.ird.observe.entities.longline.ActivityLongline; -import fr.ird.observe.entities.longline.ActivityLonglineDAO; -import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.entities.longline.TripLongline; -import fr.ird.observe.entities.longline.TripLonglineDAO; -import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.ActivitySeineDAO; -import fr.ird.observe.entities.seine.Route; -import fr.ird.observe.entities.seine.RouteDAO; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.entities.seine.TripSeineDAO; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaEntity; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created on 4/26/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class OpenableServiceImpl extends AbstractObserveService implements OpenableService { - - @Override - public String[] getOpenIds() { - - List<String> result = new ArrayList<String>(); - - { - TripSeine trip = getOpen(TripSeine.class); - if (trip != null) { - if (trip.getProgram() != null) { - result.add(trip.getProgram().getTopiaId()); - } - result.add(trip.getTopiaId()); - Route route = getOpen(Route.class); - if (route != null) { - result.add(route.getTopiaId()); - ActivitySeine activity = getOpen(ActivitySeine.class); - if (activity != null) { - result.add(activity.getTopiaId()); - SetSeine set = activity.getSetSeine(); - if (set != null) { - result.add(set.getTopiaId()); - } - } - } - } - } - - { - TripLongline trip = getOpen(TripLongline.class); - if (trip != null) { - if (trip.getProgram() != null) { - result.add(trip.getProgram().getTopiaId()); - } - result.add(trip.getTopiaId()); - ActivityLongline activity = getOpen(ActivityLongline.class); - if (activity != null) { - result.add(activity.getTopiaId()); - SetLongline set = activity.getSetLongline(); - if (set != null) { - result.add(set.getTopiaId()); - } - } - } - } - - return result.toArray(new String[result.size()]); - - } - - @Override - public <E extends OpenableEntity & TopiaEntity> E getOpen(Class<E> klass) { - - OpenableEntityDAOImpl dao = (OpenableEntityDAOImpl) getDao(klass); - E result = (E) dao.findByOpen(true); - return result; - - } - - @Override - public void updateOpenState(String topiaId, boolean openState) { - - OpenableEntity entity = findByTopiaId(OpenableEntity.class, topiaId); - entity.setOpen(openState); - - } - - public int getOpenablePosition(String containerId, String childId) { - if (childId.startsWith(TripSeine.class.getName())) { - return getTripSeinePosition(containerId, childId); - } - if (childId.startsWith(TripLongline.class.getName())) { - return getTripLonglinePosition(containerId, childId); - } - if (childId.startsWith(Route.class.getName())) { - return getRoutePosition(containerId, childId); - } - if (childId.startsWith(ActivitySeine.class.getName())) { - return getActivitySeinePosition(containerId, childId); - } - if (childId.startsWith(ActivityLongline.class.getName())) { - return getActivityLonglinePosition(containerId, childId); - } - throw new IllegalStateException("Can not come here!"); - } - - protected int getTripLonglinePosition(String programId, String tripLonglineId) { - - TripLonglineDAO dao = (TripLonglineDAO) getDao(TripLongline.class); - int pos = dao.findPositionByProgramId(programId, tripLonglineId); - return pos; - - } - - protected int getActivityLonglinePosition(String tripLonglineId, String activityLonglineId) { - - ActivityLonglineDAO dao = (ActivityLonglineDAO) getDao(ActivityLongline.class); - int pos = dao.getActivityLonglinePosition(tripLonglineId, activityLonglineId); - return pos; - - } - - protected int getTripSeinePosition(String programId, String tripSeineId) { - - TripSeineDAO dao = (TripSeineDAO) getDao(TripSeine.class); - int pos = dao.findPositionByProgramId(programId, tripSeineId); - return pos; - - } - - protected int getRoutePosition(String tripSeineId, String routeId) { - - RouteDAO dao = (RouteDAO) getDao(Route.class); - int position = dao.getRoutePosition(tripSeineId, routeId); - return position; - - } - - - protected int getActivitySeinePosition(String routeId, String activitySeineId) { - - ActivitySeineDAO dao = (ActivitySeineDAO) getDao(ActivitySeine.class); - int pos = dao.getActivitySeinePosition(routeId, activitySeineId); - return pos; - - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/TripServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/TripServiceImpl.java deleted file mode 100644 index 88cd4c4..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/TripServiceImpl.java +++ /dev/null @@ -1,233 +0,0 @@ -package fr.ird.observe.services.data; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.ObserveTechnicalException; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.Trip; -import fr.ird.observe.entities.constants.GearType; -import fr.ird.observe.entities.longline.TripLongline; -import fr.ird.observe.entities.longline.TripLonglineDAO; -import fr.ird.observe.entities.referentiel.Ocean; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.entities.referentiel.ProgramDAO; -import fr.ird.observe.entities.referentiel.Programs; -import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.entities.seine.TripSeineDAO; -import fr.ird.observe.services.AbstractObserveService; -import fr.ird.observe.services.data.longline.TripLonglineService; -import fr.ird.observe.services.data.seine.TripSeineService; -import fr.ird.observe.services.referential.ReferentialService; -import fr.ird.observe.tripMap.TripMapPoint; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Created on 4/26/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class TripServiceImpl extends AbstractObserveService implements TripService { - - /** Logger. */ - private static final Log log = LogFactory.getLog(TripServiceImpl.class); - - @Override - public DataSelectionModel loadDataSelectionModel() { - - DataSelectionModel result = new DataSelectionModel(); - - Map<String, List<String>> datas = new HashMap<String, List<String>>(); - - TripSeineService tripSeineService = newService(TripSeineService.class); - TripLonglineService tripLonglineService = newService(TripLonglineService.class); - - List<Program> programs = newService(ReferentialService.class).getAllProgramStub(); - for (Program program : programs) { - - if (Programs.isProgramSeine(program)) { - List<TripSeine> trips = tripSeineService.getTripSeineStubByProgram(program.getTopiaId()); - populate(result, program, trips, datas); - } - - if (Programs.isProgramLongline(program)) { - List<TripLongline> trips = tripLonglineService.getTripLonglineStubByProgram(program.getTopiaId()); - populate(result, program, trips, datas); - } - - } - result.setDatas(datas); - - return result; - - } - - @Override - public List<Program> getPossibleProgramsForTrip(String tripId) { - - Trip trip = getTrip(tripId); - - GearType gearType = trip.getProgram().getGearType(); - - ProgramDAO dao = (ProgramDAO) getDao(Program.class); - - List<Program> programs = dao.findAllByGearType(gearType); - - decorate(Program.class, programs); - - Programs.sort(programs); - - return programs; - - } - - @Override - public Trip getTrip(String tripId) { - - Trip trip; - - if (tripId.startsWith(TripSeine.class.getName())) { - trip = findByTopiaId(TripSeine.class, tripId); - } else { - trip = findByTopiaId(TripLongline.class, tripId); - } - - return trip; - - } - - @Override - public Ocean getTripOcean(String tripId) { - - Trip trip = getTrip(tripId); - - return trip.getOcean(); - - } - - @Override - public void moveTripToProgram(String tripId, String programId) { - - Trip trip = getTrip(tripId); - - Program program = findByTopiaId(Program.class, programId); - - trip.setProgram(program); - - } - - @Override - public List<TripMapPoint> loadTripMapActivityPoints(String tripId) { - - List<TripMapPoint> tripMapPoints; - - if (Entities.isSeineId(tripId)) { - TripSeineDAO dao = (TripSeineDAO) getDao(TripSeine.class); - - tripMapPoints = dao.extractTripMapActivityPoints(tripId); - - } else if (Entities.isLonglineId(tripId)) { - - TripLonglineDAO dao = (TripLonglineDAO) getDao(TripLongline.class); - - tripMapPoints = dao.extractTripMapActivityPoints(tripId); - - } else { - throw new ObserveTechnicalException(String.format("id '%s' is not seine id or longe line id", tripId)); - } - - return tripMapPoints; - - } - - @Override - public void deleteTrip(String tripId) { - - if (Entities.isSeineId(tripId)) { - - TripSeineDAO dao = (TripSeineDAO) getDao(TripSeine.class); - TripSeine result = dao.findByTopiaId(tripId); - dao.delete(result); - - } else { - - TripLonglineDAO dao = (TripLonglineDAO) getDao(TripLongline.class); - TripLongline result = dao.findByTopiaId(tripId); - dao.delete(result); - - } - - } - - protected static <T extends Trip> void populate(DataSelectionModel model, - Program program, - List<T> trips, - Map<String, List<String>> datas) { - - model.cacheEntity(program); - - if (!trips.isEmpty()) { - List<String> tripIds = new ArrayList<String>(); - - if (model.isUseOpenData()) { - - // ajout de toutes les marées ouvertes ou non - for (T trip : trips) { - trip.setProgram(program); - model.cacheEntity(trip); - tripIds.add(trip.getTopiaId()); - } - - } else { - - // ajout de toutes les marées non ouvertes - for (T trip : trips) { - trip.setProgram(program); - if (!trip.isOpen()) { - model.cacheEntity(trip); - tripIds.add(trip.getTopiaId()); - } - } - - } - - if (!tripIds.isEmpty()) { - - datas.put(program.getTopiaId(), tripIds); - if (log.isDebugEnabled()) { - log.debug("Add program " + program.getLabel1() + " with " + tripIds.size() + " trip(s)."); - } - - } - - } - - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java deleted file mode 100644 index f50463e..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java +++ /dev/null @@ -1,167 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.constants.ReferenceLocale; -import fr.ird.observe.entities.longline.ActivityLongline; -import fr.ird.observe.entities.longline.ActivityLonglineDAO; -import fr.ird.observe.entities.longline.TripLongline; -import fr.ird.observe.services.AbstractObserveService; - -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * Created on 4/25/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class ActivityLonglineServiceImpl extends AbstractObserveService implements ActivityLonglineService { - - @Override - public List<ActivityLongline> getActivityLonglineStubByTrip(String tripId) { - - ReferenceLocale referentielLocale = getReferentielLocale(); - List<ActivityLongline> result = getDao().findAllStubByTripId(tripId, referentielLocale); - return result; - - } - - @Override - public ActivityLongline getActivityLonglineStub(String activityId) { - - ReferenceLocale referentielLocale = getReferentielLocale(); - ActivityLongline result = getDao().findStubByTopiaId(activityId, referentielLocale); - return result; - - } - - @Override - public ActivityLongline loadForEdit(String activityLonglineId) { - - ActivityLongline loaded = getDao().newInstance(); - ActivityLongline toLoad = getDao().findByTopiaId(activityLonglineId); - copy(ActivityLongline.class, BinderService.EDIT, toLoad, loaded); - - return loaded; - - } - - - @Override - public ActivityLongline preCreate(String tripLonglineId) { - - TripLongline tripLongline = findByTopiaId(TripLongline.class, tripLonglineId); - - ActivityLongline preCreated = getDao().newInstance(); - - preCreated.setOpen(true); - - ActivityLongline lastActivityLongline = tripLongline.getLastActivity(); - - Date timestamp; - - if (lastActivityLongline == null) { - - // première activité, on utilise la date de début de marée (voir http://forge.codelutin.com/issues/6777) - Calendar calendar = Calendar.getInstance(); - calendar.setTime(tripLongline.getStartDate()); - timestamp = calendar.getTime(); - - } else { - - // passage en coordonnées absolue + quadrant - lastActivityLongline.initCoordinates(); - - // on recupère le quadrant de cette activity - // et on l'affecte à la nouvelle activity - Integer quadrant = lastActivityLongline.getQuadrant(); - - preCreated.setQuadrant(quadrant); - - // on reprend la date et l'heure de la dernière activité - timestamp = lastActivityLongline.getTimeStamp(); - } - - preCreated.setTimeStamp(timestamp); - - - return preCreated; - - } - - @Override - public String save(String tripLonglineId, ActivityLongline toSave) { - - String activityLonglineId = doSave(tripLonglineId, toSave, new SaveAction<TripLongline, ActivityLongline>(TripLongline.class, ActivityLongline.class) { - - @Override - public ActivityLongline onCreate(TripLongline parent, ActivityLongline toCreate) { - - Map<String, Object> properties = obtainProperties(ActivityLongline.class, BinderService.EDIT, toCreate); - ActivityLongline created = getDao().create(properties); - - parent.addActivityLongline(created); - return created; - } - - @Override - public ActivityLongline onUpdate(TripLongline parent, ActivityLongline toUpdate) { - - ActivityLongline updated = super.onUpdate(parent, toUpdate); - - copyExcluding(ActivityLongline.class, BinderService.EDIT, - toUpdate, updated, - ActivityLongline.PROPERTY_ENCOUNTER, - ActivityLongline.PROPERTY_SENSOR_USED); - return updated; - - } - }); - - return activityLonglineId; - - } - - @Override - public void delete(String tripLonglineId, String activityLonglineId) { - doDelete(tripLonglineId, activityLonglineId, new DeleteAction<TripLongline, ActivityLongline>(TripLongline.class, ActivityLongline.class) { - - @Override - public void onDelete(TripLongline parent, ActivityLongline toDelete) { - super.onDelete(parent, toDelete); - parent.removeActivityLongline(toDelete); - } - }); - - } - - protected ActivityLonglineDAO getDao() { - return (ActivityLonglineDAO) getDao(ActivityLongline.class); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/BaitsCompositionServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/BaitsCompositionServiceImpl.java deleted file mode 100644 index b373ea6..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/BaitsCompositionServiceImpl.java +++ /dev/null @@ -1,98 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.longline.BaitsComposition; -import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created on 4/29/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class BaitsCompositionServiceImpl extends AbstractObserveService implements BaitsCompositionService { - - @Override - public SetLongline loadForEdit(String setLonglineId) { - - SetLongline parentToLoad = findByTopiaId(SetLongline.class, setLonglineId); - - SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); - - copy(SetLongline.class, BinderService.EDIT_BAITS_COMPOSITION, parentToLoad, parentLoaded); - - if (!parentToLoad.isBaitsCompositionEmpty()) { - - TopiaEntityBinder<BaitsComposition> binder = getBinder(BaitsComposition.class, BinderService.EDIT); - - TopiaDAO<BaitsComposition> childDao = getDao(BaitsComposition.class); - - List<BaitsComposition> childs = new ArrayList<BaitsComposition>(); - - for (BaitsComposition sourceChild : parentToLoad.getBaitsComposition()) { - - BaitsComposition targetChild = childDao.newInstance(); - - binder.load(sourceChild, targetChild, true); - - childs.add(targetChild); - - } - - parentLoaded.setBaitsComposition(childs); - - } - - return parentLoaded; - - } - - @Override - public void save(SetLongline setLongline) { - - TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_BAITS_COMPOSITION); - TopiaEntityBinder<BaitsComposition> childBinder = getBinder(BaitsComposition.class, BinderService.EDIT); - - doSaveList(setLongline, new SaveCollectionAction<SetLongline, BaitsComposition>( - SetLongline.class, BaitsComposition.class, getListUpdator(), parentBinder, childBinder)); - - } - - protected EntityListUpdator<SetLongline, BaitsComposition> getListUpdator() { - EntityListUpdator<SetLongline, BaitsComposition> listUpdator = EntityListUpdator.newEntityListUpdator( - SetLongline.class, - BaitsComposition.class, - SetLongline.PROPERTY_BAITS_COMPOSITION); - return listUpdator; - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java deleted file mode 100644 index dcb4a4b..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.longline.BranchlinesComposition; -import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created on 4/29/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class BranchlinesCompositionServiceImpl extends AbstractObserveService implements BranchlinesCompositionService { - - @Override - public SetLongline loadForEdit(String setLonglineId) { - - SetLongline parentToLoad = findByTopiaId(SetLongline.class, setLonglineId); - - SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); - copy(SetLongline.class, BinderService.EDIT_BRANCHLINES_COMPOSITION, parentToLoad, parentLoaded); - - if (!parentToLoad.isBranchlinesCompositionEmpty()) { - - TopiaEntityBinder<BranchlinesComposition> binder = getBinder(BranchlinesComposition.class, BinderService.EDIT); - TopiaDAO<BranchlinesComposition> childDao = getDao(BranchlinesComposition.class); - - List<BranchlinesComposition> childs = new ArrayList<BranchlinesComposition>(); - - for (BranchlinesComposition sourceChild : parentToLoad.getBranchlinesComposition()) { - - BranchlinesComposition targetChild = childDao.newInstance(); - binder.load(sourceChild, targetChild, true); - childs.add(targetChild); - - } - - parentLoaded.setBranchlinesComposition(childs); - - } - - return parentLoaded; - - } - - @Override - public void save(SetLongline setLongline) { - - TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_BRANCHLINES_COMPOSITION); - TopiaEntityBinder<BranchlinesComposition> childBinder = getBinder(BranchlinesComposition.class, BinderService.EDIT); - - doSaveList(setLongline, new SaveCollectionAction<SetLongline, BranchlinesComposition>( - SetLongline.class, BranchlinesComposition.class, getListUpdator(), parentBinder, childBinder)); - - } - - protected EntityListUpdator<SetLongline, BranchlinesComposition> getListUpdator() { - EntityListUpdator<SetLongline, BranchlinesComposition> listUpdator = EntityListUpdator.newEntityListUpdator( - SetLongline.class, - BranchlinesComposition.class, - SetLongline.PROPERTY_BRANCHLINES_COMPOSITION); - return listUpdator; - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java deleted file mode 100644 index 899ed40..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java +++ /dev/null @@ -1,267 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.longline.Branchline; -import fr.ird.observe.entities.longline.BranchlineDAO; -import fr.ird.observe.entities.longline.CatchLongline; -import fr.ird.observe.entities.longline.CatchLonglineDAO; -import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.entities.longline.SizeMeasure; -import fr.ird.observe.entities.longline.WeightMeasure; -import fr.ird.observe.services.AbstractObserveService; -import org.apache.commons.collections4.CollectionUtils; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -/** - * Created on 4/26/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class CatchLonglineServiceImpl extends AbstractObserveService implements CatchLonglineService { - - @Override - public Branchline loadBranchlineForEdit(String branchelineId) { - - BranchlineDAO dao = (BranchlineDAO) getDao(Branchline.class); - Branchline toLoad = dao.findByTopiaId(branchelineId); - Branchline loaded = dao.newInstance(); - copy(Branchline.class, BinderService.EDIT_CATCH_LONGLINE, toLoad, loaded); - return loaded; - - } - - @Override - public Branchline saveBranchline(Branchline toSave) { - - BranchlineDAO dao = (BranchlineDAO) getDao(Branchline.class); - Branchline saved = dao.findByTopiaId(toSave.getTopiaId()); - copy(Branchline.class, BinderService.EDIT_CATCH_LONGLINE, toSave, saved); - return saved; - - } - - @Override - public SetLongline loadForEdit(String setLonglineId) { - - SetLongline parentToLoad = findByTopiaId(SetLongline.class, setLonglineId); - - SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); - copy(SetLongline.class, BinderService.EDIT_CATCH_LONGLINE, parentToLoad, parentLoaded); - - if (!parentToLoad.isCatchLonglineEmpty()) { - - TopiaEntityBinder<CatchLongline> binder = getBinder(CatchLongline.class, BinderService.EDIT); - TopiaDAO<CatchLongline> childDao = getDao(CatchLongline.class); - - List<CatchLongline> childs = new ArrayList<CatchLongline>(); - - for (CatchLongline sourceChild : parentToLoad.getCatchLongline()) { - - CatchLongline targetChild = childDao.newInstance(); - binder.load(sourceChild, targetChild, true); - childs.add(targetChild); - - } - - parentLoaded.setCatchLongline(childs); - - } - - return parentLoaded; - - } - - @Override - public void save(SetLongline setLongline) { - - TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_CATCH_LONGLINE); - TopiaEntityBinder<CatchLongline> childBinder = getBinder(CatchLongline.class, BinderService.EDIT); - - doSaveList(setLongline, - new SaveCollectionAction<SetLongline, CatchLongline>(SetLongline.class, - CatchLongline.class, - getListUpdator(), parentBinder, childBinder) { - - @Override - public CatchLongline onCreateChild(CatchLongline childToCreate) { - - CatchLongline childCreated = super.onCreateChild(childToCreate); - saveSizeMeasures(childCreated, childToCreate.getSizeMeasure()); - saveWeightMeasures(childCreated, childToCreate.getWeightMeasure()); - return childCreated; - - } - - @Override - public CatchLongline onUpdateChild(CatchLongline childToUpdate) { - - CatchLongline childUpdated = super.onUpdateChild(childToUpdate); - saveSizeMeasures(childUpdated, childToUpdate.getSizeMeasure()); - saveWeightMeasures(childUpdated, childToUpdate.getWeightMeasure()); - return childUpdated; - - } - - protected void saveSizeMeasures(CatchLongline childSaved, Collection<SizeMeasure> sizeMeasuresToSave) { - - List<SizeMeasure> sizeMeasuresSaveds = Lists.newArrayList(); - - if (CollectionUtils.isNotEmpty(sizeMeasuresToSave)) { - - TopiaDAO<SizeMeasure> dao = getDao(SizeMeasure.class); - TopiaEntityBinder<SizeMeasure> binder = getBinder(SizeMeasure.class, BinderService.EDIT); - - for (SizeMeasure sizeMeasureToSave : sizeMeasuresToSave) { - - SizeMeasure sizeMeasureSaved; - - if (Entities.isNew(sizeMeasureToSave)) { - - Map<String, Object> properties = binder.obtainProperties(sizeMeasureToSave); - sizeMeasureSaved = dao.create(properties); - - } else { - - sizeMeasureSaved = dao.findByTopiaId(sizeMeasureToSave.getTopiaId()); - binder.load(sizeMeasureToSave, sizeMeasureSaved, true); - - } - - sizeMeasuresSaveds.add(sizeMeasureSaved); - - } - - } - - childSaved.clearSizeMeasure(); - childSaved.addAllSizeMeasure(sizeMeasuresSaveds); - - } - - protected void saveWeightMeasures(CatchLongline childSaved, Collection<WeightMeasure> weightMeasuresToSave) { - - List<WeightMeasure> weightMeasuresSaved = Lists.newArrayList(); - - if (CollectionUtils.isNotEmpty(weightMeasuresToSave)) { - - TopiaDAO<WeightMeasure> dao = getDao(WeightMeasure.class); - TopiaEntityBinder<WeightMeasure> binder = getBinder(WeightMeasure.class, BinderService.EDIT); - - for (WeightMeasure weightMeasureToSave : weightMeasuresToSave) { - - WeightMeasure weightMeasureSaved; - - if (Entities.isNew(weightMeasureToSave)) { - - Map<String, Object> properties = binder.obtainProperties(weightMeasureToSave); - weightMeasureSaved = dao.create(properties); - - } else { - - weightMeasureSaved = dao.findByTopiaId(weightMeasureToSave.getTopiaId()); - binder.load(weightMeasureToSave, weightMeasureSaved, true); - - } - - weightMeasuresSaved.add(weightMeasureSaved); - - } - - } - - childSaved.clearWeightMeasure(); - childSaved.addAllWeightMeasure(weightMeasuresSaved); - - } - } - - ); - - } - - @Override - public List<SizeMeasure> getCatchLonglineSizeMeasures(String catchLonglineId) { - - CatchLongline catchLongline = getDao().findByTopiaId(catchLonglineId); - List<SizeMeasure> result = new ArrayList<SizeMeasure>(); - if (!catchLongline.isSizeMeasureEmpty()) { - - TopiaEntityBinder<SizeMeasure> binder = getBinder(SizeMeasure.class, BinderService.EDIT); - TopiaDAO<SizeMeasure> sizeMeasureDao = getDao(SizeMeasure.class); - - for (SizeMeasure sizeSource : catchLongline.getSizeMeasure()) { - SizeMeasure target = sizeMeasureDao.newInstance(); - binder.load(sizeSource, target, true); - result.add(target); - } - } - return result; - - } - - @Override - public List<WeightMeasure> getCatchLonglineWeightMeasures(String catchLonglineId) { - - CatchLongline catchLongline = getDao().findByTopiaId(catchLonglineId); - List<WeightMeasure> result = new ArrayList<WeightMeasure>(); - if (!catchLongline.isWeightMeasureEmpty()) { - - TopiaEntityBinder<WeightMeasure> binder = getBinder(WeightMeasure.class, BinderService.EDIT); - TopiaDAO<WeightMeasure> weightMeasureDao = getDao(WeightMeasure.class); - - for (WeightMeasure weightSource : catchLongline.getWeightMeasure()) { - WeightMeasure target = weightMeasureDao.newInstance(); - binder.load(weightSource, target, true); - result.add(target); - } - - } - - return result; - - } - - protected CatchLonglineDAO getDao() { - return (CatchLonglineDAO) getDao(CatchLongline.class); - } - - protected EntityListUpdator<SetLongline, CatchLongline> getListUpdator() { - EntityListUpdator<SetLongline, CatchLongline> listUpdator = EntityListUpdator.newEntityListUpdator( - SetLongline.class, - CatchLongline.class, - SetLongline.PROPERTY_CATCH_LONGLINE); - return listUpdator; - } -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/EncounterServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/EncounterServiceImpl.java deleted file mode 100644 index 86632cb..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/EncounterServiceImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.longline.ActivityLongline; -import fr.ird.observe.entities.longline.Encounter; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created on 4/29/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class EncounterServiceImpl extends AbstractObserveService implements EncounterService { - - @Override - public ActivityLongline loadForEdit(String activityLonglineId) { - - ActivityLongline parentToLoad = findByTopiaId(ActivityLongline.class, activityLonglineId); - - ActivityLongline parentLoaded = getDao(ActivityLongline.class).newInstance(); - copy(ActivityLongline.class, BinderService.EDIT_ENCOUNTER, parentToLoad, parentLoaded); - - if (!parentToLoad.isEncounterEmpty()) { - - TopiaEntityBinder<Encounter> binder = getBinder(Encounter.class, BinderService.EDIT); - TopiaDAO<Encounter> childDao = getDao(Encounter.class); - - List<Encounter> childs = new ArrayList<Encounter>(); - - for (Encounter sourceChild : parentToLoad.getEncounter()) { - - Encounter targetChild = childDao.newInstance(); - binder.load(sourceChild, targetChild, true); - childs.add(targetChild); - - } - - parentLoaded.setEncounter(childs); - - } - - return parentLoaded; - - } - - @Override - public void save(ActivityLongline activityLongline) { - - TopiaEntityBinder<ActivityLongline> parentBinder = getBinder(ActivityLongline.class, BinderService.EDIT_ENCOUNTER); - TopiaEntityBinder<Encounter> childBinder = getBinder(Encounter.class, BinderService.EDIT); - - doSaveList(activityLongline, new SaveCollectionAction<ActivityLongline, Encounter>( - ActivityLongline.class, Encounter.class, getListUpdator(), parentBinder, childBinder)); - - } - - protected EntityListUpdator<ActivityLongline, Encounter> getListUpdator() { - EntityListUpdator<ActivityLongline, Encounter> listUpdator = EntityListUpdator.newEntityListUpdator( - ActivityLongline.class, - Encounter.class, - ActivityLongline.PROPERTY_ENCOUNTER); - return listUpdator; - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java deleted file mode 100644 index 1825798..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.longline.FloatlinesComposition; -import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created on 4/29/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class FloatlinesCompositionServiceImpl extends AbstractObserveService implements FloatlinesCompositionService { - - @Override - public SetLongline loadForEdit(String setLonglineId) { - - SetLongline parentToLoad = findByTopiaId(SetLongline.class, setLonglineId); - - SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); - copy(SetLongline.class, BinderService.EDIT_FLOATLINES_COMPOSITION, parentToLoad, parentLoaded); - - if (!parentToLoad.isFloatlinesCompositionEmpty()) { - - TopiaEntityBinder<FloatlinesComposition> binder = getBinder(FloatlinesComposition.class, BinderService.EDIT); - TopiaDAO<FloatlinesComposition> childDao = getDao(FloatlinesComposition.class); - - List<FloatlinesComposition> childs = new ArrayList<FloatlinesComposition>(); - - for (FloatlinesComposition sourceChild : parentToLoad.getFloatlinesComposition()) { - - FloatlinesComposition targetChild = childDao.newInstance(); - binder.load(sourceChild, targetChild, true); - childs.add(targetChild); - - } - - parentLoaded.setFloatlinesComposition(childs); - - } - - return parentLoaded; - - } - - @Override - public void save(SetLongline setLongline) { - - TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_FLOATLINES_COMPOSITION); - TopiaEntityBinder<FloatlinesComposition> childBinder = getBinder(FloatlinesComposition.class, BinderService.EDIT); - - doSaveList(setLongline, new SaveCollectionAction<SetLongline, FloatlinesComposition>( - SetLongline.class, FloatlinesComposition.class, getListUpdator(), parentBinder, childBinder)); - - } - - protected EntityListUpdator<SetLongline, FloatlinesComposition> getListUpdator() { - EntityListUpdator<SetLongline, FloatlinesComposition> listUpdator = EntityListUpdator.newEntityListUpdator( - SetLongline.class, - FloatlinesComposition.class, - SetLongline.PROPERTY_FLOATLINES_COMPOSITION); - return listUpdator; - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java deleted file mode 100644 index 5cee70e..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java +++ /dev/null @@ -1,236 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.longline.GearUseFeaturesLongline; -import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; -import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLonglineDAO; -import fr.ird.observe.entities.longline.TripLongline; -import fr.ird.observe.entities.referentiel.Gear; -import fr.ird.observe.entities.referentiel.GearCaracteristic; -import fr.ird.observe.services.AbstractObserveService; -import org.apache.commons.collections4.CollectionUtils; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * Created on 4/26/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService implements GearUseFeaturesLonglineService { - - @Override - public List<GearUseFeaturesMeasurementLongline> getDefaultGearUseFeaturesMeasurementLongline(String gearId) { - - Gear gear = findByTopiaId(Gear.class, gearId); - - List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); - - if (gear.isGearCaracteristicEmpty()) { - - GearUseFeaturesMeasurementLonglineDAO dao = getDao(); - - for (GearCaracteristic caracteristic : gear.getGearCaracteristic()) { - - GearUseFeaturesMeasurementLongline target = dao.newInstance(); - target.setGearCaracteristic(caracteristic); - result.add(target); - - } - - } - - return result; - - } - - @Override - public List<GearUseFeaturesMeasurementLongline> loadGearUseFeaturesMeasurementLonglineForEdit(String gearUseFeaturesLonglineId) { - - GearUseFeaturesLongline gearUseFeaturesLongline = findByTopiaId(GearUseFeaturesLongline.class, gearUseFeaturesLonglineId); - List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); - - if (!gearUseFeaturesLongline.isGearUseFeaturesMeasurementEmpty()) { - - GearUseFeaturesMeasurementLonglineDAO dao = getDao(); - TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); - - for (GearUseFeaturesMeasurementLongline measurementSource : gearUseFeaturesLongline.getGearUseFeaturesMeasurement()) { - - GearUseFeaturesMeasurementLongline target = dao.newInstance(); - measurementSource.getGearCaracteristic().getGearCaracteristicType(); - binder.load(measurementSource, target, true); - result.add(target); - - } - - } - - return result; - - } - - @Override - public TripLongline loadForEdit(String tripLonglineId) { - - TripLongline toLoad = findByTopiaId(TripLongline.class, tripLonglineId); - - TripLongline loaded = getDao(TripLongline.class).newInstance(); - copy(TripLongline.class, BinderService.EDIT_GEAR_USE_FEATURES_LONGLINE, toLoad, loaded); - - if (!toLoad.isGearUseFeaturesLonglineEmpty()) { - - TopiaDAO<GearUseFeaturesLongline> childDao = getDao(GearUseFeaturesLongline.class); - TopiaDAO<GearUseFeaturesMeasurementLongline> measurementDao = getDao(GearUseFeaturesMeasurementLongline.class); - TopiaEntityBinder<GearUseFeaturesLongline> childBinder = getBinder(GearUseFeaturesLongline.class, BinderService.EDIT); - TopiaEntityBinder<GearUseFeaturesMeasurementLongline> measurementBinder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); - - List<GearUseFeaturesLongline> childsLoaded = new ArrayList<GearUseFeaturesLongline>(); - - if (!toLoad.isGearUseFeaturesLonglineEmpty()) { - - for (GearUseFeaturesLongline childToLoad : toLoad.getGearUseFeaturesLongline()) { - - GearUseFeaturesLongline childLoaded = childDao.newInstance(); - childBinder.load(childToLoad, childLoaded, true); - childsLoaded.add(childLoaded); - - if (!childToLoad.isGearUseFeaturesMeasurementEmpty()) { - - List<GearUseFeaturesMeasurementLongline> measurementsLoaded = new ArrayList<GearUseFeaturesMeasurementLongline>(); - - for (GearUseFeaturesMeasurementLongline measurementToLoad : childToLoad.getGearUseFeaturesMeasurement()) { - - GearUseFeaturesMeasurementLongline measurementLoaded = measurementDao.newInstance(); - measurementBinder.load(measurementToLoad, measurementLoaded, true); - measurementsLoaded.add(measurementLoaded); - - } - - childLoaded.setGearUseFeaturesMeasurement(measurementsLoaded); - - } - - } - - } - - loaded.setGearUseFeaturesLongline(childsLoaded); - - } - - return loaded; - - } - - @Override - public void save(TripLongline tripLongline) { - - TopiaEntityBinder<TripLongline> parentBinder = getBinder(TripLongline.class, BinderService.EDIT_GEAR_USE_FEATURES_LONGLINE); - TopiaEntityBinder<GearUseFeaturesLongline> childBinder = getBinder(GearUseFeaturesLongline.class, BinderService.EDIT); - - doSaveList(tripLongline, new SaveCollectionAction<TripLongline, GearUseFeaturesLongline>( - TripLongline.class, GearUseFeaturesLongline.class, getListUpdator(), parentBinder, childBinder) { - - @Override - public GearUseFeaturesLongline onCreateChild(GearUseFeaturesLongline childToCreate) { - - GearUseFeaturesLongline childCreated = super.onCreateChild(childToCreate); - saveMeasurement(childCreated, childToCreate.getGearUseFeaturesMeasurement()); - return childCreated; - - } - - @Override - public GearUseFeaturesLongline onUpdateChild(GearUseFeaturesLongline childToUpdate) { - - GearUseFeaturesLongline childUpdated = super.onUpdateChild(childToUpdate); - saveMeasurement(childUpdated, childToUpdate.getGearUseFeaturesMeasurement()); - return childUpdated; - - } - - protected void saveMeasurement(GearUseFeaturesLongline childSaved, List<GearUseFeaturesMeasurementLongline> measurementsToSave) { - - List<GearUseFeaturesMeasurementLongline> measurementsSaved = Lists.newArrayList(); - - if (CollectionUtils.isNotEmpty(measurementsToSave)) { - - TopiaDAO<GearUseFeaturesMeasurementLongline> dao = getDao(GearUseFeaturesMeasurementLongline.class); - TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); - - for (GearUseFeaturesMeasurementLongline measurementToSave : measurementsToSave) { - - GearUseFeaturesMeasurementLongline measurementSaved; - - if (Entities.isNew(measurementToSave)) { - - Map<String, Object> properties = binder.obtainProperties(measurementToSave); - measurementSaved = dao.create(properties); - - } else { - - measurementSaved = dao.findByTopiaId(measurementToSave.getTopiaId()); - binder.load(measurementToSave, measurementSaved, true); - - } - - measurementsSaved.add(measurementSaved); - - } - - } - - childSaved.clearGearUseFeaturesMeasurement(); - childSaved.addAllGearUseFeaturesMeasurement(measurementsSaved); - - } - - - }); - - } - - protected GearUseFeaturesMeasurementLonglineDAO getDao() { - return (GearUseFeaturesMeasurementLonglineDAO) getDao(GearUseFeaturesMeasurementLongline.class); - } - - protected EntityListUpdator<TripLongline, GearUseFeaturesLongline> getListUpdator() { - EntityListUpdator<TripLongline, GearUseFeaturesLongline> listUpdator = EntityListUpdator.newEntityListUpdator( - TripLongline.class, - GearUseFeaturesLongline.class, - TripLongline.PROPERTY_GEAR_USE_FEATURES_LONGLINE); - return listUpdator; - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java deleted file mode 100644 index 19990f8..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.longline.HooksComposition; -import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created on 4/29/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class HooksCompositionServiceImpl extends AbstractObserveService implements HooksCompositionService { - - @Override - public SetLongline loadForEdit(String setLonglineId) { - - SetLongline parentToLoad = findByTopiaId(SetLongline.class, setLonglineId); - - SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); - copy(SetLongline.class, BinderService.EDIT_HOOKS_COMPOSITION, parentToLoad, parentLoaded); - - if (!parentToLoad.isHooksCompositionEmpty()) { - - TopiaEntityBinder<HooksComposition> binder = getBinder(HooksComposition.class, BinderService.EDIT); - TopiaDAO<HooksComposition> childDao = getDao(HooksComposition.class); - - List<HooksComposition> childs = new ArrayList<HooksComposition>(); - - for (HooksComposition sourceChild : parentToLoad.getHooksComposition()) { - - HooksComposition targetChild = childDao.newInstance(); - binder.load(sourceChild, targetChild, true); - childs.add(targetChild); - - } - - parentLoaded.setHooksComposition(childs); - - } - - return parentLoaded; - - } - - @Override - public void save(SetLongline setLongline) { - - TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_HOOKS_COMPOSITION); - TopiaEntityBinder<HooksComposition> childBinder = getBinder(HooksComposition.class, BinderService.EDIT); - - doSaveList(setLongline, new SaveCollectionAction<SetLongline, HooksComposition>( - SetLongline.class, HooksComposition.class, getListUpdator(), parentBinder, childBinder)); - - } - - protected EntityListUpdator<SetLongline, HooksComposition> getListUpdator() { - EntityListUpdator<SetLongline, HooksComposition> listUpdator = EntityListUpdator.newEntityListUpdator( - SetLongline.class, - HooksComposition.class, - SetLongline.PROPERTY_HOOKS_COMPOSITION); - return listUpdator; - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java deleted file mode 100644 index 9cc0c81..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java +++ /dev/null @@ -1,213 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.longline.Basket; -import fr.ird.observe.entities.longline.Branchline; -import fr.ird.observe.entities.longline.Section; -import fr.ird.observe.entities.longline.SectionWithTemplate; -import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.services.AbstractObserveService; - -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * Created on 4/26/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class LonglineDetailCompositionServiceImpl extends AbstractObserveService implements LonglineDetailCompositionService { - - @Override - public SetLongline loadForEdit(String setLonglineId) { - - TopiaDAO<SetLongline> dao = getDao(SetLongline.class); - SetLongline toLoad = dao.findByTopiaId(setLonglineId); - SetLongline loaded = dao.newInstance(); - copy(SetLongline.class, BinderService.EDIT_DETAIL_COMPOSITION, toLoad, loaded); - - return loaded; - - } - - @Override - public void save(SetLongline toSave, List<SectionWithTemplate> sections) { - - SetLongline saved = findByTopiaId(SetLongline.class, toSave.getTopiaId()); - - copyExcluding(SetLongline.class, BinderService.EDIT_DETAIL_COMPOSITION, toSave, saved, SetLongline.PROPERTY_SECTION); - - TopiaDAO<Section> sectionsDao = getDao(Section.class); - TopiaDAO<Basket> basketDao = getDao(Basket.class); - TopiaDAO<Branchline> branchlineDao = getDao(Branchline.class); - - TopiaEntityBinder<Section> sectionBinder = getBinder(Section.class, BinderService.EDIT_DETAIL_COMPOSITION); - TopiaEntityBinder<Basket> basketBinder = getBinder(Basket.class, BinderService.EDIT_DETAIL_COMPOSITION); - TopiaEntityBinder<Branchline> branchlineBinder = getBinder(Branchline.class, BinderService.EDIT_DETAIL_COMPOSITION); - - List<Section> sectionsToSave = new ArrayList<Section>(); - - for (SectionWithTemplate section : sections) { - - Section sectionToSave = persistSection(sectionBinder, - basketBinder, - branchlineBinder, - sectionsDao, - basketDao, - branchlineDao, - section); - sectionsToSave.add(sectionToSave); - sectionToSave.setSetLongline(saved); - - } - - saved.clearSection(); - saved.addAllSection(sectionsToSave); - - } - - protected Section persistSection(TopiaEntityBinder<Section> sectionBinder, - TopiaEntityBinder<Basket> basketBinder, - TopiaEntityBinder<Branchline> branchlineBinder, - TopiaDAO<Section> sectionsDao, - TopiaDAO<Basket> basketDao, - TopiaDAO<Branchline> branchlineDao, - Section section) { - - Section sectionToSave; - - if (Entities.isNew(section)) { - - // create - sectionToSave = sectionsDao.create( - Section.PROPERTY_SETTING_IDENTIFIER, section.getSettingIdentifier(), - Section.PROPERTY_HAULING_IDENTIFIER, section.getHaulingIdentifier()); - - } else { - - sectionToSave = sectionsDao.findByTopiaId(section.getTopiaId()); - - } - - sectionBinder.copyExcluding(section, sectionToSave, Section.PROPERTY_BASKET); - - Map<String, Basket> existingBasketsByTopiaId = Entities.toIdMap(sectionToSave.getBasket()); - - List<Basket> baskets = section.getBasket(); - sectionToSave.clearBasket(); - - for (Basket basket : baskets) { - - Basket basketToSave = persistBasket(basketBinder, - branchlineBinder, - basketDao, - branchlineDao, - existingBasketsByTopiaId, - basket); - sectionToSave.addBasket(basketToSave); - - } - - return sectionToSave; - - } - - protected Basket persistBasket(TopiaEntityBinder<Basket> basketBinder, - TopiaEntityBinder<Branchline> branchlineBinder, - TopiaDAO<Basket> basketDao, - TopiaDAO<Branchline> branchlineDao, - Map<String, Basket> existingBasketsByTopiaId, - Basket basket) { - - Basket basketToSave; - - if (Entities.isNew(basket)) { - - // create - basketToSave = basketDao.create( - Basket.PROPERTY_SETTING_IDENTIFIER, basket.getSettingIdentifier(), - Basket.PROPERTY_HAULING_IDENTIFIER, basket.getHaulingIdentifier()); - - } else { - - basketToSave = existingBasketsByTopiaId.get(basket.getTopiaId()); - - } - - basketBinder.copyExcluding(basket, basketToSave, Basket.PROPERTY_BRANCHLINE); - - Map<String, Branchline> existingBranchlinesByTopiaId = Entities.toIdMap(basketToSave.getBranchline()); - - basketToSave.clearBranchline(); - - List<Branchline> branchlines = basket.getBranchline(); - - for (Branchline branchline : branchlines) { - - Branchline branchlineToSave = persistBranchline(branchlineBinder, - branchlineDao, - existingBranchlinesByTopiaId, - branchline); - basketToSave.addBranchline(branchlineToSave); - - } - - return basketToSave; - - } - - protected Branchline persistBranchline(TopiaEntityBinder<Branchline> branchlineBinder, - TopiaDAO<Branchline> branchlineDao, - Map<String, Branchline> existingBranchlinesByTopiaId, - Branchline branchline) { - - Branchline branchlineToSave; - - if (Entities.isNew(branchline)) { - - // create - branchlineToSave = branchlineDao.create( - Branchline.PROPERTY_SETTING_IDENTIFIER, branchline.getSettingIdentifier(), - Branchline.PROPERTY_HAULING_IDENTIFIER, branchline.getHaulingIdentifier()); - - } else { - - branchlineToSave = existingBranchlinesByTopiaId.get(branchline.getTopiaId()); - - } - - branchlineBinder.copy(branchline, branchlineToSave); - - return branchlineToSave; - - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java deleted file mode 100644 index 2b50ee9..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java +++ /dev/null @@ -1,87 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.entities.referentiel.longline.MitigationType; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; - -import java.util.ArrayList; -import java.util.Collection; - -/** - * @author Sylvain Bavencoff - bavencoff@codelutin.com - * @since 4.0 - */ -public class LonglineGlobalCompositionServiceImpl extends AbstractObserveService implements LonglineGlobalCompositionService { - - @Override - public SetLongline loadForEdit(String setLonglineId) { - - TopiaDAO<SetLongline> dao = getDao(SetLongline.class); - SetLongline toLoad = dao.findByTopiaId(setLonglineId); - SetLongline loaded = dao.newInstance(); - copy(SetLongline.class, BinderService.EDIT_GLOBAL_COMPOSITION, toLoad, loaded); - - return loaded; - - } - - @Override - public String save(SetLongline toSave) { - - SetLongline saved = findByTopiaId(SetLongline.class, toSave.getTopiaId()); - - copyExcluding(SetLongline.class, BinderService.EDIT_GLOBAL_COMPOSITION, toSave, saved, SetLongline.PROPERTY_MITIGATION_TYPE); - - Collection<MitigationType> mitigationTypesSaved = new ArrayList<MitigationType>(); - - if (!toSave.isMitigationTypeEmpty()) { - - TopiaDAO<MitigationType> dao = getDao(MitigationType.class); - - for (MitigationType mitigationTypeToSave : toSave.getMitigationType()) { - - MitigationType mitigationTypeSaved = dao.findByTopiaId(mitigationTypeToSave.getTopiaId()); - mitigationTypesSaved.add(mitigationTypeSaved); - - } - } - - saved.clearMitigationType(); - saved.addAllMitigationType(mitigationTypesSaved); - - getDao(SetLongline.class).update(saved); - - newService(FloatlinesCompositionService.class).save(toSave); - newService(BranchlinesCompositionService.class).save(toSave); - newService(HooksCompositionService.class).save(toSave); - newService(BaitsCompositionService.class).save(toSave); - - return saved.getTopiaId(); - - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java deleted file mode 100644 index 1532b8d..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java +++ /dev/null @@ -1,129 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.longline.ActivityLongline; -import fr.ird.observe.entities.longline.SensorUsed; -import fr.ird.observe.entities.longline.TripLongline; -import fr.ird.observe.entities.longline.TripLonglineDAO; -import fr.ird.observe.entities.referentiel.longline.SensorType; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * Created on 4/26/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class SensorUsedServiceImpl extends AbstractObserveService implements SensorUsedService { - - @Override - public String getSensorUsedDataFilename(SensorUsed sensorUsed) { - - TripLonglineDAO tripDao = (TripLonglineDAO) getDao(TripLongline.class); - TripLongline tripLongline = tripDao.findByOpen(true); - - StringBuilder filenameBuilder = new StringBuilder("sensorData"); - String code = tripLongline.getVessel().getCode(); - filenameBuilder.append("-").append(code); - - Date startDate = tripLongline.getStartDate(); - filenameBuilder.append("-").append(new SimpleDateFormat("yyyy.MM.dd").format(startDate)); - - SensorType sensorType = sensorUsed.getSensorType(); - if (sensorType != null && sensorType.getCode() != null) { - filenameBuilder.append("-").append(sensorType.getCode()); - } - - String sensorSerialNo = sensorUsed.getSensorSerialNo(); - if (sensorSerialNo != null) { - filenameBuilder.append("-").append(sensorSerialNo); - } - filenameBuilder.append("-").append(sensorUsed.getDataFilename()); - - String filename = filenameBuilder.toString(); - return filename; - - } - - - @Override - public ActivityLongline loadForEdit(String activityLonglineId) { - - ActivityLongline parentToLoad = findByTopiaId(ActivityLongline.class, activityLonglineId); - - ActivityLongline parentLoaded = getDao(ActivityLongline.class).newInstance(); - copy(ActivityLongline.class, BinderService.EDIT_SENSOR_USED, parentToLoad, parentLoaded); - - if (!parentToLoad.isSensorUsedEmpty()) { - - TopiaEntityBinder<SensorUsed> binder = getBinder(SensorUsed.class, BinderService.EDIT); - TopiaDAO<SensorUsed> childDao = getDao(SensorUsed.class); - - List<SensorUsed> childs = new ArrayList<SensorUsed>(); - - for (SensorUsed sourceChild : parentToLoad.getSensorUsed()) { - - SensorUsed targetChild = childDao.newInstance(); - binder.load(sourceChild, targetChild, true); - childs.add(targetChild); - - } - - parentLoaded.setSensorUsed(childs); - - } - - return parentLoaded; - - } - - @Override - public void save(ActivityLongline activityLongline) { - - TopiaEntityBinder<ActivityLongline> parentBinder = getBinder(ActivityLongline.class, BinderService.EDIT_SENSOR_USED); - TopiaEntityBinder<SensorUsed> childBinder = getBinder(SensorUsed.class, BinderService.EDIT); - - doSaveList(activityLongline, new SaveCollectionAction<ActivityLongline, SensorUsed>( - ActivityLongline.class, SensorUsed.class, getListUpdator(), parentBinder, childBinder)); - - } - - protected EntityListUpdator<ActivityLongline, SensorUsed> getListUpdator() { - EntityListUpdator<ActivityLongline, SensorUsed> listUpdator = EntityListUpdator.newEntityListUpdator( - ActivityLongline.class, - SensorUsed.class, - ActivityLongline.PROPERTY_SENSOR_USED); - return listUpdator; - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java deleted file mode 100644 index 6c0a39f..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java +++ /dev/null @@ -1,201 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.longline.ActivityLongline; -import fr.ird.observe.entities.longline.Basket; -import fr.ird.observe.entities.longline.Branchline; -import fr.ird.observe.entities.longline.Section; -import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.entities.longline.SetLonglineDAO; -import fr.ird.observe.services.AbstractObserveService; -import org.apache.commons.lang3.time.DateUtils; -import org.nuiton.topia.persistence.TopiaDAO; - -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * Created on 4/26/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class SetLonglineServiceImpl extends AbstractObserveService implements SetLonglineService { - - public List<Section> getSections(String setLonglineId) { - - TopiaDAO<Section> dao = getDao(Section.class); - - List<Section> sectionsSaved = dao.findAllByProperties(Section.PROPERTY_SET_LONGLINE + "." + Section.TOPIA_ID, setLonglineId); - - List<Section> sections = Lists.newLinkedList(); - - for (Section sectionSaved : sectionsSaved) { - - Section section = dao.newInstance(); - - copyExcluding(Section.class, BinderService.EDIT_DETAIL_COMPOSITION, sectionSaved, section, Section.PROPERTY_BASKET); - - for (Basket basketSaved : sectionSaved.getBasket()) { - - Basket basket = getDao(Basket.class).newInstance(); - - copyExcluding(Basket.class, BinderService.EDIT_DETAIL_COMPOSITION, basketSaved, basket, Basket.PROPERTY_BRANCHLINE); - - for (Branchline branchlineSaved : basketSaved.getBranchline()) { - - Branchline branchline = getDao(Branchline.class).newInstance(); - - copy(Branchline.class, BinderService.EDIT_DETAIL_COMPOSITION, branchlineSaved, branchline); - - basket.addBranchline(branchline); - - } - - section.addBasket(basket); - - } - - sections.add(section); - } - - return sections; - - } - - @Override - public SetLongline loadForDisplay(String setLonglineId) { - - SetLonglineDAO dao = getDao(); - - SetLongline loaded = dao.newInstance(); - SetLongline toLoad = dao.findByTopiaId(setLonglineId); - copy(SetLongline.class, BinderService.EDIT, toLoad, loaded); - return loaded; - - } - - @Override - public SetLongline loadForEdit(String setLonglineId) { - - SetLonglineDAO dao = getDao(); - - SetLongline loaded = dao.newInstance(); - SetLongline toLoad = dao.findByTopiaId(setLonglineId); - copy(SetLongline.class, BinderService.EDIT, toLoad, loaded); - return loaded; - - } - - @Override - public SetLongline preCreate(String activityLonglineId) { - - ActivityLongline activityLongline = findByTopiaId(ActivityLongline.class, activityLonglineId); - - SetLongline preCreated = getDao().newInstance(); - - // on utilise la date - heure de l'activité pour initialiser les horodatages - // de l'opération de peche - Date timeStamp = activityLongline.getTimeStamp(); - preCreated.setSettingStartTimeStamp(timeStamp); - preCreated.setSettingEndTimeStamp(DateUtils.addHours(timeStamp, 1)); - preCreated.setHaulingStartTimeStamp(DateUtils.addHours(timeStamp, 2)); - preCreated.setHaulingEndTimeStamp(DateUtils.addHours(timeStamp, 3)); - - // on reporte la position de l'activité pour la position de début de filage - Float latitude = activityLongline.getLatitude(); - Float longitude = activityLongline.getLongitude(); - - // On enregistre deux fois les coordonnées car la première fois on perd le signe à cause de l'éditeur - preCreated.setSettingStartLatitude(latitude); - preCreated.setSettingStartLongitude(longitude); - preCreated.setSettingStartLatitude(latitude); - preCreated.setSettingStartLongitude(longitude); - - return preCreated; - - } - - @Override - public String save(String activityLonglineId, SetLongline setLongline) { - - String setLonglineId = doSave(activityLonglineId, setLongline, new SaveAction<ActivityLongline, SetLongline>(ActivityLongline.class, SetLongline.class) { - - @Override - public SetLongline onCreate(ActivityLongline parent, SetLongline toCreate) { - - Map<String, Object> properties = obtainProperties(SetLongline.class, BinderService.EDIT, toCreate); - SetLongline created = getDao().create(properties); - parent.setSetLongline(created); - - return created; - } - - @Override - public SetLongline onUpdate(ActivityLongline parent, SetLongline toUpdate) { - - SetLongline updated = super.onUpdate(parent, toUpdate); - - copyExcluding(SetLongline.class, BinderService.EDIT, - toUpdate, updated, - SetLongline.PROPERTY_BAITS_COMPOSITION, - SetLongline.PROPERTY_FLOATLINES_COMPOSITION, - SetLongline.PROPERTY_HOOKS_COMPOSITION, - SetLongline.PROPERTY_BRANCHLINES_COMPOSITION, - SetLongline.PROPERTY_SECTION, - SetLongline.PROPERTY_CATCH_LONGLINE, - SetLongline.PROPERTY_MITIGATION_TYPE, - SetLongline.PROPERTY_TDR); - return updated; - - } - }); - - return setLonglineId; - - } - - @Override - public void delete(String activityLonglineId, String setLonglineId) { - - // on doit supprimer physiquement la set - // car il n'y a pas de delete-orphan sur une telle relation - SetLonglineDAO dao = getDao(); - SetLongline setsetLongline = dao.findByTopiaId(setLonglineId); - dao.delete(setsetLongline); - - // supprime la reference sur l'activite - ActivityLongline activitySeine = findByTopiaId(ActivityLongline.class, activityLonglineId); - activitySeine.setSetLongline(null); - - } - - protected SetLonglineDAO getDao() { - return (SetLonglineDAO) getDao(SetLongline.class); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/TdrServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/TdrServiceImpl.java deleted file mode 100644 index 20bc2a5..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/TdrServiceImpl.java +++ /dev/null @@ -1,127 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.longline.SetLongline; -import fr.ird.observe.entities.longline.Tdr; -import fr.ird.observe.entities.longline.TripLongline; -import fr.ird.observe.entities.longline.TripLonglineDAO; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * Created on 4/26/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class TdrServiceImpl extends AbstractObserveService implements TdrService { - - public String getTdrDataFilename(Tdr tdr) { - - TripLonglineDAO tripDao = (TripLonglineDAO) getDao(TripLongline.class); - TripLongline tripLongline = tripDao.findByOpen(true); - - StringBuilder filenameBuilder = new StringBuilder("tdr"); - String code = tripLongline.getVessel().getCode(); - filenameBuilder.append("-").append(code); - - Date startDate = tripLongline.getStartDate(); - filenameBuilder.append("-").append(new SimpleDateFormat("yyyy.MM.dd").format(startDate)); - - String homeId = tdr.getHomeId(); - if (homeId != null) { - filenameBuilder.append("-").append(homeId); - } - - String serialNo = tdr.getSerialNo(); - if (serialNo != null) { - filenameBuilder.append("-").append(serialNo); - } - filenameBuilder.append("-").append(tdr.getDataFilename()); - - String filename = filenameBuilder.toString(); - return filename; - - - } - - @Override - public SetLongline loadForEdit(String setLonglineId) { - - SetLongline parentToLoad = findByTopiaId(SetLongline.class, setLonglineId); - - SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); - copy(SetLongline.class, BinderService.EDIT_TDR, parentToLoad, parentLoaded); - - if (!parentToLoad.isTdrEmpty()) { - - TopiaEntityBinder<Tdr> binder = getBinder(Tdr.class, BinderService.EDIT); - TopiaDAO<Tdr> childDao = getDao(Tdr.class); - - List<Tdr> childs = new ArrayList<Tdr>(); - - for (Tdr sourceChild : parentToLoad.getTdr()) { - - Tdr targetChild = childDao.newInstance(); - binder.load(sourceChild, targetChild, true); - childs.add(targetChild); - - } - - parentLoaded.setTdr(childs); - - } - - return parentLoaded; - - } - - @Override - public void save(SetLongline setLongline) { - - TopiaEntityBinder<SetLongline> parentBinder = getBinder(SetLongline.class, BinderService.EDIT_TDR); - TopiaEntityBinder<Tdr> childBinder = getBinder(Tdr.class, BinderService.EDIT); - - doSaveList(setLongline, new SaveCollectionAction<SetLongline, Tdr>( - SetLongline.class, Tdr.class, getListUpdator(), parentBinder, childBinder)); - - } - - protected EntityListUpdator<SetLongline, Tdr> getListUpdator() { - EntityListUpdator<SetLongline, Tdr> listUpdator = EntityListUpdator.newEntityListUpdator( - SetLongline.class, - Tdr.class, - SetLongline.PROPERTY_TDR); - return listUpdator; - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java deleted file mode 100644 index b7f8898..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/longline/TripLonglineServiceImpl.java +++ /dev/null @@ -1,158 +0,0 @@ -package fr.ird.observe.services.data.longline; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.constants.ReferenceLocale; -import fr.ird.observe.entities.longline.ActivityLonglines; -import fr.ird.observe.entities.longline.TripLongline; -import fr.ird.observe.entities.longline.TripLonglineDAO; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.util.DateUtil; - -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * @author Sylvain Bavencoff - bavencoff@codelutin.com - */ -public class TripLonglineServiceImpl extends AbstractObserveService implements TripLonglineService { - - @Override - public List<TripLongline> getTripLonglineStubByProgram(String programId) { - - ReferenceLocale referentielLocale = getReferentielLocale(); - List<TripLongline> result = getDao().findAllStubByProgramId(programId, referentielLocale); - return result; - - } - - @Override - public TripLongline getTripLonglineStub(String tripId) { - - ReferenceLocale referentielLocale = getReferentielLocale(); - TripLongline result = getDao().findStubByTopiaId(tripId, referentielLocale); - return result; - - } - - @Override - public TripLongline loadForDisplay(String tripLonglineId) { - - TripLongline loaded = getDao().newInstance(); - TripLongline toLoad = getDao().findByTopiaId(tripLonglineId); - copy(TripLongline.class, BinderService.EDIT, toLoad, loaded); - - if (!loaded.isActivityLonglineEmpty()) { - - // on force le trie des routes - ActivityLonglines.sort(loaded.getActivityLongline()); - - } - - return loaded; - - } - - @Override - public TripLongline loadForEdit(String tripLonglineId) { - - TripLongline loaded = loadForDisplay(tripLonglineId); - - if (loaded.getEndDate() == null) { - Date date = DateUtil.getEndOfDay(now()); - loaded.setEndDate(date); - } - - return loaded; - - } - - @Override - public TripLongline preCreate(String programId) { - - Program program = findByTopiaId(Program.class, programId); - - TripLongline preCreated = getDao().newInstance(); - - Date date = DateUtil.getDay(now()); - preCreated.setStartDate(date); - preCreated.setEndDate(date); - preCreated.setProgram(program); - - return preCreated; - - } - - @Override - public String save(TripLongline toSave) { - - String tripLonglineId = doSave(null, toSave, new SaveAction<Program, TripLongline>(Program.class, TripLongline.class) { - - @Override - public void beforeSave(String parentId, TripLongline toSave) { - - super.beforeSave(parentId, toSave); - Date startDate = DateUtil.getDay(toSave.getStartDate()); - toSave.setStartDate(startDate); - - // mise a jour de la date de fin - toSave.updateDateFin(); - - } - - @Override - public TripLongline onCreate(Program parent, TripLongline toCreate) { - - Map<String, Object> properties = obtainProperties(TripLongline.class, BinderService.EDIT, toCreate); - TripLongline created = getDao().create(properties); - return created; - - } - - @Override - public TripLongline onUpdate(Program parent, TripLongline toUpdate) { - - TripLongline updated = super.onUpdate(parent, toUpdate); - copyExcluding(TripLongline.class, BinderService.EDIT, toUpdate, updated, TripLongline.PROPERTY_ACTIVITY_LONGLINE); - return updated; - - } - }); - - return tripLonglineId; - - } - - @Override - public void delete(String tripLonglineId) { - doDelete(null, tripLonglineId, new DeleteAction<Program, TripLongline>(Program.class, TripLongline.class)); - } - - protected TripLonglineDAO getDao() { - return (TripLonglineDAO) getDao(TripLongline.class); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java deleted file mode 100644 index 76d8373..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java +++ /dev/null @@ -1,224 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.constants.ReferenceLocale; -import fr.ird.observe.entities.constants.seine.SchoolType; -import fr.ird.observe.entities.referentiel.FpaZone; -import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.ActivitySeineDAO; -import fr.ird.observe.entities.seine.Route; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.util.DateUtil; - -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * Created on 4/24/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class ActivitySeineServiceImpl extends AbstractObserveService implements ActivitySeineService { - - @Override - public List<ActivitySeine> getActivitySeineStubByRoute(String routeId) { - - ReferenceLocale referentielLocale = getReferentielLocale(); - List<ActivitySeine> result = getDao().findAllStubByRouteId(routeId, referentielLocale); - return result; - - } - - @Override - public ActivitySeine getActivitySeineStub(String activityId) { - - ReferenceLocale referentielLocale = getReferentielLocale(); - ActivitySeine result = getDao().findStubByTopiaId(activityId, referentielLocale); - return result; - - } - - @Override - public ActivitySeine loadForEdit(String activitySeineId) { - - ActivitySeine loaded = getDao().newInstance(); - ActivitySeine toLoad = getDao().findByTopiaId(activitySeineId); - copy(ActivitySeine.class, BinderService.EDIT, toLoad, loaded); - return loaded; - - } - - @Override - public ActivitySeine loadForEditObservedSystem(String activitySeineId) { - - ActivitySeine toLoad = getDao().findByTopiaId(activitySeineId); - ActivitySeine loaded = getDao().newInstance(); - copy(ActivitySeine.class, BinderService.EDIT_OBSERVED_SYSTEM, toLoad, loaded); - return loaded; - - } - - @Override - public ActivitySeine preCreate(String routeId) { - - Route tripLongline = findByTopiaId(Route.class, routeId); - - ActivitySeine preCreated = getDao().newInstance(); - - preCreated.setOpen(true); - - ActivitySeine lastActivitySeine = tripLongline.getLastActivity(); - - Date time; - - FpaZone currentFpaZone = null; - - if (lastActivitySeine == null) { - - // première activité, on utilise l'heure courante - time = serviceContext.now(); - - } else { - - // passage en coordonnées absolue + quadrant - lastActivitySeine.initCoordinates(); - - // on recupère le quadrant de cette activity - // et on l'affecte à la nouvelle activity - Integer quadrant = lastActivitySeine.getQuadrant(); - if (quadrant != null) { - - preCreated.setQuadrant(quadrant); - - } - - // on reprend l'heure de la dernière activité - time = lastActivitySeine.getTime(); - - // utilisation des zones fpa de la dernière activité - currentFpaZone = lastActivitySeine.getNextFpaZone(); - if (currentFpaZone == null) { - currentFpaZone = lastActivitySeine.getCurrentFpaZone(); - } - - } - - preCreated.setTime(DateUtil.getTime(time, false, false)); - preCreated.setCurrentFpaZone(currentFpaZone); - - return preCreated; - - } - - @Override - public ActivitySeine updateObservedSystem(ActivitySeine toUpdate) { - - ActivitySeineDAO dao = getDao(); - - boolean needUpdateSet = false; - SchoolType newTypeBanc = toUpdate.getSchoolType(); - SetSeine set = toUpdate.getSetSeine(); - if (set != null) { - - // on regarde si le type de banc de la calée a changé - SchoolType oldTypeBanc = set.getSchoolType(); - needUpdateSet = oldTypeBanc == null || newTypeBanc != oldTypeBanc; - - } - - ActivitySeine updated = dao.findByTopiaId(toUpdate.getTopiaId()); - - copy(ActivitySeine.class, BinderService.EDIT_OBSERVED_SYSTEM, toUpdate, updated); - - if (needUpdateSet) { - - // mise à jour de la propriété schoolType dans la set - updated.getSetSeine().setSchoolType(newTypeBanc); - - } - - return updated; - - } - - - @Override - public String save(String routeId, ActivitySeine toSave) { - - String activitySeineId = doSave(routeId, toSave, new SaveAction<Route, ActivitySeine>(Route.class, ActivitySeine.class) { - - @Override - public ActivitySeine onCreate(Route parent, ActivitySeine toCreate) { - - Map<String, Object> properties = obtainProperties(ActivitySeine.class, BinderService.EDIT, toCreate); - ActivitySeine created = getDao().create(properties); - - parent.addActivitySeine(created); - return created; - - } - - @Override - public ActivitySeine onUpdate(Route parent, ActivitySeine toUpdate) { - - ActivitySeine updated = super.onUpdate(parent, toUpdate); - - Date d = DateUtil.getDateAndTime(parent.getDate(), toUpdate.getTime(), false, false); - - toUpdate.setTime(d); - - copyExcluding(ActivitySeine.class, BinderService.EDIT, toUpdate, updated, true, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM, ActivitySeine.PROPERTY_FLOATING_OBJECT); - return updated; - - } - }); - - return activitySeineId; - - } - - @Override - public void delete(String routeId, String activitySeineId) { - doDelete(routeId, activitySeineId, new DeleteAction<Route, ActivitySeine>(Route.class, ActivitySeine.class) { - - @Override - public void onDelete(Route parent, ActivitySeine toDelete) { - super.onDelete(parent, toDelete); - parent.removeActivitySeine(toDelete); - - } - }); - - } - - protected ActivitySeineDAO getDao() { - return (ActivitySeineDAO) getDao(ActivitySeine.class); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java deleted file mode 100644 index ed3b78f..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java +++ /dev/null @@ -1,216 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.constants.ReferenceLocale; -import fr.ird.observe.entities.referentiel.Country; -import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyOperation; -import fr.ird.observe.entities.referentiel.seine.TransmittingBuoyType; -import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.entities.seine.FloatingObjectDAO; -import fr.ird.observe.entities.seine.TransmittingBuoy; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.decorator.Decorator; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * Created on 4/24/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class FloatingObjectServiceImpl extends AbstractObserveService implements FloatingObjectService { - - @Override - public List<FloatingObject> getFloatinObjectStubByActivitySeine(String activitySeineId) { - - ReferenceLocale referentielLocale = getReferentielLocale(); - List<FloatingObject> result = getDao().findAllStubByActivityId(activitySeineId, referentielLocale); - return result; - - } - - @Override - public FloatingObject getFloatinObjectStub(String floatingObjectId) { - - ReferenceLocale referentielLocale = getReferentielLocale(); - FloatingObject result = getDao().findStubByTopiaId(floatingObjectId, referentielLocale); - return result; - - } - - @Override - public FloatingObject loadForEdit(String floatingObjectId) { - - FloatingObjectDAO dao = getDao(); - - FloatingObject loaded = dao.newInstance(); - FloatingObject toLoad = dao.findByTopiaId(floatingObjectId); - copy(FloatingObject.class, BinderService.EDIT, toLoad, loaded, true); - - return loaded; - - } - - @Override - public FloatingObject loadForTransmittingBuoyOperation(String floatingObjectId) { - - FloatingObjectDAO dao = getDao(); - - FloatingObject loaded = dao.newInstance(); - FloatingObject toLoad = dao.findByTopiaId(floatingObjectId); - - copy(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY, toLoad, loaded); - - if (!toLoad.isTransmittingBuoyEmpty()) { - - Decorator<Country> countryDecorator = getDecoratorByType(Country.class, null); - Decorator<TransmittingBuoyOperation> transmittingBuoyOperationDecorator = getDecoratorByType(TransmittingBuoyOperation.class, null); - Decorator<TransmittingBuoyType> transmittingBuoyTypeDecorator = getDecoratorByType(TransmittingBuoyType.class, null); - - TopiaEntityBinder<TransmittingBuoy> binder = getBinder(TransmittingBuoy.class, BinderService.EDIT); - TopiaDAO<TransmittingBuoy> transmittingBuoyDao = getDao(TransmittingBuoy.class); - List<TransmittingBuoy> transmittingBuoys = new ArrayList<TransmittingBuoy>(); - for (TransmittingBuoy transmittingBuoyToLoad : toLoad.getTransmittingBuoy()) { - - transmittingBuoyOperationDecorator.toString(transmittingBuoyToLoad.getTransmittingBuoyOperation()); - transmittingBuoyTypeDecorator.toString(transmittingBuoyToLoad.getTransmittingBuoyType()); - countryDecorator.toString(transmittingBuoyToLoad.getCountry()); - - TransmittingBuoy transmittingBuoyLoaded = transmittingBuoyDao.newInstance(); - binder.load(transmittingBuoyToLoad, transmittingBuoyLoaded, true); - transmittingBuoys.add(transmittingBuoyLoaded); - - } - - loaded.setTransmittingBuoy(transmittingBuoys); - - } - return loaded; - - } - - @Override - public FloatingObject preCreate(String activitySeineId) { - - FloatingObject preCreated = getDao().newInstance(); - return preCreated; - - } - - @Override - public String save(String activitySeineId, FloatingObject toSave) { - - String floatingObjectId = doSave(activitySeineId, toSave, new SaveAction<ActivitySeine, FloatingObject>(ActivitySeine.class, FloatingObject.class) { - - @Override - public FloatingObject onCreate(ActivitySeine parent, FloatingObject toCreate) { - - Map<String, Object> properties = obtainProperties(FloatingObject.class, BinderService.EDIT, toCreate); - FloatingObject created = getDao().create(properties); - parent.addFloatingObject(created); - return created; - - } - - @Override - public FloatingObject onUpdate(ActivitySeine parent, FloatingObject toUpdate) { - - FloatingObject updated = super.onUpdate(parent, toUpdate); - copy(FloatingObject.class, BinderService.EDIT, toUpdate, updated, true); - return updated; - - } - }); - - return floatingObjectId; - - } - - @Override - public void saveForTransmittingBuoyOperation(FloatingObject toSave) { - - FloatingObject saved = getDao().findByTopiaId(toSave.getTopiaId()); - saved.setComment(toSave.getComment()); - saved.clearTransmittingBuoy(); - - if (!toSave.isTransmittingBuoyEmpty()) { - - TopiaEntityBinder<TransmittingBuoy> binder = getBinder(TransmittingBuoy.class, BinderService.EDIT); - TopiaDAO<TransmittingBuoy> transmittingBuoyDAO = getDao(TransmittingBuoy.class); - - List<TransmittingBuoy> transmittingBuoys = new ArrayList<TransmittingBuoy>(); - - for (TransmittingBuoy transmittingBuoyToSave : toSave.getTransmittingBuoy()) { - - TransmittingBuoy transmittingBuoySaved; - - if (Entities.isNew(transmittingBuoyToSave)) { - - // creation de la balise - Map<String, Object> properties = binder.obtainProperties(transmittingBuoyToSave); - transmittingBuoySaved = transmittingBuoyDAO.create(properties); - - } else { - - // mise a jour de la balise - - transmittingBuoySaved = transmittingBuoyDAO.findByTopiaId(transmittingBuoyToSave.getTopiaId()); - binder.load(transmittingBuoyToSave, transmittingBuoySaved, true); - - } - - transmittingBuoys.add(transmittingBuoySaved); - - } - - saved.addAllTransmittingBuoy(transmittingBuoys); - - } - - } - - @Override - public void delete(String activitySeineId, String floatingObjectId) { - - FloatingObjectDAO dao = getDao(); - FloatingObject toDelete = dao.findByTopiaId(floatingObjectId); - - ActivitySeine activitySeine = findByTopiaId(ActivitySeine.class, activitySeineId); - activitySeine.removeFloatingObject(toDelete); - - } - - protected FloatingObjectDAO getDao() { - return (FloatingObjectDAO) getDao(FloatingObject.class); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java deleted file mode 100644 index 1ae603a..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java +++ /dev/null @@ -1,233 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.referentiel.Gear; -import fr.ird.observe.entities.referentiel.GearCaracteristic; -import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; -import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeineDAO; -import fr.ird.observe.entities.seine.GearUseFeaturesSeine; -import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.AbstractObserveService; -import org.apache.commons.collections4.CollectionUtils; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * Created on 4/26/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService implements GearUseFeaturesSeineService { - - @Override - public List<GearUseFeaturesMeasurementSeine> getDefaultGearUseFeaturesMeasurementSeine(String gearId) { - - Gear gear = findByTopiaId(Gear.class, gearId); - - List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); - - if (!gear.isGearCaracteristicEmpty()) { - - GearUseFeaturesMeasurementSeineDAO dao = getDao(); - - for (GearCaracteristic caracteristic : gear.getGearCaracteristic()) { - - GearUseFeaturesMeasurementSeine target = dao.newInstance(); - target.setGearCaracteristic(caracteristic); - result.add(target); - - } - - } - - return result; - - } - - @Override - public List<GearUseFeaturesMeasurementSeine> loadGearUseFeaturesMeasurementSeineForEdit(String gearUseFeaturesSeineId) { - - GearUseFeaturesSeine gearUseFeaturesSeine = findByTopiaId(GearUseFeaturesSeine.class, gearUseFeaturesSeineId); - List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); - - if (!gearUseFeaturesSeine.isGearUseFeaturesMeasurementEmpty()) { - - GearUseFeaturesMeasurementSeineDAO dao = getDao(); - TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); - - for (GearUseFeaturesMeasurementSeine measurementSource : gearUseFeaturesSeine.getGearUseFeaturesMeasurement()) { - - GearUseFeaturesMeasurementSeine target = dao.newInstance(); - measurementSource.getGearCaracteristic().getGearCaracteristicType(); - binder.load(measurementSource, target, true); - result.add(target); - - } - - } - - return result; - - } - - @Override - public TripSeine loadForEdit(String tripId) { - - TopiaDAO<TripSeine> dao = getDao(TripSeine.class); - TripSeine toLoad = dao.findByTopiaId(tripId); - - TripSeine loaded = dao.newInstance(); - - if (toLoad != null) { - - copyExcluding(TripSeine.class, BinderService.EDIT_GEAR_USE_FEATURES_SEINE, toLoad, loaded, TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); - - if (!toLoad.isGearUseFeaturesSeineEmpty()) { - - TopiaDAO<GearUseFeaturesSeine> childDao = getDao(GearUseFeaturesSeine.class); - TopiaDAO<GearUseFeaturesMeasurementSeine> measurementDao = getDao(GearUseFeaturesMeasurementSeine.class); - TopiaEntityBinder<GearUseFeaturesSeine> childBinder = getBinder(GearUseFeaturesSeine.class, BinderService.EDIT); - TopiaEntityBinder<GearUseFeaturesMeasurementSeine> measurementBinder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); - - List<GearUseFeaturesSeine> childsLoaded = new ArrayList<GearUseFeaturesSeine>(); - - for (GearUseFeaturesSeine childToLoad : toLoad.getGearUseFeaturesSeine()) { - - GearUseFeaturesSeine childLoaded = childDao.newInstance(); - childBinder.load(childToLoad, childLoaded, true); - childsLoaded.add(childLoaded); - - if (!childToLoad.isGearUseFeaturesMeasurementEmpty()) { - - List<GearUseFeaturesMeasurementSeine> measurementsLoaded = new ArrayList<GearUseFeaturesMeasurementSeine>(); - - for (GearUseFeaturesMeasurementSeine measurementToLoad : childToLoad.getGearUseFeaturesMeasurement()) { - - GearUseFeaturesMeasurementSeine measurementLoaded = measurementDao.newInstance(); - measurementBinder.load(measurementToLoad, measurementLoaded, true); - measurementsLoaded.add(measurementLoaded); - - } - - childLoaded.setGearUseFeaturesMeasurement(measurementsLoaded); - - } - - } - - loaded.setGearUseFeaturesSeine(childsLoaded); - - } - - } - - return loaded; - } - - @Override - public void save(TripSeine parent) { - - TopiaEntityBinder<TripSeine> parentBinder = getBinder(TripSeine.class, BinderService.EDIT_GEAR_USE_FEATURES_SEINE); - TopiaEntityBinder<GearUseFeaturesSeine> childBinder = getBinder(GearUseFeaturesSeine.class, BinderService.EDIT); - - doSaveList(parent, new SaveCollectionAction<TripSeine, GearUseFeaturesSeine>( - TripSeine.class, GearUseFeaturesSeine.class, getListUpdator(), parentBinder, childBinder) { - - @Override - public GearUseFeaturesSeine onCreateChild(GearUseFeaturesSeine childToCreate) { - - GearUseFeaturesSeine childCreated = super.onCreateChild(childToCreate); - saveMeasurement(childCreated, childToCreate.getGearUseFeaturesMeasurement()); - return childCreated; - - } - - @Override - public GearUseFeaturesSeine onUpdateChild(GearUseFeaturesSeine childToUpdate) { - - GearUseFeaturesSeine childUpdated = super.onUpdateChild(childToUpdate); - saveMeasurement(childUpdated, childToUpdate.getGearUseFeaturesMeasurement()); - return childUpdated; - - } - - protected void saveMeasurement(GearUseFeaturesSeine childSaved, List<GearUseFeaturesMeasurementSeine> measurementsToSave) { - - List<GearUseFeaturesMeasurementSeine> measurementsSaved = Lists.newArrayList(); - - if (CollectionUtils.isNotEmpty(measurementsToSave)) { - - TopiaDAO<GearUseFeaturesMeasurementSeine> dao = getDao(GearUseFeaturesMeasurementSeine.class); - TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); - - for (GearUseFeaturesMeasurementSeine measurementToSave : measurementsToSave) { - - GearUseFeaturesMeasurementSeine measurementSaved; - - if (Entities.isNew(measurementToSave)) { - - Map<String, Object> properties = binder.obtainProperties(measurementToSave); - measurementSaved = dao.create(properties); - - } else { - - measurementSaved = dao.findByTopiaId(measurementToSave.getTopiaId()); - binder.load(measurementToSave, measurementSaved, true); - - } - - measurementsSaved.add(measurementSaved); - - } - - } - - childSaved.clearGearUseFeaturesMeasurement(); - childSaved.addAllGearUseFeaturesMeasurement(measurementsSaved); - - } - }); - } - - protected EntityListUpdator<TripSeine, GearUseFeaturesSeine> getListUpdator() { - return EntityListUpdator.newEntityListUpdator( - TripSeine.class, - GearUseFeaturesSeine.class, - TripSeine.PROPERTY_GEAR_USE_FEATURES_SEINE); - } - - protected GearUseFeaturesMeasurementSeineDAO getDao() { - return (GearUseFeaturesMeasurementSeineDAO) getDao(GearUseFeaturesMeasurementSeine.class); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java deleted file mode 100644 index 8d6b3f5..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java +++ /dev/null @@ -1,136 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.seine.NonTargetCatch; -import fr.ird.observe.entities.seine.NonTargetLength; -import fr.ird.observe.entities.seine.NonTargetSample; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.services.AbstractObserveService; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.Collection; -import java.util.List; - -/** - * @author Sylvain Bavencoff - bavencoff@codelutin.com - */ -public class NonTargetCatchServiceImpl extends AbstractObserveService implements NonTargetCatchService { - - private static final Log log = LogFactory.getLog(NonTargetCatchServiceImpl.class); - - @Override - public SetSeine loadForEdit(String setId) { - - SetSeine toLoad = findByTopiaId(SetSeine.class, setId); - - SetSeine loaded = getDao(SetSeine.class).newInstance(); - - if (toLoad != null) { - - copyExcluding(SetSeine.class, BinderService.EDIT_NON_TARGET_CATCH, toLoad, loaded, SetSeine.PROPERTY_NON_TARGET_CATCH); - - if (!toLoad.isNonTargetCatchEmpty()) { - - TopiaDAO<NonTargetCatch> dao = getDao(NonTargetCatch.class); - TopiaEntityBinder<NonTargetCatch> binder = getBinder(NonTargetCatch.class, BinderService.EDIT); - - for (NonTargetCatch childToLoad : toLoad.getNonTargetCatch()) { - - NonTargetCatch childLoaded = dao.newInstance(); - binder.load(childToLoad, childLoaded, true); - loaded.addNonTargetCatch(childLoaded); - - } - } - - } - - return loaded; - - } - - @Override - public void save(SetSeine toSave, final List<NonTargetLength> nonTargetLengthsToDelete) { - - TopiaEntityBinder<SetSeine> parentBinder = getBinder(SetSeine.class, BinderService.EDIT_NON_TARGET_CATCH); - TopiaEntityBinder<NonTargetCatch> childbinder = getBinder(NonTargetCatch.class, BinderService.EDIT); - - doSaveList(toSave, new SaveCollectionAction<SetSeine, NonTargetCatch>( - SetSeine.class, NonTargetCatch.class, getListUpdator(), parentBinder, childbinder) { - - @Override - public void prepareSave(SetSeine parentToSave, Collection<NonTargetCatch> nonTargetCatchesToSave) { - - // mise a jour de la propriete nonTargetDiscarded - - boolean hasRejet = false; - for (NonTargetCatch c : nonTargetCatchesToSave) { - if (c.getReasonForDiscard() != null) { - // on a trouve un rejet de faune - hasRejet = true; - break; - } - } - - parentToSave.setNonTargetDiscarded(hasRejet); - - } - - @Override - public void onUpdateFinalize(SetSeine parentSaved, Collection<NonTargetCatch> oldChilds) { - - if (CollectionUtils.isNotEmpty(nonTargetLengthsToDelete)) { - - // on a demande la suppression de taille obsoletes - - if (log.isInfoEnabled()) { - log.info("Will remove " + nonTargetLengthsToDelete.size() + " obsolete nonTargetSample(s)."); - } - - NonTargetSample echantillon = parentSaved.getNonTargetSample().get(0); - - // on supprime les echantillons obsoletes - echantillon.getNonTargetLength().removeAll(nonTargetLengthsToDelete); - - } - } - }); - - } - - protected EntityListUpdator<SetSeine, NonTargetCatch> getListUpdator() { - return EntityListUpdator.newEntityListUpdator( - SetSeine.class, - NonTargetCatch.class, - SetSeine.PROPERTY_NON_TARGET_CATCH); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java deleted file mode 100644 index 214547b..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java +++ /dev/null @@ -1,267 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.referentiel.Species; -import fr.ird.observe.entities.seine.NonTargetCatch; -import fr.ird.observe.entities.seine.NonTargetLength; -import fr.ird.observe.entities.seine.NonTargetSample; -import fr.ird.observe.entities.seine.NonTargetSampleDAO; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.services.AbstractObserveService; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Created on 4/26/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class NonTargetSampleServiceImpl extends AbstractObserveService implements NonTargetSampleService { - - /** Logger. */ - private static final Log log = LogFactory.getLog(NonTargetSampleServiceImpl.class); - - protected NonTargetSampleDAO getDao() { - return (NonTargetSampleDAO) getDao(NonTargetSample.class); - } - - @Override - public List<Species> getAvailableSpeciesForNonTargetSample(String setSeineId) { - - List<Species> speciesList = new ArrayList<Species>(); - - SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); - - // on recupere la liste des espèces faune utilisees dans le rejet - Collection<NonTargetCatch> nonTargetCatches = setSeine.getNonTargetCatch(); - - if (nonTargetCatches != null) { - - for (NonTargetCatch nonTargetCatch : nonTargetCatches) { - // on retient toute les espèces (capturées ou rejetées) - if (!speciesList.contains(nonTargetCatch.getSpecies())) { - speciesList.add(nonTargetCatch.getSpecies()); - } - } - - } - - return speciesList; - - } - - @Override - public NonTargetSample loadForEdit(String setSeineId) { - - SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); - - NonTargetSample toLoad; - - if (setSeine.isNonTargetSampleEmpty()) { - - toLoad = null; - - } else { - - List<NonTargetSample> nonTargetSamples = setSeine.getNonTargetSample(); - toLoad = nonTargetSamples.get(0); - - } - - NonTargetSample loaded = getDao(NonTargetSample.class).newInstance(); - - if (toLoad != null) { - - copyExcluding(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH, toLoad, loaded, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); - - if (!toLoad.isNonTargetLengthEmpty()) { - - TopiaDAO<NonTargetLength> dao = getDao(NonTargetLength.class); - TopiaEntityBinder<NonTargetLength> binder = getBinder(NonTargetLength.class, BinderService.EDIT); - - for (NonTargetLength childToLoad : toLoad.getNonTargetLength()) { - - NonTargetLength childLoaded = dao.newInstance(); - binder.load(childToLoad, childLoaded, true); - loaded.addNonTargetLength(childLoaded); - - } - } - } - - return loaded; - } - - @Override - public boolean canUseNonTargetSample(String setSeineId) { - - SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); - return setSeine.canUseNonTargetSample(); - - } - - @Override - public List<NonTargetLength> getObsoleteNonTargetLengths(String setSeineId, Set<String> speciesIdsUsed) { - - SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); - - List<NonTargetLength> nonTargetLengthsToDelete = new ArrayList<NonTargetLength>(); - - if (!setSeine.isNonTargetSampleEmpty()) { - - NonTargetSample nonTargetSample = setSeine.getNonTargetSample().get(0); - - if (!nonTargetSample.isNonTargetLengthEmpty()) { - - for (NonTargetLength taille : nonTargetSample.getNonTargetLength()) { - - Species species = taille.getSpecies(); - if (!speciesIdsUsed.contains(species.getTopiaId())) { - - // l'espèce n'existe plus dans les rejet faune, on doit le supprimer - nonTargetLengthsToDelete.add(taille); - if (log.isDebugEnabled()) { - log.debug("remove obsolote echantillon " + taille + " for species " + species); - } - - } - - } - - } - - } - - return nonTargetLengthsToDelete; - - } - - @Override - public String save(String setSeineId, NonTargetSample nonTargetSampleToSave) { - - String savedId = doSave(setSeineId, nonTargetSampleToSave, new SaveAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { - - @Override - public NonTargetSample onCreate(SetSeine parent, NonTargetSample toCreate) { - - NonTargetSampleDAO dao = getDao(); - - Map<String, Object> properties = obtainProperties(NonTargetSample.class, BinderService.EDIT, toCreate); - NonTargetSample created = dao.create(properties); - parent.addNonTargetSample(created); - - saveTargetLengths(toCreate.getNonTargetLength(), created); - - dao.update(created); - return created; - - } - - @Override - public NonTargetSample onUpdate(SetSeine parent, NonTargetSample toUpdate) { - - NonTargetSample updated = super.onUpdate(parent, toUpdate); - - copyExcluding(NonTargetSample.class, BinderService.EDIT, toUpdate, updated, false, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); - - saveTargetLengths(toUpdate.getNonTargetLength(), updated); - - getDao().update(updated); - return updated; - - } - - protected void saveTargetLengths(Collection<NonTargetLength> nonTargetLengthsToSave, NonTargetSample childSaved) { - - List<NonTargetLength> nonTargetLengthsSaved = Lists.newArrayList(); - - if (CollectionUtils.isNotEmpty(nonTargetLengthsToSave)) { - - TopiaDAO<NonTargetLength> dao = getDao(NonTargetLength.class); - TopiaEntityBinder<NonTargetLength> binder = getBinder(NonTargetLength.class, BinderService.EDIT); - - for (NonTargetLength nonTargetLengthToSave : nonTargetLengthsToSave) { - - NonTargetLength nonTargetLengthSaved; - - if (Entities.isNew(nonTargetLengthToSave)) { - - Map<String, Object> properties = binder.obtainProperties(nonTargetLengthToSave); - nonTargetLengthSaved = dao.create(properties); - - } else { - - nonTargetLengthSaved = dao.findByTopiaId(nonTargetLengthToSave.getTopiaId()); - binder.load(nonTargetLengthToSave, nonTargetLengthSaved, true); - - } - - nonTargetLengthsSaved.add(nonTargetLengthSaved); - - } - - } - - childSaved.clearNonTargetLength(); - childSaved.addAllNonTargetLength(nonTargetLengthsSaved); - - } - - }); - - return savedId; - - } - - @Override - public void delete(String setSeineId, NonTargetSample nonTargetSampleToDelete) { - - doDelete(setSeineId, nonTargetSampleToDelete.getTopiaId(), new DeleteAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { - - @Override - public void onDelete(SetSeine parent, NonTargetSample toDelete) { - - super.onDelete(parent, toDelete); - parent.removeNonTargetSample(toDelete); - - } - - }); - - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java deleted file mode 100644 index 5c1f06d..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java +++ /dev/null @@ -1,88 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.entities.seine.ObjectObservedSpecies; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Sylvain Bavencoff - bavencoff@codelutin.com - */ -public class ObjectObservedSpeciesServiceImpl extends AbstractObserveService implements ObjectObservedSpeciesService { - - @Override - public FloatingObject loadForEdit(String floatingObjectId) { - - FloatingObject parentToLoad = findByTopiaId(FloatingObject.class, floatingObjectId); - - FloatingObject parentLoaded = getDao(FloatingObject.class).newInstance(); - - copy(FloatingObject.class, BinderService.EDIT_OBJECT_OBSERVED_SPECIES, parentToLoad, parentLoaded); - - if (!parentToLoad.isObjectObservedSpeciesEmpty()) { - - TopiaDAO<ObjectObservedSpecies> childDao = getDao(ObjectObservedSpecies.class); - TopiaEntityBinder<ObjectObservedSpecies> binder = getBinder(ObjectObservedSpecies.class, BinderService.EDIT); - List<ObjectObservedSpecies> childs = new ArrayList<ObjectObservedSpecies>(); - - for (ObjectObservedSpecies sourceChild : parentToLoad.getObjectObservedSpecies()) { - - ObjectObservedSpecies targetChild = childDao.newInstance(); - binder.load(sourceChild, targetChild, true); - childs.add(targetChild); - - } - - parentLoaded.setObjectObservedSpecies(childs); - - } - - return parentLoaded; - } - - @Override - public void save(FloatingObject floatingObject) { - - TopiaEntityBinder<FloatingObject> parentBinder = getBinder(FloatingObject.class, BinderService.EDIT_OBJECT_OBSERVED_SPECIES); - TopiaEntityBinder<ObjectObservedSpecies> childbinder = getBinder(ObjectObservedSpecies.class, BinderService.EDIT); - - doSaveList(floatingObject, new SaveCollectionAction<FloatingObject, ObjectObservedSpecies>( - FloatingObject.class, ObjectObservedSpecies.class, getListUpdator(), parentBinder, childbinder)); - - } - - protected EntityListUpdator<FloatingObject, ObjectObservedSpecies> getListUpdator() { - return EntityListUpdator.newEntityListUpdator( - FloatingObject.class, - ObjectObservedSpecies.class, - FloatingObject.PROPERTY_OBJECT_OBSERVED_SPECIES); - } -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java deleted file mode 100644 index 9e8afad..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java +++ /dev/null @@ -1,89 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.entities.seine.ObjectSchoolEstimate; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author Sylvain Bavencoff - bavencoff@codelutin.com - */ -public class ObjectSchoolEstimateServiceImpl extends AbstractObserveService implements ObjectSchoolEstimateService { - - @Override - public FloatingObject loadForEdit(String floatingObjectId) { - - FloatingObject parentToLoad = findByTopiaId(FloatingObject.class, floatingObjectId); - - FloatingObject parentLoaded = getDao(FloatingObject.class).newInstance(); - - copy(FloatingObject.class, BinderService.EDIT_OBJECT_SCHOOL_ESTIMATE, parentToLoad, parentLoaded); - - if (!parentToLoad.isObjectSchoolEstimateEmpty()) { - - TopiaDAO<ObjectSchoolEstimate> childDao = getDao(ObjectSchoolEstimate.class); - TopiaEntityBinder<ObjectSchoolEstimate> binder = getBinder(ObjectSchoolEstimate.class, BinderService.EDIT); - - List<ObjectSchoolEstimate> childs = new ArrayList<ObjectSchoolEstimate>(); - - for (ObjectSchoolEstimate sourceChild : parentToLoad.getObjectSchoolEstimate()) { - - ObjectSchoolEstimate targetChild = childDao.newInstance(); - binder.load(sourceChild, targetChild, true); - childs.add(targetChild); - - } - - parentLoaded.setObjectSchoolEstimate(childs); - - } - - return parentLoaded; - } - - @Override - public void save(FloatingObject floatingObject) { - - TopiaEntityBinder<FloatingObject> parentBinder = getBinder(FloatingObject.class, BinderService.EDIT_OBJECT_SCHOOL_ESTIMATE); - TopiaEntityBinder<ObjectSchoolEstimate> childBinder = getBinder(ObjectSchoolEstimate.class, BinderService.EDIT); - - doSaveList(floatingObject, new SaveCollectionAction<FloatingObject, ObjectSchoolEstimate>( - FloatingObject.class, ObjectSchoolEstimate.class, getListUpdator(), parentBinder, childBinder)); - - } - - protected EntityListUpdator<FloatingObject, ObjectSchoolEstimate> getListUpdator() { - return EntityListUpdator.newEntityListUpdator( - FloatingObject.class, - ObjectSchoolEstimate.class, - FloatingObject.PROPERTY_OBJECT_SCHOOL_ESTIMATE); - } -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/RouteServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/RouteServiceImpl.java deleted file mode 100644 index 487bdef..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/RouteServiceImpl.java +++ /dev/null @@ -1,184 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.seine.ActivitySeines; -import fr.ird.observe.entities.seine.Route; -import fr.ird.observe.entities.seine.RouteDAO; -import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.AbstractObserveService; -import org.apache.commons.lang3.time.DateUtils; -import org.nuiton.util.DateUtil; - -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * Created on 4/24/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class RouteServiceImpl extends AbstractObserveService implements RouteService { - - @Override - public List<Route> getRouteStubByTrip(String tripSeineId) { - - List<Route> result = getDao().findAllStubByTripId(tripSeineId); - return result; - - } - - @Override - public Route getRouteStub(String routeId) { - - Route result = getDao().findStubByTopiaId(routeId); - return result; - - } - - @Override - public Route loadForEdit(String routeId) { - - Route loaded = getDao().newInstance(); - Route toLoad = getDao().findByTopiaId(routeId); - copy(Route.class, BinderService.EDIT, toLoad, loaded); - - if (!loaded.isActivitySeineEmpty()) { - - // on force le trie des activites - ActivitySeines.sort(loaded.getActivitySeine()); - } - - return loaded; - - } - - @Override - public Route preCreate(String tripSeineId) { - - TripSeine tripLongline = findByTopiaId(TripSeine.class, tripSeineId); - - Route preCreated = getDao().newInstance(); - - preCreated.setOpen(true); - - Route lastRoute = tripLongline.getLastRoute(); - - Date date; - if (lastRoute == null) { - - // aucune route defini, on utilise la date courante - date = now(); - - } else { - - // une route precedente est definie sur la maree - // le jour d'observation est le jour suivant celui de la - // derniere route - date = DateUtils.addDays(lastRoute.getDate(), 1); - - // le loch du matin est le loch du soir de la derniere route - preCreated.setStartLogValue(lastRoute.getEndLogValue()); - } - - preCreated.setDate(DateUtil.getDay(date)); - - return preCreated; - - } - - @Override - public String save(String tripSeineId, Route toSave) { - - String routeId = doSave(tripSeineId, toSave, new SaveAction<TripSeine, Route>(TripSeine.class, Route.class) { - - @Override - public Route onCreate(TripSeine parent, Route toCreate) { - - Map<String, Object> properties = obtainProperties(Route.class, BinderService.EDIT, toCreate); - Route created = getDao().create(properties); - - parent.addRoute(created); - - // on met a jour si necessaire la date de fin de la maree - parent.updateDateFin(); - - return created; - } - - @Override - public Route onUpdate(TripSeine parent, Route toUpdate) { - - Route updated = super.onUpdate(parent, toUpdate); - - // on conserve l'ancienne date d'observation - Date oldDate = DateUtil.getDay(toUpdate.getDate()); - - // recopie des propriétés vers le bean a sauver - copyExcluding(Route.class, BinderService.EDIT, toUpdate, updated, Route.PROPERTY_ACTIVITY_SEINE); - - if (!oldDate.equals(toUpdate.getDate())) { - - //FIXME Faire cela avec une requete sql, sinon ca charge trop de données - // le jour a change, il faut mettre à jour les dates des activites et des calees - updated.updateDates(); - - } - - // on met a jour si necessaire la date de fin de la maree - parent.updateDateFin(); - - return updated; - - } - }); - - return routeId; - - } - - @Override - public void delete(String tripSeineId, String routeId) { - doDelete(tripSeineId, routeId, new DeleteAction<TripSeine, Route>(TripSeine.class, Route.class) { - - @Override - public void onDelete(TripSeine parent, Route toDelete) { - super.onDelete(parent, toDelete); - - // suppression de la route - parent.removeRoute(toDelete); - - // mise à jour de la date de fin de marée - parent.updateDateFin(); - } - }); - } - - protected RouteDAO getDao() { - return (RouteDAO) getDao(Route.class); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java deleted file mode 100644 index 597a70d..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.seine.SchoolEstimate; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created on 4/28/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class SchoolEstimateServiceImpl extends AbstractObserveService implements SchoolEstimateService { - - @Override - public SetSeine loadForEdit(String setSeineId) { - - SetSeine parentToLoad = findByTopiaId(SetSeine.class, setSeineId); - - SetSeine parentLoaded = getDao(SetSeine.class).newInstance(); - - copy(SetSeine.class, BinderService.EDIT_SCHOOL_ESTIMATE, parentToLoad, parentLoaded); - - if (!parentToLoad.isSchoolEstimateEmpty()) { - - TopiaDAO<SchoolEstimate> childDao = getDao(SchoolEstimate.class); - TopiaEntityBinder<SchoolEstimate> binder = getBinder(SchoolEstimate.class, BinderService.EDIT); - - List<SchoolEstimate> childs = new ArrayList<SchoolEstimate>(); - - for (SchoolEstimate sourceChild : parentToLoad.getSchoolEstimate()) { - - SchoolEstimate targetChild = childDao.newInstance(); - binder.load(sourceChild, targetChild, true); - childs.add(targetChild); - - } - - parentLoaded.setSchoolEstimate(childs); - - } - - return parentLoaded; - - } - - @Override - public void save(SetSeine parent) { - - TopiaEntityBinder<SetSeine> parentBinder = getBinder(SetSeine.class, BinderService.EDIT_SCHOOL_ESTIMATE); - TopiaEntityBinder<SchoolEstimate> childBinder = getBinder(SchoolEstimate.class, BinderService.EDIT); - - doSaveList(parent, new SaveCollectionAction<SetSeine, SchoolEstimate>( - SetSeine.class, SchoolEstimate.class, getListUpdator(), parentBinder, childBinder)); - } - - protected EntityListUpdator<SetSeine, SchoolEstimate> getListUpdator() { - return EntityListUpdator.newEntityListUpdator( - SetSeine.class, - SchoolEstimate.class, - SetSeine.PROPERTY_SCHOOL_ESTIMATE); - } - - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java deleted file mode 100644 index 463fdb9..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/SetSeineServiceImpl.java +++ /dev/null @@ -1,173 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.constants.seine.SchoolType; -import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.NonTargetSample; -import fr.ird.observe.entities.seine.Route; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.entities.seine.SetSeineDAO; -import fr.ird.observe.entities.seine.TargetSample; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.util.DateUtil; - -import java.util.Date; -import java.util.Map; - -/** - * Created on 4/24/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class SetSeineServiceImpl extends AbstractObserveService implements SetSeineService { - - @Override - public SetSeine loadSet(String setSeineId) { - return null; - } - - @Override - public Date getRouteDate(String routeId) { - - Route route = findByTopiaId(Route.class, routeId); - Date date = route.getDate(); - return date; - - } - - @Override - public SetSeine loadForEdit(String setSeineId) { - - SetSeineDAO dao = getDao(); - SetSeine loaded = dao.newInstance(); - SetSeine toLoad = dao.findByTopiaId(setSeineId); - copy(SetSeine.class, BinderService.EDIT, toLoad, loaded); - - //FIXME See why need this ? - if (!loaded.isTargetSampleEmpty()) { - for (TargetSample e : loaded.getTargetSample()) { - e.isTargetLengthEmpty(); - } - } - - //FIXME See why need this ? - if (!loaded.isNonTargetSampleEmpty()) { - for (NonTargetSample e : loaded.getNonTargetSample()) { - e.isNonTargetLengthEmpty(); - } - } - - return loaded; - - } - - - @Override - public SetSeine preCreate(String routeId, String activitySeineId) { - - ActivitySeine activitySeine = findByTopiaId(ActivitySeine.class, activitySeineId); - - // on utilise l'heure de l'activité comme début de calée - Date date = DateUtil.getTime(activitySeine.getTime(), false, false); - - SetSeine preCreated = getDao().newInstance(); - - preCreated.setStartTime(date); - - // pour les dates de fin on utilise la date de la route - Date routeDate = getRouteDate(routeId); - - preCreated.setEndSetTimeStamp(date); - preCreated.setEndPursingTimeStamp(date); - - preCreated.setEndSetDate(routeDate); - preCreated.setEndPursingDate(routeDate); - - // recuperation du type de set a partir de l'activity - SchoolType schoolType = activitySeine.getSchoolType(); - preCreated.setSchoolType(schoolType); - - return preCreated; - - } - - @Override - public String save(String activitySeineId, SetSeine toSave) { - - String setSeineId = doSave(activitySeineId, toSave, new SaveAction<ActivitySeine, SetSeine>(ActivitySeine.class, SetSeine.class) { - - @Override - public SetSeine onCreate(ActivitySeine parent, SetSeine toCreate) { - - Map<String, Object> properties = obtainProperties(SetSeine.class, BinderService.EDIT, toCreate); - SetSeine created = getDao().create(properties); - - parent.setSetSeine(created); - - return created; - } - - @Override - public SetSeine onUpdate(ActivitySeine parent, SetSeine toUpdate) { - - SetSeine updated = super.onUpdate(parent, toUpdate); - - copyExcluding(SetSeine.class, - BinderService.EDIT, - toUpdate, - updated, - SetSeine.PROPERTY_TARGET_SAMPLE, - SetSeine.PROPERTY_NON_TARGET_SAMPLE); - return updated; - - } - }); - - return setSeineId; - - } - - - @Override - public void delete(String activitySeineId, String setSeineId) { - - // on doit supprimer physiquement la set - // car il n'y a pas de delete-orphan sur une telle relation - SetSeineDAO dao = getDao(); - SetSeine setSeine = dao.findByTopiaId(setSeineId); - dao.delete(setSeine); - - // supprime la reference sur l'activité - ActivitySeine activitySeine = findByTopiaId(ActivitySeine.class, activitySeineId); - activitySeine.setSetSeine(null); - - } - - protected SetSeineDAO getDao() { - return (SetSeineDAO) getDao(SetSeine.class); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java deleted file mode 100644 index 2c726b5..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/TargetCatchServiceImpl.java +++ /dev/null @@ -1,186 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Predicate; -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.referentiel.seine.WeightCategory; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.entities.seine.TargetCatch; -import fr.ird.observe.entities.seine.TargetCatches; -import fr.ird.observe.entities.seine.TargetLength; -import fr.ird.observe.entities.seine.TargetSample; -import fr.ird.observe.services.AbstractObserveService; -import fr.ird.observe.services.referential.ReferentialService; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * Created on 5/2/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class TargetCatchServiceImpl extends AbstractObserveService implements TargetCatchService { - - /** Logger. */ - private static final Log log = LogFactory.getLog(TargetCatchServiceImpl.class); - - @Override - public SetSeine loadForEdit(String setSeineId) { - - SetSeine loaded = load(setSeineId, BinderService.EDIT_TARGET_CATCH, TargetCatches.TARGET_CATCH_IS_NOT_DISCARDED); - return loaded; - - } - - @Override - public SetSeine loadForEditDiscarded(String setSeineId) { - - SetSeine loaded = load(setSeineId, BinderService.EDIT_DISCARD_TARGET_CATCH, TargetCatches.TARGET_CATCH_IS_DISCARDED); - return loaded; - - } - - @Override - public void save(SetSeine setSeinetoSave, final List<TargetLength> targetLengthsToDelete) { - - save(setSeinetoSave, BinderService.EDIT_TARGET_CATCH, TargetCatches.TARGET_CATCH_IS_NOT_DISCARDED, targetLengthsToDelete); - - } - - @Override - public void saveForDiscarded(SetSeine setSeinetoSave, final List<TargetLength> targetLengthsToDelete) { - - save(setSeinetoSave, BinderService.EDIT_DISCARD_TARGET_CATCH, TargetCatches.TARGET_CATCH_IS_DISCARDED, targetLengthsToDelete); - - } - - protected SetSeine load(String setId, String binderContext, Predicate<TargetCatch> predicate) { - - TopiaDAO<SetSeine> setSeineDao = getDao(SetSeine.class); - SetSeine toLoad = setSeineDao.findByTopiaId(setId); - SetSeine loaded = setSeineDao.newInstance(); - - copyExcluding(SetSeine.class, binderContext, toLoad, loaded, SetSeine.PROPERTY_TARGET_CATCH); - - if (!toLoad.isTargetCatchEmpty()) { - - ReferentialService referentialService = newService(ReferentialService.class); - - TopiaDAO<TargetCatch> dao = getDao(TargetCatch.class); - TopiaEntityBinder<TargetCatch> binder = getBinder(TargetCatch.class, binderContext); - - List<TargetCatch> childsLoaded = new ArrayList<TargetCatch>(); - - for (TargetCatch childToLoad : toLoad.getTargetCatch()) { - - if (predicate.apply(childToLoad)) { - - WeightCategory weightCategory = childToLoad.getWeightCategory(); - if (weightCategory != null) { - referentialService.loadDecoratedWeightCategory(weightCategory); - } - - TargetCatch childLoaded = dao.newInstance(); - binder.load(childToLoad, childLoaded, true); - childsLoaded.add(childLoaded); - - } - - } - - loaded.setTargetCatch(childsLoaded); - - } - - return loaded; - - } - - void save(SetSeine setSeinetoSave, String binderContext, final Predicate<TargetCatch> predicate, final List<TargetLength> targetLengthsToDelete) { - - TopiaEntityBinder<SetSeine> parentBinder = getBinder(SetSeine.class, binderContext); - TopiaEntityBinder<TargetCatch> childBinder = getBinder(TargetCatch.class, binderContext); - - doSaveList(setSeinetoSave, new SaveCollectionAction<SetSeine, TargetCatch>( - SetSeine.class, TargetCatch.class, getListUpdator(), parentBinder, childBinder, predicate) { - - @Override - public void onUpdateFinalize(SetSeine parentSaved, Collection<TargetCatch> oldChilds) { - - if (CollectionUtils.isNotEmpty(oldChilds)) { - - Collection<TargetCatch> targetCatchesToReinject = new ArrayList<TargetCatch>(); - - for (TargetCatch oldChild : oldChilds) { - - if (predicate.apply(oldChild)) { - - // on réinjecte cette capture - targetCatchesToReinject.add(oldChild); - - } - - } - - parentSaved.addAllTargetCatch(targetCatchesToReinject); - - } - - if (CollectionUtils.isNotEmpty(targetLengthsToDelete)) { - - // suppression des échantillons obsoletes - - if (log.isInfoEnabled()) { - log.info("Will remove " + targetLengthsToDelete.size() + " obsolete targetLength(s)."); - } - - TargetSample targetSample = parentSaved.getTargetSample().get(0); - - // on supprime les echantillons obsoletes - targetSample.getTargetLength().removeAll(targetLengthsToDelete); - - } - } - }); - - } - - protected EntityListUpdator<SetSeine, TargetCatch> getListUpdator() { - return EntityListUpdator.newEntityListUpdator( - SetSeine.class, - TargetCatch.class, - SetSeine.PROPERTY_TARGET_CATCH); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java deleted file mode 100644 index f1147a2..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java +++ /dev/null @@ -1,298 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.referentiel.Species; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.entities.seine.TargetCatch; -import fr.ird.observe.entities.seine.TargetLength; -import fr.ird.observe.entities.seine.TargetLengthDAO; -import fr.ird.observe.entities.seine.TargetSample; -import fr.ird.observe.entities.seine.TargetSampleDAO; -import fr.ird.observe.services.AbstractObserveService; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; - -/** - * Created on 4/26/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class TargetSampleServiceImpl extends AbstractObserveService implements TargetSampleService { - - /** Logger. */ - private static final Log log = LogFactory.getLog(TargetSampleServiceImpl.class); - - @Override - public List<Species> getAvailableSpeciesForTargetSample(String setSeineId, boolean discarded) { - - List<Species> speciesList = new ArrayList<Species>(); - - SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); - - // on recupere la liste des espèces thon utilisees dans le rejet - Collection<TargetCatch> targetCatches = setSeine.getTargetCatch(); - - // on filtre sur les espèces montées sur le pont et rejetées - - if (targetCatches != null) { - - for (TargetCatch targetCatch : targetCatches) { - - boolean keep; - - if (discarded) { - - // on ne conserve que les espèces rejectées montées sur le pont - keep = targetCatch.isDiscarded() && targetCatch.getBroughtOnDeck(); - - } else { - - // on ne conserve que les espèces rejectées - keep = !targetCatch.isDiscarded(); - } - - if (keep && - !speciesList.contains(targetCatch.getWeightCategory().getSpecies())) { - speciesList.add(targetCatch.getWeightCategory().getSpecies()); - } - - } - - } - - return speciesList; - - } - - @Override - public TargetSample loadForEdit(String setSeineId, boolean discarded) { - - SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); - - TargetSample toLoad = null; - - if (!setSeine.isTargetSampleEmpty()) { - - List<TargetSample> targetSamples = setSeine.getTargetSample(); - for (TargetSample targetSample : targetSamples) { - - Boolean isDiscarded = targetSample.getDiscarded(); - - if (discarded == (isDiscarded != null && isDiscarded)) { - toLoad = targetSample; - } - - } - - } - - TargetSample loaded = getDao().newInstance(); - - if (toLoad != null) { - - copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGTH, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); - - - if (!toLoad.isTargetLengthEmpty()) { - - TopiaEntityBinder<TargetLength> binder = getBinder(TargetLength.class, BinderService.EDIT); - TopiaDAO<TargetLength> dao = getDao(TargetLength.class); - - for (TargetLength childToLoad : toLoad.getTargetLength()) { - - TargetLength childLoaded = dao.newInstance(); - binder.load(childToLoad, childLoaded, true); - loaded.addTargetLength(childLoaded); - - } - } - } - - - return loaded; - } - - @Override - public boolean canUseTargetSample(String setSeineId, boolean discarded) { - - SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); - return setSeine.canUseTargetSample(discarded); - - } - - @Override - public List<TargetLength> getObsoleteTargetLengths(String setSeineId, Set<String> speciesIdsUsed, boolean discarded) { - - SetSeine setSeine = findByTopiaId(SetSeine.class, setSeineId); - - List<TargetLength> targetLengthsToDelete = new ArrayList<TargetLength>(); - - if (!setSeine.isTargetSampleEmpty()) { - - TargetSample targetSample = setSeine.getTargetSample(discarded); - if (targetSample != null && !targetSample.isTargetLengthEmpty()) { - - for (TargetLength targetLength : targetSample.getTargetLength()) { - - Species species = targetLength.getSpecies(); - - if (!speciesIdsUsed.contains(species.getTopiaId())) { - // l'espèce n'existe plus dans les rejet faune, on doit le supprimer - targetLengthsToDelete.add(targetLength); - if (log.isDebugEnabled()) { - log.debug("remove obsolote echantillon " + targetLength + " for species " + species); - } - } - - } - - } - - } - - return targetLengthsToDelete; - - } - - @Override - public String save(String setSeineId, TargetSample toSave) { - - String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { - - @Override - public TargetSample onCreate(SetSeine parent, TargetSample toCreate) { - - TargetSample created = getDao().create(); - copyExcluding(TargetSample.class, BinderService.EDIT, toCreate, created, false, TargetSample.PROPERTY_TARGET_LENGTH); - parent.addTargetSample(created); - - saveTargetLengths(toCreate.getTargetLength(), created); - - getDao().update(created); - return created; - - } - - @Override - public TargetSample onUpdate(SetSeine parent, TargetSample toUpdate) { - - TargetSample updated = super.onUpdate(parent, toUpdate); - - copyExcluding(TargetSample.class, BinderService.EDIT, toUpdate, updated, false, TargetSample.PROPERTY_TARGET_LENGTH); - - saveTargetLengths(toUpdate.getTargetLength(), updated); - - getDao().update(updated); - return updated; - - } - - protected void saveTargetLengths(Collection<TargetLength> targetLengthsToSave, TargetSample childSaved) { - - List<TargetLength> targetLengthsSaved = Lists.newArrayList(); - - if (CollectionUtils.isNotEmpty(targetLengthsToSave)) { - - TopiaDAO<TargetLength> dao = getDao(TargetLength.class); - TopiaEntityBinder<TargetLength> binder = getBinder(TargetLength.class, BinderService.EDIT); - - for (TargetLength targetLengthToSave : targetLengthsToSave) { - - TargetLength targetLengthSaved; - - if (Entities.isNew(targetLengthToSave)) { - - targetLengthSaved = dao.create(); - binder.load(targetLengthToSave, targetLengthSaved, false); - - } else { - - targetLengthSaved = dao.findByTopiaId(targetLengthToSave.getTopiaId()); - binder.load(targetLengthToSave, targetLengthSaved, true); - - } - - targetLengthsSaved.add(targetLengthSaved); - - } - - } - - childSaved.clearTargetLength(); - childSaved.addAllTargetLength(targetLengthsSaved); - - } - - - }); - - return savedId; - - } - - @Override - public void delete(String setSeineId, TargetSample bean) { - - doDelete(setSeineId, bean.getTopiaId(), new DeleteAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { - - @Override - public void onDelete(SetSeine parent, TargetSample toDelete) { - - super.onDelete(parent, toDelete); - parent.removeTargetSample(toDelete); - - } - }); - - } - - protected TargetSampleDAO getDao() { - return (TargetSampleDAO) getDao(TargetSample.class); - } - - protected TargetLengthDAO getChildDao() { - return (TargetLengthDAO) getDao(TargetLength.class); - } - - protected EntityListUpdator<TargetSample, TargetLength> getListUpdator() { - return EntityListUpdator.newEntityListUpdator( - TargetSample.class, - TargetLength.class, - TargetSample.PROPERTY_TARGET_LENGTH); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java deleted file mode 100644 index ed8182c..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/data/seine/TripSeineServiceImpl.java +++ /dev/null @@ -1,158 +0,0 @@ -package fr.ird.observe.services.data.seine; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.BinderService; -import fr.ird.observe.entities.constants.ReferenceLocale; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.entities.seine.Routes; -import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.entities.seine.TripSeineDAO; -import fr.ird.observe.services.AbstractObserveService; -import org.nuiton.util.DateUtil; - -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * Created on 4/24/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class TripSeineServiceImpl extends AbstractObserveService implements TripSeineService { - - protected TripSeineDAO getDao() { - return (TripSeineDAO) getDao(TripSeine.class); - } - - @Override - public List<TripSeine> getTripSeineStubByProgram(String programId) { - - ReferenceLocale referentielLocale = getReferentielLocale(); - List<TripSeine> result = getDao().findAllStubByProgramId(programId, referentielLocale); - return result; - - } - - @Override - public TripSeine getTripSeineStub(String tripId) { - - ReferenceLocale referentielLocale = getReferentielLocale(); - TripSeine result = getDao().findStubByTopiaId(tripId, referentielLocale); - return result; - - } - - @Override - public TripSeine loadForDisplay(String tripSeineId) { - - TripSeine loaded = getDao().newInstance(); - TripSeine toLoad = getDao().findByTopiaId(tripSeineId); - copy(TripSeine.class, BinderService.EDIT, toLoad, loaded); - - if (!loaded.isRouteEmpty()) { - - // on force le trie des routes - Routes.sort(loaded.getRoute()); - } - - return loaded; - - } - - @Override - public TripSeine loadForEdit(String tripSeineId) { - - TripSeine loaded = loadForDisplay(tripSeineId); - if (loaded.getEndDate() == null) { - Date date = DateUtil.getEndOfDay(now()); - loaded.setEndDate(date); - } - - return loaded; - - } - - @Override - public TripSeine preCreate(String programId) { - - Program program = findByTopiaId(Program.class, programId); - - TripSeine preCreated = getDao().newInstance(); - - Date date = DateUtil.getDay(now()); - preCreated.setStartDate(date); - preCreated.setEndDate(date); - preCreated.setProgram(program); - - return preCreated; - - } - - @Override - public String save(TripSeine toSave) { - String tripSeineId = doSave(null, toSave, new SaveAction<Program, TripSeine>(Program.class, TripSeine.class) { - - @Override - public void beforeSave(String parentId, TripSeine toSave) { - - super.beforeSave(parentId, toSave); - Date startDate = DateUtil.getDay(toSave.getStartDate()); - toSave.setStartDate(startDate); - - // mise a jour de la date de fin - toSave.updateDateFin(); - - } - - @Override - public TripSeine onCreate(Program parent, TripSeine toCreate) { - - Map<String, Object> properties = obtainProperties(TripSeine.class, BinderService.EDIT, toCreate); - TripSeine created = getDao().create(properties); - return created; - - } - - @Override - public TripSeine onUpdate(Program parent, TripSeine toUpdate) { - - TripSeine updated = super.onUpdate(parent, toUpdate); - copyExcluding(TripSeine.class, BinderService.EDIT, toUpdate, updated, TripSeine.PROPERTY_ROUTE); - return updated; - - } - }); - - return tripSeineId; - - } - - @Override - public void delete(String idtoDelete) { - doDelete(null, idtoDelete, new DeleteAction<Program, TripSeine>(Program.class, TripSeine.class)); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/operation/ComputeDataServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/operation/ComputeDataServiceImpl.java deleted file mode 100644 index 7fd4f0e..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/operation/ComputeDataServiceImpl.java +++ /dev/null @@ -1,854 +0,0 @@ -package fr.ird.observe.services.operation; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.Collections2; -import com.google.common.collect.Iterables; -import com.google.common.collect.Sets; -import fr.ird.observe.DecoratorService; -import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.SendMessageAble; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.LengthWeightComputable; -import fr.ird.observe.entities.constants.seine.NonTargetCatchComputedValueSource; -import fr.ird.observe.entities.constants.seine.SchoolType; -import fr.ird.observe.entities.referentiel.LengthWeightParameter; -import fr.ird.observe.entities.referentiel.Ocean; -import fr.ird.observe.entities.referentiel.Sex; -import fr.ird.observe.entities.referentiel.Species; -import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.NonTargetCatch; -import fr.ird.observe.entities.seine.NonTargetLength; -import fr.ird.observe.entities.seine.NonTargetSample; -import fr.ird.observe.entities.seine.Route; -import fr.ird.observe.entities.seine.SetSeine; -import fr.ird.observe.entities.seine.TargetLength; -import fr.ird.observe.entities.seine.TargetSample; -import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.AbstractObserveService; -import fr.ird.observe.services.referential.ReferentialService; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.TopiaEntityHelper; -import org.nuiton.topia.persistence.util.TopiaEntityRef; -import org.nuiton.util.beans.BeanMonitor; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.SortedMap; - -import static org.nuiton.i18n.I18n.t; - -/** - * FIXME A revoir, utiliser un context pour ne pas avoir d'état dans le service + on ne peut plus utiliser de messager - * On retounera un objet de type result. - * - * Created on 5/3/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class ComputeDataServiceImpl extends AbstractObserveService implements ComputeDataService { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ComputeDataServiceImpl.class); - - private static final String MESSAGE_FORMAT_3 = - "[%1$s] %2$s calculé : %3$s (%4$s:%5$s, %6$s:%7$s)"; - - protected final BeanMonitor targetLengthMonitor = new BeanMonitor( - TargetLength.PROPERTY_LENGTH, - TargetLength.PROPERTY_LENGTH_SOURCE, - TargetLength.PROPERTY_WEIGHT, - TargetLength.PROPERTY_WEIGHT_SOURCE); - - protected final BeanMonitor nonTargetLengthMonitor = new BeanMonitor( - NonTargetLength.PROPERTY_LENGTH, - NonTargetLength.PROPERTY_LENGTH_SOURCE, - NonTargetLength.PROPERTY_WEIGHT, - NonTargetLength.PROPERTY_WEIGHT_SOURCE); - - protected final BeanMonitor nonTargetCatchMonitor = new BeanMonitor( - NonTargetCatch.PROPERTY_MEAN_LENGTH, - NonTargetCatch.PROPERTY_MEAN_LENGTH_COMPUTED_SOURCE, - NonTargetCatch.PROPERTY_MEAN_WEIGHT, - NonTargetCatch.PROPERTY_MEAN_WEIGHT_COMPUTED_SOURCE, - NonTargetCatch.PROPERTY_CATCH_WEIGHT, - NonTargetCatch.PROPERTY_CATCH_WEIGHT_COMPUTED_SOURCE, - NonTargetCatch.PROPERTY_TOTAL_COUNT, - NonTargetCatch.PROPERTY_TOTAL_COUNT_COMPUTED_SOURCE - ); - - protected String nonTargetCatcheLabel; - - protected String speciesLabel; - - protected ReferentialService referentialService; - - protected ReferentialService getReferentialService() { - if (referentialService == null) { - referentialService = newService(ReferentialService.class); - } - return referentialService; - } - - protected String getNonTargetCatcheLabel() { - if (nonTargetCatcheLabel == null) { - nonTargetCatcheLabel = t(DecoratorService.getEntityLabel(NonTargetCatch.class)); - } - return nonTargetCatcheLabel; - } - - protected String getSpeciesLabel() { - if (speciesLabel == null) { - speciesLabel = t(DecoratorService.getEntityLabel(Species.class)); - } - return speciesLabel; - - } - - protected void clear() { - - nonTargetLengthMonitor.setBean(null); - targetLengthMonitor.setBean(null); - nonTargetCatchMonitor.setBean(null); - nonTargetCatcheLabel = null; - speciesLabel = null; - - } - - @Override - public void consolidateTrips(SendMessageAble messager, Set<String> tripIds) { - - if (messager == null) { - - messager = new SendMessageAble() { - - @Override - public void sendMessage(String message) { - if (log.isInfoEnabled()) { - log.info(message); - } - } - }; - - } - - TopiaDAO<TripSeine> dao = getDao(TripSeine.class); - - List<TripSeine> toUpdate = new ArrayList<TripSeine>(tripIds.size()); - - for (String tripId : tripIds) { - - if (Entities.isSeineId(tripId)) { - - TripSeine trip = dao.findByTopiaId(tripId); - - boolean needUpdate = consolidateTripSeine(messager, trip); - if (needUpdate) { - - // on met a jour la maree en base - dao.update(trip); - - // on conserve une reference sur la maree mise à jour - toUpdate.add(trip); - - } - - } - - } - - // on commite si quelque chose a ete mise a jour - boolean needCommit = !toUpdate.isEmpty(); - - if (needCommit) { - - messager.sendMessage(t("observe.message.consolidate.save.changes", toUpdate.size())); - getTransaction().commitTransaction(); - - } - - } - - protected boolean consolidateTripSeine(SendMessageAble messager, TripSeine maree) { - - clear(); - - String mareeStr = decorateEntity(maree); - - messager.sendMessage(t("observe.message.consolidate.start.maree", mareeStr)); - - // recuperation des ids des sets de la maree - String[] activityIds = getActivityIds(maree); - - if (activityIds.length == 0) { - - // pas de set dans cette maree, donc rien a sauvegarder - messager.sendMessage(t("observe.message.consolidate.no.activity.from.maree", mareeStr)); - return false; - } - - // recuperation des references vers les activitys avec set - SortedMap<TopiaEntity, List<TopiaEntityRef>> result; - - result = TopiaEntityHelper.detectReferences( - ObserveDAOHelper.getContracts(), activityIds, maree); - - List<ActivitySeine> toUpdate = new ArrayList<ActivitySeine>(result.size()); - for (Map.Entry<TopiaEntity, List<TopiaEntityRef>> e : - result.entrySet()) { - ActivitySeine activitySeine = (ActivitySeine) e.getKey(); - List<TopiaEntityRef> refs = e.getValue(); - TopiaEntityRef ref = refs.get(0); - TopiaEntity[] path = ref.getPath(); - Route route = (Route) path[path.length - 2]; - boolean needUpdate = consolidateActivity(messager, - maree, - route, - activitySeine - ); - if (needUpdate) { - toUpdate.add(activitySeine); - } - } - if (toUpdate.isEmpty()) { - - // rien n'a ete modifie - messager.sendMessage(t("observe.message.consolidate.nothing.to.save.for.maree", mareeStr)); - return false; - - } - - // on devra mettre a jour en base la maree - messager.sendMessage(t("observe.message.consolidate.maree.need.update", mareeStr)); - - return true; - - } - - protected boolean consolidateActivity(SendMessageAble messager, - TripSeine maree, - Route route, - ActivitySeine activity) { - - messager.sendMessage(t("observe.message.consolidate.start.activity", decorateEntity(activity))); - - boolean needUpdate = false; - SetSeine set = activity.getSetSeine(); - SchoolType oldTypeBanc = set.getSchoolType(); - SchoolType newTypeBanc = activity.getSchoolType(); - if (oldTypeBanc == null || oldTypeBanc != newTypeBanc) { - - // le type de banc a change, on doit sauver l'activity - needUpdate = true; - set.setSchoolType(newTypeBanc); - } - - if (!set.isTargetSampleEmpty()) { - - // des echantillons thons trouves - for (TargetSample targetSample : set.getTargetSample()) { - if (!targetSample.isTargetLengthEmpty()) { - for (TargetLength targetLength : - targetSample.getTargetLength()) { - - targetLengthMonitor.setBean(targetLength); - - updateLengthWeightAble( - maree, - route.getDate(), - targetLength.getSpecies(), - null, // pas de gender precise - targetLength - ); - - if (targetLengthMonitor.wasModified()) { - needUpdate = true; - } - } - } - } - } - - if (!set.isNonTargetSampleEmpty()) { - - // des echantillons faunes trouves - for (NonTargetSample nonTargetSample : - set.getNonTargetSample()) { - - if (!nonTargetSample.isNonTargetLengthEmpty()) { - for (NonTargetLength nonTargetLength : - nonTargetSample.getNonTargetLength()) { - - nonTargetLengthMonitor.setBean(nonTargetLength); - - updateLengthWeightAble( - maree, - route.getDate(), - nonTargetLength.getSpecies(), - nonTargetLength.getSex(), - nonTargetLength - ); - if (nonTargetLengthMonitor.wasModified()) { - needUpdate = true; - } - } - } - } - } - - if (!set.isNonTargetCatchEmpty()) { - - // des captures (ou rejets) faunes trouves - for (NonTargetCatch nonTargetCatch : set.getNonTargetCatch()) { - - nonTargetCatchMonitor.setBean(nonTargetCatch); - - // suppression de tous les champs précédemment calculés - - if (nonTargetCatch.isCatchWeightComputed()) { - nonTargetCatch.setCatchWeight(null); - nonTargetCatch.setCatchWeightComputedSource(null); - } - - if (nonTargetCatch.isTotalCountComputed()) { - nonTargetCatch.setTotalCount(null); - nonTargetCatch.setTotalCountComputedSource(null); - } - - if (nonTargetCatch.isMeanWeightComputed()) { - nonTargetCatch.setMeanWeight(null); - nonTargetCatch.setMeanWeightComputedSource(null); - } - - if (nonTargetCatch.isMeanLengthComputed()) { - nonTargetCatch.setMeanLength(null); - nonTargetCatch.setMeanLengthComputedSource(null); - } - - updateNonTargetCatch( - maree, - set, - route.getDate(), - nonTargetCatch - ); - - if (nonTargetCatchMonitor.wasModified()) { - needUpdate = true; - } - } - } - return needUpdate; - } - - protected void updateNonTargetCatch(TripSeine maree, - SetSeine set, - Date jour, - NonTargetCatch nonTargetCatch) { - - final Species species = nonTargetCatch.getSpecies(); - - // récupération du référentiel - LengthWeightParameter parametrage = getReferentialService().findLengthWeightParameter(species, - maree.getOcean(), - null, // pas de sexe spécifié - jour); - - // -- Cas n°1 (calcul uniquement à partir des relations taille - poids) - updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); - - if (allNonTargetCatchDataFilled(nonTargetCatch)) { - - // tout est rempli, plus rien à faire - return; - } - - // répération des échantillon de cette espèce sur les calée - - Collection<NonTargetLength> samples = null; - - if (!set.isNonTargetSampleEmpty()) { - samples = Collections2.filter(set.getNonTargetSample().iterator().next().getNonTargetLength(), new Predicate<NonTargetLength>() { - - @Override - public boolean apply(NonTargetLength input) { - return species.equals(input.getSpecies()); - } - }); - } - - - if (nonTargetCatch.getCatchWeight() != null || nonTargetCatch.getTotalCount() != null) { - - // -- Cas n°2 (pas de taille / poids moyen mais au moins un des deux taille / poids) - computeNonTargetCatchTailleMoyenne(nonTargetCatch, samples, parametrage); - } - - if (allNonTargetCatchDataFilled(nonTargetCatch)) { - - // tout est rempli, plus rien à faire - return; - } - - // -- Cas n°3 (pas de nombre estimé) - - if (nonTargetCatch.getTotalCount() == null) { - - computeNonTargetCatchNombreEstime(nonTargetCatch, samples, parametrage); - - } - - if (allNonTargetCatchDataFilled(nonTargetCatch)) { - - // tout est rempli, plus rien à faire - return; - } - - // -- Cas n°4 (pas de poids moyen, taille moyenne) - - computeNonTargetCatchMeanValues(nonTargetCatch, parametrage); - } - - protected void updateNonTargetCatchByLengthWeightRelation(NonTargetCatch nonTargetCatch, - LengthWeightParameter parametrage) { - - // calcul via le paramétrage taille - poids - updateLengthWeightAble( - nonTargetCatch.getSpecies(), - nonTargetCatch, - parametrage - ); - - // calcule l'un des trois champs poids estimé - nbEstime - poids moyen - updateNonTargetCatchPoidsEstimeNbEstimePoidsMoyen(nonTargetCatch); - - // on ressaye d'appliquer la relation taille - poids au cas où une des - // trois valeurs précédentes a été calculée, on pourrait peut-être - // ainsi en déduire via le paramétrage la taille moyenne - updateLengthWeightAble( - nonTargetCatch.getSpecies(), - nonTargetCatch, - parametrage - ); - } - - protected void updateNonTargetCatchPoidsEstimeNbEstimePoidsMoyen(NonTargetCatch nonTargetCatch) { - - Float meanWeight = nonTargetCatch.getMeanWeight(); - Float catchWeight = nonTargetCatch.getCatchWeight(); - Integer nbEstime = nonTargetCatch.getTotalCount(); - - String entityLabel = getNonTargetCatcheLabel(); - - if (catchWeight == null && nbEstime != null && meanWeight != null) { - - // calcul le weight poids à partir de nb estime et du poids moyen - catchWeight = meanWeight * (float) nbEstime / 1000; - nonTargetCatch.setCatchWeight(catchWeight); - nonTargetCatch.setCatchWeightComputedSource(NonTargetCatchComputedValueSource.FROM_DATA); - String message = String.format(MESSAGE_FORMAT_3, - entityLabel, - t("observe.common.catchWeight"), - catchWeight, - t("observe.common.meanWeight"), - meanWeight, - t("observe.common.totalCount"), - nbEstime); - if (log.isInfoEnabled()) { - log.info(message); - } - } - - if (nbEstime == null && catchWeight != null && meanWeight != null) { - - // calcul le nb estime à partir du poids estime et du poids moyen - nbEstime = (int) ((float) 1000 * catchWeight / meanWeight); - nonTargetCatch.setTotalCount(nbEstime); - nonTargetCatch.setTotalCountComputedSource(NonTargetCatchComputedValueSource.FROM_DATA); - String message = String.format(MESSAGE_FORMAT_3, - entityLabel, - t("observe.common.totalCount"), - nbEstime, - t("observe.common.meanWeight"), - meanWeight, - t("observe.common.catchWeight"), - catchWeight); - if (log.isInfoEnabled()) { - log.info(message); - } - } - - if (meanWeight == null && nbEstime != null && nbEstime != 0 && catchWeight != null && - !NonTargetCatchComputedValueSource.FROM_SAMPLE.equals(nonTargetCatch.getTotalCountComputedSource())) { - - // calcul le poids moyen à partir de nb estime et du poids estime - // uniquement si le nombre estimé ne vient pas des échantillons (voir http://forge.codelutin.com/issues/4670) - - meanWeight = catchWeight * (float) 1000 / (float) nbEstime; - nonTargetCatch.setMeanWeight(meanWeight); - nonTargetCatch.setMeanWeightComputedSource(NonTargetCatchComputedValueSource.FROM_DATA); - String message = String.format(MESSAGE_FORMAT_3, - entityLabel, - t("observe.common.meanWeight"), - meanWeight, - t("observe.common.totalCount"), - nbEstime, - t("observe.common.catchWeight"), - catchWeight); - if (log.isInfoEnabled()) { - log.info(message); - } - } - } - - protected void updateLengthWeightAble(TripSeine maree, - Date jour, - Species species, - Sex sex, - LengthWeightComputable e) { - - Ocean ocean = maree.getOcean(); - - String entityLabel = getSpeciesLabel(); - - Float weight = e.getWeight(); - boolean computePoids = false; - boolean computeTaille = false; - Float taille = e.getLength(); - - if (weight == null && taille != null) { - - // on essaye de calculer le weight - computePoids = true; - } - - if (taille == null && weight != null) { - - // on essaye de calcule la length - computeTaille = true; - } - - if (!computeTaille && !computePoids) { - - // rien a calculer - return; - } - - // recherche du parametrage adequate - LengthWeightParameter parametrage = - getReferentialService().findLengthWeightParameter( - species, - ocean, - sex, - jour - ); - - if (parametrage == null) { - - // aucun parametrage connu - - String message = t("observe.message.consolidate.no.parametrage.found", - t(entityLabel), - decorateEntity(species) - ); - if (log.isWarnEnabled()) { - log.warn(message); - } - return; - } - - if (computeTaille) { - Float newTaille = parametrage.computeLength(weight); - if (newTaille != null) { - - // la taille a ete calculee - String message = - "[" + t(entityLabel) + "] " + - t("observe.message.consolidate.computed.taille", - newTaille, - weight, - parametrage.getWeightLengthFormula(), - parametrage.getCoefficients() - ); - if (log.isInfoEnabled()) { - log.info(message); - } - e.setLength(newTaille); - e.setLengthSource(true); - return; - } - - // la taille n'a pas changee, on peut quitter car il est impossible - // de calculer et la taille et le poids... - return; - } - - // on cherche obligatoirement a calculer le poids - Float newPoids = parametrage.computeWeight(taille); - if (newPoids != null) { - - // le poids a ete calcule - String message = "[" + t(entityLabel) + "] " + - t("observe.message.consolidate.computed.weight", - newPoids, - taille, - parametrage.getLengthWeightFormula(), - parametrage.getCoefficients()); - if (log.isInfoEnabled()) { - log.info(message); - } - e.setWeight(newPoids); - e.setWeightSource(true); - } - } - - protected void updateLengthWeightAble(Species species, - LengthWeightComputable e, - LengthWeightParameter parametrage) { - - String entityLabel = getSpeciesLabel(); - - Float weight = e.getWeight(); - boolean computePoids = false; - boolean computeTaille = false; - Float taille = e.getLength(); - - if (weight == null && taille != null) { - - // on essaye de calculer le weight - computePoids = true; - } - - if (taille == null && weight != null) { - - // on essaye de calcule la length - computeTaille = true; - } - - if (!computeTaille && !computePoids) { - - // rien a calculer - return; - } - - if (parametrage == null) { - - // aucun parametrage connu - - String message = t("observe.message.consolidate.no.parametrage.found", - t(entityLabel), - decorateEntity(species) - ); - if (log.isWarnEnabled()) { - log.warn(message); - } - return; - } - - if (computeTaille) { - Float newTaille = parametrage.computeLength(weight); - if (newTaille != null) { - - // la taille a ete calculee - String message = - "[" + t(entityLabel) + "] " + - t("observe.message.consolidate.computed.taille", - newTaille, - weight, - parametrage.getWeightLengthFormula(), - parametrage.getCoefficients() - ); - if (log.isInfoEnabled()) { - log.info(message); - } - e.setLength(newTaille); - e.setLengthSource(true); - return; - } - - // la taille n'a pas changee, on peut quitter car il est impossible - // de calculer et la taille et le poids... - return; - } - - // on cherche obligatoirement a calculer le weight - Float newPoids = parametrage.computeWeight(taille); - if (newPoids != null) { - - // le weight a ete calcule - String message = "[" + t(entityLabel) + "] " + - t("observe.message.consolidate.computed.weight", - newPoids, - taille, - parametrage.getLengthWeightFormula(), - parametrage.getCoefficients()); - if (log.isInfoEnabled()) { - log.info(message); - } - e.setWeight(newPoids); - e.setWeightSource(true); - } - } - - protected void computeNonTargetCatchTailleMoyenne(NonTargetCatch nonTargetCatch, - Collection<NonTargetLength> samples, - LengthWeightParameter parametrage) { - - Float meanLength = null; - NonTargetCatchComputedValueSource computedSource = null; - - if (CollectionUtils.isNotEmpty(samples)) { - - // on calcul la taille moyenne à partir des échantillons - float totalTaille = 0f; - int nbIndividus = 0; - for (NonTargetLength sample : samples) { - - Integer count = sample.getCount(); - Float length = sample.getLength(); - - if (count != null && length != null) { - nbIndividus += count; - totalTaille += length * count; - } - } - - if (nbIndividus != 0) { - - meanLength = totalTaille / nbIndividus; - - computedSource = NonTargetCatchComputedValueSource.FROM_SAMPLE; - } - } - - if (meanLength == null && parametrage != null) { - - // on prend directement la valeur fournie par le référentiel - - meanLength = parametrage.getMeanLength(); - computedSource = NonTargetCatchComputedValueSource.FROM_REFERENTIEL; - } - - if (meanLength != null) { - - // la taille moyenne a pu etre calculee, on la pousse alors - nonTargetCatch.setMeanLength(meanLength); - nonTargetCatch.setMeanLengthComputedSource(computedSource); - - // on peut aussi relancer la calcul du cas n°1 - updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); - } - - } - - private void computeNonTargetCatchNombreEstime(NonTargetCatch nonTargetCatch, - Collection<NonTargetLength> samples, - LengthWeightParameter parametrage) { - - - if (CollectionUtils.isNotEmpty(samples)) { - - // on calcul la taille moyenne à partir des échantillons - int nbIndividus = 0; - for (NonTargetLength sample : samples) { - - Integer count = sample.getCount(); - - if (count != null) { - nbIndividus += count; - } - } - - if (nbIndividus != 0) { - - nonTargetCatch.setTotalCount(nbIndividus); - nonTargetCatch.setTotalCountComputedSource(NonTargetCatchComputedValueSource.FROM_SAMPLE); - - if (nonTargetCatch.getMeanWeight() != null || nonTargetCatch.getMeanLength() != null) { - - // on peut aussi relancer la calcul du cas n°1 - updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); - } - } - } - } - - private void computeNonTargetCatchMeanValues(NonTargetCatch nonTargetCatch, - LengthWeightParameter parametrage) { - - if (parametrage != null) { - - nonTargetCatch.setMeanLength(parametrage.getMeanLength()); - nonTargetCatch.setMeanLengthComputedSource(NonTargetCatchComputedValueSource.FROM_REFERENTIEL); - - nonTargetCatch.setMeanWeight(parametrage.getMeanWeight()); - nonTargetCatch.setMeanWeightComputedSource(NonTargetCatchComputedValueSource.FROM_REFERENTIEL); - - if (nonTargetCatch.getMeanWeight() != null || nonTargetCatch.getMeanLength() != null) { - - // on peut aussi relancer la calcul du cas n°1 - updateNonTargetCatchByLengthWeightRelation(nonTargetCatch, parametrage); - } - } - } - - //FIXME Use a simple sql query - protected String[] getActivityIds(TripSeine maree) { - List<String> tmpIds = new ArrayList<String>(); - if (!maree.isRouteEmpty()) { - for (Route route : maree.getRoute()) { - if (!route.isActivitySeineEmpty()) { - for (ActivitySeine activitySeine : route.getActivitySeine()) { - if (activitySeine.getSetSeine() != null) { - - // on ne retient que les activitys avec set - tmpIds.add(activitySeine.getTopiaId()); - } - } - } - } - } - String[] result = tmpIds.toArray(new String[tmpIds.size()]); - return result; - } - - protected boolean allNonTargetCatchDataFilled(NonTargetCatch nonTargetCatch) { - return Iterables.all( - Sets.newHashSet(nonTargetCatch.getCatchWeight(), - nonTargetCatch.getTotalCount(), - nonTargetCatch.getMeanWeight(), - nonTargetCatch.getMeanLength()), - Predicates.notNull()); - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/operation/GpsImportServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/operation/GpsImportServiceImpl.java deleted file mode 100644 index af83412..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/operation/GpsImportServiceImpl.java +++ /dev/null @@ -1,153 +0,0 @@ -package fr.ird.observe.services.operation; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.SendMessageAble; -import fr.ird.observe.entities.seine.ActivitySeine; -import fr.ird.observe.entities.seine.Route; -import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.entities.seine.TripSeineDAO; -import fr.ird.observe.business.gps.GPSPoint; -import fr.ird.observe.services.AbstractObserveService; -import org.apache.commons.collections.primitives.ArrayIntList; -import org.apache.commons.collections.primitives.IntIterator; -import org.apache.commons.collections.primitives.IntList; -import org.nuiton.decorator.Decorator; -import org.nuiton.topia.persistence.TopiaDAO; - -import java.util.HashMap; -import java.util.Map; - -/** - * Created on 5/3/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class GpsImportServiceImpl extends AbstractObserveService implements GpsImportService { - - @Override - public Map<ActivitySeine, GPSPoint> getActivitiesForOpenRoute(String openTripSeineId) { - - Map<ActivitySeine, GPSPoint> data; - - - TripSeine openTripSeine = findByTopiaId(TripSeine.class, openTripSeineId); - - if (openTripSeine.isRouteEmpty()) { - - // pas de route sur la maree ouverte - data = null; - - } else { - - data = new HashMap<ActivitySeine, GPSPoint>(); - - for (Route r : openTripSeine.getRoute()) { - if (!r.isActivitySeineEmpty()) { - // on enregistre les actitives - for (ActivitySeine a : r.getActivitySeine()) { - data.put(a, null); - } - } - } - } - - return data; - - } - - @Override - public void applyPoints(Map<ActivitySeine, GPSPoint> data, int[] selectedIndex, SendMessageAble messanger) { - - Decorator<ActivitySeine> dActivity = getDecoratorByType(ActivitySeine.class, "activity-gps"); - Decorator<GPSPoint> dGPSPoint = getDecoratorByType(GPSPoint.class, "gpsPoint-gps"); - - IntList lIndex = new ArrayIntList(selectedIndex.length); - - for (int i : selectedIndex) { - lIndex.add(i); - } - IntIterator indexItr = lIndex.iterator(); - - int currentActivityIndex = 0; - int nextActivityIndex = indexItr.next(); - - TopiaDAO<ActivitySeine> activityDAO = getDao(ActivitySeine.class); - - for (ActivitySeine a : data.keySet()) { - - if (currentActivityIndex == nextActivityIndex) { - - // l'activité courante a ete selectionne - GPSPoint p = data.get(a); - - messanger.sendMessage(t("observe.message.importGPS.apply.point", dGPSPoint.toString(p), dActivity.toString(a))); -// sendMessage(t("observe.message.importGPS.apply.point", p, a.getVesselActivity().getLabel2())); - float latitude = Math.abs(p.getLatitude()); - float longitude = Math.abs(p.getLongitude()); - int quadrant = p.getQuadrant(); - // application de la position - - ActivitySeine aa = activityDAO.findByTopiaId(a.getTopiaId()); - aa.setLatitude(latitude); - aa.setLongitude(longitude); - aa.setQuadrant(quadrant); - //TODO appliquer la vitesse ? - //a.setVesselSpeed(p.getVitesse()); - - // mise a jour de l'activité - - activityDAO.update(aa); - - if (indexItr.hasNext()) { - - // il reste au moins une activité a traiter - // recuperation du prochain index d'activité a traiter - nextActivityIndex = indexItr.next(); - - } else { - - // plus d'activité a traiter - break; - - } - - } - - currentActivityIndex++; - - } - - } - - @Override - public TripSeine getOpenTrip() { - - TripSeineDAO dao = (TripSeineDAO) getDao(TripSeine.class); - TripSeine openTrip = dao.findByOpen(true); - return openTrip; - - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/operation/SynchronizeServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/operation/SynchronizeServiceImpl.java deleted file mode 100644 index a63e645..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/operation/SynchronizeServiceImpl.java +++ /dev/null @@ -1,240 +0,0 @@ -package fr.ird.observe.services.operation; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.DecoratorService; -import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.ObserveEntityEnum; -import fr.ird.observe.SendMessageAble; -import fr.ird.observe.business.db.DataSource; -import fr.ird.observe.business.db.DataSourceException; -import fr.ird.observe.entities.Entities; -import fr.ird.observe.entities.referentiel.ReferenceEntities; -import fr.ird.observe.entities.seine.TripSeine; -import fr.ird.observe.services.AbstractObserveService; -import fr.ird.observe.services.ReplicationService; -import fr.ird.observe.services.referential.ReferentialService; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.jdbc.Work; - -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.DiffState; -import org.nuiton.topia.persistence.util.TopiaEntityHelper; -import org.nuiton.topia.persistence.util.TopiaEntityRef; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedMap; - -import static org.nuiton.i18n.I18n.t; - -/** - * FIXME Utiliser des pattern Request, Result, Context - * FIXME Ne plus utilisers des messanger - * - * Created on 5/3/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class SynchronizeServiceImpl extends AbstractObserveService implements SynchronizeService { - - /** Logger. */ - private static final Log log = LogFactory.getLog(SynchronizeServiceImpl.class); - - @Override - public DiffState.DiffStateMap buildReferentielDifferentiel(final DataSource centralDataSource, final SendMessageAble messanger) { - - final DiffState.DiffStateMap result = DiffState.newMap(); - - final ReferentialService centralReferentialService = newService(centralDataSource, ReferentialService.class); - - ReferenceEntities.walk(new ReferenceEntities.ReferentielWalker() { - - - public <E extends TopiaEntity> void walk(Class<E> contractClass) { - - String s = t(DecoratorService.getEntityLabel(contractClass)); - String message = - t("observe.service.build.synchro.referentiel", s); - if (messanger != null) { - messanger.sendMessage(message); - } - if (log.isInfoEnabled()) { - log.info(message); - } - List<E> list = centralReferentialService.getList(contractClass); - List<E> list2 = getList(contractClass); - DiffState.DiffStateMap tmp; - // recuperation du differentiel pour le type d'entitétmp = - tmp = TopiaEntityHelper.buildDifferentiel(list, list2); - // ajout au resultat - DiffState.addAll(result, tmp); - // on nettoie - DiffState.clear(tmp); - } - }); - DiffState.removeEmptyStates(result); - return result; - - } - - @Override - public SortedMap<TopiaEntity, List<TopiaEntityRef>> detectObsoleteEntities(DiffState.DiffStateMap diff) { - - // detection des entites obsoletes - - List<String> removedList = diff.get(DiffState.REMOVED); - - String[] ids = removedList.toArray(new String[removedList.size()]); - - // detection des entites obsoletes - - // des suppressions ont ete detectees, on doit retrouver - // dans la base locale les entites utilisant ces entites obsoletes - List<TripSeine> marees = getDao(TripSeine.class).findAll(); - - ObserveEntityEnum[] contracts = ObserveDAOHelper.getContracts(); - - SortedMap<TopiaEntity, List<TopiaEntityRef>> result; - - result = TopiaEntityHelper.detectReferences(contracts, ids, marees); - return result; - - } - - @Override - public void saveReferentiel(DataSource centralDataSource, - DiffState.DiffStateMap diff, - List<ObsoleteReferenceToReplace> obsoleteReferencesToReplace, - SendMessageAble messanger) throws DataSourceException { - - Map<TopiaEntity, Long> versionsToUpdate = new HashMap<TopiaEntity, Long>(); - - List<String> ids; - - // ajout des nouvelles entites du referentiel - - ids = diff.get(DiffState.NEW); - if (CollectionUtils.isNotEmpty(ids)) { - - ReplicationService replicationService = newService(ReplicationService.class); - - replicationService.replicateReferentiel(centralDataSource, ids, messanger); - - } - - ReferentialService localReferentialService = newService(ReferentialService.class); - - // mis a jour des entites modifiees - - ids = diff.get(DiffState.MODIFIED); - if (CollectionUtils.isNotEmpty(ids)) { - - ReferentialService service = newService(centralDataSource, ReferentialService.class); - Collection<? extends TopiaEntity> entitiesToCopy = service.loadSimpleEntities(ids); - - localReferentialService.copySimpleEntities(entitiesToCopy); - - } - - // mise à jour des données utilisateurs (remplacements d'objets obsolètes) - - for (ObsoleteReferenceToReplace referenceToReplace : obsoleteReferencesToReplace) { - - String message = t("observe.synchro.replaceObsolete.object", referenceToReplace.getObsoleteId()); - messanger.sendMessage(message); - - localReferentialService.replaceObsoleteReference(referenceToReplace); - - } - - // si on ne commite pas ici, les modifications utilisateurs sont perdues - getTransaction().commitTransaction(); - - // suppression des entités obsoletes de la base source - - ids = diff.get(DiffState.REMOVED); - if (CollectionUtils.isNotEmpty(ids)) { - - localReferentialService.deleteEntities(ids); - - } - - if (MapUtils.isNotEmpty(versionsToUpdate)) { - - // on applique le patch sur les versions pour bien avoir - // la bonne version de topiaversion et pas seulement un incrément - // de 1 puisque ce champs est géré par hibernate et qu'il ne nous laisse - // pas la possibilité de choisir la valeur qu'on veut attribuer au champs... - patchTopiaVersions(versionsToUpdate); - } - - getTransaction().commitTransaction(); - - } - - private static final String UPDATE_VERSION_PATTERN = "UPDATE %1$s SET topiaversion = %2$d WHERE topiaid='%3$s';\n"; - - protected void patchTopiaVersions(Map<TopiaEntity, Long> versionsToUpdate) { - - final StringBuilder buffer = new StringBuilder(); - - for (Map.Entry<TopiaEntity, Long> entry : - versionsToUpdate.entrySet()) { - TopiaEntity entity = entry.getKey(); - String id = entity.getTopiaId(); - Long version = entry.getValue(); - String tableName = Entities.getTableName(entity); - buffer.append(String.format(UPDATE_VERSION_PATTERN, tableName, version, id)); - - } - ((TopiaContextImplementor) getTransaction()).getHibernate().doWork(new Work() { - - @Override - public void execute(Connection connection) throws SQLException { - String sql = buffer.toString(); - PreparedStatement sta = connection.prepareStatement(sql); - try { - if (log.isDebugEnabled()) { - log.debug("Will execute sql code :\n" + sql); - } - sta.executeUpdate(); - } finally { - sta.close(); - } - } - }); - } - - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/operation/ValidationServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/operation/ValidationServiceImpl.java deleted file mode 100644 index b636e79..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/operation/ValidationServiceImpl.java +++ /dev/null @@ -1,116 +0,0 @@ -package fr.ird.observe.services.operation; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import fr.ird.observe.DecoratorService; -import fr.ird.observe.SendMessageAble; -import fr.ird.observe.entities.Trip; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.services.AbstractObserveService; -import fr.ird.observe.services.data.TripService; -import fr.ird.observe.services.data.DataSelectionModel; -import fr.ird.observe.business.validation.ValidationMessageDetector; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; - -import java.util.List; -import java.util.Set; - -import static org.nuiton.i18n.I18n.t; - -/** - * //FIXME A revoir, on doit utiliser un pattern de Request, Context et Result - * //FIXME Le detector doit être interne - * Created on 5/3/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class ValidationServiceImpl extends AbstractObserveService implements ValidationService { - - @Override - public void validate(SendMessageAble messager, ValidationMessageDetector detector, DataSelectionModel dataModel) { - - if (dataModel.isUseReferentiel()) { - - // validation des referentiels selectionnes - - validateReferentiel(messager, detector, dataModel); - } - - if (dataModel.isUseData()) { - - // validation des donnees observateur selectionnee - - validateData(messager, detector, dataModel); - } - - } - - protected void validateData(SendMessageAble messager, - ValidationMessageDetector detector, - DataSelectionModel dataModel) { - - Set<String> tripIds = dataModel.getSelectedData(); - - TripService tripService = newService(TripService.class); - - for (String tripId : tripIds) { - - Trip trip = tripService.getTrip(tripId); - Program program = trip.getProgram(); - - messager.sendMessage(t("observe.message.validation.start.maree", decorateEntity(trip), decorateEntity(program))); - detector.detectMessages(trip); - - } - - } - - protected void validateReferentiel(SendMessageAble messager, - ValidationMessageDetector detector, - DataSelectionModel dataModel) { - - Set<Class<?>> classes = dataModel.getSelectedReferentiel(); - - for (Class<?> klass : classes) { - - Class<? extends TopiaEntity> refClass = (Class<? extends TopiaEntity>) klass; - TopiaDAO<? extends TopiaEntity> dao = getDao(refClass); - - List<String> ids = dao.findAllIds(); - String entityLabel = t(DecoratorService.getEntityLabel(klass)); - messager.sendMessage(t("observe.message.validation.start.referentiel", entityLabel, ids.size())); - - for (String id : ids) { - TopiaEntity entity = dao.findByTopiaId(id); - detector.detectMessages(entity); - } - - ids.clear(); - - } - - } - -} diff --git a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/referential/ReferentialServiceImpl.java deleted file mode 100644 index 8193714..0000000 --- a/observe-services-topia/src/main/fromRefactor/fr/ird/observe/services/referential/ReferentialServiceImpl.java +++ /dev/null @@ -1,540 +0,0 @@ -package fr.ird.observe.services.referential; - -/* - * #%L - * ObServe :: Services ToPIA Implementation - * %% - * Copyright (C) 2008 - 2015 IRD, Codelutin, Tony Chemit - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import fr.ird.observe.BinderService; -import fr.ird.observe.ObserveTechnicalException; -import fr.ird.observe.entities.constants.ReferenceLocale; -import fr.ird.observe.entities.constants.ReferenceStatus; -import fr.ird.observe.entities.referentiel.LengthWeightParameter; -import fr.ird.observe.entities.referentiel.LengthWeightParameterDAO; -import fr.ird.observe.entities.referentiel.LengthWeightParemeterHelper; -import fr.ird.observe.entities.referentiel.Ocean; -import fr.ird.observe.entities.referentiel.Program; -import fr.ird.observe.entities.referentiel.ProgramDAO; -import fr.ird.observe.entities.referentiel.Programs; -import fr.ird.observe.entities.referentiel.ReferenceEntity; -import fr.ird.observe.entities.referentiel.Sex; -import fr.ird.observe.entities.referentiel.SexDAO; -import fr.ird.observe.entities.referentiel.Species; -import fr.ird.observe.entities.referentiel.SpeciesList; -import fr.ird.observe.entities.referentiel.seine.WeightCategory; -import fr.ird.observe.services.AbstractObserveService; -import fr.ird.observe.services.operation.ObsoleteReferenceToReplace; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.jxpath.JXPathContext; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.decorator.Decorator; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.EntityListUpdator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; -import org.nuiton.topia.persistence.util.TopiaEntityHelper; -import org.nuiton.topia.persistence.util.TopiaEntityRef; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Created on 4/25/15. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 4.0 - */ -public class ReferentialServiceImpl extends AbstractObserveService implements ReferentialService { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ReferentialServiceImpl.class); - - @Override - public List<Program> getAllProgramStub() { - - ProgramDAO dao = (ProgramDAO) getDao(Program.class); - ReferenceLocale referentielLocale = getReferentielLocale(); - List<Program> result = dao.findAllStub(referentielLocale); - return result; - - } - - @Override - public int getProgramPosition(String programId) { - - List<Program> allProgramStub = getAllProgramStub(); - Program programStub = getProgramStub(programId); - int result = 0; - if (CollectionUtils.isNotEmpty(allProgramStub)) { - Programs.sort(allProgramStub); - result = allProgramStub.indexOf(programStub); - } - return result; - - } - - @Override - public Program getProgramStub(String programId) { - - ProgramDAO dao = (ProgramDAO) getDao(Program.class); - ReferenceLocale referentielLocale = getReferentielLocale(); - Program result = dao.findStubByTopiaId(programId, referentielLocale); - return result; - - } - - @Override - public <E extends ReferenceEntity> List<E> loadListForEdit(Class<E> entityType) { - - List<E> entities = getDao(entityType).findAll(); - TopiaEntityBinder<E> binder = getBinder(entityType, BinderService.EDIT); - for (E entity : entities) { - binder.obtainProperties(entity); - } - return Lists.newArrayList(entities); - - } - - @Override - public <E extends ReferenceEntity> List<E> loadAndDecorateList(Class<E> entityType) { - - List<E> entities = getDao(entityType).findAll(); - decorate(entityType, entities); - return Lists.newArrayList(entities); - - } - - @Override - public <E extends ReferenceEntity> E loadAndDecorate(Class<E> entityType, String topiaId) { - - E entity = findByTopiaId(entityType, topiaId); - decorate(entityType, entity); - return entity; - - } - - @Override - public List<Species> loadDecoratedSpecies(String speciesListCode) { - - List<Species> speciess = new ArrayList<Species>(); - - SpeciesList speciesList = findByTopiaId(SpeciesList.class, speciesListCode); - - speciess.addAll(speciesList.getSpecies()); - - decorate(Species.class, speciess); - - return speciess; - - } - - @Override - public List<WeightCategory> loadDecoratedWeightCategory() { - - List<WeightCategory> weightCategories = loadAndDecorateList(WeightCategory.class); - Decorator<Species> speciesDecorator = getDecoratorByType(Species.class, null); - for (WeightCategory weightCategory : weightCategories) { - speciesDecorator.toString(weightCategory.getSpecies()); - } - return weightCategories; - } - - @Override - public void loadDecoratedWeightCategory(WeightCategory weightCategory) { - - decorate(WeightCategory.class, weightCategory); - decorate(Species.class, weightCategory.getSpecies()); - - } - - @Override - public Collection<? extends TopiaEntity> loadSimpleEntities(Collection<String> entityIds) { - - Collection<TopiaEntity> result = new ArrayList<TopiaEntity>(); - - for (String entityId : entityIds) { - - TopiaEntity entityToLoad = getTransaction().findByTopiaId(entityId); - TopiaDAO<TopiaEntity> dao = getDao(entityToLoad); - TopiaEntity entityLoaded = dao.newInstance(); - loadEntity(entityToLoad, entityLoaded, true); - - result.add(entityLoaded); - - } - - return result; - - } - - @Override - public Set<String> getSpeciesListSpeciesIds(String speciesListId) { - - SpeciesList speciesList = findByTopiaId(SpeciesList.class, speciesListId); - - Set<String> ids = Sets.newHashSet(TopiaEntityHelper.getTopiaIdList(speciesList.getSpecies())); - - return ids; - - } - - /** - * Recherche d'un {@link LengthWeightParameter} à partir des paramètres donnés. - * - * La recherche peut ne peut être aussi exacte que les paramètres donnés : - * - * Dans le cas d'une espèce faune, si non trouvé alors on recherche sur son - * speciesGroup d'espèce. - * - * Si non trouvé pour l'océan donné (et que celui-ci est non null), alors on - * recherche avec un ocean vide. - * - * Si non trouvé sur le gender (et que le gender n'est pas indéterminé) , alors - * on recherche avec le gender indéterminé (gender=0). - * - * @param species l'espèce sur lequel on recherche le paramétrage - * @param ocean l'ocean recherché (peut être null) - * @param sex le sexe recherché (on essayera sans sexe (sexe.code=0) si non trouvé) - * @param date le jour recherché - * @return le paramétrage adéquate - * @since 1.5 - */ - public LengthWeightParameter findLengthWeightParameter(Species species, Ocean ocean, Sex sex, Date date) throws ObserveTechnicalException { - - LengthWeightParameterDAO dao = (LengthWeightParameterDAO) getDao(LengthWeightParameter.class); - List<LengthWeightParameter> list = dao.findAllBySpecies(species); - - if (CollectionUtils.isEmpty(list)) { - - // aucun parametrage pour le type donne - return null; - - } - - // filtrage par ocean - list = LengthWeightParemeterHelper.filterByOcean(list, ocean); - - if (CollectionUtils.isEmpty(list) && ocean != null) { - - // filtre par ocean null - list = LengthWeightParemeterHelper.filterByOcean(list, null); - - } - - if (CollectionUtils.isEmpty(list)) { - - // pas d'ocean adequate - return null; - - } - - // filtrage par sexe - list = LengthWeightParemeterHelper.filterBySexe(list, sex); - - if (CollectionUtils.isEmpty(list)) { - - // Sex with code 0 - Sex unkwonSex = ((SexDAO) getDao(Sex.class)).getUnknownSex(); - - if (unkwonSex.equals(sex)) { - - // filtrage par sexe indetermine - list = LengthWeightParemeterHelper.filterBySexe(list, unkwonSex); - - } - - } - - if (CollectionUtils.isEmpty(list)) { - - // pas de sexe adequate - return null; - - } - - // filtrage par startDate de validite - list = LengthWeightParemeterHelper.filterByDateDebutValidite(list, date); - - if (CollectionUtils.isEmpty(list)) { - - // pas de date de debut adequate - return null; - - } - - // filtrage par endDate de validite - list = LengthWeightParemeterHelper.filterByDateFinValidite(list, date); - - if (CollectionUtils.isEmpty(list)) { - - // pas de date de fin adequate - return null; - - } - - // au final il ne devrait en rester qu'un - - if (list.size() > 1) { - - StringBuilder sb = new StringBuilder("Il existe plusieurs paramétrages possibles pour les données suivantes :"); - sb.append("\nEspece : "); - sb.append(decorateEntity(species)); - sb.append("\nOcean : "); - sb.append(decorateEntity(ocean)); - sb.append("\nSex : "); - sb.append(decorateEntity(sex)); - sb.append("\nDate : ").append(date); - sb.append("\nParamétrages trouvés : "); - for (LengthWeightParameter p : list) { - sb.append("\n - ").append(decorateEntity(p)); - } - - //FIXME Use a specific exception for this - throw new ObserveTechnicalException(sb.toString()); - - } - - LengthWeightParameter result = list.get(0); - if (log.isDebugEnabled()) { - - StringBuilder sb = new StringBuilder("Paramétrage trouvé pour les données suivantes :"); - sb.append("\nEspece : "); - sb.append(decorateEntity(species)); - sb.append("\nOcean : "); - sb.append(decorateEntity(ocean)); - sb.append("\nSex : "); - sb.append(decorateEntity(sex)); - sb.append("\nDate : ").append(date); - sb.append("\nParamétrage: ").append(decorateEntity(result)); - log.debug(sb.toString()); - - } - - return result; - - } - - @Override - public <R extends ReferenceEntity> R preCreate(Class<R> entityType) { - - R preCreated = getDao(entityType).newInstance(); - preCreated.setStatus(ReferenceStatus.enabled); - return preCreated; - - } - - @Override - public <R extends ReferenceEntity> String save(R toSave) { - - Class<R> entityType = getEntityContractClass(toSave); - - String referentialId = doSave(null, toSave, new SaveAction<R, R>(entityType, entityType) { - - @Override - public R onCreate(R parent, R toCreate) { - - Map<String, Object> properties = obtainProperties(entityClass, BinderService.EDIT, toCreate); - R created = getDao(entityClass).create(properties); - - return created; - - } - - @Override - public R onUpdate(R parent, R toUpdate) { - - R updated = super.onUpdate(parent, toUpdate); - copy(entityClass, BinderService.EDIT, toUpdate, updated); - return updated; - - } - }); - - return referentialId; - - } - - @Override - public <R extends ReferenceEntity> void delete(Class<R> entityType, String referentialId) { - - doDelete(null, referentialId, new DeleteAction<R, R>(entityType, entityType)); - - } - - @Override - public void deleteEntities(Collection<String> entityIds) { - - for (String entityId : entityIds) { - - TopiaEntity entityToDelete = getTransaction().findByTopiaId(entityId); - Class<TopiaEntity> entityType = getEntityContractClass(entityToDelete); - TopiaDAO<TopiaEntity> dao = getDao(entityType); - dao.delete(entityToDelete); - - } - } - - @Override - public void copySimpleEntities(Collection<? extends TopiaEntity> entities) { - - for (TopiaEntity entity : entities) { - - TopiaDAO<TopiaEntity> dao = getDao(entity); - - TopiaEntity entityLoaded = dao.findByTopiaId(entity.getTopiaId()); - loadEntity(entity, entityLoaded, false); - - } - - } - - @Override - public void replaceObsoleteReference(ObsoleteReferenceToReplace action) { - - String obsoleteId = action.getObsoleteId(); - String safeId = action.getSafeId(); - TopiaEntityRef[] refs = action.getRefs(); - - if (log.isInfoEnabled()) { - log.info("load obsolete object " + obsoleteId); - } - - if (log.isInfoEnabled()) { - log.info("load safe object " + safeId); - } - - TopiaEntity safeRef = getTransaction().findByTopiaId(safeId); - - // on remplace les references - for (TopiaEntityRef ref : refs) { - - TopiaEntity invoker = ref.getInvoker(); - - if (invoker == null) { - throw new NullPointerException("can not have a null invoker in " + ref); - } - - TopiaDAO<TopiaEntity> dao = getDao(invoker); - - - if (log.isInfoEnabled()) { - log.info("load invoker object " + invoker.getTopiaId()); - } - - invoker = dao.findByTopiaId(invoker.getTopiaId()); - - // switch entity - - String path = ref.getInvokerProperty(); - - JXPathContext jxcontext = JXPathContext.newContext(invoker); - - TopiaEntity oldValue = (TopiaEntity) jxcontext.getValue(path); - - if (log.isDebugEnabled()) { - log.debug("property to switch " + path + " old : " + - oldValue); - } - - if (log.isInfoEnabled()) { - log.info("change path : " + path); - log.info("old value : " + oldValue.getTopiaId()); - } - - jxcontext.setValue(path, safeRef); - - TopiaEntity newValue = (TopiaEntity) jxcontext.getValue(path); - - if (log.isInfoEnabled()) { - log.info("new value : " + newValue.getTopiaId()); - } - if (log.isDebugEnabled()) { - log.debug("property to switch " + path + " new : " + - safeRef); - log.debug("property to switch " + path + " new Check : " + - newValue); - } - - dao.update(invoker); - - } - - } - - protected <E extends TopiaEntity> void loadEntity(E source, E target, boolean tech) { - - getBinderService().simpleCopy(source, target, tech); - - if (source instanceof Species) { - - // Need also to bind ocean - loadAssociation(Species.class, Ocean.class, Species.PROPERTY_OCEAN, (Species) source, (Species) target); - - } else if (source instanceof SpeciesList) { - - // Need also to bind species - loadAssociation(SpeciesList.class, Species.class, SpeciesList.PROPERTY_SPECIES, (SpeciesList) source, (SpeciesList) target); - - } - - } - - public <E extends TopiaEntity, C extends TopiaEntity> void loadAssociation(Class<E> entityType, - Class<C> childEntityType, - String propertyName, - E source, - E target) { - - EntityListUpdator<E, C> listUpdator = EntityListUpdator.newEntityListUpdator(entityType, childEntityType, propertyName); - - int size = listUpdator.size(source); - - List<C> targetList = Lists.newArrayListWithCapacity(size); - - if (size > 0) { - - TopiaDAO<C> dao = getDao(childEntityType); - - Collection<C> sourceList = listUpdator.getChilds(source); - - for (C childToLoad : sourceList) { - - C childLoaded = dao.newInstance(); - childLoaded.setTopiaId(childToLoad.getTopiaId()); - childLoaded.setTopiaVersion(childToLoad.getTopiaVersion()); - childLoaded.setTopiaCreateDate(childToLoad.getTopiaCreateDate()); - targetList.add(childLoaded); - - } - - } - - listUpdator.setChilds(target, targetList); - - } - -} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm