branch feature/7017 updated (f3e984a -> d8e7ac2)
This is an automated email from the git hooks/post-receive script. New change to branch feature/7017 in repository observe. See http://git.codelutin.com/observe.git from f3e984a debut d'implantation pour les ecrans de type tableau (refs #7017) new d8e7ac2 refactor save action for table entities (in schoolEstimate) The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit d8e7ac2ad343f92887c6bd4e4ca606d52d32b64e Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 10:16:15 2015 +0200 refactor save action for table entities (in schoolEstimate) Summary of changes: .../observe/services/AbstractObserveService.java | 32 ++--- .../services/data/seine/SchoolEstimateService.java | 3 +- .../data/seine/SchoolEstimateServiceImpl.java | 46 ++++++- .../data/seine/TargetSampleServiceImpl.java | 132 ++++++++++----------- .../ui/content/table/ContentTableUIHandler.java | 33 ++++++ .../table/impl/seine/SchoolEstimateUIHandler.java | 14 +-- 6 files changed, 167 insertions(+), 93 deletions(-) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
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 d8e7ac2ad343f92887c6bd4e4ca606d52d32b64e Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Wed Apr 29 10:16:15 2015 +0200 refactor save action for table entities (in schoolEstimate) --- .../observe/services/AbstractObserveService.java | 32 ++--- .../services/data/seine/SchoolEstimateService.java | 3 +- .../data/seine/SchoolEstimateServiceImpl.java | 46 ++++++- .../data/seine/TargetSampleServiceImpl.java | 132 ++++++++++----------- .../ui/content/table/ContentTableUIHandler.java | 33 ++++++ .../table/impl/seine/SchoolEstimateUIHandler.java | 14 +-- 6 files changed, 167 insertions(+), 93 deletions(-) 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 807403a..c887367 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 @@ -17,6 +17,7 @@ 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.TopiaEntityBinder; import org.nuiton.topia.persistence.util.TopiaEntityHelper; import org.nuiton.util.beans.BinderModelBuilder; @@ -315,19 +316,23 @@ public abstract class AbstractObserveService implements ObserveService { } - public <P extends TopiaEntity, E extends TopiaEntity> void doSaveList(P parentToSave, Collection<E> childrentoSave, SaveCollectionAction<P, E> saveCollectionAction ) { + public <P extends TopiaEntity, E extends TopiaEntity> void doSaveList(P parentToSave, SaveCollectionAction<P, E> saveCollectionAction ) { - saveCollectionAction.prepareSave(parentToSave, childrentoSave); + Collection<E> childrenToSave = saveCollectionAction.listUpdator.getChilds(parentToSave); + + saveCollectionAction.prepareSave(parentToSave, childrenToSave); P parentSaved = getDao(saveCollectionAction.parentClass).findByTopiaId(parentToSave.getTopiaId()); - List<E> oldChilds = new ArrayList<E>(saveCollectionAction.getChildren(parentSaved)); + saveCollectionAction.onUpdateParent(parentToSave, parentSaved); + + List<E> oldChilds = new ArrayList<E>(saveCollectionAction.listUpdator.getChilds(parentSaved)); - saveCollectionAction.clearChildren(parentSaved); + saveCollectionAction.listUpdator.removeAll(parentSaved); TopiaDAO<E> dao = getDao(saveCollectionAction.entityClass); - for (E childToSave : childrentoSave) { + for (E childToSave : childrenToSave) { E childSaved; @@ -344,7 +349,7 @@ public abstract class AbstractObserveService implements ObserveService { childSaved = saveCollectionAction.onUpdateChild(childToSave, childSaved); } - saveCollectionAction.addChild(parentSaved, childSaved); + saveCollectionAction.listUpdator.addToList(parentSaved, childSaved); } // on donne la main aux implantations pour faire des traitements @@ -361,12 +366,15 @@ public abstract class AbstractObserveService implements ObserveService { protected final Class<E> entityClass; - public SaveCollectionAction(Class<P> parentClass, Class<E> entityClass) { + protected final EntityListUpdator<P, E> listUpdator; + + public SaveCollectionAction(Class<P> parentClass, Class<E> entityClass, EntityListUpdator<P, E> listUpdator) { this.parentClass = parentClass; this.entityClass = entityClass; + this.listUpdator = listUpdator; } - public void prepareSave(P parent, Collection<E> tosaves) { + public void prepareSave(P parent, Collection<E> toSaves) { // par defaut, rien de specifique a faire avant de faire la sauvegarde } @@ -374,17 +382,11 @@ public abstract class AbstractObserveService implements ObserveService { // par défaut, rien à faire } - - public abstract Collection<E> getChildren(P parent); - - public abstract void clearChildren(P parent); + public abstract P onUpdateParent(P parentToSave, P parentSaved); public abstract E onCreateChild(E childToSave); public abstract E onUpdateChild(E childToSave, E childSaved); - - public abstract void addChild(P parent, E child); - } 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 ce72a1b..2b4f831 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 @@ -3,7 +3,6 @@ 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.EntityAssociation; import fr.ird.observe.services.NoTransaction; import fr.ird.observe.services.ObserveService; import org.nuiton.topia.persistence.util.TopiaEntityBinder; @@ -19,7 +18,7 @@ public interface SchoolEstimateService extends ObserveService { SetSeine loadForEdit(String setSeineId); @Commit - void save(EntityAssociation<SetSeine, SchoolEstimate> setSeine); + void save(SetSeine parent); @NoTransaction TopiaEntityBinder<SetSeine> getBinderForSetSeineEdit(); 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 fa2da33..a7b0afa 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 @@ -4,12 +4,13 @@ import fr.ird.observe.BinderService; import fr.ird.observe.entities.seine.SchoolEstimate; import fr.ird.observe.entities.seine.SetSeine; import fr.ird.observe.services.AbstractObserveService; -import fr.ird.observe.services.EntityAssociation; import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.util.EntityListUpdator; import org.nuiton.topia.persistence.util.TopiaEntityBinder; import org.nuiton.util.beans.BinderModelBuilder; import java.util.ArrayList; +import java.util.Collection; import java.util.List; /** @@ -51,14 +52,44 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements } @Override - public void save(EntityAssociation<SetSeine, SchoolEstimate> setSeine) { + public void save(SetSeine parent) { + doSaveList(parent, new SaveCollectionAction<SetSeine, SchoolEstimate>(SetSeine.class, SchoolEstimate.class, getListUpdator()) { + + @Override + public void prepareSave(SetSeine parent, Collection<SchoolEstimate> toSaves) { + for (SchoolEstimate child : toSaves) { + child.setSetSeine(parent); + } + } + + @Override + public SetSeine onUpdateParent(SetSeine parentToSave, SetSeine parentSaved) { + getBinderForSetSeineEdit().copyExcluding(parentToSave, parentSaved, SetSeine.PROPERTY_SCHOOL_ESTIMATE); + getDao(SetSeine.class).update(parentSaved); + return parentSaved; + } + + @Override + public SchoolEstimate onCreateChild(SchoolEstimate childToSave) { + SchoolEstimate childSaved = getDao(SchoolEstimate.class).newInstance(); + getBinderForSchoolEstimateEdit().copy(childToSave, childSaved); + getDao(SchoolEstimate.class).create(childSaved); + return childSaved; + } + + @Override + public SchoolEstimate onUpdateChild(SchoolEstimate childToSave, SchoolEstimate childSaved) { + getBinderForSchoolEstimateEdit().copy(childToSave, childSaved); + getDao(SchoolEstimate.class).update(childSaved); + return childSaved; + } + }); } @Override public TopiaEntityBinder<SetSeine> getBinderForSetSeineEdit() { - TopiaEntityBinder<SetSeine> binder = loadBinder("-forSchoolEstimateEdit", SetSeine.class, new CreateBinder<SetSeine>() { @Override @@ -117,4 +148,13 @@ public class SchoolEstimateServiceImpl extends AbstractObserveService implements } + public EntityListUpdator<SetSeine, SchoolEstimate> getListUpdator() { + return EntityListUpdator.newEntityListUpdator( + SetSeine.class, + SchoolEstimate.class, + SetSeine.PROPERTY_SCHOOL_ESTIMATE); + } + + + } 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 4b8021c..5fd0a8f 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 @@ -181,72 +181,72 @@ public class TargetSampleServiceImpl extends AbstractObserveService implements T @Override public String save(String setSeineId, TargetSample toSave, Collection<TargetLength> childrenToSave) { - String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { - @Override - public TargetSample onCreate(SetSeine parent, TargetSample toCreate) { - - TargetSample created = getDao().create(); - getBinderForEdit().copyExcluding(toCreate, created, TargetSample.PROPERTY_TARGET_LENGTH); - parent.addTargetSample(created); - getDao().update(created); - return created; - } - - @Override - public TargetSample onUpdate(SetSeine parentBean, TargetSample toSave, TargetSample beanToSave) { - getBinderForEdit().copyExcluding(toSave, beanToSave, TargetSample.PROPERTY_TARGET_LENGTH); - getDao().update(beanToSave); - return beanToSave; - } - }); - - toSave.setTopiaId(savedId); - - doSaveList(toSave, childrenToSave, new SaveCollectionAction<TargetSample, TargetLength>(TargetSample.class, TargetLength.class) { - - @Override - public void prepareSave(TargetSample parent, Collection<TargetLength> tosaves) { - - for (TargetLength targetLength : tosaves) { - - // on attache a l'echantillon - targetLength.setTargetSample(parent); - } - - } - - @Override - public Collection<TargetLength> getChildren(TargetSample parent) { - return parent.getTargetLength(); - } - - @Override - public void clearChildren(TargetSample parent) { - parent.clearTargetLength(); - } - - @Override - public TargetLength onCreateChild(TargetLength childToSave) { - TargetLength childSaved = getChildDao().create(); - getChildBinderForEdit().copy(childToSave, childSaved); - getChildDao().update(childSaved); - return childSaved; - } - - @Override - public TargetLength onUpdateChild(TargetLength childToSave, TargetLength childSaved) { - getChildBinderForEdit().copy(childToSave, childSaved); - getChildDao().update(childSaved); - return childSaved; - } - - @Override - public void addChild(TargetSample parent, TargetLength child) { - parent.addTargetLength(child); - } - }); - - return savedId; +// String savedId = doSave(setSeineId, toSave, new SaveAction<SetSeine, TargetSample>(SetSeine.class, TargetSample.class) { +// @Override +// public TargetSample onCreate(SetSeine parent, TargetSample toCreate) { +// +// TargetSample created = getDao().create(); +// getBinderForEdit().copyExcluding(toCreate, created, TargetSample.PROPERTY_TARGET_LENGTH); +// parent.addTargetSample(created); +// getDao().update(created); +// return created; +// } +// +// @Override +// public TargetSample onUpdate(SetSeine parentBean, TargetSample toSave, TargetSample beanToSave) { +// getBinderForEdit().copyExcluding(toSave, beanToSave, TargetSample.PROPERTY_TARGET_LENGTH); +// getDao().update(beanToSave); +// return beanToSave; +// } +// }); +// +// toSave.setTopiaId(savedId); +// +// doSaveList(toSave, childrenToSave, new SaveCollectionAction<TargetSample, TargetLength>(TargetSample.class, TargetLength.class) { +// +// @Override +// public void prepareSave(TargetSample parent, Collection<TargetLength> tosaves) { +// +// for (TargetLength targetLength : tosaves) { +// +// // on attache a l'echantillon +// targetLength.setTargetSample(parent); +// } +// +// } +// +// @Override +// public Collection<TargetLength> getChildren(TargetSample parent) { +// return parent.getTargetLength(); +// } +// +// @Override +// public void clearChildren(TargetSample parent) { +// parent.clearTargetLength(); +// } +// +// @Override +// public TargetLength onCreateChild(TargetLength childToSave) { +// TargetLength childSaved = getChildDao().create(); +// getChildBinderForEdit().copy(childToSave, childSaved); +// getChildDao().update(childSaved); +// return childSaved; +// } +// +// @Override +// public TargetLength onUpdateChild(TargetLength childToSave, TargetLength childSaved) { +// getChildBinderForEdit().copy(childToSave, childSaved); +// getChildDao().update(childSaved); +// return childSaved; +// } +// +// @Override +// public void addChild(TargetSample parent, TargetLength child) { +// parent.addTargetLength(child); +// } +// }); + + return 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 bd2bb30..0d2093d 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 @@ -427,11 +427,44 @@ public abstract class ContentTableUIHandler<E extends TopiaEntity, D extends Top return true; } + @Override + protected boolean doSave(E bean) { + + 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); + + + return true; + } + + 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 { 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 43a449c..01b461d 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 @@ -170,14 +170,14 @@ public class SchoolEstimateUIHandler extends ContentTableUIHandler<SetSeine, Sch } @Override - protected boolean prepareSave(SetSeine editBean, List<SchoolEstimate> objets) { - - for (SchoolEstimate schoolEstimate : objets) { + protected void doPersist(SetSeine editBean) { + getService(SchoolEstimateService.class).save(editBean); + } - // on attache la set - schoolEstimate.setSetSeine(editBean); - } - return true; + //TODO Supprimer saveUI et mettre saveUI2 a la place + @Override + public final void saveUI(boolean refresh) { + saveUI2(refresh); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
participants (1)
-
codelutin.com scm