This is an automated email from the git hooks/post-receive script. New commit to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git commit 7b6c1256fd39acd96fde603b37a12b8c46e694d6 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat May 2 00:14:16 2015 +0200 - Suppression dans les handlers to code avec les transactions - Amélioration du code dans les services - faire fonctionner la sauvegarde de CatchLongine refs #7017 --- .../main/java/fr/ird/observe/BinderService.java | 55 ++- .../java/fr/ird/observe/entities/Entities.java | 4 + .../observe/services/AbstractObserveService.java | 53 +-- .../observe/services/ObserveServiceFactory.java | 32 +- .../data/longline/ActivityLonglineServiceImpl.java | 24 -- .../BranchlinesCompositionServiceImpl.java | 3 +- .../data/longline/CatchLonglineServiceImpl.java | 143 +++++++- .../data/longline/EncounterServiceImpl.java | 3 +- .../longline/FloatlinesCompositionServiceImpl.java | 4 +- .../GearUseFeaturesLonglineServiceImpl.java | 132 ++++--- .../data/longline/HooksCompositionServiceImpl.java | 1 + .../longline/LonglineDetailCompositionService.java | 11 + .../LonglineDetailCompositionServiceImpl.java | 182 ++++++++++ .../longline/LonglineGlobalCompositionService.java | 3 +- .../LonglineGlobalCompositionServiceImpl.java | 33 +- .../data/longline/SensorUsedServiceImpl.java | 1 - .../services/data/longline/SetLonglineService.java | 11 +- .../data/longline/SetLonglineServiceImpl.java | 56 ++- .../services/data/longline/TdrServiceImpl.java | 1 - .../services/data/seine/ActivitySeineService.java | 15 - .../data/seine/ActivitySeineServiceImpl.java | 115 +----- .../services/data/seine/FloatingObjectService.java | 21 -- .../data/seine/FloatingObjectServiceImpl.java | 193 ++++------ .../data/seine/GearUseFeaturesSeineService.java | 6 - .../seine/GearUseFeaturesSeineServiceImpl.java | 125 ++++--- .../services/data/seine/NonTargetCatchService.java | 6 - .../data/seine/NonTargetCatchServiceImpl.java | 23 +- .../data/seine/NonTargetLengthService.java | 6 - .../data/seine/NonTargetLengthServiceImpl.java | 18 +- .../data/seine/NonTargetSampleServiceImpl.java | 49 ++- .../data/seine/ObjectObservedSpeciesService.java | 3 - .../seine/ObjectObservedSpeciesServiceImpl.java | 8 +- .../data/seine/ObjectSchoolEstimateService.java | 3 - .../seine/ObjectSchoolEstimateServiceImpl.java | 6 +- .../services/data/seine/SchoolEstimateService.java | 4 - .../data/seine/SchoolEstimateServiceImpl.java | 6 +- .../services/data/seine/TargetLengthService.java | 7 - .../data/seine/TargetLengthServiceImpl.java | 17 +- .../data/seine/TargetSampleServiceImpl.java | 15 +- .../services/referential/ReferentialService.java | 3 + .../referential/ReferentialServiceImpl.java | 12 + .../ird/observe/ui/content/ContentUIHandler.java | 177 ++------- .../content/impl/longline/BranchlineUIHandler.java | 14 +- .../LonglineDetailCompositionUIHandler.java | 165 +-------- .../LonglineGlobalCompositionUIHandler.java | 33 +- .../impl/longline/SetLonglineUIHandler.java | 135 +++---- .../ActivitySeineObservedSystemUIHandler.java | 11 +- ...ngObjectTransmittingBuoyOperationUIHandler.java | 112 +----- ...tingObjectTransmittingBuoyOperationUIModel.java | 31 +- .../impl/seine/FloatingObjectUIHandler.java | 14 +- .../ui/content/impl/seine/SetSeineUIHandler.java | 12 - .../ui/content/open/ContentOpenableUIHandler.java | 12 - .../open/impl/seine/ActivitySeineUIHandler.java | 9 +- .../ui/content/ref/ContentReferenceUIHandler.java | 12 - .../ui/content/table/ContentTableUIHandler.java | 329 +++++++++-------- .../impl/longline/BaitsCompositionUIHandler.java | 9 +- .../longline/BranchlinesCompositionUIHandler.java | 10 +- .../impl/longline/CatchLonglineUIHandler.java | 182 +++------- .../table/impl/longline/EncounterUIHandler.java | 9 +- .../longline/FloatlinesCompositionUIHandler.java | 9 +- .../longline/GearUseFeaturesLonglineUIHandler.java | 8 +- .../impl/longline/HooksCompositionUIHandler.java | 10 +- .../table/impl/longline/SensorUsedUIHandler.java | 10 +- .../content/table/impl/longline/TdrUIHandler.java | 8 +- .../impl/seine/GearUseFeaturesSeineUIHandler.java | 17 +- .../table/impl/seine/NonTargetCatchUIHandler.java | 58 +-- .../table/impl/seine/NonTargetSampleUIHandler.java | 58 ++- .../impl/seine/ObjectObservedSpeciesUIHandler.java | 14 +- .../impl/seine/ObjectSchoolEstimateUIHandler.java | 14 +- .../table/impl/seine/SchoolEstimateUIHandler.java | 9 +- .../table/impl/seine/TargetCatchUIHandler.java | 190 +++++----- .../impl/seine/TargetDiscardCatchUIHandler.java | 394 ++++++++++----------- .../table/impl/seine/TargetSampleUIHandler.java | 34 +- 73 files changed, 1507 insertions(+), 2015 deletions(-) diff --git a/observe-business/src/main/java/fr/ird/observe/BinderService.java b/observe-business/src/main/java/fr/ird/observe/BinderService.java index 701b12f..0874332 100644 --- a/observe-business/src/main/java/fr/ird/observe/BinderService.java +++ b/observe-business/src/main/java/fr/ird/observe/BinderService.java @@ -115,6 +115,8 @@ 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.TargetSample; +import fr.ird.observe.entities.seine.TransmittingBuoy; +import fr.ird.observe.entities.seine.TransmittingBuoyImpl; import fr.ird.observe.entities.seine.TripSeine; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -167,7 +169,7 @@ public class BinderService { public static final String EDIT_OBJECT_OBSERVED_SPECIES = "editObjectObservedSpecies"; - public static final String EDIT_OBJECT_OPERATION = "editObjectOperation"; + public static final String EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY = "editObjectOperation"; public static final String EDIT_OBSERVED_SYSTEM = "editObservedSystem"; @@ -538,13 +540,41 @@ public class BinderService { ActivitySeine.PROPERTY_QUADRANT, ActivitySeine.PROPERTY_LATITUDE, ActivitySeine.PROPERTY_LONGITUDE, + ActivitySeine.PROPERTY_ERS_ID, ActivitySeine.PROPERTY_TIME, ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, + ActivitySeine.PROPERTY_COMMENT, + ActivitySeine.PROPERTY_VESSEL_SPEED, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE, ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, + ActivitySeine.PROPERTY_SURROUNDING_ACTIVITY, ActivitySeine.PROPERTY_WIND, - ActivitySeine.PROPERTY_OPEN); + ActivitySeine.PROPERTY_DETECTION_MODE, + ActivitySeine.PROPERTY_SET_SEINE, + ActivitySeine.PROPERTY_FLOATING_OBJECT, + ActivitySeine.PROPERTY_OPEN, + ActivitySeine.PROPERTY_CURRENT_FPA_ZONE, + ActivitySeine.PROPERTY_PREVIOUS_FPA_ZONE, + ActivitySeine.PROPERTY_NEXT_FPA_ZONE); + + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_OBSERVED_SYSTEM); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_FLOATING_OBJECT); + //FIXME this one was used ? +// BinderModelBuilder<ActivitySeine, ActivitySeine> builder = newBinderBuilder( +// ActivitySeine.class, +// ActivitySeine.PROPERTY_QUADRANT, +// ActivitySeine.PROPERTY_LATITUDE, +// ActivitySeine.PROPERTY_LONGITUDE, +// ActivitySeine.PROPERTY_TIME, +// ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, +// ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, +// ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, +// ActivitySeine.PROPERTY_WIND, +// ActivitySeine.PROPERTY_OPEN); +// registerTopiaBinder(ActivitySeine.class, builder, EDIT); } @@ -644,10 +674,29 @@ public class BinderService { BinderModelBuilder<FloatingObject, FloatingObject> builder = newBinderBuilder( FloatingObject.class, + FloatingObject.PROPERTY_TRANSMITTING_BUOY, FloatingObject.PROPERTY_OBJECT_OPERATION, FloatingObject.PROPERTY_COMMENT); - registerTopiaBinder(FloatingObject.class, builder, EDIT_OBJECT_OPERATION); + builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, FloatingObject.PROPERTY_TRANSMITTING_BUOY); + + registerTopiaBinder(FloatingObject.class, builder, EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY); + + } + + { + + BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> builder = newBinderBuilder( + TransmittingBuoy.class, + TransmittingBuoy.PROPERTY_CODE, + TransmittingBuoy.PROPERTY_OWNERSHIP, + TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_TYPE, + TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_OPERATION, + TransmittingBuoy.PROPERTY_BRAND, + TransmittingBuoy.PROPERTY_COUNTRY); + + TopiaEntityBinder<TransmittingBuoy> binder = registerTopiaBinder(TransmittingBuoy.class, builder, EDIT); + binder.setEmpty(new TransmittingBuoyImpl()); } diff --git a/observe-entities/src/main/java/fr/ird/observe/entities/Entities.java b/observe-entities/src/main/java/fr/ird/observe/entities/Entities.java index f69517c..822d926 100644 --- a/observe-entities/src/main/java/fr/ird/observe/entities/Entities.java +++ b/observe-entities/src/main/java/fr/ird/observe/entities/Entities.java @@ -365,4 +365,8 @@ public class Entities { return id.contains("Longline"); } + public static <E extends TopiaEntity> boolean isNew(E entity) { + return entity.getTopiaId()==null; + } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java index d9f5bf5..2f2df05 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/AbstractObserveService.java @@ -7,11 +7,9 @@ import fr.ird.observe.BinderService; import fr.ird.observe.IObserveConfig; import fr.ird.observe.ObserveEntityEnum; import fr.ird.observe.ObserveServiceHelper; -import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.EntityMap; import fr.ird.observe.entities.constants.ReferenceLocale; -import org.apache.commons.lang3.reflect.ConstructorUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; @@ -143,7 +141,7 @@ public abstract class AbstractObserveService implements ObserveService { 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) { + 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); } @@ -246,7 +244,7 @@ public abstract class AbstractObserveService implements ObserveService { checkNotNullAndExistingEntity(PARENT_BEAN, parent); } - if (toSave.getTopiaId() == null) { + if (Entities.isNew(toSave)) { checkNotNullAndNoneExistingEntity(BEAN, toSave); @@ -342,7 +340,7 @@ public abstract class AbstractObserveService implements ObserveService { } - public <P extends TopiaEntity, E extends TopiaEntity> void doSaveList(P parentToSave, SaveCollectionAction<P, E> saveCollectionAction ) { + public <P extends TopiaEntity, E extends TopiaEntity> void doSaveList(P parentToSave, SaveCollectionAction<P, E> saveCollectionAction) { Collection<E> childrenToSave = saveCollectionAction.listUpdator.getChilds(parentToSave); @@ -356,13 +354,11 @@ public abstract class AbstractObserveService implements ObserveService { saveCollectionAction.listUpdator.removeAll(parentSaved); - TopiaDAO<E> dao = getDao(saveCollectionAction.entityClass); - for (E childToSave : childrenToSave) { E childSaved; - if (childToSave.getTopiaId() == null) { + if (Entities.isNew(childToSave)) { // creation du fils childSaved = saveCollectionAction.onCreateChild(childToSave); @@ -370,16 +366,14 @@ public abstract class AbstractObserveService implements ObserveService { } else { // mise a jour du fils - childSaved = dao.findByTopiaId(childToSave.getTopiaId()); + childSaved = saveCollectionAction.onUpdateChild(childToSave); - childSaved = saveCollectionAction.onUpdateChild(childToSave, childSaved); } saveCollectionAction.listUpdator.addToList(parentSaved, childSaved); } - // on donne la main aux implantations pour faire des traitements - // supplémentaires + // on donne la main aux implantations pour faire des traitements supplémentaires saveCollectionAction.onUpdateFinalize(parentToSave, oldChilds); @@ -412,7 +406,7 @@ public abstract class AbstractObserveService implements ObserveService { } public void onUpdateFinalize(P parent, Collection<E> oldChilds) throws TopiaException { - // par défaut, rien à faire + // par défaut, rien à faire après la sauvegarde de la liste } public P onUpdateParent(P parentToSave, P parentSaved) { @@ -431,17 +425,21 @@ public abstract class AbstractObserveService implements ObserveService { } - public E onUpdateChild(E childToSave, E childSaved) { + public E onUpdateChild(E childToSave) { + + TopiaDAO<E> dao = getDao(entityClass); + + E childSaved = dao.findByTopiaId(childToSave.getTopiaId()); childBinder.load(childToSave, childSaved, true); - childSaved = getDao(entityClass).update(childSaved); + childSaved = dao.update(childSaved); + return childSaved; } } - public <E extends TopiaEntity> void checkNotNullAndNoneExistingEntity(String variableName, E entity) { TopiaEntityHelper.checkNotNullAndNoneExistingEntity(variableName, entity); } @@ -453,29 +451,10 @@ public abstract class AbstractObserveService implements ObserveService { protected <S extends ObserveService> S newService(Class<S> serviceType) { - Class<S> serviceImpl; - try { - //FIXME Cela devrait dépendre de la datasource ? - 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); - } + S service = ObserveServiceFactory.newService(serviceType, serviceContext); + return service; } - - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java index 79f76ef..3e6af98 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java +++ b/observe-services/src/main/java/fr/ird/observe/services/ObserveServiceFactory.java @@ -56,7 +56,7 @@ public class ObserveServiceFactory implements Closeable { public ObserveService load(Class<? extends ObserveService> key) throws Exception { Preconditions.checkNotNull(key, "service key can't be null"); Preconditions.checkNotNull(dataSource, "can't ask a service if not datasource is setted"); - ObserveService service = createService(key, ObserveServiceFactory.this.applicationContext, ObserveServiceFactory.this.dataSource); + ObserveService service = newProxyService(key, ObserveServiceFactory.this.applicationContext, ObserveServiceFactory.this.dataSource); if (log.isDebugEnabled()) { log.debug("New service " + service); } @@ -102,7 +102,7 @@ public class ObserveServiceFactory implements Closeable { services.invalidateAll(); } - protected <S extends ObserveService> S createService(Class<S> serviceType, ObserveApplicationContext applicationContext, DataSource dataSource) { + public <S extends ObserveService> S newProxyService(Class<S> serviceType, ObserveApplicationContext applicationContext, DataSource dataSource) { Preconditions.checkNotNull(serviceType, "serviceType can't be null"); Preconditions.checkArgument(serviceType.isInterface(), "serviceType must be an interface"); @@ -110,23 +110,24 @@ public class ObserveServiceFactory implements Closeable { ObserveServiceContext serviceContext = new ObserveServiceContext(applicationContext, dataSource); - S service = newService(serviceType, serviceContext); - return service; + S service = newProxyService(serviceType, serviceContext); + return service ; } - protected <S extends ObserveService> S createService(Class<S> serviceType, ObserveServiceContext serviceContext) { + public <S extends ObserveService> S newProxyService(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 = newService(serviceType, serviceContext); - return service; + S proxyService = addProxyService(serviceType, service, serviceContext); + return proxyService; } - protected <S extends ObserveService> S newService(Class<S> serviceType, ObserveServiceContext serviceContext) { + public static <S extends ObserveService> S newService(Class<S> serviceType, ObserveServiceContext serviceContext) { Class<S> serviceImpl; try { @@ -142,11 +143,7 @@ public class ObserveServiceFactory implements Closeable { S service = ConstructorUtils.invokeConstructor(serviceImpl); service.setServiceContext(serviceContext); - // Instanciate transactional proxied service - ServiceInvocationHandler invocationHandler = new ServiceInvocationHandler(serviceContext, service); - S proxyService = (S) Proxy.newProxyInstance(ObserveServiceFactory.class.getClassLoader(), new Class[]{serviceType}, invocationHandler); - - return proxyService; + return service; } catch (Exception e) { throw new ObserveTechnicalException("Could not create service: " + serviceType, e); @@ -154,6 +151,17 @@ public class ObserveServiceFactory implements Closeable { } + 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(ObserveServiceFactory.class.getClassLoader(), new Class[]{serviceType}, invocationHandler); + + return proxyService; + + + } + protected static class ServiceInvocationHandler implements InvocationHandler { private final ObserveServiceContext serviceContext; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java index 72406a9..8a81987 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/ActivityLonglineServiceImpl.java @@ -139,30 +139,6 @@ public class ActivityLonglineServiceImpl extends AbstractObserveService implemen } - protected ActivityLongline create(String tripLonglineId, ActivityLongline toCreate) { - - ActivityLonglineDAO dao = getDao(); - ActivityLongline created = dao.create(toCreate); - - TripLongline tripLongline = findByTopiaId(TripLongline.class, tripLonglineId); - tripLongline.addActivityLongline(created); - - return created; - - } - - protected ActivityLongline update(ActivityLongline toUpdate) { - - ActivityLonglineDAO dao = getDao(); - ActivityLongline updated = dao.findByTopiaId(toUpdate.getTopiaId()); - copyExcluding(ActivityLongline.class, BinderService.EDIT, - toUpdate, updated, - ActivityLongline.PROPERTY_ENCOUNTER, - ActivityLongline.PROPERTY_SENSOR_USED); - return updated; - - } - protected ActivityLonglineDAO getDao() { return (ActivityLonglineDAO) getDao(ActivityLongline.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java index 4986d00..0eb34f6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/BranchlinesCompositionServiceImpl.java @@ -18,6 +18,7 @@ import java.util.List; * @since 4.0 */ public class BranchlinesCompositionServiceImpl extends AbstractObserveService implements BranchlinesCompositionService { + @Override public SetLongline loadForEdit(String setLonglineId) { @@ -26,9 +27,9 @@ public class BranchlinesCompositionServiceImpl extends AbstractObserveService im SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); copy(SetLongline.class, BinderService.EDIT_BRANCHLINES_COMPOSITION, parentToLoad, parentLoaded); - TopiaEntityBinder<BranchlinesComposition> binder = getBinder(BranchlinesComposition.class, BinderService.EDIT); if (!parentToLoad.isBranchlinesCompositionEmpty()) { + TopiaEntityBinder<BranchlinesComposition> binder = getBinder(BranchlinesComposition.class, BinderService.EDIT); TopiaDAO<BranchlinesComposition> childDao = getDao(BranchlinesComposition.class); List<BranchlinesComposition> childs = new ArrayList<BranchlinesComposition>(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java index 212ce50..2f0c60a 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/CatchLonglineServiceImpl.java @@ -1,21 +1,23 @@ package fr.ird.observe.services.data.longline; +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.SizeMeasureImpl; import fr.ird.observe.entities.longline.WeightMeasure; -import fr.ird.observe.entities.longline.WeightMeasureImpl; 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; /** @@ -55,10 +57,9 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); copy(SetLongline.class, BinderService.EDIT_CATCH_LONGLINE, parentToLoad, parentLoaded); - TopiaEntityBinder<CatchLongline> binder = getBinder(CatchLongline.class, BinderService.EDIT); - if (!parentToLoad.isCatchLonglineEmpty()) { + TopiaEntityBinder<CatchLongline> binder = getBinder(CatchLongline.class, BinderService.EDIT); TopiaDAO<CatchLongline> childDao = getDao(CatchLongline.class); List<CatchLongline> childs = new ArrayList<CatchLongline>(); @@ -85,22 +86,123 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements 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)); + doSaveList(setLongline, + new SaveCollectionAction<SetLongline, CatchLongline>(SetLongline.class, + CatchLongline.class, + getListUpdator(), parentBinder, childBinder) { + + @Override + public CatchLongline onCreateChild(CatchLongline childToCreate) { + + CatchLongline createdChild = super.onCreateChild(childToCreate); + saveSizeMeasures(childToCreate.getSizeMeasure(), createdChild); + saveWeightMeasures(childToCreate.getWeightMeasure(), createdChild); + return createdChild; + + } + + @Override + public CatchLongline onUpdateChild(CatchLongline childToSave) { + + CatchLongline childSaved = super.onUpdateChild(childToSave); + saveSizeMeasures(childToSave.getSizeMeasure(), childSaved); + saveWeightMeasures(childToSave.getWeightMeasure(), childSaved); + return childSaved; + + } + + protected void saveSizeMeasures(Collection<SizeMeasure> sizeMeasurementsToSave, CatchLongline childSaved) { + + List<SizeMeasure> sizeMeasuresToSave = Lists.newArrayList(); + + if (CollectionUtils.isNotEmpty(sizeMeasurementsToSave)) { + + TopiaDAO<SizeMeasure> dao = getDao(SizeMeasure.class); + TopiaEntityBinder<SizeMeasure> binder = getBinder(SizeMeasure.class, BinderService.EDIT); + + for (SizeMeasure sizeMeasureToSave : sizeMeasurementsToSave) { + + SizeMeasure sizeMeasureSaved; + + if (Entities.isNew(sizeMeasureToSave)) { + + sizeMeasureSaved = dao.create(); + binder.load(sizeMeasureToSave, sizeMeasureSaved, false); + + } else { + + sizeMeasureSaved = dao.findByTopiaId(sizeMeasureToSave.getTopiaId()); + binder.load(sizeMeasureToSave, sizeMeasureSaved, true); + + } + + sizeMeasuresToSave.add(sizeMeasureSaved); + + } + + } + + childSaved.clearSizeMeasure(); + childSaved.addAllSizeMeasure(sizeMeasuresToSave); + + } + + protected void saveWeightMeasures(Collection<WeightMeasure> weightMeasurementsTosave, CatchLongline childSaved) { + + List<WeightMeasure> weightMeasuresToSave = Lists.newArrayList(); + + if (CollectionUtils.isNotEmpty(weightMeasurementsTosave)) { + + TopiaDAO<WeightMeasure> dao = getDao(WeightMeasure.class); + TopiaEntityBinder<WeightMeasure> binder = getBinder(WeightMeasure.class, BinderService.EDIT); + + for (WeightMeasure weightMeasureToSave : weightMeasurementsTosave) { + + WeightMeasure weightMeasureSaved; + + if (Entities.isNew(weightMeasureToSave)) { + + weightMeasureSaved = dao.create(); + binder.load(weightMeasureToSave, weightMeasureSaved, false); + + } else { + + weightMeasureSaved = dao.findByTopiaId(weightMeasureToSave.getTopiaId()); + binder.load(weightMeasureToSave, weightMeasureSaved, true); + + } + + weightMeasuresToSave.add(weightMeasureSaved); + + } + + } + + childSaved.clearWeightMeasure(); + childSaved.addAllWeightMeasure(weightMeasuresToSave); + + } + } + + ); } @Override public List<SizeMeasure> getCatchLonglineSizeMeasures(String catchLonglineId) { - TopiaEntityBinder<SizeMeasure> binder = getBinder(SizeMeasure.class, BinderService.EDIT); - CatchLongline catchLongline = getDao().findByTopiaId(catchLonglineId); List<SizeMeasure> result = new ArrayList<SizeMeasure>(); - for (SizeMeasure sizeSource : catchLongline.getSizeMeasure()) { - SizeMeasure target = new SizeMeasureImpl(); - binder.load(sizeSource, target, true); - result.add(target); + 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; @@ -109,14 +211,19 @@ public class CatchLonglineServiceImpl extends AbstractObserveService implements @Override public List<WeightMeasure> getCatchLonglineWeightMeasures(String catchLonglineId) { - TopiaEntityBinder<WeightMeasure> binder = getBinder(WeightMeasure.class, BinderService.EDIT); - CatchLongline catchLongline = getDao().findByTopiaId(catchLonglineId); List<WeightMeasure> result = new ArrayList<WeightMeasure>(); - for (WeightMeasure weightSource : catchLongline.getWeightMeasure()) { - WeightMeasure target = new WeightMeasureImpl(); - binder.load(weightSource, target, true); - result.add(target); + 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; diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java index ac74e05..eaaa8ee 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/EncounterServiceImpl.java @@ -27,10 +27,9 @@ public class EncounterServiceImpl extends AbstractObserveService implements Enco ActivityLongline parentLoaded = getDao(ActivityLongline.class).newInstance(); copy(ActivityLongline.class, BinderService.EDIT_ENCOUNTER, parentToLoad, parentLoaded); - TopiaEntityBinder<Encounter> binder = getBinder(Encounter.class, BinderService.EDIT); - if (!parentToLoad.isEncounterEmpty()) { + TopiaEntityBinder<Encounter> binder = getBinder(Encounter.class, BinderService.EDIT); TopiaDAO<Encounter> childDao = getDao(Encounter.class); List<Encounter> childs = new ArrayList<Encounter>(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java index 44a444f..07f8d26 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/FloatlinesCompositionServiceImpl.java @@ -18,6 +18,7 @@ import java.util.List; * @since 4.0 */ public class FloatlinesCompositionServiceImpl extends AbstractObserveService implements FloatlinesCompositionService { + @Override public SetLongline loadForEdit(String setLonglineId) { @@ -26,10 +27,9 @@ public class FloatlinesCompositionServiceImpl extends AbstractObserveService imp SetLongline parentLoaded = getDao(SetLongline.class).newInstance(); copy(SetLongline.class, BinderService.EDIT_FLOATLINES_COMPOSITION, parentToLoad, parentLoaded); - TopiaEntityBinder<FloatlinesComposition> binder = getBinder(FloatlinesComposition.class, BinderService.EDIT); - if (!parentToLoad.isFloatlinesCompositionEmpty()) { + TopiaEntityBinder<FloatlinesComposition> binder = getBinder(FloatlinesComposition.class, BinderService.EDIT); TopiaDAO<FloatlinesComposition> childDao = getDao(FloatlinesComposition.class); List<FloatlinesComposition> childs = new ArrayList<FloatlinesComposition>(); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java index b089a8e..541605d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/GearUseFeaturesLonglineServiceImpl.java @@ -2,6 +2,7 @@ package fr.ird.observe.services.data.longline; 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; @@ -9,12 +10,12 @@ 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.Collection; import java.util.List; /** @@ -28,16 +29,22 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i @Override public List<GearUseFeaturesMeasurementLongline> getDefaultGearUseFeaturesMeasurementLongline(String gearId) { - GearUseFeaturesMeasurementLonglineDAO dao = getDao(); - Gear gear = findByTopiaId(Gear.class, gearId); - Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); - for (GearCaracteristic caracteristic : gearCaracteristic) { - GearUseFeaturesMeasurementLongline target = dao.newInstance(); - target.setGearCaracteristic(caracteristic); - result.add(target); + + if (gear.isGearCaracteristicEmpty()) { + + GearUseFeaturesMeasurementLonglineDAO dao = getDao(); + + for (GearCaracteristic caracteristic : gear.getGearCaracteristic()) { + + GearUseFeaturesMeasurementLongline target = dao.newInstance(); + target.setGearCaracteristic(caracteristic); + result.add(target); + + } + } return result; @@ -47,18 +54,23 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i @Override public List<GearUseFeaturesMeasurementLongline> loadGearUseFeaturesMeasurementLonglineForEdit(String gearUseFeaturesLonglineId) { - GearUseFeaturesMeasurementLonglineDAO dao = getDao(); - - TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); - GearUseFeaturesLongline gearUseFeaturesLongline = findByTopiaId(GearUseFeaturesLongline.class, gearUseFeaturesLonglineId); List<GearUseFeaturesMeasurementLongline> result = new ArrayList<GearUseFeaturesMeasurementLongline>(); - for (GearUseFeaturesMeasurementLongline measurementSource : gearUseFeaturesLongline.getGearUseFeaturesMeasurement()) { - GearUseFeaturesMeasurementLongline target = dao.newInstance(); - measurementSource.getGearCaracteristic().getGearCaracteristicType(); - binder.load(measurementSource, target, true); - result.add(target); + 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; @@ -68,31 +80,53 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i @Override public TripLongline loadForEdit(String tripLonglineId) { - TripLongline parentToLoad = findByTopiaId(TripLongline.class, tripLonglineId); + TripLongline toLoad = findByTopiaId(TripLongline.class, tripLonglineId); - TripLongline parentLoaded = getDao(TripLongline.class).newInstance(); - copy(TripLongline.class, BinderService.EDIT_GEAR_USE_FEATURES_LONGLINE, parentToLoad, parentLoaded); + TripLongline loaded = getDao(TripLongline.class).newInstance(); + copy(TripLongline.class, BinderService.EDIT_GEAR_USE_FEATURES_LONGLINE, toLoad, loaded); - if (!parentToLoad.isGearUseFeaturesLonglineEmpty()) { + if (!toLoad.isGearUseFeaturesLonglineEmpty()) { - TopiaEntityBinder<GearUseFeaturesLongline> binder = getBinder(GearUseFeaturesLongline.class, BinderService.EDIT); 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>(); - List<GearUseFeaturesLongline> childs = new ArrayList<GearUseFeaturesLongline>(); + if (!toLoad.isGearUseFeaturesLonglineEmpty()) { - for (GearUseFeaturesLongline sourceChild : parentToLoad.getGearUseFeaturesLongline()) { + for (GearUseFeaturesLongline childToLoad : toLoad.getGearUseFeaturesLongline()) { - GearUseFeaturesLongline targetChild = childDao.newInstance(); - binder.load(sourceChild, targetChild, true); - childs.add(targetChild); + 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); + + } + + } } - parentLoaded.setGearUseFeaturesLongline(childs); + loaded.setGearUseFeaturesLongline(childsLoaded); } - return parentLoaded; + return loaded; } @@ -109,59 +143,55 @@ public class GearUseFeaturesLonglineServiceImpl extends AbstractObserveService i public GearUseFeaturesLongline onCreateChild(GearUseFeaturesLongline childToCreate) { GearUseFeaturesLongline childCreated = getDao(entityClass).create( - GearUseFeaturesLongline.PROPERTY_GEAR,childToCreate.getGear(), - GearUseFeaturesLongline.PROPERTY_NUMBER,childToCreate.getNumber() + GearUseFeaturesLongline.PROPERTY_GEAR, childToCreate.getGear(), + GearUseFeaturesLongline.PROPERTY_NUMBER, childToCreate.getNumber() ); childBinder.load(childToCreate, childCreated, false); - saveMeasurement(childToCreate, childCreated); + saveMeasurement(childToCreate.getGearUseFeaturesMeasurement(), childCreated); return childCreated; } @Override - public GearUseFeaturesLongline onUpdateChild(GearUseFeaturesLongline childToSave, GearUseFeaturesLongline childSaved) { - super.onUpdateChild(childToSave, childSaved); - saveMeasurement(childToSave, childSaved); + public GearUseFeaturesLongline onUpdateChild(GearUseFeaturesLongline childToSave) { + GearUseFeaturesLongline childSaved = super.onUpdateChild(childToSave); + saveMeasurement(childToSave.getGearUseFeaturesMeasurement(), childSaved); return childSaved; } - protected void saveMeasurement(GearUseFeaturesLongline childToSave, GearUseFeaturesLongline childSaved) { - - TopiaDAO<GearUseFeaturesMeasurementLongline> dao = getDao(GearUseFeaturesMeasurementLongline.class); + protected void saveMeasurement(List<GearUseFeaturesMeasurementLongline> measurementsToSave, GearUseFeaturesLongline childSaved) { - TopiaEntityBinder<GearUseFeaturesMeasurementLongline> measurementBinder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); + List<GearUseFeaturesMeasurementLongline> measurementsSaved = Lists.newArrayList(); - List<GearUseFeaturesMeasurementLongline> measurementsNew = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(measurementsToSave)) { - if (!childToSave.isGearUseFeaturesMeasurementEmpty()) { + TopiaDAO<GearUseFeaturesMeasurementLongline> dao = getDao(GearUseFeaturesMeasurementLongline.class); + TopiaEntityBinder<GearUseFeaturesMeasurementLongline> binder = getBinder(GearUseFeaturesMeasurementLongline.class, BinderService.EDIT); - for (GearUseFeaturesMeasurementLongline measurementToSave : childToSave.getGearUseFeaturesMeasurement()) { + for (GearUseFeaturesMeasurementLongline measurementToSave : measurementsToSave) { GearUseFeaturesMeasurementLongline measurementSaved; - if (measurementToSave.getTopiaId() == null) { - - measurementSaved = dao.create(GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, measurementToSave.getGearCaracteristic()); + if (Entities.isNew(measurementToSave)) { - measurementBinder.load(measurementToSave, measurementSaved, false); + measurementSaved = dao.create(GearUseFeaturesMeasurementLongline.PROPERTY_GEAR_CARACTERISTIC, measurementToSave.getGearCaracteristic()); + binder.load(measurementToSave, measurementSaved, false); } else { measurementSaved = dao.findByTopiaId(measurementToSave.getTopiaId()); - - measurementBinder.load(measurementToSave, measurementSaved, true); + binder.load(measurementToSave, measurementSaved, true); } - measurementsNew.add(measurementSaved); + measurementsSaved.add(measurementSaved); } } childSaved.clearGearUseFeaturesMeasurement(); - - childSaved.addAllGearUseFeaturesMeasurement(measurementsNew); + childSaved.addAllGearUseFeaturesMeasurement(measurementsSaved); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java index 0f8fc53..043b3dc 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/HooksCompositionServiceImpl.java @@ -18,6 +18,7 @@ import java.util.List; * @since 4.0 */ public class HooksCompositionServiceImpl extends AbstractObserveService implements HooksCompositionService { + @Override public SetLongline loadForEdit(String setLonglineId) { diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java index f9891f9..d0b3637 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionService.java @@ -1,7 +1,12 @@ package fr.ird.observe.services.data.longline; +import fr.ird.observe.entities.longline.SectionWithTemplate; +import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; +import java.util.List; + /** * Created on 4/26/15. * @@ -9,4 +14,10 @@ import fr.ird.observe.services.ObserveService; * @since 4.0 */ public interface LonglineDetailCompositionService extends ObserveService { + + SetLongline loadForEdit(String setLonglineId); + + @Commit + void save(SetLongline toSave, List<SectionWithTemplate> sections); + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java index 63fa0f9..40dd524 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineDetailCompositionServiceImpl.java @@ -1,6 +1,20 @@ package fr.ird.observe.services.data.longline; +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.TopiaException; +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. @@ -10,4 +24,172 @@ import fr.ird.observe.services.AbstractObserveService; */ 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) { + + Map<String, Section> existingSectionsByTopiaId = Entities.toIdMap(toSave.getSection()); + + toSave.clearSection(); + + 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, + existingSectionsByTopiaId, + 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, + Map<String, Section> existingSectionsByTopiaId, + Section section) throws TopiaException { + + Section sectionToSave; + + if (section.getTopiaId() == null) { + + // create + sectionToSave = sectionsDao.create( + Section.PROPERTY_SETTING_IDENTIFIER, section.getSettingIdentifier(), + Section.PROPERTY_HAULING_IDENTIFIER, section.getHaulingIdentifier()); + + } else { + + sectionToSave = existingSectionsByTopiaId.get(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) throws TopiaException { + + Basket basketToSave; + + if (basket.getTopiaId() == null) { + + // 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) throws TopiaException { + + Branchline branchlineToSave; + + if (branchline.getTopiaId() == null) { + + // 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/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java index 41fe50e..9c245c2 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionService.java @@ -9,7 +9,8 @@ import fr.ird.observe.services.ObserveService; */ public interface LonglineGlobalCompositionService extends ObserveService{ + SetLongline loadForEdit(String setLonglineId); + @Commit String save(SetLongline bean); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java index 2ffef64..9e5060f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/LonglineGlobalCompositionServiceImpl.java @@ -4,29 +4,53 @@ 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); - saved.clearMitigationType(); + Collection<MitigationType> mitigationTypesSaved = new ArrayList<MitigationType>(); + + if (!toSave.isMitigationTypeEmpty()) { - for (MitigationType mitigationTypeToSave : toSave.getMitigationType()) { + TopiaDAO<MitigationType> dao = getDao(MitigationType.class); - MitigationType mitigationTypeSaved = findByTopiaId(MitigationType.class, mitigationTypeToSave.getTopiaId()); + for (MitigationType mitigationTypeToSave : toSave.getMitigationType()) { - saved.addMitigationType(mitigationTypeSaved); + MitigationType mitigationTypeSaved = dao.findByTopiaId(mitigationTypeToSave.getTopiaId()); + mitigationTypesSaved.add(mitigationTypeSaved); + } } + saved.clearMitigationType(); + saved.addAllMitigationType(mitigationTypesSaved); + getDao(SetLongline.class).update(saved); newService(FloatlinesCompositionService.class).save(toSave); @@ -36,4 +60,5 @@ public class LonglineGlobalCompositionServiceImpl extends AbstractObserveService return saved.getTopiaId(); } + } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java index 170fd5b..d10093c 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SensorUsedServiceImpl.java @@ -62,7 +62,6 @@ public class SensorUsedServiceImpl extends AbstractObserveService implements Sen 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); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java index 5253955..89c8324 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineService.java @@ -2,6 +2,7 @@ package fr.ird.observe.services.data.longline; import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; +import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; import java.util.List; @@ -18,6 +19,14 @@ public interface SetLonglineService extends ObserveService { List<Section> getSections(String setLonglineId); - String save(String activityId, SetLongline bean); + SetLongline preCreate(String activityLonglineId); + + SetLongline loadForEdit(String setLonglineId); + + @Commit + String save(String activityLonglineId, SetLongline setLongline); + + @Commit + void delete(String activityLonglineId, String setLonglineId); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java index 7c44be2..793e631 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/SetLonglineServiceImpl.java @@ -8,9 +8,11 @@ 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.decorator.Decorator; import org.nuiton.topia.persistence.TopiaDAO; +import java.util.Date; import java.util.List; /** @@ -67,8 +69,43 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se } @Override - public String save(String activityLonglineId, SetLongline toSave) { - String setLonglineId = doSave(activityLonglineId, toSave, new SaveAction<ActivityLongline, SetLongline>(ActivityLongline.class, SetLongline.class) { + 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 SetLongline loadForEdit(String setLonglineId) { + return null; + } + + @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) { @@ -102,6 +139,21 @@ public class SetLonglineServiceImpl extends AbstractObserveService implements Se 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/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java index b650614..e59f6d6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/longline/TdrServiceImpl.java @@ -60,7 +60,6 @@ public class TdrServiceImpl extends AbstractObserveService implements TdrService 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); diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java index 2ded71e..212b8d1 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineService.java @@ -2,9 +2,7 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.ActivitySeine; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -20,8 +18,6 @@ public interface ActivitySeineService extends ObserveService { List<ActivitySeine> getActivitySeineStubByRoute(String routeId); - ActivitySeine loadForDisplay(String activitySeineId); - ActivitySeine loadForEdit(String activitySeineId); ActivitySeine loadForEditObservedSystem(String activitySeineId); @@ -37,15 +33,4 @@ public interface ActivitySeineService extends ObserveService { @Commit void delete(String routeId, String activitySeineId); - @NoTransaction - TopiaEntityBinder<ActivitySeine> getBinderForEdit(); - - @NoTransaction - TopiaEntityBinder<ActivitySeine> getBinderForEditObservedSystem() ; - - @NoTransaction - void copyForEdit(ActivitySeine source, ActivitySeine target); - - @NoTransaction - void copyForEditObservedSystem(ActivitySeine source, ActivitySeine target); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java index 860cc3e..6dfb81e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ActivitySeineServiceImpl.java @@ -9,10 +9,7 @@ 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.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.DateUtil; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderModelBuilder; import java.util.Date; import java.util.List; @@ -44,20 +41,11 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements } @Override - public ActivitySeine loadForDisplay(String activitySeineId) { + public ActivitySeine loadForEdit(String activitySeineId) { ActivitySeine loaded = getDao().newInstance(); ActivitySeine toLoad = getDao().findByTopiaId(activitySeineId); - copyForEdit(toLoad, loaded); - - return loaded; - - } - - @Override - public ActivitySeine loadForEdit(String activitySeineId) { - - ActivitySeine loaded = loadForDisplay(activitySeineId); + copy(ActivitySeine.class, BinderService.EDIT, toLoad, loaded); return loaded; } @@ -67,8 +55,9 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements ActivitySeine toLoad = getDao().findByTopiaId(activitySeineId); ActivitySeine loaded = getDao().newInstance(); - //TODO + copy(ActivitySeine.class, BinderService.EDIT_OBSERVED_SYSTEM, toLoad, loaded); return loaded; + } @Override @@ -139,7 +128,8 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements } ActivitySeine updated = dao.findByTopiaId(toUpdate.getTopiaId()); - getBinderForEditObservedSystem().copyExcluding(toUpdate, updated, ActivitySeine.PROPERTY_SET_SEINE); + + copyExcluding(ActivitySeine.class, BinderService.EDIT, toUpdate, updated, true, ActivitySeine.PROPERTY_SET_SEINE); if (needUpdateSet) { @@ -154,13 +144,14 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements @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) { ActivitySeine created = getDao().create(); - getBinderForEdit().copy(toCreate, created); + copy(ActivitySeine.class, BinderService.EDIT, toCreate, created, false); parent.addActivitySeine(created); return created; @@ -172,9 +163,8 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements toUpdate.setTime(d); - getBinderForEdit().copyExcluding(toUpdate, updated, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM, - ActivitySeine.PROPERTY_FLOATING_OBJECT); + copyExcluding(ActivitySeine.class, BinderService.EDIT, toUpdate, updated, true, + ActivitySeine.PROPERTY_OBSERVED_SYSTEM, ActivitySeine.PROPERTY_FLOATING_OBJECT); return updated; } @@ -197,91 +187,6 @@ public class ActivitySeineServiceImpl extends AbstractObserveService implements } - @Override - public TopiaEntityBinder<ActivitySeine> getBinderForEditObservedSystem() { - - TopiaEntityBinder<ActivitySeine> binder = loadBinder("-forEditObservedSystem", ActivitySeine.class, new CreateBinder<ActivitySeine>() { - - @Override - public BinderModelBuilder<ActivitySeine, ActivitySeine> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<ActivitySeine, ActivitySeine> builder = binderService.newBinderBuilder( - ActivitySeine.class, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM, - ActivitySeine.PROPERTY_SET_SEINE, - ActivitySeine.PROPERTY_COMMENT, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE); - - return builder; - - } - - }); - - return binder; - - } - - @Override - public TopiaEntityBinder<ActivitySeine> getBinderForEdit() { - - TopiaEntityBinder<ActivitySeine> binder = loadBinder("-forEdit", ActivitySeine.class, new CreateBinder<ActivitySeine>() { - - @Override - public BinderModelBuilder<ActivitySeine, ActivitySeine> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<ActivitySeine, ActivitySeine> builder = binderService.newBinderBuilder( - ActivitySeine.class, - ActivitySeine.PROPERTY_QUADRANT, - ActivitySeine.PROPERTY_LATITUDE, - ActivitySeine.PROPERTY_LONGITUDE, - ActivitySeine.PROPERTY_ERS_ID, - ActivitySeine.PROPERTY_TIME, - ActivitySeine.PROPERTY_SEA_SURFACE_TEMPERATURE, - ActivitySeine.PROPERTY_REASON_FOR_NO_FISHING, - ActivitySeine.PROPERTY_COMMENT, - ActivitySeine.PROPERTY_VESSEL_SPEED, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM, - ActivitySeine.PROPERTY_OBSERVED_SYSTEM_DISTANCE, - ActivitySeine.PROPERTY_VESSEL_ACTIVITY_SEINE, - ActivitySeine.PROPERTY_SURROUNDING_ACTIVITY, - ActivitySeine.PROPERTY_WIND, - ActivitySeine.PROPERTY_DETECTION_MODE, - ActivitySeine.PROPERTY_SET_SEINE, - ActivitySeine.PROPERTY_FLOATING_OBJECT, - ActivitySeine.PROPERTY_OPEN, - ActivitySeine.PROPERTY_CURRENT_FPA_ZONE, - ActivitySeine.PROPERTY_PREVIOUS_FPA_ZONE, - ActivitySeine.PROPERTY_NEXT_FPA_ZONE); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_OBSERVED_SYSTEM); - - builder.addCollectionStrategy(Binder.CollectionStrategy.duplicate, ActivitySeine.PROPERTY_FLOATING_OBJECT); - - return builder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEdit(ActivitySeine source, ActivitySeine target) { - - getBinderForEdit().load(source, target, true); - - } - - @Override - public void copyForEditObservedSystem(ActivitySeine source, ActivitySeine target) { - - getBinderForEditObservedSystem().load(source, target, true); - - } - protected ActivitySeineDAO getDao() { return (ActivitySeineDAO) getDao(ActivitySeine.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java index c9dec98..c4c6ba2 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectService.java @@ -1,11 +1,8 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.entities.seine.TransmittingBuoy; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.List; @@ -36,22 +33,4 @@ public interface FloatingObjectService extends ObserveService { @Commit void delete(String activitySeineId, String floatingObjectId); - @NoTransaction - TopiaEntityBinder<FloatingObject> getBinderForEdit(); - - @NoTransaction - TopiaEntityBinder<FloatingObject> getBinderForEditTransmittingBuoyOperation(); - - @NoTransaction - TopiaEntityBinder<TransmittingBuoy> getBinderForEditTransmittingBuoy(); - - @NoTransaction - void copyForEdit(FloatingObject source, FloatingObject target); - - @NoTransaction - void copyForEditTransmittingBuoyOperation(FloatingObject source, FloatingObject target); - - @NoTransaction - void copyForEditTransmittingBuoy(TransmittingBuoy source, TransmittingBuoy target); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java index f4e9fa4..7d937af 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/FloatingObjectServiceImpl.java @@ -1,16 +1,21 @@ package fr.ird.observe.services.data.seine; 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 org.nuiton.util.beans.BinderModelBuilder; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -43,9 +48,11 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements @Override public FloatingObject loadForEdit(String floatingObjectId) { - FloatingObject loaded = getDao().newInstance(); - FloatingObject toLoad = getDao().findByTopiaId(floatingObjectId); - copyForEdit(toLoad, loaded); + FloatingObjectDAO dao = getDao(); + + FloatingObject loaded = dao.newInstance(); + FloatingObject toLoad = dao.findByTopiaId(floatingObjectId); + copy(FloatingObject.class, BinderService.EDIT, toLoad, loaded, true); return loaded; @@ -54,10 +61,37 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements @Override public FloatingObject loadForEditTransmittingBuoyOperation(String floatingObjectId) { - FloatingObject loaded = getDao().newInstance(); - FloatingObject toLoad = getDao().findByTopiaId(floatingObjectId); - copyForEditTransmittingBuoyOperation(toLoad, loaded); + 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; } @@ -79,8 +113,7 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements public FloatingObject onCreate(ActivitySeine parent, FloatingObject toCreate) { FloatingObject created = getDao().create(); - getBinderForEdit().copy(toCreate, created); - + copy(FloatingObject.class, BinderService.EDIT, toCreate, created, false); parent.addFloatingObject(created); return created; @@ -89,7 +122,8 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements @Override public FloatingObject onUpdate(ActivitySeine parent, FloatingObject toUpdate, FloatingObject updated) { - copyForEdit(toUpdate, updated); + + copy(FloatingObject.class, BinderService.EDIT, toUpdate, updated, true); return updated; } }); @@ -105,33 +139,35 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements updated.setComment(toUpdate.getComment()); updated.clearTransmittingBuoy(); - TopiaEntityBinder<TransmittingBuoy> childLoador = getBinderForEditTransmittingBuoy(); + if (!toUpdate.isTransmittingBuoyEmpty()) { - TopiaDAO<TransmittingBuoy> transmittingBuoyDAO = getDao(TransmittingBuoy.class); + TopiaEntityBinder<TransmittingBuoy> binder = getBinder(TransmittingBuoy.class, BinderService.EDIT); + TopiaDAO<TransmittingBuoy> transmittingBuoyDAO = getDao(TransmittingBuoy.class); - for (TransmittingBuoy transmittingBuoy : toUpdate.getTransmittingBuoy()) { + for (TransmittingBuoy transmittingBuoy : toUpdate.getTransmittingBuoy()) { - TransmittingBuoy newTransmittingBuoy; + TransmittingBuoy newTransmittingBuoy; - if (transmittingBuoy.getTopiaId() == null) { + if (Entities.isNew(transmittingBuoy)) { - // creation de la balise + // creation de la balise + Map<String, Object> map = binder.obtainProperties(transmittingBuoy); + newTransmittingBuoy = transmittingBuoyDAO.create(map); - Map<String, Object> map = childLoador.obtainProperties(transmittingBuoy); - newTransmittingBuoy = transmittingBuoyDAO.create(map); + } else { - } else { + // mise a jour de la balise - // mise a jour de la balise + newTransmittingBuoy = transmittingBuoyDAO.findByTopiaId(transmittingBuoy.getTopiaId()); + binder.load(transmittingBuoy, newTransmittingBuoy, true); - newTransmittingBuoy = transmittingBuoyDAO.findByTopiaId(transmittingBuoy.getTopiaId()); - childLoador.load(transmittingBuoy, newTransmittingBuoy, false); + } - } - - updated.addTransmittingBuoy(newTransmittingBuoy); + updated.addTransmittingBuoy(newTransmittingBuoy); + } } + return updated; } @@ -147,113 +183,6 @@ public class FloatingObjectServiceImpl extends AbstractObserveService implements } - @Override - public TopiaEntityBinder<FloatingObject> getBinderForEdit() { - - TopiaEntityBinder<FloatingObject> binder = loadBinder("-forEdit", FloatingObject.class, new CreateBinder<FloatingObject>() { - - @Override - public BinderModelBuilder<FloatingObject, FloatingObject> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<FloatingObject, FloatingObject> builder = binderService.newBinderBuilder( - FloatingObject.class, - FloatingObject.PROPERTY_OBJECT_TYPE, - FloatingObject.PROPERTY_OBJECT_FATE, - FloatingObject.PROPERTY_OBJECT_OPERATION, - FloatingObject.PROPERTY_COMMENT, - FloatingObject.PROPERTY_SUPPORT_VESSEL_NAME, - FloatingObject.PROPERTY_DAYS_AT_SEA_COUNT); - - return builder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEdit(FloatingObject source, FloatingObject target) { - - getBinderForEdit().load(source, target, true); - - } - - @Override - public TopiaEntityBinder<FloatingObject> getBinderForEditTransmittingBuoyOperation() { - - TopiaEntityBinder<FloatingObject> binder = loadBinder("-forEdit", FloatingObject.class, new CreateBinder<FloatingObject>() { - - @Override - public BinderModelBuilder<FloatingObject, FloatingObject> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<FloatingObject, FloatingObject> builder = binderService.newBinderBuilder( - FloatingObject.class, - FloatingObject.PROPERTY_COMMENT, - FloatingObject.PROPERTY_OBJECT_OPERATION - ); - return builder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEditTransmittingBuoyOperation(FloatingObject source, FloatingObject target) { - - getBinderForEditTransmittingBuoyOperation().load(source, target, true); - - } - - @Override - public TopiaEntityBinder<TransmittingBuoy> getBinderForEditTransmittingBuoy() { - - TopiaEntityBinder<TransmittingBuoy> binder = loadBinder("-forEdit", TransmittingBuoy.class, new CreateBinder<TransmittingBuoy>() { - - @Override - public BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> createBinderBuilder(BinderService binderService, String name) { - - BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> builder = binderService.newBinderBuilder( - TransmittingBuoy.class, - TransmittingBuoy.PROPERTY_CODE, - TransmittingBuoy.PROPERTY_OWNERSHIP, - TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_TYPE, - TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_OPERATION, - TransmittingBuoy.PROPERTY_BRAND, - TransmittingBuoy.PROPERTY_COUNTRY); - - return builder; - - } - - @Override - public TopiaEntityBinder<TransmittingBuoy> registerTopiaBinder(BinderService binderService, Class<TransmittingBuoy> entityType, BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> builder, String name) { - - TopiaEntityBinder<TransmittingBuoy> binder = super.registerTopiaBinder(binderService, entityType, builder, name); - binder.setEmpty(getDao(TransmittingBuoy.class).newInstance()); - return binder; - - } - - }); - - return binder; - - } - - @Override - public void copyForEditTransmittingBuoy(TransmittingBuoy source, TransmittingBuoy target) { - - getBinderForEditTransmittingBuoy().load(source, target, true); - - } - protected FloatingObjectDAO getDao() { return (FloatingObjectDAO) getDao(FloatingObject.class); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java index 3e42f29..28c9636 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineService.java @@ -1,12 +1,9 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.GearUseFeaturesMeasurementSeine; -import fr.ird.observe.entities.seine.GearUseFeaturesSeine; import fr.ird.observe.entities.seine.TripSeine; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; import java.util.List; @@ -27,7 +24,4 @@ public interface GearUseFeaturesSeineService extends ObserveService { @Commit void save(TripSeine parent); - @NoTransaction - EntityListUpdator<TripSeine, GearUseFeaturesSeine> getListUpdator(); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java index 1f61015..49d0f1c 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/GearUseFeaturesSeineServiceImpl.java @@ -2,6 +2,7 @@ package fr.ird.observe.services.data.seine; 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; @@ -9,12 +10,12 @@ 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.Collection; import java.util.List; /** @@ -28,15 +29,22 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl @Override public List<GearUseFeaturesMeasurementSeine> getDefaultGearUseFeaturesMeasurementSeine(String gearId) { - GearUseFeaturesMeasurementSeineDAO dao = getDao(); Gear gear = findByTopiaId(Gear.class, gearId); - Collection<GearCaracteristic> gearCaracteristic = gear.getGearCaracteristic(); List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); - for (GearCaracteristic caracteristic : gearCaracteristic) { - GearUseFeaturesMeasurementSeine target = dao.newInstance(); - target.setGearCaracteristic(caracteristic); - result.add(target); + + if (!gear.isGearCaracteristicEmpty()) { + + GearUseFeaturesMeasurementSeineDAO dao = getDao(); + + for (GearCaracteristic caracteristic : gear.getGearCaracteristic()) { + + GearUseFeaturesMeasurementSeine target = dao.newInstance(); + target.setGearCaracteristic(caracteristic); + result.add(target); + + } + } return result; @@ -46,17 +54,23 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl @Override public List<GearUseFeaturesMeasurementSeine> loadGearUseFeaturesMeasurementSeineForEdit(String gearUseFeaturesSeineId) { - GearUseFeaturesMeasurementSeineDAO dao = getDao(); - TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); - GearUseFeaturesSeine gearUseFeaturesSeine = findByTopiaId(GearUseFeaturesSeine.class, gearUseFeaturesSeineId); List<GearUseFeaturesMeasurementSeine> result = new ArrayList<GearUseFeaturesMeasurementSeine>(); - for (GearUseFeaturesMeasurementSeine measurementSource : gearUseFeaturesSeine.getGearUseFeaturesMeasurement()) { - GearUseFeaturesMeasurementSeine target = dao.newInstance(); - measurementSource.getGearCaracteristic().getGearCaracteristicType(); - binder.load(measurementSource, target, true); - result.add(target); + 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; @@ -65,31 +79,50 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl @Override public TripSeine loadForEdit(String tripId) { - TripSeine toLoad = findByTopiaId(TripSeine.class, tripId); - TripSeine loaded = getDao(TripSeine.class).newInstance(); + 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); - for (GearUseFeaturesSeine childToLoad : toLoad.getGearUseFeaturesSeine()) { + if (!toLoad.isGearUseFeaturesSeineEmpty()) { - GearUseFeaturesSeine childLoaded = getDao(GearUseFeaturesSeine.class).newInstance(); + 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); - copy(GearUseFeaturesSeine.class, BinderService.EDIT, childToLoad, childLoaded); + if (!childToLoad.isGearUseFeaturesMeasurementEmpty()) { - for (GearUseFeaturesMeasurementSeine measurementToLoad : childToLoad.getGearUseFeaturesMeasurement()) { + List<GearUseFeaturesMeasurementSeine> measurementsLoaded = new ArrayList<GearUseFeaturesMeasurementSeine>(); - GearUseFeaturesMeasurementSeine measurementLoaded = getDao(GearUseFeaturesMeasurementSeine.class).newInstance(); + for (GearUseFeaturesMeasurementSeine measurementToLoad : childToLoad.getGearUseFeaturesMeasurement()) { - copy(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT, measurementToLoad, measurementLoaded); + GearUseFeaturesMeasurementSeine measurementLoaded = measurementDao.newInstance(); + measurementBinder.load(measurementToLoad, measurementLoaded, true); + measurementsLoaded.add(measurementLoaded); - childLoaded.addGearUseFeaturesMeasurement(measurementLoaded); + } + + childLoaded.setGearUseFeaturesMeasurement(measurementsLoaded); + + } } - loaded.addGearUseFeaturesSeine(childLoaded); + loaded.setGearUseFeaturesSeine(childsLoaded); } @@ -100,11 +133,12 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl @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); + TopiaEntityBinder<GearUseFeaturesSeine> childBinder = getBinder(GearUseFeaturesSeine.class, BinderService.EDIT); doSaveList(parent, new SaveCollectionAction<TripSeine, GearUseFeaturesSeine>( - TripSeine.class, GearUseFeaturesSeine.class, getListUpdator(), parentBinder, childbinder) { + TripSeine.class, GearUseFeaturesSeine.class, getListUpdator(), parentBinder, childBinder) { @Override public GearUseFeaturesSeine onCreateChild(GearUseFeaturesSeine childToCreate) { @@ -112,62 +146,57 @@ public class GearUseFeaturesSeineServiceImpl extends AbstractObserveService impl GearUseFeaturesSeine.PROPERTY_GEAR, childToCreate.getGear(), GearUseFeaturesSeine.PROPERTY_NUMBER, childToCreate.getNumber()); childBinder.load(childToCreate, childCreated, false); - saveMeasurement(childToCreate, childCreated); + saveMeasurement(childToCreate.getGearUseFeaturesMeasurement(), childCreated); return childCreated; } @Override - public GearUseFeaturesSeine onUpdateChild(GearUseFeaturesSeine childToSave, GearUseFeaturesSeine childSaved) { - super.onUpdateChild(childToSave, childSaved); - saveMeasurement(childToSave, childSaved); + public GearUseFeaturesSeine onUpdateChild(GearUseFeaturesSeine childToSave) { + GearUseFeaturesSeine childSaved = super.onUpdateChild(childToSave); + saveMeasurement(childToSave.getGearUseFeaturesMeasurement(), childSaved); return childSaved; } - protected void saveMeasurement(GearUseFeaturesSeine childToSave, GearUseFeaturesSeine childSaved) { - - TopiaDAO<GearUseFeaturesMeasurementSeine> dao = getDao(GearUseFeaturesMeasurementSeine.class); + protected void saveMeasurement(List<GearUseFeaturesMeasurementSeine> measurementsToSave, GearUseFeaturesSeine childSaved) { - TopiaEntityBinder<GearUseFeaturesMeasurementSeine> measurementBinder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); + List<GearUseFeaturesMeasurementSeine> measurementsSaved = Lists.newArrayList(); - List<GearUseFeaturesMeasurementSeine> measurementsNew = Lists.newArrayList(); + if (CollectionUtils.isNotEmpty(measurementsToSave)) { - if (!childToSave.isGearUseFeaturesMeasurementEmpty()) { + TopiaDAO<GearUseFeaturesMeasurementSeine> dao = getDao(GearUseFeaturesMeasurementSeine.class); + TopiaEntityBinder<GearUseFeaturesMeasurementSeine> binder = getBinder(GearUseFeaturesMeasurementSeine.class, BinderService.EDIT); - for (GearUseFeaturesMeasurementSeine measurementToSave : childToSave.getGearUseFeaturesMeasurement()) { + for (GearUseFeaturesMeasurementSeine measurementToSave : measurementsToSave) { GearUseFeaturesMeasurementSeine measurementSaved; - if (measurementToSave.getTopiaId() == null) { + if (Entities.isNew(measurementToSave)) { measurementSaved = dao.create(GearUseFeaturesMeasurementSeine.PROPERTY_GEAR_CARACTERISTIC, measurementToSave.getGearCaracteristic()); - - measurementBinder.load(measurementToSave, measurementSaved, false); + binder.load(measurementToSave, measurementSaved, false); } else { measurementSaved = dao.findByTopiaId(measurementToSave.getTopiaId()); - - measurementBinder.load(measurementToSave, measurementSaved, true); + binder.load(measurementToSave, measurementSaved, true); } - measurementsNew.add(measurementSaved); + measurementsSaved.add(measurementSaved); } } childSaved.clearGearUseFeaturesMeasurement(); - - childSaved.addAllGearUseFeaturesMeasurement(measurementsNew); + childSaved.addAllGearUseFeaturesMeasurement(measurementsSaved); } }); } - @Override - public EntityListUpdator<TripSeine, GearUseFeaturesSeine> getListUpdator() { + protected EntityListUpdator<TripSeine, GearUseFeaturesSeine> getListUpdator() { return EntityListUpdator.newEntityListUpdator( TripSeine.class, GearUseFeaturesSeine.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java index f83dbd8..a92d6b4 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchService.java @@ -1,12 +1,9 @@ package fr.ird.observe.services.data.seine; -import fr.ird.observe.entities.seine.NonTargetCatch; import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; import java.util.List; @@ -20,7 +17,4 @@ public interface NonTargetCatchService extends ObserveService { @Commit void save(SetSeine parent, List<NonTargetLength> tailleToDelete); - @NoTransaction - EntityListUpdator<SetSeine, NonTargetCatch> getListUpdator(); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java index 91bf7d2..c7a6139 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetCatchServiceImpl.java @@ -6,9 +6,11 @@ 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.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; @@ -33,14 +35,18 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements copyExcluding(SetSeine.class, BinderService.EDIT_NON_TARGET_CATCH, toLoad, loaded, SetSeine.PROPERTY_NON_TARGET_CATCH); - for (NonTargetCatch childToLoad : toLoad.getNonTargetCatch()) { + if (!toLoad.isNonTargetCatchEmpty()) { - NonTargetCatch childLoaded = getDao(NonTargetCatch.class).newInstance(); + TopiaDAO<NonTargetCatch> dao = getDao(NonTargetCatch.class); + TopiaEntityBinder<NonTargetCatch> binder = getBinder(NonTargetCatch.class, BinderService.EDIT); - copy(NonTargetCatch.class, BinderService.EDIT, childToLoad, childLoaded); + for (NonTargetCatch childToLoad : toLoad.getNonTargetCatch()) { - loaded.addNonTargetCatch(childLoaded); + NonTargetCatch childLoaded = dao.newInstance(); + binder.load(childToLoad, childLoaded, true); + loaded.addNonTargetCatch(childLoaded); + } } } @@ -75,27 +81,26 @@ public class NonTargetCatchServiceImpl extends AbstractObserveService implements @Override public void onUpdateFinalize(SetSeine parent, Collection<NonTargetCatch> oldChilds) throws TopiaException { - if (tailleToDelete != null && !tailleToDelete.isEmpty()) { + if (CollectionUtils.isNotEmpty(tailleToDelete)) { // on a demande la suppression de taille obsoletes if (log.isInfoEnabled()) { - log.info("Will remove " + tailleToDelete.size() + - " obsolete nonTargetSample(s)."); + log.info("Will remove " + tailleToDelete.size() + " obsolete nonTargetSample(s)."); } NonTargetSample echantillon = parent.getNonTargetSample().get(0); // on supprime les echantillons obsoletes echantillon.getNonTargetLength().removeAll(tailleToDelete); + } } }); } - @Override - public EntityListUpdator<SetSeine, NonTargetCatch> getListUpdator() { + protected EntityListUpdator<SetSeine, NonTargetCatch> getListUpdator() { return EntityListUpdator.newEntityListUpdator( SetSeine.class, NonTargetCatch.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java index c52635d..1423c61 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthService.java @@ -1,11 +1,8 @@ package fr.ird.observe.services.data.seine; -import fr.ird.observe.entities.seine.NonTargetLength; import fr.ird.observe.entities.seine.NonTargetSample; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; /** * @author Sylvain Bavencoff - bavencoff@codelutin.com @@ -17,7 +14,4 @@ public interface NonTargetLengthService extends ObserveService { @Commit void save(NonTargetSample parent); - @NoTransaction - EntityListUpdator<NonTargetSample, NonTargetLength> getListUpdator(); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java index 2e068b6..a70b69e 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetLengthServiceImpl.java @@ -5,6 +5,7 @@ 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.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; @@ -20,7 +21,7 @@ public class NonTargetLengthServiceImpl extends AbstractObserveService implement SetSeine setSeine = findByTopiaId(SetSeine.class, setId); - NonTargetSample toLoad = null; + NonTargetSample toLoad; if (setSeine.isNonTargetSampleEmpty()) { @@ -39,14 +40,18 @@ public class NonTargetLengthServiceImpl extends AbstractObserveService implement copyExcluding(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH, toLoad, loaded, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); - for (NonTargetLength childToLoad : toLoad.getNonTargetLength()) { + if (!toLoad.isNonTargetLengthEmpty()) { - NonTargetLength childLoaded = getDao(NonTargetLength.class).newInstance(); + TopiaDAO<NonTargetLength> dao = getDao(NonTargetLength.class); + TopiaEntityBinder<NonTargetLength> binder = getBinder(NonTargetLength.class, BinderService.EDIT); - copy(NonTargetLength.class, BinderService.EDIT, childToLoad, childLoaded); + for (NonTargetLength childToLoad : toLoad.getNonTargetLength()) { - loaded.addNonTargetLength(childLoaded); + NonTargetLength childLoaded = dao.newInstance(); + binder.load(childToLoad, childLoaded, true); + loaded.addNonTargetLength(childLoaded); + } } } @@ -63,8 +68,7 @@ public class NonTargetLengthServiceImpl extends AbstractObserveService implement NonTargetSample.class, NonTargetLength.class, getListUpdator(), parentBinder, childbinder)); } - @Override - public EntityListUpdator<NonTargetSample, NonTargetLength> getListUpdator() { + protected EntityListUpdator<NonTargetSample, NonTargetLength> getListUpdator() { return EntityListUpdator.newEntityListUpdator( NonTargetSample.class, NonTargetLength.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java index 06eeb03..b453188 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/NonTargetSampleServiceImpl.java @@ -10,6 +10,8 @@ import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.AbstractObserveService; 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; @@ -79,14 +81,18 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement copyExcluding(NonTargetSample.class, BinderService.EDIT_NON_TARGET_LENGTH, toLoad, loaded, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); - for (NonTargetLength childToLoad : toLoad.getNonTargetLength()) { + if (!toLoad.isNonTargetLengthEmpty()) { - NonTargetLength childLoaded = getDao(NonTargetLength.class).newInstance(); + TopiaDAO<NonTargetLength> dao = getDao(NonTargetLength.class); + TopiaEntityBinder<NonTargetLength> binder = getBinder(NonTargetLength.class, BinderService.EDIT); - copy(NonTargetLength.class, BinderService.EDIT, childToLoad, childLoaded); + for (NonTargetLength childToLoad : toLoad.getNonTargetLength()) { - loaded.addNonTargetLength(childLoaded); + NonTargetLength childLoaded = dao.newInstance(); + binder.load(childToLoad, childLoaded, true); + loaded.addNonTargetLength(childLoaded); + } } } @@ -138,36 +144,29 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } @Override - public void delete(String setId, NonTargetSample bean) { - doDelete(setId, bean.getTopiaId(), new DeleteAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { - @Override - public void onDelete(SetSeine parent, NonTargetSample toDelete) { - super.onDelete(parent, toDelete); - parent.removeNonTargetSample(toDelete); - } - }); - - } - - @Override public String save(String setSeineId, NonTargetSample toSave) { String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, NonTargetSample>(SetSeine.class, NonTargetSample.class) { @Override public NonTargetSample onCreate(SetSeine parent, NonTargetSample toCreate) { - NonTargetSample created = getDao().create(); + NonTargetSampleDAO dao = getDao(); + + NonTargetSample created = dao.create(); copyExcluding(NonTargetSample.class, BinderService.EDIT, toCreate, created, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); parent.addNonTargetSample(created); - getDao().update(created); + dao.update(created); return created; + } @Override public NonTargetSample onUpdate(SetSeine parentBean, NonTargetSample toSave, NonTargetSample beanToSave) { + copyExcluding(NonTargetSample.class, BinderService.EDIT, toSave, beanToSave, NonTargetSample.PROPERTY_NON_TARGET_LENGTH); getDao().update(beanToSave); return beanToSave; + } }); @@ -175,4 +174,18 @@ public class NonTargetSampleServiceImpl extends AbstractObserveService implement } + @Override + public void delete(String setId, NonTargetSample bean) { + doDelete(setId, bean.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/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java index 2bd726a..f83bcfe 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesService.java @@ -1,10 +1,8 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.entities.seine.ObjectObservedSpecies; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; /** * Created on 4/28/15. @@ -19,5 +17,4 @@ public interface ObjectObservedSpeciesService extends ObserveService { @Commit void save(FloatingObject floatingObject); - EntityListUpdator<FloatingObject, ObjectObservedSpecies> getListUpdator(); } \ No newline at end of file diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java index 5f8e84f..bd4b6f2 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectObservedSpeciesServiceImpl.java @@ -15,6 +15,7 @@ import java.util.List; * @author Sylvain Bavencoff - bavencoff@codelutin.com */ public class ObjectObservedSpeciesServiceImpl extends AbstractObserveService implements ObjectObservedSpeciesService { + @Override public FloatingObject loadForEdit(String floatingObjectId) { @@ -27,13 +28,13 @@ public class ObjectObservedSpeciesServiceImpl extends AbstractObserveService imp 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(); - copy(ObjectObservedSpecies.class, BinderService.EDIT, sourceChild, targetChild); + binder.load(sourceChild, targetChild, true); childs.add(targetChild); } @@ -56,8 +57,7 @@ public class ObjectObservedSpeciesServiceImpl extends AbstractObserveService imp } - @Override - public EntityListUpdator<FloatingObject, ObjectObservedSpecies> getListUpdator() { + protected EntityListUpdator<FloatingObject, ObjectObservedSpecies> getListUpdator() { return EntityListUpdator.newEntityListUpdator( FloatingObject.class, ObjectObservedSpecies.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java index 4581a6d..e253b52 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateService.java @@ -1,10 +1,8 @@ package fr.ird.observe.services.data.seine; import fr.ird.observe.entities.seine.FloatingObject; -import fr.ird.observe.entities.seine.ObjectSchoolEstimate; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; /** * Created on 4/28/15. @@ -19,5 +17,4 @@ public interface ObjectSchoolEstimateService extends ObserveService { @Commit void save(FloatingObject floatingObject); - EntityListUpdator<FloatingObject, ObjectSchoolEstimate> getListUpdator(); } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java index 060ecb1..10913c3 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/ObjectSchoolEstimateServiceImpl.java @@ -28,13 +28,14 @@ public class ObjectSchoolEstimateServiceImpl extends AbstractObserveService impl 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(); - copy(ObjectSchoolEstimate.class, BinderService.EDIT, sourceChild, targetChild); + binder.load(sourceChild, targetChild, true); childs.add(targetChild); } @@ -57,8 +58,7 @@ public class ObjectSchoolEstimateServiceImpl extends AbstractObserveService impl } - @Override - public EntityListUpdator<FloatingObject, ObjectSchoolEstimate> getListUpdator() { + protected EntityListUpdator<FloatingObject, ObjectSchoolEstimate> getListUpdator() { return EntityListUpdator.newEntityListUpdator( FloatingObject.class, ObjectSchoolEstimate.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java index 6030cd3..8feaac6 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateService.java @@ -1,10 +1,8 @@ package fr.ird.observe.services.data.seine; -import fr.ird.observe.entities.seine.SchoolEstimate; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; /** * Created on 4/28/15. @@ -19,6 +17,4 @@ public interface SchoolEstimateService extends ObserveService { @Commit void save(SetSeine parent); - EntityListUpdator<SetSeine, SchoolEstimate> getListUpdator(); - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java index 351ec2b..045a27d 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/SchoolEstimateServiceImpl.java @@ -31,13 +31,14 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements 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(); - copy(SchoolEstimate.class, BinderService.EDIT, sourceChild, targetChild); + binder.load(sourceChild, targetChild, true); childs.add(targetChild); } @@ -60,8 +61,7 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements SetSeine.class, SchoolEstimate.class, getListUpdator(), parentBinder, childBinder)); } - @Override - public EntityListUpdator<SetSeine, SchoolEstimate> getListUpdator() { + protected EntityListUpdator<SetSeine, SchoolEstimate> getListUpdator() { return EntityListUpdator.newEntityListUpdator( SetSeine.class, SchoolEstimate.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java index b70ca5d..4201f7f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthService.java @@ -1,11 +1,8 @@ package fr.ird.observe.services.data.seine; -import fr.ird.observe.entities.seine.TargetLength; import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.services.Commit; -import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; -import org.nuiton.topia.persistence.util.EntityListUpdator; /** * @author Sylvain Bavencoff - bavencoff@codelutin.com @@ -17,8 +14,4 @@ public interface TargetLengthService extends ObserveService { @Commit void save(TargetSample parent); - @NoTransaction - EntityListUpdator<TargetSample, TargetLength> getListUpdator(); - - } diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java index d6b6a85..e6fa067 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetLengthServiceImpl.java @@ -5,6 +5,7 @@ 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.services.AbstractObserveService; +import org.nuiton.topia.persistence.TopiaDAO; import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; @@ -44,14 +45,19 @@ public class TargetLengthServiceImpl extends AbstractObserveService implements T copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGTH, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); - for (TargetLength childToLoad : toLoad.getTargetLength()) { - TargetLength childLoaded = getDao(TargetLength.class).newInstance(); + if (!toLoad.isTargetLengthEmpty()) { - copy(TargetLength.class, BinderService.EDIT, childToLoad, childLoaded); + TopiaEntityBinder<TargetLength> binder = getBinder(TargetLength.class, BinderService.EDIT); + TopiaDAO<TargetLength> dao = getDao(TargetLength.class); - loaded.addTargetLength(childLoaded); + for (TargetLength childToLoad : toLoad.getTargetLength()) { + TargetLength childLoaded = dao.newInstance(); + binder.load(childToLoad, childLoaded, true); + loaded.addTargetLength(childLoaded); + + } } } @@ -81,8 +87,7 @@ public class TargetLengthServiceImpl extends AbstractObserveService implements T }); } - @Override - public EntityListUpdator<TargetSample, TargetLength> getListUpdator() { + protected EntityListUpdator<TargetSample, TargetLength> getListUpdator() { return EntityListUpdator.newEntityListUpdator( TargetSample.class, TargetLength.class, diff --git a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java index 084a408..2ce82b8 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/data/seine/TargetSampleServiceImpl.java @@ -11,6 +11,7 @@ import fr.ird.observe.entities.seine.TargetSampleDAO; import fr.ird.observe.services.AbstractObserveService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.util.TopiaEntityBinder; import java.util.ArrayList; import java.util.Collection; @@ -106,14 +107,18 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T copyExcluding(TargetSample.class, BinderService.EDIT_TARGET_LENGTH, toLoad, loaded, TargetSample.PROPERTY_TARGET_LENGTH); - for (TargetLength childToLoad : toLoad.getTargetLength()) { + if (!toLoad.isTargetLengthEmpty()) { - TargetLength childLoaded = getChildDao().newInstance(); + TargetLengthDAO childDao = getChildDao(); + TopiaEntityBinder<TargetLength> binder = getBinder(TargetLength.class, BinderService.EDIT); - copy(TargetLength.class, BinderService.EDIT, childToLoad, childLoaded); + for (TargetLength childToLoad : toLoad.getTargetLength()) { - loaded.addTargetLength(childLoaded); + TargetLength childLoaded = childDao.newInstance(); + binder.load(childToLoad, childLoaded, true); + loaded.addTargetLength(childLoaded); + } } } @@ -192,9 +197,11 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T @Override public TargetSample onUpdate(SetSeine parentBean, TargetSample toSave, TargetSample beanToSave) { + copyExcluding(TargetSample.class, BinderService.EDIT, toSave, beanToSave, TargetSample.PROPERTY_TARGET_LENGTH); getDao().update(beanToSave); return beanToSave; + } }); diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java index 0a7a418..5ae0df8 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialService.java @@ -3,6 +3,7 @@ package fr.ird.observe.services.referential; import fr.ird.observe.entities.referentiel.Program; import fr.ird.observe.entities.referentiel.ReferenceEntity; import fr.ird.observe.entities.referentiel.Species; +import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.services.Commit; import fr.ird.observe.services.ObserveService; @@ -31,6 +32,8 @@ public interface ReferentialService extends ObserveService { List<Species> loadDecoratedSpecies(String speciesListCode); + List<WeightCategory> loadDecoratedWeightCategory(); + Set<String> getSpeciesListSpeciesIds(String speciesListId); <R extends ReferenceEntity> R preCreate(Class<R> entityType); diff --git a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java index 63b1078..270858f 100644 --- a/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java +++ b/observe-services/src/main/java/fr/ird/observe/services/referential/ReferentialServiceImpl.java @@ -16,6 +16,7 @@ import fr.ird.observe.entities.referentiel.SpeciesList; import fr.ird.observe.entities.referentiel.seine.WeightCategory; import fr.ird.observe.services.AbstractObserveService; import org.apache.commons.collections.CollectionUtils; +import org.nuiton.decorator.Decorator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.topia.persistence.util.TopiaEntityHelper; @@ -111,6 +112,17 @@ public class ReferentialServiceImpl extends AbstractObserveService implements Re } @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 Set<String> getSpeciesListSpeciesIds(String speciesListId) { SpeciesList speciesList = findByTopiaId(SpeciesList.class, speciesListId); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java index 823a9d9..01dad8b 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ContentUIHandler.java @@ -30,8 +30,6 @@ import fr.ird.observe.ObserveTechnicalException; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor; -import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.referentiel.ReferenceEntity; import fr.ird.observe.services.ObserveService; import fr.ird.observe.ui.UIHelper; @@ -85,16 +83,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { protected final String prefix; - private final TopiaExecutor<E> loadExecutor; - - private final TopiaExecutor2<? extends TopiaEntity, E> preCreateExecutor; - - private final TopiaExecutor2<? extends TopiaEntity, E> createExecutor; - - private final TopiaExecutor2<? extends TopiaEntity, E> updateExecutor; - - private final TopiaExecutor2<? extends TopiaEntity, E> deleteExecutor; - private final DataContextType parentType; private final DataContextType type; @@ -112,37 +100,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { if (log.isDebugEnabled()) { log.debug("New handler [" + this + "] for ui " + prefix); } - loadExecutor = new TopiaExecutor<E>() { - @Override - public void execute(TopiaContext tx, E bean) throws TopiaException { - onLoad(tx, bean); - } - }; - preCreateExecutor = new TopiaExecutor2<TopiaEntity, E>() { - @Override - public E execute(TopiaContext tx, TopiaEntity parentBean, E bean) throws TopiaException { - return onPreCreate(tx, parentBean, bean); - } - }; - createExecutor = new TopiaExecutor2<TopiaEntity, E>() { - @Override - public E execute(TopiaContext tx, TopiaEntity parentBean, E bean) throws TopiaException { - return onCreate(tx, parentBean, bean); - } - }; - updateExecutor = new TopiaExecutor2<TopiaEntity, E>() { - @Override - public E execute(TopiaContext tx, TopiaEntity parentBean, E bean) throws TopiaException { - return onUpdate(tx, parentBean, bean); - } - }; - deleteExecutor = new TopiaExecutor2<TopiaEntity, E>() { - @Override - public E execute(TopiaContext tx, TopiaEntity parentBean, E beanToDelete) throws TopiaException { - onDelete(tx, parentBean, beanToDelete); - return null; - } - }; errorIcon = UIManager.getIcon("action.error"); } @@ -163,10 +120,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } -// protected static void attachTopiaContext(DataSource service, TopiaEntityAbstract entity) { -// DBHelper.attachTopiaContext(service.getRootCtxt(), entity); -// } - public static ObserveTreeHelper getTreeHelper(JAXXContext context) { return context.getContextValue(ObserveTreeHelper.class); } @@ -277,11 +230,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { model.addMessages((JComponent) ui, fieldName, scope, message); } -// public static void removeAllMessages(ContentUI<?> ui, NuitonValidatorScope scope, String fieldName) { -// SwingValidatorMessageTableModel model = ui.getErrorTableModel(); -// model.removeMessages(ui, fieldName, scope); -// } - public static void removeAllMessages(ObserveContentUI<?> ui) { SwingValidatorMessageTableModel model = ui.getErrorTableModel(); model.removeMessages((JComponent) ui, null); @@ -357,10 +305,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { getBinderService().copy(type, context, source, target); } - public <E extends TopiaEntity> void copyEdit(Class<E> type, String context, E source, E target) { - getBinderService().copy(type, BinderService.EDIT, 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); } @@ -522,30 +466,9 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { updateActions(); } - //TODO a remplacer par saveUI2 public void saveUI(boolean refresh) { boolean ok = false; try { - ok = doSave(getBean(), - getDataService(), - getDataSource(), - getLoadBinder() - ); - } catch (Exception e) { - ErrorDialogUI.showError(e); - if (log.isErrorEnabled()) { - log.error(e); - } - } finally { - if (ok) { - afterSave(refresh); - } - } - } - - public void saveUI2(boolean refresh) { - boolean ok = false; - try { ok = doSave(getBean()); } catch (Exception e) { ErrorDialogUI.showError(e); @@ -559,14 +482,6 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } } - //TODO a remplacer par doSave simple - protected boolean doSave(E bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<E> binder) throws Exception { - return false; - } - protected boolean doSave(E bean) throws Exception { return false; } @@ -609,41 +524,11 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } - //TODO a remplacer par deleteUI2 public void deleteUI() { boolean ok = false; ui.stopEdit(); removeAllMessages(ui); try { - ok = doDelete(getBean(), - getDataService(), - getDataSource(), - getDeleteExecutor()); - } catch (Exception e) { - ErrorDialogUI.showError(e); - if (log.isErrorEnabled()) { - log.error(e); - } - } finally { - if (ok) { - afterDelete(); - } - } - } - - //TODO a remplacer par doDelete simple - protected boolean doDelete(E bean, - DataService dataService, - DataSource dataSource, - TopiaExecutor2<? extends TopiaEntity, E> deletor) throws Exception { - return false; - } - - public void deleteUI2() { - boolean ok = false; - ui.stopEdit(); - removeAllMessages(ui); - try { ok = doDelete(getBean()); } catch (Exception e) { ErrorDialogUI.showError(e); @@ -728,18 +613,18 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { } } - protected E onCreate(TopiaContext tx, Object parentBean, E editBean) throws TopiaException { - return editBean; - } - - protected E onUpdate(TopiaContext tx, Object parentBean, E beanToSave) throws TopiaException { - // rien par defaut - return beanToSave; - } - - protected void onDelete(TopiaContext tx, Object parentBean, E beanToDelete) throws TopiaException { - // rien par defaut - } +// protected E onCreate(TopiaContext tx, Object parentBean, E editBean) throws TopiaException { +// return editBean; +// } +// +// protected E onUpdate(TopiaContext tx, Object parentBean, E beanToSave) throws TopiaException { +// // rien par defaut +// return beanToSave; +// } +// +// protected void onDelete(TopiaContext tx, Object parentBean, E beanToDelete) throws TopiaException { +// // rien par defaut +// } protected void addInfoMessage(String message) { addMessage(ui, @@ -764,25 +649,25 @@ public abstract class ContentUIHandler<E extends TopiaEntity> { return getModel().getLoadBinder(); } - protected final TopiaExecutor<E> getLoadExecutor() { - return loadExecutor; - } - - protected final TopiaExecutor2<? extends TopiaEntity, E> getPreCreateExecutor() { - return preCreateExecutor; - } - - protected final TopiaExecutor2<? extends TopiaEntity, E> getCreateExecutor() { - return createExecutor; - } - - protected final TopiaExecutor2<? extends TopiaEntity, E> getUpdateExecutor() { - return updateExecutor; - } - - protected final TopiaExecutor2<? extends TopiaEntity, E> getDeleteExecutor() { - return deleteExecutor; - } +// protected final TopiaExecutor<E> getLoadExecutor() { +// return loadExecutor; +// } +// +// protected final TopiaExecutor2<? extends TopiaEntity, E> getPreCreateExecutor() { +// return preCreateExecutor; +// } +// +// protected final TopiaExecutor2<? extends TopiaEntity, E> getCreateExecutor() { +// return createExecutor; +// } +// +// protected final TopiaExecutor2<? extends TopiaEntity, E> getUpdateExecutor() { +// return updateExecutor; +// } +// +// protected final TopiaExecutor2<? extends TopiaEntity, E> getDeleteExecutor() { +// return deleteExecutor; +// } protected final ContentMode computeContentMode() { ContentMode mode; diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIHandler.java index 929b591..22fa0a9 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/BranchlineUIHandler.java @@ -22,7 +22,7 @@ package fr.ird.observe.ui.content.impl.longline; * #L% */ -import fr.ird.observe.DataService; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; @@ -39,7 +39,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; import org.nuiton.i18n.I18n; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JOptionPane; @@ -83,7 +82,7 @@ public class BranchlineUIHandler extends ContentUIHandler<Branchline> { } getModel().setBranchline(branchline); - getLoadBinder().copy(branchline, getBean()); + copy(Branchline.class, BinderService.EDIT, branchline, getBean()); if (branchline == null) { @@ -218,14 +217,11 @@ public class BranchlineUIHandler extends ContentUIHandler<Branchline> { } @Override - protected boolean doSave(Branchline bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<Branchline> binder) throws Exception { + protected boolean doSave(Branchline bean) { // bind back to model branchline Branchline beanToSave = getModel().getBranchline(); - binder.copy(bean, beanToSave); + copy(Branchline.class, BinderService.EDIT, bean, beanToSave); // for external models getModel().fireSaved(); @@ -358,7 +354,7 @@ public class BranchlineUIHandler extends ContentUIHandler<Branchline> { boolean generalTabValid = !errorProperties.removeAll(BranchlineUIModel.GENERAL_TAB_PROPERTIES); boolean hookAndBaitTabValid = !errorProperties.removeAll(BranchlineUIModel.HOOK_AND_BAIT_TAB_PROPERTIES); - BranchlineUIModel model = getModel(); + BranchlineUIModel model = getModel(); model.setGeneralTabValid(generalTabValid); model.setHookAndBaitTabValid(hookAndBaitTabValid); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java index 2227310..641ebf5 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineDetailCompositionUIHandler.java @@ -22,12 +22,11 @@ package fr.ird.observe.ui.content.impl.longline; * #L% */ -import fr.ird.observe.DataService; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.entities.Entities; import fr.ird.observe.entities.EntityMap; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.Basket; @@ -48,10 +47,6 @@ import org.apache.commons.lang3.BooleanUtils; 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.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JComboBox; @@ -65,7 +60,6 @@ import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import static org.nuiton.i18n.I18n.t; @@ -398,12 +392,10 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong } ContentMode mode = computeContentMode(); - DataService dataService = getDataService(); - - DataSource source = getDataSource(); - // update mode - dataService.loadEditEntity(source, setId, getLoadExecutor()); + LonglineDetailCompositionService service = getService(LonglineDetailCompositionService.class); + SetLongline loaded = service.loadForEdit(setId); + copy(SetLongline.class, BinderService.EDIT_DETAIL_COMPOSITION, loaded, getBean()); // utilisation du mode requis setContentMode(mode); @@ -479,14 +471,11 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong } @Override - protected boolean doSave(SetLongline bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<SetLongline> binder) throws Exception { - + protected boolean doSave(SetLongline bean) { SectionsTableModel sectionsTableModel = getSectionsTableModel(); SectionWithTemplate selectedSection = sectionsTableModel.getSelectedRow(); + if (selectedSection != null) { // flush selected section before save @@ -494,146 +483,12 @@ public class LonglineDetailCompositionUIHandler extends ContentUIHandler<SetLong } - dataService.update(dataSource, null, bean, getUpdateExecutor()); - - return true; - } - - @Override - protected SetLongline onUpdate(TopiaContext tx, Object parentBean, SetLongline beanToSave) throws TopiaException { - - Map<String, Section> existingSectionsByTopiaId = Entities.toIdMap(beanToSave.getSection()); - - TopiaDAO<Section> sectionsDao = getDataSource().getDAO(tx, Section.class); - TopiaDAO<Basket> basketDao = getDataSource().getDAO(tx, Basket.class); - TopiaDAO<Branchline> branchlineDao = getDataSource().getDAO(tx, Branchline.class); - - List<SectionWithTemplate> sections = getSectionsTableModel().getNotEmptyData(); - - beanToSave.clearSection(); - - for (SectionWithTemplate section : sections) { - - Section sectionToSave = persistSection(sectionsDao, - basketDao, - branchlineDao, - existingSectionsByTopiaId, - section); - beanToSave.addSection(sectionToSave); - sectionToSave.setSetLongline(beanToSave); - - } - - return beanToSave; + List<SectionWithTemplate> sections = sectionsTableModel.getNotEmptyData(); - } - - protected Section persistSection(TopiaDAO<Section> sectionsDao, - TopiaDAO<Basket> basketDao, - TopiaDAO<Branchline> branchlineDao, - Map<String, Section> existingSectionsByTopiaId, - Section section) throws TopiaException { - - Section sectionToSave; - - if (section.getTopiaId() == null) { - - // create - sectionToSave = sectionsDao.create( - Section.PROPERTY_SETTING_IDENTIFIER, section.getSettingIdentifier(), - Section.PROPERTY_HAULING_IDENTIFIER, section.getHaulingIdentifier()); - - } else { - - sectionToSave = existingSectionsByTopiaId.get(section.getTopiaId()); - - } - - TopiaEntityBinder<Section> sectionBinder = getModel().getSectionBinder(); - 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(basketDao, - branchlineDao, - existingBasketsByTopiaId, - basket); - sectionToSave.addBasket(basketToSave); - - } + LonglineDetailCompositionService service = getService(LonglineDetailCompositionService.class); + service.save(bean, sections); - return sectionToSave; - - } - - protected Basket persistBasket(TopiaDAO<Basket> basketDao, - TopiaDAO<Branchline> branchlineDao, - Map<String, Basket> existingBasketsByTopiaId, - Basket basket) throws TopiaException { - - Basket basketToSave; - - if (basket.getTopiaId() == null) { - - // create - basketToSave = basketDao.create( - Basket.PROPERTY_SETTING_IDENTIFIER, basket.getSettingIdentifier(), - Basket.PROPERTY_HAULING_IDENTIFIER, basket.getHaulingIdentifier()); - - } else { - - basketToSave = existingBasketsByTopiaId.get(basket.getTopiaId()); - - } - - TopiaEntityBinder<Basket> basketBinder = getModel().getBasketBinder(); - 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(branchlineDao, existingBranchlinesByTopiaId, branchline); - basketToSave.addBranchline(branchlineToSave); - - } - - return basketToSave; - - } - - protected Branchline persistBranchline(TopiaDAO<Branchline> branchlineDao, - Map<String, Branchline> existingBranchlinesByTopiaId, - Branchline branchline) throws TopiaException { - - Branchline branchlineToSave; - - if (branchline.getTopiaId() == null) { - - // create - branchlineToSave = branchlineDao.create( - Branchline.PROPERTY_SETTING_IDENTIFIER, branchline.getSettingIdentifier(), - Branchline.PROPERTY_HAULING_IDENTIFIER, branchline.getHaulingIdentifier()); - - } else { - - branchlineToSave = existingBranchlinesByTopiaId.get(branchline.getTopiaId()); - - } - - TopiaEntityBinder<Branchline> branchlineBinder = getModel().getBranchlineBinder(); - branchlineBinder.copy(branchline, branchlineToSave); - - return branchlineToSave; + return true; } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java index 821f821..3a5fec7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/LonglineGlobalCompositionUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.content.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; @@ -38,7 +37,6 @@ import fr.ird.observe.ui.content.table.impl.longline.FloatlinesCompositionUI; import fr.ird.observe.ui.content.table.impl.longline.HooksCompositionUI; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import static org.nuiton.i18n.I18n.t; @@ -124,6 +122,7 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong @Override public void openUI() throws Exception { + super.openUI(); String activityId = getSelectedParentId(); @@ -135,12 +134,10 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong } ContentMode mode = computeContentMode(); - DataService dataService = getDataService(); - - DataSource source = getDataSource(); - // update mode - dataService.loadEditEntity(source, setId, getLoadExecutor()); + LonglineGlobalCompositionService service = getService(LonglineGlobalCompositionService.class); + SetLongline loaded = service.loadForEdit(setId); + copy(SetLongline.class, BinderService.EDIT_GLOBAL_COMPOSITION, loaded, getBean()); // utilisation du mode requis setContentMode(mode); @@ -177,22 +174,13 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong @Override public void startEditUI(String... binding) { + LonglineGlobalCompositionUIModel model = (LonglineGlobalCompositionUIModel) getModel(); addInfoMessage(t("observe.longlineGlobalComposition.message.updating")); super.startEditUI(LonglineGlobalCompositionUI.BINDING_COMMENT2_TEXT); model.setModified(false); - } - - @Override - protected boolean doSave(SetLongline bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<SetLongline> binder) throws Exception { - dataService.update(dataSource, null, bean, getUpdateExecutor()); - - return true; } @Override @@ -203,25 +191,24 @@ public class LonglineGlobalCompositionUIHandler extends ContentUIHandler<SetLong copy(SetLongline.class, BinderService.EDIT_HOOKS_COMPOSITION, getUi().getHooksCompositionUI().getBean(), bean); copy(SetLongline.class, BinderService.EDIT_BAITS_COMPOSITION, getUi().getBaitsCompositionUI().getBean(), bean); - getService(LonglineGlobalCompositionService.class).save(bean); + LonglineGlobalCompositionService service = getService(LonglineGlobalCompositionService.class); + String id = service.save(bean); + bean.setTopiaId(id); return true; + } @Override protected void afterSave(boolean refresh) { + super.afterSave(refresh); getUi().getFloatlinesCompositionUI().getHandler().afterSave(refresh); getUi().getBranchlinesCompositionUI().getHandler().afterSave(refresh); getUi().getHooksCompositionUI().getHandler().afterSave(refresh); getUi().getBaitsCompositionUI().getHandler().afterSave(refresh); - } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java index 11414a1..7cf9f43 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/longline/SetLonglineUIHandler.java @@ -22,12 +22,10 @@ package fr.ird.observe.ui.content.impl.longline; * #L% */ -import fr.ird.observe.DataService; -import fr.ird.observe.ObserveDAOHelper; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor2; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.services.data.longline.SetLonglineService; @@ -40,22 +38,16 @@ import jaxx.runtime.swing.HidorButton; import jaxx.runtime.validator.swing.SwingValidatorMessage; import jaxx.runtime.validator.swing.SwingValidatorMessageTableModel; import jaxx.runtime.validator.swing.SwingValidatorUtil; -import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.jaxx.widgets.gis.CoordinateFormat; import org.nuiton.jaxx.widgets.gis.absolute.CoordinatesEditorModel; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.Date; import java.util.HashSet; import java.util.Set; @@ -166,7 +158,6 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } - @Override public void openUI() throws Exception { @@ -190,26 +181,45 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } ContentMode mode = computeContentMode(); - DataService dataService = getDataService(); + SetLonglineService service = getService(SetLonglineService.class); - SetLongline bean = getBean(); + SetLongline loaded; - TopiaEntityBinder<SetLongline> binder = getLoadBinder(); - DataSource source = getDataSource(); if (setId == null) { // creation mode - dataService.preCreate(source, activityId, bean, binder, getPreCreateExecutor()); + loaded = service.preCreate(activityId); getUi().getFishingOperationTabPane().setSelectedIndex(0); } else { // update mode - dataService.loadEditEntity(source, setId, getLoadExecutor()); + loaded = service.loadForEdit(setId); } + Float settingStartLatitude = loaded.getSettingStartLatitude(); + Float settingStartLongitude = loaded.getSettingStartLongitude(); + Float settingEndLatitude = loaded.getSettingEndLatitude(); + Float settingEndLongitude = loaded.getSettingEndLongitude(); + Float haulingStartLatitude = loaded.getHaulingStartLatitude(); + Float haulingStartLongitude = loaded.getHaulingStartLongitude(); + Float haulingEndLatitude = loaded.getHaulingEndLatitude(); + Float haulingEndLongitude = loaded.getHaulingEndLongitude(); + + SetLongline bean = getBean(); + copy(SetLongline.class, BinderService.EDIT, loaded, bean); + + bean.setSettingStartLatitude(settingStartLatitude); + bean.setSettingStartLongitude(settingStartLongitude); + bean.setSettingEndLatitude(settingEndLatitude); + bean.setSettingEndLongitude(settingEndLongitude); + bean.setHaulingStartLatitude(haulingStartLatitude); + bean.setHaulingStartLongitude(haulingStartLongitude); + bean.setHaulingEndLatitude(haulingEndLatitude); + bean.setHaulingEndLongitude(haulingEndLongitude); + // passage en coordonnes absolues + utilisation du quadrant bean.initCoordinates(); @@ -231,31 +241,6 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } @Override - protected void onLoad(TopiaContext tx, SetLongline bean) throws TopiaException { - - Float settingStartLatitude = bean.getSettingStartLatitude(); - Float settingStartLongitude = bean.getSettingStartLongitude(); - Float settingEndLatitude = bean.getSettingEndLatitude(); - Float settingEndLongitude = bean.getSettingEndLongitude(); - Float haulingStartLatitude = bean.getHaulingStartLatitude(); - Float haulingStartLongitude = bean.getHaulingStartLongitude(); - Float haulingEndLatitude = bean.getHaulingEndLatitude(); - Float haulingEndLongitude = bean.getHaulingEndLongitude(); - - super.onLoad(tx, bean); - - getBean().setSettingStartLatitude(settingStartLatitude); - getBean().setSettingStartLongitude(settingStartLongitude); - getBean().setSettingEndLatitude(settingEndLatitude); - getBean().setSettingEndLongitude(settingEndLongitude); - getBean().setHaulingStartLatitude(haulingStartLatitude); - getBean().setHaulingStartLongitude(haulingStartLongitude); - getBean().setHaulingEndLatitude(haulingEndLatitude); - getBean().setHaulingEndLongitude(haulingEndLongitude); - - } - - @Override protected void closeSafeUI() { if (log.isInfoEnabled()) { @@ -269,35 +254,6 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } @Override - protected SetLongline onPreCreate(TopiaContext tx, - Object parent, - SetLongline bean) throws TopiaException { - - ActivityLongline parentBean = (ActivityLongline) parent; - - // on utilise la date - heure de l'activité pour initialiser les horodatages - // de l'opération de peche - Date timeStamp = parentBean.getTimeStamp(); - bean.setSettingStartTimeStamp(timeStamp); - bean.setSettingEndTimeStamp(DateUtils.addHours(timeStamp, 1)); - bean.setHaulingStartTimeStamp(DateUtils.addHours(timeStamp, 2)); - bean.setHaulingEndTimeStamp(DateUtils.addHours(timeStamp, 3)); - - // on reporte la position de l'activité pour la position de début de filage - Float latitude = parentBean.getLatitude(); - Float longitude = parentBean.getLongitude(); - - // On enregistre deux fois les coordonnées car la première fois on perd le signe à cause de l'éditeur - bean.setSettingStartLatitude(latitude); - bean.setSettingStartLongitude(longitude); - bean.setSettingStartLatitude(latitude); - bean.setSettingStartLongitude(longitude); - - return bean; - - } - - @Override public void startEditUI(String... binding) { ContentUIModel<SetLongline> model = getModel(); @@ -368,10 +324,7 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } @Override - protected boolean doSave(SetLongline bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<SetLongline> binder) throws Exception { + protected boolean doSave(SetLongline bean) { String activityId = getSelectedParentId(); @@ -379,6 +332,7 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { String savedId = service.save(activityId, bean); bean.setTopiaId(savedId); return true; + } @Override @@ -409,7 +363,6 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } else { // select ancestor node -// treeHelper.refreshNode(node, false); treeHelper.reloadSelectedNode(false, false); } @@ -417,33 +370,26 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } @Override - protected boolean doDelete(SetLongline bean, - DataService dataService, - DataSource dataSource, - TopiaExecutor2<? extends TopiaEntity, SetLongline> deletor) throws Exception { + protected boolean doDelete(SetLongline bean) { + + boolean result; if (askToDelete(bean)) { - return false; - } - String activityId = getSelectedParentId(); - dataService.delete(dataSource, activityId, bean, deletor); + result = false; - return true; + } else { - } + SetLonglineService service = getService(SetLonglineService.class); - @Override - protected void onDelete(TopiaContext tx, Object parent, SetLongline beanToDelete) throws TopiaException { + String activityId = getSelectedParentId(); + service.delete(activityId, bean.getTopiaId()); - ActivityLongline parentBean = (ActivityLongline) parent; + result = true; - // on doit supprimer physiquement la set - // car il n'y a pas de delete-orphan sur une telle - // relation - ObserveDAOHelper.getSetLonglineDAO(tx).delete(parentBean.getSetLongline()); - // supprime la reference sur l'activity - parentBean.setSetLongline(null); + } + + return result; } @@ -525,4 +471,5 @@ public class SetLonglineUIHandler extends ContentUIHandler<SetLongline> { } } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java index 58214c3..86ace0a 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/ActivitySeineObservedSystemUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; @@ -85,7 +86,7 @@ public class ActivitySeineObservedSystemUIHandler extends ContentUIHandler<Activ ActivitySeineService service = getService(ActivitySeineService.class); ActivitySeine activitySeine = service.loadForEditObservedSystem(activityId); - service.copyForEditObservedSystem(activitySeine, getBean()); + copy(ActivitySeine.class, BinderService.EDIT_OBSERVED_SYSTEM, activitySeine, getBean()); getModel().setMode(mode); @@ -105,15 +106,9 @@ public class ActivitySeineObservedSystemUIHandler extends ContentUIHandler<Activ ActivitySeineService service = getService(ActivitySeineService.class); ActivitySeine saved = service.updateObservedSystem(getBean()); - service.copyForEditObservedSystem(saved, bean); + copy(ActivitySeine.class, BinderService.EDIT_OBSERVED_SYSTEM, saved, bean); return true; } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java index 21c72a3..186d458 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIHandler.java @@ -21,15 +21,13 @@ */ package fr.ird.observe.ui.content.impl.seine; -import fr.ird.observe.DecoratorService; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.constants.seine.Ownership; import fr.ird.observe.entities.constants.seine.TypeTransmittingBuoyOperation; -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.TransmittingBuoy; @@ -39,9 +37,6 @@ import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIHandler; 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.TopiaException; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JPanel; @@ -121,7 +116,7 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH FloatingObjectService service = getService(FloatingObjectService.class); FloatingObject loaded = service.loadForEditTransmittingBuoyOperation(floatingObjectId); - service.copyForEditTransmittingBuoyOperation(loaded, getBean()); + copy(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY, loaded, bean); getUi().processDataBinding(FloatingObjectTransmittingBuoyOperationUI.BINDING_TYPE_OPERATION_SELECTED_ITEM); @@ -136,55 +131,6 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH } @Override - protected void onLoad(TopiaContext tx, FloatingObject bean) throws TopiaException { - - FloatingObject editBean = getBean(); - - // chargement du bean depuis celui qui vient de la base - getLoadBinder().load(bean, editBean, true); - - editBean.clearTransmittingBuoy(); - - List<TransmittingBuoy> objets = bean.getTransmittingBuoy(); - - if (objets != null) { - DecoratorService decoratorService = getDecoratorService(); - Decorator<TransmittingBuoy> dB = decoratorService.getDecoratorByType(TransmittingBuoy.class); - Decorator<TransmittingBuoyOperation> dB2 = decoratorService.getDecoratorByType(TransmittingBuoyOperation.class); - Decorator<TransmittingBuoyType> dB3 = decoratorService.getDecoratorByType(TransmittingBuoyType.class); - Decorator<Country> dB4 = decoratorService.getDecoratorByType(Country.class); - for (TransmittingBuoy transmittingBuoy : objets) { - String s = dB.toString(transmittingBuoy); - if (log.isDebugEnabled()) { - log.debug("use balise lue : " + s); - } - TransmittingBuoyOperation objectOperation = transmittingBuoy.getTransmittingBuoyOperation(); - if (objectOperation != null) { - s = dB2.toString(objectOperation); - if (log.isDebugEnabled()) { - log.debug("use objectOperation balise : " + s); - } - } - TransmittingBuoyType type = transmittingBuoy.getTransmittingBuoyType(); - if (type != null) { - s = dB3.toString(type); - if (log.isDebugEnabled()) { - log.debug("use type balise : " + s); - } - } - Country country = transmittingBuoy.getCountry(); - if (country != null) { - s = dB4.toString(country); - if (log.isDebugEnabled()) { - log.debug("use country : " + s); - } - } - editBean.addTransmittingBuoy(transmittingBuoy); - } - } - } - - @Override public void startEditUI(String... binding) { super.startEditUI( FloatingObjectTransmittingBuoyOperationUI.BINDING_TRANSMITTING_BUOY_OPERATION1_SELECTED_ITEM, @@ -238,56 +184,15 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH @Override protected boolean doSave(FloatingObject bean) { + //FIXME On ne doit pas retourner l'objet... FloatingObjectService service = getService(FloatingObjectService.class); FloatingObject saved = service.updateTransmittingBuoyOperation(bean); - service.copyForEditTransmittingBuoyOperation(saved, bean); + copy(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY, saved, bean); //FIXME, il faut declancher un evenement dans le cache du storage pour pouvoir redessiner le noeud return true; } -// @Override -// protected FloatingObject onUpdate(TopiaContext tx, -// Object parentBean, -// FloatingObject beanToSave) throws TopiaException { -// -// FloatingObject editBean = getBean(); -// -// List<TransmittingBuoy> objets = editBean.getTransmittingBuoy(); -// -// beanToSave.setComment(editBean.getComment()); -// -// beanToSave.clearTransmittingBuoy(); -// -// TopiaEntityBinder<TransmittingBuoy> childLoador = getModel().getChildLoador(); -// -// TopiaDAO<TransmittingBuoy> transmittingBuoyDAO = ObserveDAOHelper.getTransmittingBuoyDAO(tx); -// -// for (TransmittingBuoy transmittingBuoy : objets) { -// TransmittingBuoy newBalise; -// -// if (transmittingBuoy.getTopiaId() == null) { -// -// // creation de la balise -// -// Map<String, Object> map = childLoador.obtainProperties(transmittingBuoy); -// -// newBalise = transmittingBuoyDAO.create(map); -// -// } else { -// -// // mise a jour de la balise -// -// newBalise = transmittingBuoyDAO.findByTopiaId(transmittingBuoy.getTopiaId()); -// -// childLoador.load(transmittingBuoy, newBalise, false); -// } -// -// beanToSave.addTransmittingBuoy(newBalise); -// } -// return beanToSave; -// } - @Override protected void afterSave(boolean refresh) { // rien a rafraichir ? @@ -388,8 +293,7 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH TransmittingBuoyOperation transmittingBuoyOperation, TransmittingBuoy transmittingBuoy) { - FloatingObjectService service = getService(FloatingObjectService.class); - service.copyForEditTransmittingBuoy(transmittingBuoy, editBean); + copy(TransmittingBuoy.class, BinderService.EDIT, transmittingBuoy, editBean); if (transmittingBuoy == null) { @@ -433,10 +337,4 @@ public class FloatingObjectTransmittingBuoyOperationUIHandler extends ContentUIH return objectOperation; } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java index 36d6015..b424211 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectTransmittingBuoyOperationUIModel.java @@ -36,38 +36,9 @@ public class FloatingObjectTransmittingBuoyOperationUIModel extends ContentUIMod private static final long serialVersionUID = 1L; -// protected TopiaEntityBinder<TransmittingBuoy> childLoador; - public FloatingObjectTransmittingBuoyOperationUIModel() { - super(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION); - -// String binderName = getClass().getName() + "-open"; -// -// BinderService binderService = ObserveServiceHelper.get().getBinderService(); - -// childLoador = binderService.getTopiaBinder(TransmittingBuoy.class, binderName); -// -// if (childLoador == null) { -// -// BinderModelBuilder<TransmittingBuoy, TransmittingBuoy> builder = binderService.newBinderBuilder( -// TransmittingBuoy.class, -// TransmittingBuoy.PROPERTY_CODE, -// TransmittingBuoy.PROPERTY_OWNERSHIP, -// TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_TYPE, -// TransmittingBuoy.PROPERTY_TRANSMITTING_BUOY_OPERATION, -// TransmittingBuoy.PROPERTY_BRAND, -// TransmittingBuoy.PROPERTY_COUNTRY); -// -// // enregistrement du binder -// childLoador = binderService.registerTopiaBinder(TransmittingBuoy.class, builder, binderName); -// -// // positionnement de l'entite empty -// childLoador.setEmpty(new TransmittingBuoyImpl()); -// } + super(FloatingObject.class, BinderService.EDIT_OBJECT_OPERATION_TRANSMITTING_BUOY); } -// @Override -// protected BinderModelBuilder<FloatingObject, FloatingObject> createOpeningBinder(BinderService binderService, String binderName) { return null; } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java index cec5c6c..591d1e3 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/FloatingObjectUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.constants.DataContextType; @@ -121,7 +122,7 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObject> { } FloatingObject bean = getBean(); - service.copyForEdit(loaded, bean); + copy(FloatingObject.class, BinderService.EDIT, loaded, bean); // utilisation du mode requis setContentMode(mode); @@ -217,15 +218,4 @@ public class FloatingObjectUIHandler extends ContentUIHandler<FloatingObject> { } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - - //TODO Supprimer deleteUI et mettre deleteUI2 a la place - @Override - public final void deleteUI() { - deleteUI2(); - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java index 913edb4..1fe72ea 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/impl/seine/SetSeineUIHandler.java @@ -351,16 +351,4 @@ public class SetSeineUIHandler extends ContentUIHandler<SetSeine> { } - //TODO Supprimer deleteUI et mettre deleteUI2 a la place - @Override - public final void deleteUI() { - deleteUI2(); - } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java index acc0335..1b52eef 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/ContentOpenableUIHandler.java @@ -77,18 +77,6 @@ public abstract class ContentOpenableUIHandler<E extends TopiaEntity & OpenableE return service.getOpenablePosition(containerId, beanId); } - //TODO Supprimer deleteUI et mettre deleteUI2 a la place - @Override - public final void deleteUI() { - deleteUI2(); - } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - @Override public ContentOpenableUI<E> getUi() { return (ContentOpenableUI<E>) super.getUi(); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java index 10cf6ab..7e0e1fe 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/open/impl/seine/ActivitySeineUIHandler.java @@ -21,6 +21,7 @@ */ package fr.ird.observe.ui.content.open.impl.seine; +import fr.ird.observe.BinderService; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.seine.VesselActivitySeine; @@ -174,16 +175,12 @@ public class ActivitySeineUIHandler extends ContentOpenableUIHandler<ActivitySei } else { // update mode - if (mode == ContentMode.UPDATE) { - loaded = service.loadForEdit(activityId); - } else { - loaded = service.loadForDisplay(activityId); - } + loaded = service.loadForEdit(activityId); } ActivitySeine bean = getBean(); - service.copyForEdit(loaded, bean); + copy(ActivitySeine.class, BinderService.EDIT, loaded, bean); SwingValidatorMessageTableModel errorTableModel = getUi().getErrorTableModel(); computeTabValidState(errorTableModel); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java index d597124..7e64197 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/ref/ContentReferenceUIHandler.java @@ -112,18 +112,6 @@ public class ContentReferenceUIHandler<E extends ReferenceEntity> extends Conten } }; - //TODO Supprimer deleteUI et mettre deleteUI2 a la place - @Override - public final void deleteUI() { - deleteUI2(); - } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - public ContentReferenceUIHandler(ContentReferenceUI<E> ui) { super(ui, null, null); } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java index 0d2093d..c5be916 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/ContentTableUIHandler.java @@ -21,9 +21,7 @@ */ package fr.ird.observe.ui.content.table; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveContext; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; @@ -36,16 +34,11 @@ import fr.ird.observe.ui.content.ContentUIHandler; import fr.ird.observe.ui.content.ObserveContentUI; import fr.ird.observe.ui.tree.ObserveNode; import jaxx.runtime.swing.ErrorDialogUI; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -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.Loador; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JComponent; @@ -54,11 +47,9 @@ import javax.swing.SwingUtilities; import javax.swing.event.ListSelectionEvent; import javax.swing.table.DefaultTableCellRenderer; import java.awt.Rectangle; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Set; import static org.nuiton.i18n.I18n.n; @@ -193,86 +184,88 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top protected abstract void initTableUI(DefaultTableCellRenderer renderer); - protected String getEditBeanIdToLoad(DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { - throw new IllegalStateException("Do NOT USE ME!!!"); - } +// protected String getEditBeanIdToLoad(DataContext dataContext, +// DataService dataService, +// DataSource dataSource) throws DataSourceException { +// throw new IllegalStateException("Do NOT USE ME!!!"); +// } - protected E loadEditBean(ContentMode mode, - DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { +// protected E loadEditBean(ContentMode mode, +// DataContext dataContext, +// DataService dataService, +// DataSource dataSource) throws DataSourceException { +// +// loadEditBean(mode); +// +//// String id = getEditBeanIdToLoad(dataContext, dataService, dataSource); +//// +//// if (id == null) { +//// throw new IllegalStateException("Could not find id form " + this); +//// } +//// +//// // preparation du bean d'édition +//// dataService.loadEditEntity(dataSource, id, getLoadExecutor()); +// +//// getModel().setMode(mode); +//// +//// // initialisation du modèle du tableau +//// getUi().getTableModel().attachModel(); +// +// E editBean = getBean(); +// return editBean; +// +// } - loadEditBean(); + //FIXME Rendre cette methode abstract + protected abstract void loadEditBean(ContentMode mode) ; -// String id = getEditBeanIdToLoad(dataContext, dataService, dataSource); +// protected abstract void loadEditBean() throws DataSourceException { +// +// String id = getEditBeanIdToLoad(getDataContext(), getDataService(), getDataSource()); // // if (id == null) { // throw new IllegalStateException("Could not find id form " + this); // } // // // preparation du bean d'édition -// dataService.loadEditEntity(dataSource, id, getLoadExecutor()); - -// getModel().setMode(mode); +// getDataService().loadEditEntity(getDataSource(), id, getLoadExecutor()); // -// // initialisation du modèle du tableau -// getUi().getTableModel().attachModel(); - - E editBean = getBean(); - return editBean; - - } - - //FIXME Rendre cette methode abstract - protected void loadEditBean() throws DataSourceException { +// } - String id = getEditBeanIdToLoad(getDataContext(), getDataService(), getDataSource()); - - if (id == null) { - throw new IllegalStateException("Could not find id form " + this); - } - - // preparation du bean d'édition - getDataService().loadEditEntity(getDataSource(), id, getLoadExecutor()); - - } - - //FIXME A supprimer - @Override - protected final void onLoad(TopiaContext tx, E bean) throws TopiaException { - super.onLoad(tx, bean); - - // on duplique la liste des fils traites dans le tableau - // sinon on reste sur les references d'origine et on aura pas - // la possibilité d'annuler l'edition ensuite car on aura modifie - // les entrées d'origine... - E editBean = getBean(); - Collection<D> data = loadChilds(tx, editBean); - getModel().getChildsUpdator().setChilds(editBean, data); - } - - //FIXME A supprimer - protected Collection<D> loadChilds(TopiaContext tx, E bean) throws TopiaException { - Collection<D> childs = getModel().getChildsUpdator().getChilds(bean); - Collection<D> data = new ArrayList<D>(); - if (CollectionUtils.isNotEmpty(childs)) { - Loador<D> loader = getModel().getChildLoador(); - TopiaDAO<D> dao = getDataSource().getDAO(tx, getTableEditBean()); - for (D c : childs) { - try { - D cUp = dao.findByTopiaId(c.getTopiaId()); - D c2 = getModel().newTableEditBean(); - loader.load(cUp, c2, true); - data.add(c2); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - return data; - } +// //FIXME A supprimer +// @Override +// protected final void onLoad(TopiaContext tx, E bean) throws TopiaException { +// super.onLoad(tx, bean); +// +// // on duplique la liste des fils traites dans le tableau +// // sinon on reste sur les references d'origine et on aura pas +// // la possibilité d'annuler l'edition ensuite car on aura modifie +// // les entrées d'origine... +// E editBean = getBean(); +// Collection<D> data = loadChilds(tx, editBean); +// getModel().getChildsUpdator().setChilds(editBean, data); +// } +// +// //FIXME A supprimer +// protected Collection<D> loadChilds(TopiaContext tx, E bean) throws TopiaException { +// Collection<D> childs = getModel().getChildsUpdator().getChilds(bean); +// Collection<D> data = new ArrayList<D>(); +// if (CollectionUtils.isNotEmpty(childs)) { +// Loador<D> loader = getModel().getChildLoador(); +// TopiaDAO<D> dao = getDataSource().getDAO(tx, getTableEditBean()); +// for (D c : childs) { +// try { +// D cUp = dao.findByTopiaId(c.getTopiaId()); +// D c2 = getModel().newTableEditBean(); +// loader.load(cUp, c2, true); +// data.add(c2); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// } +// return data; +// } @Override public void initUI() throws Exception { @@ -329,7 +322,7 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top ui.getTableModel().dettachModel(); // chargement du bean d'édition - loadEditBean(mode, getDataContext(), getDataService(), getDataSource()); + loadEditBean(mode); // chargement de l'écran d'édition loadTableEditBeanForm(mode); @@ -396,36 +389,36 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top } } - @Override - protected boolean doSave(E bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<E> binder) throws Exception { - - ObserveContentTableUI<E, D> ui = getUi(); - - List<D> objets = ui.getTableModel().getData(); - - boolean canContinue; - try { - canContinue = prepareSave(bean, objets); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error(e); - } - ErrorDialogUI.showError(e); - canContinue = false; - } - if (!canContinue) { - - // l'utilisateur a choisi de ne pas sauvegarder - return false; - } - doPersist(bean, dataService, dataSource); - - - return true; - } +// @Override +// protected boolean doSave(E bean, +// DataService dataService, +// DataSource dataSource, +// TopiaEntityBinder<E> binder) throws Exception { +// +// ObserveContentTableUI<E, D> ui = getUi(); +// +// List<D> objets = ui.getTableModel().getData(); +// +// boolean canContinue; +// try { +// canContinue = prepareSave(bean, objets); +// } catch (Exception e) { +// if (log.isErrorEnabled()) { +// log.error(e); +// } +// ErrorDialogUI.showError(e); +// canContinue = false; +// } +// if (!canContinue) { +// +// // l'utilisateur a choisi de ne pas sauvegarder +// return false; +// } +// doPersist(bean, dataService, dataSource); +// +// +// return true; +// } @Override protected boolean doSave(E bean) { @@ -456,70 +449,70 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top } - protected void doPersist(E bean, DataService dataService, DataSource dataSource) throws DataSourceException { - // sauvegarde du bean en base - dataService.update(dataSource, null, bean, getUpdateExecutor()); - } +// protected void doPersist(E bean, DataService dataService, DataSource dataSource) throws DataSourceException { +// // sauvegarde du bean en base +// dataService.update(dataSource, null, bean, getUpdateExecutor()); +// } protected void doPersist(E editBean) { } - @Override - protected E onUpdate(TopiaContext tx, Object parentBean, E beanToSave) throws TopiaException { - - List<D> childs = getUi().getTableModel().getData(); - - E editBean = getBean(); - - TopiaEntityBinder<E> binder = getLoadBinder(); - - Loador<D> childBinder = getModel().getChildLoador(); - - EntityListUpdator<E, D> childUpdator = getModel().getChildsUpdator(); - - // recopie des propriétés du bean en excluant toujours la liste des fils - binder.copyExcluding(editBean, beanToSave, childUpdator.getPropertyName()); - - // on conserve l'ancienne liste des fils (pour traitement ultérieure) - Collection<D> oldChilds = - new ArrayList<D>(childUpdator.getChilds(beanToSave)); - - // suppression des fils dans le bean a sauver - childUpdator.removeAll(beanToSave); - - TopiaDAO<D> dao = ObserveDAOHelper.getDAO(tx, getModel().getChildType()); - - for (D child : childs) { - - D childToSave; - - if (child.getTopiaId() == null) { - - // creation du fils - Map<String, Object> map = childBinder.obtainProperties(child); - - childToSave = dao.create(map); - - } else { - - // mise a jour du fils - - childToSave = dao.findByTopiaId(child.getTopiaId()); - - childBinder.load(child, childToSave, false); - } - - // ajout du fils au bean à sauver - childUpdator.addToList(beanToSave, childToSave); - } - - // on donne la main aux implantations pour faire des traitements - // supplémentaires - onUpdateFinalize(tx, beanToSave, oldChilds); - - return beanToSave; - } +// @Override +// protected E onUpdate(TopiaContext tx, Object parentBean, E beanToSave) throws TopiaException { +// +// List<D> childs = getUi().getTableModel().getData(); +// +// E editBean = getBean(); +// +// TopiaEntityBinder<E> binder = getLoadBinder(); +// +// Loador<D> childBinder = getModel().getChildLoador(); +// +// EntityListUpdator<E, D> childUpdator = getModel().getChildsUpdator(); +// +// // recopie des propriétés du bean en excluant toujours la liste des fils +// binder.copyExcluding(editBean, beanToSave, childUpdator.getPropertyName()); +// +// // on conserve l'ancienne liste des fils (pour traitement ultérieure) +// Collection<D> oldChilds = +// new ArrayList<D>(childUpdator.getChilds(beanToSave)); +// +// // suppression des fils dans le bean a sauver +// childUpdator.removeAll(beanToSave); +// +// TopiaDAO<D> dao = ObserveDAOHelper.getDAO(tx, getModel().getChildType()); +// +// for (D child : childs) { +// +// D childToSave; +// +// if (child.getTopiaId() == null) { +// +// // creation du fils +// Map<String, Object> map = childBinder.obtainProperties(child); +// +// childToSave = dao.create(map); +// +// } else { +// +// // mise a jour du fils +// +// childToSave = dao.findByTopiaId(child.getTopiaId()); +// +// childBinder.load(child, childToSave, false); +// } +// +// // ajout du fils au bean à sauver +// childUpdator.addToList(beanToSave, childToSave); +// } +// +// // on donne la main aux implantations pour faire des traitements +// // supplémentaires +// onUpdateFinalize(tx, beanToSave, oldChilds); +// +// return beanToSave; +// } @Override protected void afterSave(boolean refresh) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java index 42bdefa..af75db0 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BaitsCompositionUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.BaitsComposition; import fr.ird.observe.entities.longline.SetLongline; @@ -31,6 +30,7 @@ import fr.ird.observe.entities.referentiel.longline.BaitSettingStatus; import fr.ird.observe.entities.referentiel.longline.BaitType; import fr.ird.observe.services.data.longline.BaitsCompositionService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -63,7 +63,7 @@ public class BaitsCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -135,9 +135,4 @@ public class BaitsCompositionUIHandler extends ContentTableUIHandler<SetLongline super.afterSave(refresh); } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java index cdfcc88..001bb49 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/BranchlinesCompositionUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.BranchlinesComposition; import fr.ird.observe.entities.longline.SetLongline; @@ -31,6 +30,7 @@ import fr.ird.observe.entities.referentiel.longline.HookSize; import fr.ird.observe.entities.referentiel.longline.HookType; import fr.ird.observe.services.data.longline.BranchlinesCompositionService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -107,7 +107,7 @@ public class BranchlinesCompositionUIHandler extends ContentTableUIHandler<SetLo } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -133,10 +133,4 @@ public class BranchlinesCompositionUIHandler extends ContentTableUIHandler<SetLo super.afterSave(refresh); } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java index fdfc42c..710b8ad 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/CatchLonglineUIHandler.java @@ -26,8 +26,6 @@ import fr.ird.observe.BinderService; import fr.ird.observe.DecoratorService; import fr.ird.observe.ObserveConfig; import fr.ird.observe.ObserveContext; -import fr.ird.observe.ObserveDAOHelper; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.Basket; import fr.ird.observe.entities.longline.Branchline; @@ -35,9 +33,7 @@ import fr.ird.observe.entities.longline.CatchLongline; import fr.ird.observe.entities.longline.Section; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.longline.SizeMeasure; -import fr.ird.observe.entities.longline.SizeMeasureDAO; import fr.ird.observe.entities.longline.WeightMeasure; -import fr.ird.observe.entities.longline.WeightMeasureDAO; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.referentiel.longline.CatchFateLongline; import fr.ird.observe.entities.referentiel.longline.Healthness; @@ -47,6 +43,7 @@ import fr.ird.observe.services.data.longline.CatchLonglineService; import fr.ird.observe.services.data.longline.SetLonglineService; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.ContentUIInitializer; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIHandler; @@ -58,9 +55,6 @@ import org.apache.commons.lang3.BooleanUtils; 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.TopiaException; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JComponent; @@ -70,8 +64,6 @@ import javax.swing.event.TableModelListener; import javax.swing.table.DefaultTableCellRenderer; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -156,7 +148,7 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -184,11 +176,61 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C @Override protected void doPersist(SetLongline editBean) { + List<CatchLongline> catchLonglines = editBean.getCatchLongline(); + + { + SizeMeasuresTableModel tableModel = getModel().getSizeMeasuresTableModel(); + + Set<Integer> rowsChanged = tableModel.getCacheRowsChanged(); + + for (Integer row : rowsChanged) { + + CatchLongline catchLongline = catchLonglines.get(row); + + List<SizeMeasure> measurements = tableModel.getCacheForRowNotEmpty(row); + catchLongline.clearSizeMeasure(); + catchLongline.addAllSizeMeasure(measurements); + + } + } + + { + WeightMeasuresTableModel tableModel = getModel().getWeightMeasuresTableModel(); + + Set<Integer> rowsChanged = tableModel.getCacheRowsChanged(); + + for (Integer row : rowsChanged) { + + CatchLongline catchLongline = catchLonglines.get(row); + + List<WeightMeasure> measurements = tableModel.getCacheForRowNotEmpty(row); + catchLongline.clearWeightMeasure(); + catchLongline.addAllWeightMeasure(measurements); + + } + } + CatchLonglineService service = getService(CatchLonglineService.class); service.save(editBean); } + public void saveBranchline() { + + if (log.isInfoEnabled()) { + log.info("Saved modified branchline"); + } + + Branchline branchline = getTableEditBean().getBranchline(); + + CatchLonglineService service = getService(CatchLonglineService.class); + + Branchline beanSaved = service.saveBranchline(branchline); + getTableEditBean().setBranchline(beanSaved); + getUi().getBranchlineValidator().setChanged(false); + + } + @Override protected void onSelectedRowChanged(int editingRow, CatchLongline bean, boolean create) { @@ -542,103 +584,6 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } @Override - protected void onUpdateFinalize(TopiaContext tx, SetLongline bean, Collection<CatchLongline> oldChilds) throws TopiaException { - - List<CatchLongline> catchLonglines = bean.getCatchLongline(); - - // remove less precise position on longline - LonglinePositionHelper<CatchLongline> positionHelper = POSITION_HELPER_ENTRY.getContextValue(getUi()); - positionHelper.savePosition(catchLonglines); - - CatchLonglineUIModel model = getModel(); - { - - // save sizes - - SizeMeasureDAO measureDao = ObserveDAOHelper.getSizeMeasureDAO(tx); - - SizeMeasuresTableModel sizeMeasuresTableModel = model.getSizeMeasuresTableModel(); - Set<Integer> rowsChanged = sizeMeasuresTableModel.getCacheRowsChanged(); - - TopiaEntityBinder<SizeMeasure> loader = sizeMeasuresTableModel.getLoader(); - for (Integer row : rowsChanged) { - - CatchLongline catchLongline = catchLonglines.get(row); - - List<SizeMeasure> measures = sizeMeasuresTableModel.getCacheForRow(row); - List<SizeMeasure> measuresToSave = new ArrayList<SizeMeasure>(measures.size()); - - for (SizeMeasure measure : measures) { - - if (sizeMeasuresTableModel.isRowNotEmpty(measure)) { - - SizeMeasure measureToSave; - - if (measure.getTopiaId() == null) { - measureToSave = measureDao.create(measure); - loader.load(measureToSave, measure, true); - } else { - measureToSave = catchLongline.getSizeMeasureByTopiaId(measure.getTopiaId()); - loader.load(measure, measureToSave, true); - } - - measuresToSave.add(measureToSave); - - } - - } - - catchLongline.clearSizeMeasure(); - catchLongline.addAllSizeMeasure(measuresToSave); - - } - - } - - { - - // save weights - - WeightMeasureDAO dao = ObserveDAOHelper.getWeightMeasureDAO(tx); - - WeightMeasuresTableModel weightMeasuresTableModel = model.getWeightMeasuresTableModel(); - TopiaEntityBinder<WeightMeasure> loader = weightMeasuresTableModel.getLoader(); - Set<Integer> rowsChanged = weightMeasuresTableModel.getCacheRowsChanged(); - - for (Integer row : rowsChanged) { - - CatchLongline catchLongline = catchLonglines.get(row); - - List<WeightMeasure> measures = weightMeasuresTableModel.getCacheForRow(row); - List<WeightMeasure> measuresToSave = new ArrayList<WeightMeasure>(measures.size()); - for (WeightMeasure measure : measures) { - - if (weightMeasuresTableModel.isRowNotEmpty(measure)) { - - WeightMeasure measureToSave; - - if (measure.getTopiaId() == null) { - measureToSave = dao.create(measure); - loader.load(measureToSave, measure, true); - } else { - measureToSave = catchLongline.getWeightMeasureByTopiaId(measure.getTopiaId()); - loader.load(measure, measureToSave, true); - } - measuresToSave.add(measureToSave); - - } - - } - - catchLongline.clearWeightMeasure(); - catchLongline.addAllWeightMeasure(measuresToSave); - } - - } - - } - - @Override protected void resetEditBean() { UIHelper.stopEditing(getUi().getSizeMeasuresTable()); @@ -659,23 +604,6 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C } - public void saveBranchline() { - - if (log.isInfoEnabled()) { - log.info("Saved modified branchline"); - } - - Branchline branchline = getTableEditBean().getBranchline(); - - CatchLonglineService service = getService(CatchLonglineService.class); - - Branchline beanSaved = service.saveBranchline(branchline); - getTableEditBean().setBranchline(beanSaved); - getUi().getBranchlineValidator().setChanged(false); - - - } - public void updateCatchAcquisitionMode(CatchAcquisitionModeEnum newMode) { if (log.isDebugEnabled()) { @@ -925,10 +853,4 @@ public class CatchLonglineUIHandler extends ContentTableUIHandler<SetLongline, C return (CatchLonglineTableModel) super.getTableModel(); } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java index 166b706..a00e5c0 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/EncounterUIHandler.java @@ -24,7 +24,6 @@ package fr.ird.observe.ui.content.table.impl.longline; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.Encounter; @@ -32,6 +31,7 @@ import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.referentiel.longline.EncounterType; import fr.ird.observe.services.data.longline.EncounterService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -62,7 +62,7 @@ public class EncounterUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String activityLonglineId = getDataContext().getSelectedActivityId(); @@ -124,9 +124,4 @@ public class EncounterUIHandler extends ContentTableUIHandler<ActivityLongline, } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java index e27355b..89bd006 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/FloatlinesCompositionUIHandler.java @@ -23,13 +23,13 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.FloatlinesComposition; import fr.ird.observe.entities.longline.SetLongline; import fr.ird.observe.entities.referentiel.longline.LineType; import fr.ird.observe.services.data.longline.FloatlinesCompositionService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -62,7 +62,7 @@ public class FloatlinesCompositionUIHandler extends ContentTableUIHandler<SetLon } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -129,9 +129,4 @@ public class FloatlinesCompositionUIHandler extends ContentTableUIHandler<SetLon super.afterSave(refresh); } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java index 6d1421f..98b64bf 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/GearUseFeaturesLonglineUIHandler.java @@ -25,7 +25,6 @@ package fr.ird.observe.ui.content.table.impl.longline; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.GearUseFeaturesLongline; import fr.ird.observe.entities.longline.GearUseFeaturesMeasurementLongline; @@ -117,7 +116,7 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String activityLonglineId = getDataContext().getSelectedTripLonglineId(); @@ -538,9 +537,4 @@ public class GearUseFeaturesLonglineUIHandler extends ContentTableUIHandler<Trip } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java index 40cc700..765f2c5 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/HooksCompositionUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.content.table.impl.longline; */ import fr.ird.observe.BinderService; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.HooksComposition; import fr.ird.observe.entities.longline.SetLongline; @@ -31,6 +30,7 @@ import fr.ird.observe.entities.referentiel.longline.HookSize; import fr.ird.observe.entities.referentiel.longline.HookType; import fr.ird.observe.services.data.longline.HooksCompositionService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -63,7 +63,7 @@ public class HooksCompositionUIHandler extends ContentTableUIHandler<SetLongline } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -127,12 +127,6 @@ public class HooksCompositionUIHandler extends ContentTableUIHandler<SetLongline } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - @Override public void afterSave(boolean refresh) { super.afterSave(refresh); diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java index 662960c..cbdf74d 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/SensorUsedUIHandler.java @@ -28,7 +28,6 @@ import com.google.common.io.Files; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveContext; import fr.ird.observe.ObserveTechnicalException; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.longline.ActivityLongline; import fr.ird.observe.entities.longline.SensorUsed; @@ -38,6 +37,7 @@ import fr.ird.observe.entities.referentiel.longline.SensorType; import fr.ird.observe.services.data.longline.SensorUsedService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -80,7 +80,7 @@ public class SensorUsedUIHandler extends ContentTableUIHandler<ActivityLongline, } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String activityLonglineId = getDataContext().getSelectedActivityId(); @@ -243,10 +243,4 @@ public class SensorUsedUIHandler extends ContentTableUIHandler<ActivityLongline, } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java index f2fee7c..973161c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/longline/TdrUIHandler.java @@ -39,6 +39,7 @@ import fr.ird.observe.services.data.longline.SetLonglineService; import fr.ird.observe.services.data.longline.TdrService; import fr.ird.observe.ui.ObserveMainUI; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.context.JAXXContextEntryDef; @@ -121,7 +122,7 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setLonglineId = getDataContext().getSelectedSetId(); @@ -485,9 +486,4 @@ public class TdrUIHandler extends ContentTableUIHandler<SetLongline, Tdr> { } - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } } \ No newline at end of file diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java index 9416c2f..c030953 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/GearUseFeaturesSeineUIHandler.java @@ -23,11 +23,8 @@ package fr.ird.observe.ui.content.table.impl.seine; */ import fr.ird.observe.BinderService; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveContext; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Gear; import fr.ird.observe.entities.referentiel.GearCaracteristic; @@ -269,11 +266,6 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedTripSeineId(); - } - - @Override public void initUI() throws Exception { super.initUI(); @@ -293,7 +285,7 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String tripSeineId = getDataContext().getSelectedTripSeineId(); @@ -409,13 +401,6 @@ public class GearUseFeaturesSeineUIHandler extends ContentTableUIHandler<TripSei getService(GearUseFeaturesSeineService.class).save(editBean); } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - @Override protected void resetEditBean() { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java index 300f200..0a96590 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetCatchUIHandler.java @@ -22,11 +22,7 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; -import fr.ird.observe.DataService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.constants.seine.NonTargetCatchComputedValueSource; import fr.ird.observe.entities.referentiel.Ocean; @@ -50,7 +46,6 @@ import jaxx.runtime.context.JAXXContextEntryDef; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import javax.swing.JComponent; import javax.swing.JOptionPane; @@ -218,22 +213,14 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); - } - - @Override - protected SetSeine loadEditBean(ContentMode mode, - DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { + protected void loadEditBean(ContentMode mode) { List<Species> speciesList; if (mode == ContentMode.UPDATE) { // get current ocean - Ocean ocean = getService(TripService.class).getTripOcean(dataContext.getSelectedTripId()); + Ocean ocean = getService(TripService.class).getTripOcean(getDataContext().getSelectedTripId()); ObserveConfig config = getUi().getContextValue(ObserveConfig.class); String speciesListId = config.getSpeciesListSeineNonTargetCatchId(); @@ -256,11 +243,6 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non if (log.isDebugEnabled()) { log.debug("speciesList = " + speciesList.size()); } - return super.loadEditBean(mode, dataContext, dataService, dataSource); - } - - @Override - protected void loadEditBean() { String setId = getDataContext().getSelectedSetId(); @@ -391,33 +373,23 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } @Override - protected boolean doSave(SetSeine bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<SetSeine> binder) throws Exception { - try { - return super.doSave(bean, dataService, dataSource, binder); - } finally { - - // toujours supprimer la référence du context, quoiqu'il arrive - ALL_TAILLES_TO_DELETE_ENTRY.removeContextValue(getUi()); - } - } - - @Override protected boolean doSave(SetSeine bean) { + try { return super.doSave(bean); + } finally { // toujours supprimer la référence du context, quoiqu'il arrive ALL_TAILLES_TO_DELETE_ENTRY.removeContextValue(getUi()); } + } @Override protected boolean prepareSave(SetSeine editBean, List<NonTargetCatch> objets) throws Exception { + super.prepareSave(editBean, objets); List<Species> speciessUsed = getTableModel().getColumnValues(0); @@ -427,9 +399,9 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non NonTargetSampleService service = getService(NonTargetSampleService.class); service.getObsoleteEspeceForNonTargetSample(editBean.getTopiaId(), - speciessUsed, - speciessToDelete, - tailleToDelete); + speciessUsed, + speciessToDelete, + tailleToDelete); if (!tailleToDelete.isEmpty()) { @@ -476,21 +448,17 @@ public class NonTargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Non } return true; + } @Override protected void doPersist(SetSeine editBean) { - List<NonTargetLength> tailleToDelete = - ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); - getService(NonTargetCatchService.class).save(editBean, tailleToDelete); - } + List<NonTargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); + NonTargetCatchService service = getService(NonTargetCatchService.class); + service.save(editBean, tailleToDelete); - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java index 2bd8bfa..920fd6c 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/NonTargetSampleUIHandler.java @@ -22,7 +22,6 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; -import fr.ird.observe.ObserveDAOHelper; import fr.ird.observe.db.DataContext; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Sex; @@ -39,8 +38,6 @@ import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.context.JAXXContextEntryDef; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; import org.nuiton.validator.NuitonValidatorScope; import javax.swing.JComponent; @@ -117,7 +114,7 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam } @Override - protected void loadEditBean() { + protected void loadEditBean(ContentMode mode) { String setId = getDataContext().getSelectedSetId(); @@ -174,36 +171,29 @@ public class NonTargetSampleUIHandler extends ContentTableUIHandler<NonTargetSam } } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - - @Override - protected NonTargetSample onCreate(TopiaContext tx, - Object parent, - NonTargetSample editBean) throws TopiaException { - SetSeine parentBean = (SetSeine) parent; - NonTargetSample beanToSave = - ObserveDAOHelper.getNonTargetSampleDAO(tx).create(); - if (log.isInfoEnabled()) { - log.info("Echantillon faune " + beanToSave.getTopiaId() + - " was created."); - } - editBean.setTopiaId(beanToSave.getTopiaId()); - editBean.setTopiaCreateDate(beanToSave.getTopiaCreateDate()); - editBean.setTopiaVersion(beanToSave.getTopiaVersion()); - parentBean.addNonTargetSample(beanToSave); - return beanToSave; - } - - @Override - protected void onDelete(TopiaContext tx, Object parent, NonTargetSample beanToDelete) throws TopiaException { - SetSeine parentBean = (SetSeine) parent; - parentBean.removeNonTargetSample(beanToDelete); - } +// @Override +// protected NonTargetSample onCreate(TopiaContext tx, +// Object parent, +// NonTargetSample editBean) throws TopiaException { +// SetSeine parentBean = (SetSeine) parent; +// NonTargetSample beanToSave = +// ObserveDAOHelper.getNonTargetSampleDAO(tx).create(); +// if (log.isInfoEnabled()) { +// log.info("Echantillon faune " + beanToSave.getTopiaId() + +// " was created."); +// } +// editBean.setTopiaId(beanToSave.getTopiaId()); +// editBean.setTopiaCreateDate(beanToSave.getTopiaCreateDate()); +// editBean.setTopiaVersion(beanToSave.getTopiaVersion()); +// parentBean.addNonTargetSample(beanToSave); +// return beanToSave; +// } + +// @Override +// protected void onDelete(TopiaContext tx, Object parent, NonTargetSample beanToDelete) throws TopiaException { +// SetSeine parentBean = (SetSeine) parent; +// parentBean.removeNonTargetSample(beanToDelete); +// } @SuppressWarnings("unchecked") @Override diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java index 04d98f4..f012ad7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectObservedSpeciesUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.referentiel.seine.SpeciesStatus; @@ -31,6 +30,7 @@ import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.ObjectObservedSpecies; import fr.ird.observe.services.data.seine.ObjectObservedSpeciesService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -60,7 +60,7 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String floatingObjectId = getDataContext().getSelectedFloatingObjectId(); @@ -110,7 +110,7 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati // add a listPredicate to get only species from the correct configured speciesList ObserveConfig config = getUi().getContextValue(ObserveConfig.class); String speciesListId = config.getSpeciesListSeineObjectObservedSpeciesId(); - prepareSpeciesList(speciesListId, getUi().getSpecies(),n("observe.error.speciesList.seine.objectObservedSpecies.notFound")); + prepareSpeciesList(speciesListId, getUi().getSpecies(), n("observe.error.speciesList.seine.objectObservedSpecies.notFound")); super.initUI(); @@ -121,12 +121,4 @@ public class ObjectObservedSpeciesUIHandler extends ContentTableUIHandler<Floati getService(ObjectObservedSpeciesService.class).save(editBean); } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java index 49902b0..2245c1e 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/ObjectSchoolEstimateUIHandler.java @@ -23,13 +23,13 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.FloatingObject; import fr.ird.observe.entities.seine.ObjectSchoolEstimate; import fr.ird.observe.services.data.seine.ObjectSchoolEstimateService; import fr.ird.observe.ui.UIHelper; +import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableUIHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -45,7 +45,6 @@ import static org.nuiton.i18n.I18n.n; */ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<FloatingObject, ObjectSchoolEstimate> { - /** Logger */ static private Log log = LogFactory.getLog(ObjectSchoolEstimateUIHandler.class); @@ -60,7 +59,7 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String floatingObjectId = getDataContext().getSelectedFloatingObjectId(); @@ -118,13 +117,4 @@ public class ObjectSchoolEstimateUIHandler extends ContentTableUIHandler<Floatin getService(ObjectSchoolEstimateService.class).save(editBean); } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - - - } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java index bc72d5d..ec3d09b 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/SchoolEstimateUIHandler.java @@ -23,7 +23,6 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.ReferenceEntities; @@ -73,7 +72,7 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch } @Override - protected void loadEditBean() throws DataSourceException { + protected void loadEditBean(ContentMode mode) { String setSeineId = getDataContext().getSelectedSetId(); @@ -175,10 +174,4 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch getService(SchoolEstimateService.class).save(editBean); } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java index 6d0361c..d9a3e19 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetCatchUIHandler.java @@ -21,14 +21,10 @@ */ package fr.ird.observe.ui.content.table.impl.seine; -import fr.ird.observe.DataService; -import fr.ird.observe.DecoratorService; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor; import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.ReferenceEntities; import fr.ird.observe.entities.referentiel.Species; @@ -37,9 +33,10 @@ 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.TargetLength; -import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.services.data.TripService; +import fr.ird.observe.services.data.seine.NonTargetCatchService; import fr.ird.observe.services.data.seine.TargetSampleService; +import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; import fr.ird.observe.ui.content.table.ContentTableModel; @@ -47,14 +44,9 @@ import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.JAXXContext; import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.swing.editor.bean.BeanComboBox; -import org.apache.commons.collections.CollectionUtils; 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.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import javax.swing.JComponent; import javax.swing.JOptionPane; @@ -92,13 +84,6 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target JAXXContextEntryDef<List<WeightCategory>> ALL_CATEGORIES_ENTRY = UIHelper.newListContextEntryDef("TargetCatchUI-all-categories"); - TopiaExecutor<WeightCategory> weightCategoryTopiaExecutor = new TopiaExecutor<WeightCategory>() { - @Override - public void execute(TopiaContext tx, WeightCategory bean) { - getDecoratorService().decorate(bean.getSpecies()); - } - }; - public TargetCatchUIHandler(TargetCatchUI ui) { super(ui, DataContextType.SetSeine); } @@ -142,15 +127,7 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); - } - - @Override - protected SetSeine loadEditBean(ContentMode mode, - DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { + protected void loadEditBean(ContentMode mode) { List<Species> speciesList; List<WeightCategory> categorieList; @@ -159,10 +136,7 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target // on charge le formulaire uniquement si en mode édition - categorieList = new ArrayList<WeightCategory>( - dataService.loadDecoratedEntities(dataSource, - WeightCategory.class, - weightCategoryTopiaExecutor)); + categorieList = getService(ReferentialService.class).loadDecoratedWeightCategory(); // Keep only weight categories for the species ObserveConfig config = getUi().getContextValue(ObserveConfig.class); @@ -170,14 +144,13 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target java.util.Set<String> speciesIds = loadSpeciesList(speciesListId, n("observe.error.speciesList.seine.targetCatch.notFound")); - categorieList = Species2.filterWeightCategoryBySpeciesIds( - categorieList, speciesIds); + categorieList = Species2.filterWeightCategoryBySpeciesIds(categorieList, speciesIds); // filtre par status actif ReferenceEntities.filterReferentielListByStatus(categorieList); // get current ocean - Ocean ocean = getService(TripService.class).getTripOcean(dataContext.getSelectedTripId()); + Ocean ocean = getService(TripService.class).getTripOcean(getDataContext().getSelectedTripId()); // filtre par ocean categorieList = Species2.filterWeightCategoryByOcean(categorieList, ocean); @@ -200,48 +173,53 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target ui.getSpecies().setData(speciesList); - return super.loadEditBean(mode, dataContext, dataService, dataSource); - } + String setId = getDataContext().getSelectedSetId(); + + SetSeine setSeine = getService(NonTargetCatchService.class).loadForEdit(setId); + + copy(SetSeine.class, BinderService.EDIT_TARGET_CATCH, setSeine, getBean()); - @Override - protected Collection<TargetCatch> loadChilds(TopiaContext tx, SetSeine bean) throws TopiaException { - Collection<TargetCatch> childs = getModel().getChildsUpdator().getChilds(bean); - Collection<TargetCatch> data = new ArrayList<TargetCatch>(); - if (CollectionUtils.isNotEmpty(childs)) { - TopiaDAO<TargetCatch> dao = - getDataSource().getDAO(tx, getTableEditBean()); - TopiaEntityBinder<TargetCatch> childLoador = getModel().getChildLoador(); - - DecoratorService decoratorService = getDecoratorService(); - - for (TargetCatch c : childs) { - if (c.isDiscarded()) { - // c'est un rejet, on ne le retient pas dans cette liste - if (log.isDebugEnabled()) { - log.debug("targetDiscarded " + c.getSpecies().getLabel2() + - " non retenu."); - } - continue; - } - try { - - TargetCatch c2 = getModel().newTableEditBean(); - TargetCatch safeC = dao.findByTopiaId(c.getTopiaId()); - WeightCategory weightCategory = safeC.getWeightCategory(); - if (weightCategory != null) { - Species species = weightCategory.getSpecies(); - decoratorService.decorate(species); - } - childLoador.load(safeC, c2, true); - data.add(c2); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - return data; } +// @Override +// protected Collection<TargetCatch> loadChilds(TopiaContext tx, SetSeine bean) throws TopiaException { +// Collection<TargetCatch> childs = getModel().getChildsUpdator().getChilds(bean); +// Collection<TargetCatch> data = new ArrayList<TargetCatch>(); +// if (CollectionUtils.isNotEmpty(childs)) { +// TopiaDAO<TargetCatch> dao = +// getDataSource().getDAO(tx, getTableEditBean()); +// TopiaEntityBinder<TargetCatch> childLoador = getModel().getChildLoador(); +// +// DecoratorService decoratorService = getDecoratorService(); +// +// for (TargetCatch c : childs) { +// if (c.isDiscarded()) { +// // c'est un rejet, on ne le retient pas dans cette liste +// if (log.isDebugEnabled()) { +// log.debug("targetDiscarded " + c.getSpecies().getLabel2() + +// " non retenu."); +// } +// continue; +// } +// try { +// +// TargetCatch c2 = getModel().newTableEditBean(); +// TargetCatch safeC = dao.findByTopiaId(c.getTopiaId()); +// WeightCategory weightCategory = safeC.getWeightCategory(); +// if (weightCategory != null) { +// Species species = weightCategory.getSpecies(); +// decoratorService.decorate(species); +// } +// childLoador.load(safeC, c2, true); +// data.add(c2); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// } +// return data; +// } + @Override protected boolean prepareSave(SetSeine bean, List<TargetCatch> objets) throws DataSourceException { @@ -320,37 +298,37 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target return true; } - @Override - protected void onUpdateFinalize(TopiaContext tx, SetSeine bean, Collection<TargetCatch> oldChilds) { - - if (oldChilds != null && !oldChilds.isEmpty()) { - - // on reinjecte les rejet thon precedemment saisie dans la set - for (TargetCatch targetCatch : oldChilds) { - if (targetCatch.isDiscarded()) { - bean.addTargetCatch(targetCatch); - } - } - } - - - List<TargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); - - if (tailleToDelete != null && !tailleToDelete.isEmpty()) { - - // on a demande la suppression de taille obsoletes - - if (log.isInfoEnabled()) { - log.info("Will remove " + tailleToDelete.size() + - " obsolete targetLength(s)."); - } - - TargetSample echantillon = bean.getTargetSample(false); - - // on supprime les echantillons obsoletes - echantillon.getTargetLength().removeAll(tailleToDelete); - } - } +// @Override +// protected void onUpdateFinalize(TopiaContext tx, SetSeine bean, Collection<TargetCatch> oldChilds) { +// +// if (oldChilds != null && !oldChilds.isEmpty()) { +// +// // on reinjecte les rejet thon precedemment saisie dans la set +// for (TargetCatch targetCatch : oldChilds) { +// if (targetCatch.isDiscarded()) { +// bean.addTargetCatch(targetCatch); +// } +// } +// } +// +// +// List<TargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); +// +// if (tailleToDelete != null && !tailleToDelete.isEmpty()) { +// +// // on a demande la suppression de taille obsoletes +// +// if (log.isInfoEnabled()) { +// log.info("Will remove " + tailleToDelete.size() + +// " obsolete targetLength(s)."); +// } +// +// TargetSample echantillon = bean.getTargetSample(false); +// +// // on supprime les echantillons obsoletes +// echantillon.getTargetLength().removeAll(tailleToDelete); +// } +// } @Override protected void onSelectedRowChanged(int editingRow, TargetCatch bean, boolean create) { @@ -466,8 +444,8 @@ public class TargetCatchUIHandler extends ContentTableUIHandler<SetSeine, Target } protected List<WeightCategory> getAllCategories(JAXXContext context) { - List<WeightCategory> list = new ArrayList<WeightCategory>( - ALL_CATEGORIES_ENTRY.getContextValue(context)); + List<WeightCategory> list = new ArrayList<WeightCategory>(ALL_CATEGORIES_ENTRY.getContextValue(context)); return list; } + } diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java index 22bd908..f1ad697 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetDiscardCatchUIHandler.java @@ -21,14 +21,9 @@ */ package fr.ird.observe.ui.content.table.impl.seine; -import fr.ird.observe.DataService; -import fr.ird.observe.DecoratorService; +import fr.ird.observe.BinderService; import fr.ird.observe.ObserveConfig; -import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; -import fr.ird.observe.db.util.TopiaExecutor; import fr.ird.observe.entities.referentiel.Ocean; import fr.ird.observe.entities.referentiel.ReferenceEntities; import fr.ird.observe.entities.referentiel.Species; @@ -38,9 +33,8 @@ 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.TargetLength; -import fr.ird.observe.entities.seine.TargetSample; import fr.ird.observe.services.data.TripService; -import fr.ird.observe.services.data.seine.TargetSampleService; +import fr.ird.observe.services.data.seine.NonTargetCatchService; import fr.ird.observe.services.referential.ReferentialService; import fr.ird.observe.ui.UIHelper; import fr.ird.observe.ui.content.ContentMode; @@ -49,17 +43,10 @@ import fr.ird.observe.ui.content.table.ContentTableUIHandler; import jaxx.runtime.JAXXContext; import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.swing.editor.bean.BeanComboBox; -import org.apache.commons.collections.CollectionUtils; 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.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.util.TopiaEntityBinder; import javax.swing.JComponent; -import javax.swing.JOptionPane; import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; import java.beans.PropertyChangeEvent; @@ -73,7 +60,6 @@ import java.util.Iterator; import java.util.List; import static org.nuiton.i18n.I18n.n; -import static org.nuiton.i18n.I18n.t; /** * @author Tony Chemit - chemit@codelutin.com @@ -93,13 +79,6 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, JAXXContextEntryDef<List<TargetLength>> ALL_TAILLES_TO_DELETE_ENTRY = UIHelper.newListContextEntryDef("RejetThonUI-all-taille-to-delete"); - TopiaExecutor<WeightCategory> weightCategoryTopiaExecutor = new TopiaExecutor<WeightCategory>() { - @Override - public void execute(TopiaContext tx, WeightCategory bean) { - getDecoratorService().decorate(bean.getSpecies()); - } - }; - public TargetDiscardCatchUIHandler(TargetDiscardCatchUI ui) { super(ui, DataContextType.SetSeine); } @@ -197,15 +176,7 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, } @Override - protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { - return dataContext.getSelectedSetId(); - } - - @Override - protected SetSeine loadEditBean(ContentMode mode, - DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { + protected void loadEditBean(ContentMode mode) { List<WeightCategory> categorieList; List<ReasonForDiscard> reasonForDiscardList; @@ -214,31 +185,26 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, // on charge le formulaire uniquement si en mode édition - categorieList = new ArrayList<WeightCategory>( - dataService.loadDecoratedEntities( - dataSource, - WeightCategory.class, - weightCategoryTopiaExecutor) - ); + ReferentialService service = getService(ReferentialService.class); + + categorieList = service.loadDecoratedWeightCategory(); // filtre sur la liste d'espèce configuree ObserveConfig config = getUi().getContextValue(ObserveConfig.class); String speciesListId = config.getSpeciesListSeineTargetCatchId(); java.util.Set<String> speciesIds = loadSpeciesList(speciesListId, n("observe.error.speciesList.seine.targetCatch.notFound")); - categorieList = Species2.filterWeightCategoryBySpeciesIds( - categorieList, speciesIds); + categorieList = Species2.filterWeightCategoryBySpeciesIds(categorieList, speciesIds); // filtre par status actif ReferenceEntities.filterReferentielListByStatus(categorieList); // get current ocean - Ocean ocean = getService(TripService.class).getTripOcean(dataContext.getSelectedTripId()); + Ocean ocean = getService(TripService.class).getTripOcean(getDataContext().getSelectedTripId()); // filtre par ocean categorieList = Species2.filterWeightCategoryByOcean(categorieList, ocean); - ReferentialService service = getService(ReferentialService.class); reasonForDiscardList = service.loadAndDecorateList(ReasonForDiscard.class); // filtre par status actif @@ -255,178 +221,188 @@ public class TargetDiscardCatchUIHandler extends ContentTableUIHandler<SetSeine, ALL_CATEGORIES_ENTRY.setContextValue(ui, categorieList); ALL_RAISONS_REJET_ENTRY.setContextValue(ui, reasonForDiscardList); - return super.loadEditBean(mode, dataContext, dataService, dataSource); - } - - @Override - protected Collection<TargetCatch> loadChilds(TopiaContext tx, SetSeine bean) throws TopiaException { - Collection<TargetCatch> childs = getModel().getChildsUpdator().getChilds(bean); - Collection<TargetCatch> data = new ArrayList<TargetCatch>(); - if (CollectionUtils.isNotEmpty(childs)) { - TopiaDAO<TargetCatch> dao = - getDataSource().getDAO(tx, getTableEditBean()); - TopiaEntityBinder<TargetCatch> childLoador = getModel().getChildLoador(); - DecoratorService decoratorService = getDecoratorService(); - for (TargetCatch c : childs) { - if (!c.isDiscarded()) { - // ce n'est pas un rejet, on ne le retient pas dans cette - // liste - if (log.isDebugEnabled()) { - log.debug("targetCatch " + c.getSpecies().getLabel2() + " non retenu."); - } - continue; - } - try { - TargetCatch c2 = getModel().newTableEditBean(); - TargetCatch safeC = dao.findByTopiaId(c.getTopiaId()); - WeightCategory weightCategory = safeC.getWeightCategory(); - if (weightCategory != null) { - Species species = weightCategory.getSpecies(); - decoratorService.decorate(species); - } - childLoador.load(safeC, c2, true); - data.add(c2); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - return data; - } - - @Override - protected boolean doSave(SetSeine bean, - DataService dataService, - DataSource dataSource, - TopiaEntityBinder<SetSeine> binder) throws Exception { - try { - return super.doSave(bean, dataService, dataSource, binder); - } finally { - - // toujours supprimer la référence du context, quoiqu'il arrive - ALL_TAILLES_TO_DELETE_ENTRY.removeContextValue(getUi()); - } - } - - @Override - protected boolean prepareSave(SetSeine bean, List<TargetCatch> objets) throws DataSourceException { - - // on recupere les speciess acceptables pour des echantillonnages - // i.e une species d'un targetDiscarded montee sur le pont - - java.util.Set<Species> speciessUsed = new HashSet<Species>(); - for (TargetCatch c : objets) { - if (c.getBroughtOnDeck() != null && c.getBroughtOnDeck()) { - speciessUsed.add(c.getSpecies()); - } - } - - // il faut supprimer les echantillon thons sur des speciess qui ne - // sont plus sur un rejet - - List<TargetLength> tailleToDelete = new ArrayList<TargetLength>(); - java.util.Set<Species> speciessToDelete = new HashSet<Species>(); + String setId = getDataContext().getSelectedSetId(); - TargetSampleService service = getService(TargetSampleService.class); - service.getObsoleteEspeceForTargetSample(bean.getTopiaId(), - speciessUsed, - speciessToDelete, - tailleToDelete, - true); + SetSeine setSeine = getService(NonTargetCatchService.class).loadForEdit(setId); - if (!tailleToDelete.isEmpty()) { + copy(SetSeine.class, BinderService.EDIT_DISCARD_TARGET_CATCH, setSeine, getBean()); - // il existe des echantillon thon a supprimer on demande une - // confirmation - StringBuilder sb = new StringBuilder(512); - StringBuilder sb2 = new StringBuilder(512); - Decorator<Species> decorator = - getDecoratorService().getDecoratorByType(Species.class); - Decorator<TargetLength> decorator2 = - getDecoratorService().getDecoratorByType(TargetLength.class); - - for (Species e : speciessToDelete) { - sb.append(" - ").append(decorator.toString(e)).append('\n'); - } - for (TargetLength t : tailleToDelete) { - sb2.append(" - ").append(decorator2.toString(t)).append('\n'); - } - int reponse = UIHelper.askUser( - t("observe.title.need.confirm"), - t("observe.targetDiscarded.message.table.will.delete.targetLength", sb.toString(), sb2.toString()), - JOptionPane.ERROR_MESSAGE, - new Object[]{ - t("observe.choice.continue"), - t("observe.choice.cancel")}, - 0); - if (log.isDebugEnabled()) { - log.debug("response : " + reponse); - } - boolean canContinue = false; - switch (reponse) { - case 0: - // wil reset ui - canContinue = true; - break; - } - - if (!canContinue) { - - // l'utilisateur a choisi de ne pas continuer - return false; - } - - // on conserve les tailles a supprimer - ALL_TAILLES_TO_DELETE_ENTRY.setContextValue(getUi(), tailleToDelete); - } - - // mise a jour de la propriete targetDiscarded - bean.setTargetDiscarded(!objets.isEmpty()); - - for (TargetCatch discarded : objets) { - - // FIXME : on devrait pas a avoir a repositionner la propriete discarded - discarded.setDiscarded(true); - - // on attache la set - discarded.setSetSeine(bean); - } - - return true; } - @Override - protected void onUpdateFinalize(TopiaContext tx, SetSeine bean, Collection<TargetCatch> oldChilds) { - - if (oldChilds != null && !oldChilds.isEmpty()) { - - // on reinjecte les discarded thon precedemment saisies dans la set - // et qui ne sont pas des rejets - - for (TargetCatch targetCatch : oldChilds) { - if (!targetCatch.isDiscarded()) { - bean.addTargetCatch(targetCatch); - } - } - } - - List<TargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); - - if (tailleToDelete != null && !tailleToDelete.isEmpty()) { - - // on a demande la suppression de taille obsoletes - - if (log.isInfoEnabled()) { - log.info("Will remove " + tailleToDelete.size() + - " obsolete targetLength(s)."); - } - - TargetSample echantillon = bean.getTargetSample(true); - - // on supprime les echantillons obsoletes - echantillon.getTargetLength().removeAll(tailleToDelete); - } - } +// @Override +// protected String getEditBeanIdToLoad(DataContext dataContext, DataService dataService, DataSource dataSource) { +// return dataContext.getSelectedSetId(); +// } + +// @Override +// protected Collection<TargetCatch> loadChilds(TopiaContext tx, SetSeine bean) throws TopiaException { +// Collection<TargetCatch> childs = getModel().getChildsUpdator().getChilds(bean); +// Collection<TargetCatch> data = new ArrayList<TargetCatch>(); +// if (CollectionUtils.isNotEmpty(childs)) { +// TopiaDAO<TargetCatch> dao = +// getDataSource().getDAO(tx, getTableEditBean()); +// TopiaEntityBinder<TargetCatch> childLoador = getModel().getChildLoador(); +// DecoratorService decoratorService = getDecoratorService(); +// for (TargetCatch c : childs) { +// if (!c.isDiscarded()) { +// // ce n'est pas un rejet, on ne le retient pas dans cette +// // liste +// if (log.isDebugEnabled()) { +// log.debug("targetCatch " + c.getSpecies().getLabel2() + " non retenu."); +// } +// continue; +// } +// try { +// TargetCatch c2 = getModel().newTableEditBean(); +// TargetCatch safeC = dao.findByTopiaId(c.getTopiaId()); +// WeightCategory weightCategory = safeC.getWeightCategory(); +// if (weightCategory != null) { +// Species species = weightCategory.getSpecies(); +// decoratorService.decorate(species); +// } +// childLoador.load(safeC, c2, true); +// data.add(c2); +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// } +// } +// return data; +// } + +// @Override +// protected boolean doSave(SetSeine bean, +// DataService dataService, +// DataSource dataSource, +// TopiaEntityBinder<SetSeine> binder) throws Exception { +// try { +// return super.doSave(bean, dataService, dataSource, binder); +// } finally { +// +// // toujours supprimer la référence du context, quoiqu'il arrive +// ALL_TAILLES_TO_DELETE_ENTRY.removeContextValue(getUi()); +// } +// } + +// @Override +// protected boolean prepareSave(SetSeine bean, List<TargetCatch> objets) throws DataSourceException { +// +// // on recupere les speciess acceptables pour des echantillonnages +// // i.e une species d'un targetDiscarded montee sur le pont +// +// java.util.Set<Species> speciessUsed = new HashSet<Species>(); +// for (TargetCatch c : objets) { +// if (c.getBroughtOnDeck() != null && c.getBroughtOnDeck()) { +// speciessUsed.add(c.getSpecies()); +// } +// } +// +// // il faut supprimer les echantillon thons sur des speciess qui ne +// // sont plus sur un rejet +// +// List<TargetLength> tailleToDelete = new ArrayList<TargetLength>(); +// java.util.Set<Species> speciessToDelete = new HashSet<Species>(); +// +// TargetSampleService service = getService(TargetSampleService.class); +// service.getObsoleteEspeceForTargetSample(bean.getTopiaId(), +// speciessUsed, +// speciessToDelete, +// tailleToDelete, +// true); +// +// if (!tailleToDelete.isEmpty()) { +// +// // il existe des echantillon thon a supprimer on demande une +// // confirmation +// StringBuilder sb = new StringBuilder(512); +// StringBuilder sb2 = new StringBuilder(512); +// Decorator<Species> decorator = +// getDecoratorService().getDecoratorByType(Species.class); +// Decorator<TargetLength> decorator2 = +// getDecoratorService().getDecoratorByType(TargetLength.class); +// +// for (Species e : speciessToDelete) { +// sb.append(" - ").append(decorator.toString(e)).append('\n'); +// } +// for (TargetLength t : tailleToDelete) { +// sb2.append(" - ").append(decorator2.toString(t)).append('\n'); +// } +// int reponse = UIHelper.askUser( +// t("observe.title.need.confirm"), +// t("observe.targetDiscarded.message.table.will.delete.targetLength", sb.toString(), sb2.toString()), +// JOptionPane.ERROR_MESSAGE, +// new Object[]{ +// t("observe.choice.continue"), +// t("observe.choice.cancel")}, +// 0); +// if (log.isDebugEnabled()) { +// log.debug("response : " + reponse); +// } +// boolean canContinue = false; +// switch (reponse) { +// case 0: +// // wil reset ui +// canContinue = true; +// break; +// } +// +// if (!canContinue) { +// +// // l'utilisateur a choisi de ne pas continuer +// return false; +// } +// +// // on conserve les tailles a supprimer +// ALL_TAILLES_TO_DELETE_ENTRY.setContextValue(getUi(), tailleToDelete); +// } +// +// // mise a jour de la propriete targetDiscarded +// bean.setTargetDiscarded(!objets.isEmpty()); +// +// for (TargetCatch discarded : objets) { +// +// // FIXME : on devrait pas a avoir a repositionner la propriete discarded +// discarded.setDiscarded(true); +// +// // on attache la set +// discarded.setSetSeine(bean); +// } +// +// return true; +// } + +// @Override +// protected void onUpdateFinalize(TopiaContext tx, SetSeine bean, Collection<TargetCatch> oldChilds) { +// +// if (oldChilds != null && !oldChilds.isEmpty()) { +// +// // on reinjecte les discarded thon precedemment saisies dans la set +// // et qui ne sont pas des rejets +// +// for (TargetCatch targetCatch : oldChilds) { +// if (!targetCatch.isDiscarded()) { +// bean.addTargetCatch(targetCatch); +// } +// } +// } +// +// List<TargetLength> tailleToDelete = ALL_TAILLES_TO_DELETE_ENTRY.getContextValue(getUi()); +// +// if (tailleToDelete != null && !tailleToDelete.isEmpty()) { +// +// // on a demande la suppression de taille obsoletes +// +// if (log.isInfoEnabled()) { +// log.info("Will remove " + tailleToDelete.size() + +// " obsolete targetLength(s)."); +// } +// +// TargetSample echantillon = bean.getTargetSample(true); +// +// // on supprime les echantillons obsoletes +// echantillon.getTargetLength().removeAll(tailleToDelete); +// } +// } @Override protected void onSelectedRowChanged(int editingRow, TargetCatch bean, boolean create) { diff --git a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java index 91434fa..bcfc0d7 100644 --- a/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java +++ b/observe-swing/src/main/java/fr/ird/observe/ui/content/table/impl/seine/TargetSampleUIHandler.java @@ -22,10 +22,7 @@ package fr.ird.observe.ui.content.table.impl.seine; import fr.ird.observe.BinderService; -import fr.ird.observe.DataService; import fr.ird.observe.db.DataContext; -import fr.ird.observe.db.DataSource; -import fr.ird.observe.db.DataSourceException; import fr.ird.observe.db.constants.DataContextType; import fr.ird.observe.entities.referentiel.Species; import fr.ird.observe.entities.seine.SetSeine; @@ -120,20 +117,20 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T getUi().getLength().grabFocus(); } - @Override - protected String getEditBeanIdToLoad(DataContext dataContext, - DataService dataService, - DataSource dataSource) throws DataSourceException { - String setId = dataContext.getSelectedSetId(); - // on doit récupérer l'unique échantillonThon de la calée - - TargetSample targetSample = getService(TargetSampleService.class).getTargetSample(setId, discarded); - String id = targetSample == null ? null : targetSample.getTopiaId(); - return id; - } +// @Override +// protected String getEditBeanIdToLoad(DataContext dataContext, +// DataService dataService, +// DataSource dataSource) throws DataSourceException { +// String setId = dataContext.getSelectedSetId(); +// // on doit récupérer l'unique échantillonThon de la calée +// +// TargetSample targetSample = getService(TargetSampleService.class).getTargetSample(setId, discarded); +// String id = targetSample == null ? null : targetSample.getTopiaId(); +// return id; +// } @Override - protected void loadEditBean() { + protected void loadEditBean(ContentMode mode) { String setId = getDataContext().getSelectedSetId(); @@ -189,13 +186,6 @@ public class TargetSampleUIHandler extends ContentTableUIHandler<TargetSample, T } } - - //TODO Supprimer saveUI et mettre saveUI2 a la place - @Override - public final void saveUI(boolean refresh) { - saveUI2(refresh); - } - @Override protected void onSelectedRowChanged(int editingRow, TargetLength bean, boolean create) { -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.