This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository observe. See https://gitlab.nuiton.org/codelutin/observe.git commit 560313efe35d4db7f9079b5856deadd5585bc0dc Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Oct 27 13:40:12 2016 +0200 [REFERENTIEL] Automatiser la réattribution de code lors de la désactivation ou la suppression d'une ligne de référentiel (fixes #8338) --- .../ui/content/ref/ContentReferenceUIHandler.java | 124 ++++++++++++++++----- .../application/swing/ui/usage/UsagesUI.jaxx | 27 +++-- .../swing/ui/usage/UsagesUIHandler.java | 43 +++++-- .../i18n/application-swing_en_GB.properties | 5 +- .../i18n/application-swing_es_ES.properties | 5 +- .../i18n/application-swing_fr_FR.properties | 5 +- .../v1/ReferentialServiceController.java | 5 + application-web/src/main/resources/mapping | 1 + .../observe/entities/seine/TripSeineTopiaDao.java | 8 +- .../dto/reference/DataReferenceSetDefinitions.java | 2 +- .../topia/service/ReferentialServiceTopia.java | 24 ++++ .../services/service/ReferentialService.java | 11 +- 12 files changed, 197 insertions(+), 63 deletions(-) diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/ContentReferenceUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/ContentReferenceUIHandler.java index 1c33032..5121fa2 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/ContentReferenceUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/content/ref/ContentReferenceUIHandler.java @@ -34,7 +34,6 @@ import fr.ird.observe.application.swing.ui.tree.ObserveTreeHelper; import fr.ird.observe.application.swing.ui.usage.UsagesUI; import fr.ird.observe.application.swing.validation.ValidationContext; import fr.ird.observe.services.dto.Form; -import fr.ird.observe.services.dto.IdDto; import fr.ird.observe.services.dto.ReferenceMap; import fr.ird.observe.services.dto.constants.ReferenceStatus; import fr.ird.observe.services.dto.constants.ReferentialLocale; @@ -53,6 +52,7 @@ import jaxx.runtime.swing.editor.bean.BeanListHeader; import jaxx.runtime.validator.swing.SwingValidatorUtil; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; @@ -82,6 +82,7 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import static org.nuiton.i18n.I18n.t; @@ -95,8 +96,7 @@ import static org.nuiton.i18n.I18n.t; public class ContentReferenceUIHandler<E extends ReferentialDto> extends ContentUIHandler<E> { /** Logger */ - private static final Log log = - LogFactory.getLog(ContentReferenceUIHandler.class); + private static final Log log = LogFactory.getLog(ContentReferenceUIHandler.class); private final Runnable revalidate; @@ -123,35 +123,53 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content }; } - private static <E extends IdDto> void showUsagesForDelete(JAXXContext tx, - E entity, - ReferenceMap usages) { + private static <E extends ReferentialDto> Pair<Boolean, ReferentialReference<E>> showUsagesForDelete(JAXXContext tx, + E entity, + ReferenceMap usages, + List<ReferentialReference<E>> referenceList) { DecoratorService service = ObserveSwingApplicationContext.get().getDecoratorService(); Decorator<?> decorator = service.getDecoratorByType(entity.getClass()); + + //FIXME utiliser une template String type = ObserveI18nDecoratorHelper.getTypeI18nKey(entity.getClass()); type = t(type); String message = t("observe.message.show.usage.for.delete", type, decorator.toString(entity)); String message2 = t("observe.message.show.usage.for.delete2"); + String message3 = t("observe.message.show.usage.for.delete3"); UsagesUI usagesUI = new UsagesUI(tx); - usagesUI.init(message, message2, null, usages); + usagesUI.init(message, message2, message3, usages, (List) referenceList); - UIHelper.askUser(null, - t("observe.title.can.not.delete.referentiel"), - usagesUI, - JOptionPane.WARNING_MESSAGE, - new Object[]{ - t("observe.choice.cancel")}, - 0); + int reponse = UIHelper.askUser(null, + t("observe.title.can.not.delete.referentiel"), + usagesUI, + JOptionPane.WARNING_MESSAGE, + new Object[]{ + t("observe.choice.replace"), + t("observe.choice.cancel")}, + 0); + + switch (reponse) { + case 0: + // will replace and delete + ReferentialReference<E> selectedReplace = usagesUI.getSelectedReplace(); + return Pair.of(true, selectedReplace); + + } + // any other case : do not replace, do not delete + return Pair.of(false, null); } - private static <E extends IdDto> boolean showUsagesForDesactivated(JAXXContext tx, - E entity, - ReferenceMap usages) { + private static <E extends ReferentialDto> Pair<Boolean, ReferentialReference<E>> showUsagesForDesactivated(JAXXContext tx, + E entity, + ReferenceMap usages, + List<ReferentialReference<E>> referenceList) { DecoratorService service = ObserveSwingApplicationContext.get().getDecoratorService(); Decorator<?> decorator = service.getDecoratorByType(entity.getClass()); + + //FIXME utiliser une template String type = ObserveI18nDecoratorHelper.getTypeI18nKey(entity.getClass()); type = t(type); String message = t("observe.message.show.usage.for.desactivated", type, decorator.toString(entity)); @@ -159,7 +177,7 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content String message3 = t("observe.message.show.usage.for.desactivated3"); UsagesUI usagesUI = new UsagesUI(tx); - usagesUI.init(message, message2, message3, usages); + usagesUI.init(message, message2, message3, usages, (List) referenceList); int reponse = UIHelper.askUser(null, t("observe.title.need.confirm.to.desactivate.referentiel"), @@ -176,11 +194,12 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content switch (reponse) { case 0: // will save ui - return true; + ReferentialReference<E> selectedReplace = usagesUI.getSelectedReplace(); + return Pair.of(true, selectedReplace); } // any other case : do not save - return false; + return Pair.of(false, null); } public void selectBean(ReferentialReference<E> selectedReference) { @@ -351,7 +370,7 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content ContentReferenceUI<E> ui = getUi(); UsagesUI usagesUI = new UsagesUI(ui); - usagesUI.init(message, null, null, usages); + usagesUI.init(message, null, null, usages, null); UIHelper.askUser(ui, t("observe.title.show.usage"), @@ -639,6 +658,8 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content // le bean original E oldBean = model.getSelectedBean(); + ReferentialReference<E> replaceReference = null; + if (oldBean != null && oldBean.getStatus() == ReferenceStatus.enabled && bean.getStatus() == ReferenceStatus.disabled) { @@ -647,8 +668,7 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content // on recherche les objets utilisant cette entitee // on indique a l'utilisateur ce changement if (log.isDebugEnabled()) { - log.debug("entity status was desactivated, looking " + - "for usage"); + log.debug("entity status was desactivated, looking for usage"); } ReferenceMap usages = getReferentialService().findAllUsages(bean); @@ -659,18 +679,33 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content } } else { // some usages were found - boolean willsave = showUsagesForDesactivated(getUi(), bean, - usages); + + // get replacements + Set<ReferentialReference<E>> referentialReferences = getDataSource().getReferentialReferences(getBeanType()); + List<ReferentialReference<E>> referenceList = referentialReferences + .stream() + .filter(ReferentialReference::isEnabled) + .filter(r -> !bean.getId().equals(r.getId())) + .collect(Collectors.toList()); + + Pair<Boolean, ReferentialReference<E>> result = showUsagesForDesactivated(getUi(), bean, usages, referenceList); + boolean willsave = result.getLeft(); + + replaceReference = result.getRight(); if (!willsave) { if (log.isDebugEnabled()) { - log.debug("User refuses to continue, skip " + - "saving..."); + log.debug("User refuses to continue, skip saving..."); } return false; } } } + if (replaceReference != null) { + + // on effectue le remplacement en base + getReferentialService().replaceReference(getBeanType(), bean.getId(), replaceReference.getId()); + } // sauvegarde du bean d'edition dans le bean de la base SaveResultDto saveResult = getReferentialService().save(bean); @@ -703,6 +738,8 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content // recherche des utilisation du bean dans la base ReferenceMap usages = getReferentialService().findAllUsages(bean); + ReferentialReference<E> replaceReference = null; + if (MapUtils.isEmpty(usages)) { if (log.isDebugEnabled()) { log.debug("No usage found, no warning to display"); @@ -710,11 +747,35 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content } else { // some usages were found + + // get replacements + Set<ReferentialReference<E>> referentialReferences = getDataSource().getReferentialReferences(getBeanType()); + List<ReferentialReference<E>> referenceList = referentialReferences + .stream() + .filter(ReferentialReference::isEnabled) + .filter(r -> !bean.getId().equals(r.getId())) + .collect(Collectors.toList()); + if (log.isDebugEnabled()) { - log.debug("can not delete referentiel entity (found usages)"); + log.debug("found some usages, ask user to select a replacement"); + } + + Pair<Boolean, ReferentialReference<E>> result = showUsagesForDelete(ui, bean, usages, referenceList); + Boolean canContinue = result.getLeft(); + if (!canContinue) { + if (log.isDebugEnabled()) { + log.debug("user refuse to continue"); + } + return false; + } + + replaceReference = result.getRight(); + if (replaceReference == null) { + if (log.isDebugEnabled()) { + log.debug("user did not select replace"); + } + return false; } - showUsagesForDelete(ui, bean, usages); - return false; } if (!UIHelper.confirmForEntityDelete(ui, model.getBeanType(), bean)) { @@ -722,6 +783,9 @@ public class ContentReferenceUIHandler<E extends ReferentialDto> extends Content } String beanId = bean.getId(); + if (replaceReference != null) { + getReferentialService().replaceReference(getBeanType(), beanId, replaceReference.getId()); + } getReferentialService().delete(getBeanType(), beanId); return true; diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUI.jaxx b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUI.jaxx index 0558ebd..ab1cfd2 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUI.jaxx +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUI.jaxx @@ -26,12 +26,15 @@ Interface graphique pour afficher la liste des usages d'une entitee donnee. <JPanel id='usagePanel' layout='{new BorderLayout()}'> <import> - fr.ird.observe.application.swing.ObserveSwingApplicationContext fr.ird.observe.application.swing.ui.UIHelper + fr.ird.observe.services.dto.AbstractReference fr.ird.observe.services.dto.ReferenceMap - java.awt.Dimension + jaxx.runtime.swing.editor.bean.BeanComboBox + + java.util.List + static org.nuiton.i18n.I18n.t </import> <script><![CDATA[ @@ -41,14 +44,17 @@ private UsagesUIHandler handler = new UsagesUIHandler(); public void init(String message, String message2, String message3, - ReferenceMap usages) { - getHandler().initUI(this, message,message2, message3, usages); + ReferenceMap usages, + List<AbstractReference> referenceList) { + getHandler().initUI(this, message,message2, message3, usages, referenceList); } public void clean() { getHandler().cleanUI(this); } +public <T> T getSelectedReplace() { return (T) replace.getSelectedItem(); } + protected UsagesUIHandler getHandler() { return handler; } @@ -70,21 +76,20 @@ protected void finalize() throws Throwable { ]]> </script> - <JPanel constraints="BorderLayout.NORTH" - layout='{new BorderLayout()}'> + <JPanel constraints="BorderLayout.NORTH" layout='{new BorderLayout()}'> <JPanel layout='{new BorderLayout()}' constraints="BorderLayout.CENTER"> <JLabel id="message" constraints="BorderLayout.NORTH"/> <JLabel id="message2" constraints="BorderLayout.CENTER"/> <JLabel id="message3" constraints="BorderLayout.SOUTH"/> </JPanel> - <JPanel constraints="BorderLayout.SOUTH" - minimumSize='{new Dimension(10,30)}'/> - <!--layout='{new BorderLayout()}'--> - <!--<JSeparator constraints="BorderLayout.SOUTH"/>--> + <JPanel id="replacePanel" border='{new TitledBorder(t("observe.usage.replaceTitle"))}' visible="false" + constraints="BorderLayout.SOUTH" layout="{new GridLayout(0, 1)}"> + <BeanComboBox id="replace"/> + </JPanel> </JPanel> - <JPanel id="usages" constraints="BorderLayout.CENTER" + <JPanel id="usages" border='{new TitledBorder(t("observe.usage.usageTitle"))}' constraints="BorderLayout.CENTER" layout="{new GridLayout(0, 1)}"/> diff --git a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUIHandler.java b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUIHandler.java index 3b8d083..40990f5 100644 --- a/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUIHandler.java +++ b/application-swing/src/main/java/fr/ird/observe/application/swing/ui/usage/UsagesUIHandler.java @@ -22,6 +22,7 @@ package fr.ird.observe.application.swing.ui.usage; import fr.ird.observe.application.swing.ObserveSwingApplicationContext; +import fr.ird.observe.application.swing.decoration.DecoratorService; import fr.ird.observe.application.swing.decoration.ObserveI18nDecoratorHelper; import fr.ird.observe.services.dto.AbstractReference; import fr.ird.observe.services.dto.DataDto; @@ -30,12 +31,14 @@ import fr.ird.observe.services.dto.IdDto; import fr.ird.observe.services.dto.ReferenceMap; import fr.ird.observe.services.dto.referential.ReferentialDto; import fr.ird.observe.services.dto.referential.ReferentialReference; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import jaxx.runtime.swing.editor.bean.BeanComboBox; +import org.apache.commons.collections4.CollectionUtils; import org.nuiton.decorator.Decorator; +import org.nuiton.decorator.JXPathDecorator; import javax.swing.JLabel; import javax.swing.JList; +import javax.swing.JPanel; import javax.swing.JScrollPane; import java.awt.Dimension; import java.util.ArrayList; @@ -54,23 +57,22 @@ import static org.nuiton.i18n.I18n.t; */ public class UsagesUIHandler { - /** Logger */ - private static final Log log = LogFactory.getLog(UsagesUIHandler.class); - /** * Afficher les usages d'une entite donnee. * - * @param ui l'ui - * @param message le message a afficher en haut - * @param message2 message supplementaire a afficher en haut - * @param message3 message supplementaire a afficher en haut - * @param usages les utilisations de l'entite donnee + * @param ui l'ui + * @param message le message a afficher en haut + * @param message2 message supplementaire a afficher en haut + * @param message3 message supplementaire a afficher en haut + * @param usages les utilisations de l'entite donnee + * @param referenceList la liste optionnel des références possibles de remplacement */ public void initUI(UsagesUI ui, String message, String message2, String message3, - ReferenceMap usages) { + ReferenceMap usages, + List<AbstractReference> referenceList) { // toujours nettoyer l'ui avant tout cleanUI(ui); @@ -98,6 +100,25 @@ public class UsagesUIHandler { } } + + JPanel panel = ui.getReplacePanel(); + + if (CollectionUtils.isNotEmpty(referenceList)) { + + panel.setVisible(true); + AbstractReference reference = referenceList.get(0); + Class type = reference.getType(); + BeanComboBox<?> comboBox = ui.getReplace(); + comboBox.setBeanType(type); + comboBox.setI18nPrefix("observe.common."); + DecoratorService decoratorService = ObserveSwingApplicationContext.get().getDecoratorService(); + Decorator referenceDecorator = decoratorService.getReferenceDecorator(type); + + comboBox.init((JXPathDecorator) referenceDecorator, (List) referenceList); + + } else { + panel.setVisible(false); + } } } diff --git a/application-swing/src/main/resources/i18n/application-swing_en_GB.properties b/application-swing/src/main/resources/i18n/application-swing_en_GB.properties index cfa4eb7..36e3454 100644 --- a/application-swing/src/main/resources/i18n/application-swing_en_GB.properties +++ b/application-swing/src/main/resources/i18n/application-swing_en_GB.properties @@ -1470,8 +1470,9 @@ observe.message.referentiel.home=< Referential > observe.message.referentiel.no.editable=You are not allowed to edit referential. observe.message.select.report=Select a report observe.message.server.info=Local database %1$s is ready in server mode. -observe.message.show.usage.for.delete=Referential %1$s "%2$s" can not be deleted. +observe.message.show.usage.for.delete=Referential %1$s "%2$s" can be deleted if you choose a replacement. observe.message.show.usage.for.delete2=Some data are using this referential, see following references. +observe.message.show.usage.for.delete3=Choose a replacement reference to be able to delete. observe.message.show.usage.for.desactivated=Referential %1$s "%2$s" will be disabled. observe.message.show.usage.for.desactivated2=Some data are using this referential, see following reference observe.message.show.usage.for.desactivated3=Those data need to use another enabled referential to be saved. @@ -1698,6 +1699,8 @@ observe.type.setLongline.unsaved=New fishing operation observe.type.setSeine.unsaved=New set observe.type.tripLongline.unsaved=New trip observe.type.tripSeine.unsaved=New trip +observe.usage.replaceTitle=Replacement object +observe.usage.usageTitle=Founded references observe.validator.field.tip=Property '%1$s' observe.validator.message.tip=Message\: %1$s observe.validator.scope.tip=Message type\: '%1$s' diff --git a/application-swing/src/main/resources/i18n/application-swing_es_ES.properties b/application-swing/src/main/resources/i18n/application-swing_es_ES.properties index 375f23d..1f3c1e3 100644 --- a/application-swing/src/main/resources/i18n/application-swing_es_ES.properties +++ b/application-swing/src/main/resources/i18n/application-swing_es_ES.properties @@ -1470,8 +1470,9 @@ observe.message.referentiel.home=< Referencial > observe.message.referentiel.no.editable=No tiene permisos para editar el referencial. observe.message.select.report=Seleccione informe observe.message.server.info=Información modo servidor -observe.message.show.usage.for.delete=El referencial %1$s "%2$s" no se puede eliminar. +observe.message.show.usage.for.delete=El referencial %1$s "%2$s" no se puede eliminar. \#TODO observe.message.show.usage.for.delete2=Los objetos están usando actualmente las referencias que se enumeran a continuación. +observe.message.show.usage.for.delete3=Choose a replacement reference to be able to delete. \#TODO observe.message.show.usage.for.desactivated=El referencial %1$s "%2$s" se desactivará. observe.message.show.usage.for.desactivated2=Los objetos están usando actualmente las referencias que se enumeran a continuación.. observe.message.show.usage.for.desactivated3=Estos objetos deben usar otro referencial (no desactivado) para poder actualizarse. @@ -1698,6 +1699,8 @@ observe.type.setLongline.unsaved=Nuevo lance observe.type.setSeine.unsaved=Nuevo lance observe.type.tripLongline.unsaved=Nueva marea observe.type.tripSeine.unsaved=Nueva marea +observe.usage.replaceTitle=Objet de remplacement \#TODO +observe.usage.usageTitle=Références trouvées \#TODO observe.validator.field.tip=Propriedad '%1$s' observe.validator.message.tip=Mensaje \: %1$s observe.validator.scope.tip=Tipo de mensaje \: '%1$s' diff --git a/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties b/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties index 16a0fd8..a688252 100644 --- a/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties +++ b/application-swing/src/main/resources/i18n/application-swing_fr_FR.properties @@ -1470,8 +1470,9 @@ observe.message.referentiel.home=< Référentiel > observe.message.referentiel.no.editable=Vous n'êtes pas autorisé à éditer le référentiel. observe.message.select.report=Choisissez une requête observe.message.server.info=La base locale %1$s est démarrée en mode serveur. -observe.message.show.usage.for.delete=Le référentiel %1$s "%2$s" ne peut pas être supprimé. +observe.message.show.usage.for.delete=Le référentiel %1$s "%2$s" ne peut pas être supprimé sans effectuer au préalable un remplacement. observe.message.show.usage.for.delete2=Des objets utilisent actuellement cet entité dont les références sont citées plus bas. +observe.message.show.usage.for.delete3=Pour pouvoir supprimer l'objet, vous devez choisir une autre référence de remplacement. observe.message.show.usage.for.desactivated=Le référentiel %1$s "%2$s" va être désactivé. observe.message.show.usage.for.desactivated2=Des objets utilisent actuellement cet entité dont les références sont citées plus bas. observe.message.show.usage.for.desactivated3=Ces objets devront utiliser un autre référentiel (non désactivé) pour pouvoir être mis à jour. @@ -1698,6 +1699,8 @@ observe.type.setLongline.unsaved=Nouvelle opération de pêche observe.type.setSeine.unsaved=Nouvelle calée observe.type.tripLongline.unsaved=Nouvelle marée observe.type.tripSeine.unsaved=Nouvelle marée +observe.usage.replaceTitle=Objet de remplacement +observe.usage.usageTitle=Références trouvées observe.validator.field.tip=Propriété '%1$s' observe.validator.message.tip=Message \: %1$s observe.validator.scope.tip=Type de message \: '%1$s' diff --git a/application-web/src/main/java/fr/ird/observe/application/web/controller/v1/ReferentialServiceController.java b/application-web/src/main/java/fr/ird/observe/application/web/controller/v1/ReferentialServiceController.java index 0fdfe9b..76d4ff6 100644 --- a/application-web/src/main/java/fr/ird/observe/application/web/controller/v1/ReferentialServiceController.java +++ b/application-web/src/main/java/fr/ird/observe/application/web/controller/v1/ReferentialServiceController.java @@ -94,6 +94,11 @@ public class ReferentialServiceController extends ObserveAuthenticatedServiceCon } @Override + public <E extends ReferentialDto> void replaceReference(Class<E> beanType, String idToReplace, String replaceId) { + service.replaceReference(beanType, idToReplace, replaceId); + } + + @Override public <R extends ReferentialDto> ReferenceMap findAllUsages(R bean) throws DataNotFoundException { return service.findAllUsages(bean); } diff --git a/application-web/src/main/resources/mapping b/application-web/src/main/resources/mapping index e47165f..0435142 100644 --- a/application-web/src/main/resources/mapping +++ b/application-web/src/main/resources/mapping @@ -85,6 +85,7 @@ GET /api/v1/ReferentialService/loadForm GET /api/v1/ReferentialService/loadReference v1.ReferentialServiceController.loadReference GET /api/v1/ReferentialService/loadSpecies v1.ReferentialServiceController.loadSpecies GET /api/v1/ReferentialService/preCreate v1.ReferentialServiceController.preCreate +GET /api/v1/ReferentialService/replaceReference v1.ReferentialServiceController.replaceReference GET /api/v1/SqlScriptProducerService/produceAddSqlScript v1.SqlScriptProducerServiceController.produceAddSqlScript GET /api/v1/SqlScriptProducerService/produceDeleteSqlScript v1.SqlScriptProducerServiceController.produceDeleteSqlScript GET /api/v1/actions/synchro/referential/diff/ReferentialSynchronizeDiffService/getEnabledReferentialReferenceSet v1.actions.synchro.referential.diff.ReferentialSynchronizeDiffServiceController.getEnabledReferentialReferenceSet diff --git a/entities/src/main/java/fr/ird/observe/entities/seine/TripSeineTopiaDao.java b/entities/src/main/java/fr/ird/observe/entities/seine/TripSeineTopiaDao.java index b6df52e..b7c83d1 100644 --- a/entities/src/main/java/fr/ird/observe/entities/seine/TripSeineTopiaDao.java +++ b/entities/src/main/java/fr/ird/observe/entities/seine/TripSeineTopiaDao.java @@ -197,7 +197,7 @@ public class TripSeineTopiaDao extends AbstractTripSeineTopiaDao<TripSeine> { " p.firstName," + " v.topiaId, " + " v." + I18nReferenceEntities.getPropertyName(referenceLocale) + "," + - " select count(*) from observe_seine.route r where r.trip = t.topiaId" + + " (select count(*) from observe_seine.route r where r.trip = t.topiaId) as routeCount" + " FROM observe_seine.trip t, observe_common.person p, observe_common.vessel v,observe_common.program pr " + " WHERE " + " t.program = ?" + @@ -222,7 +222,7 @@ public class TripSeineTopiaDao extends AbstractTripSeineTopiaDao<TripSeine> { " p.firstName," + " v.topiaId," + " v." + I18nReferenceEntities.getPropertyName(referenceLocale) + "," + - " select count(*) from observe_seine.route r where r.trip = t.topiaId" + + " (select count(*) from observe_seine.route r where r.trip = t.topiaId) as routeCount" + " FROM observe_seine.trip t, observe_common.person p, observe_common.vessel v, observe_common.program pr" + " WHERE " + " t.topiaId = ?" + @@ -344,9 +344,7 @@ public class TripSeineTopiaDao extends AbstractTripSeineTopiaDao<TripSeine> { public static Date find(TopiaSqlSupport context, String tripId) { - String sql = "SELECT max(r.date)" + - " FROM observe_seine.route r" + - " WHERE r.trip = ?"; + String sql = "SELECT max(r.date) FROM observe_seine.route r WHERE r.trip = ?"; TheoricalEndOfDateSqlQuery request = new TheoricalEndOfDateSqlQuery(sql, tripId); return context.findSingleResult(request); diff --git a/services-dto/src/main/java/fr/ird/observe/services/dto/reference/DataReferenceSetDefinitions.java b/services-dto/src/main/java/fr/ird/observe/services/dto/reference/DataReferenceSetDefinitions.java index 4b29461..48a19a0 100644 --- a/services-dto/src/main/java/fr/ird/observe/services/dto/reference/DataReferenceSetDefinitions.java +++ b/services-dto/src/main/java/fr/ird/observe/services/dto/reference/DataReferenceSetDefinitions.java @@ -70,7 +70,7 @@ public enum DataReferenceSetDefinitions { .addProperty(Date.class, TripSeineDto.PROPERTY_START_DATE) .addProperty(Date.class, TripSeineDto.PROPERTY_END_DATE) .addProperty(String.class, TripSeineDto.PROPERTY_PROGRAM + "Id") - .addProperty(String.class, TripSeineDto.PROPERTY_ROUTE_COUNT) + .addProperty(int.class, TripSeineDto.PROPERTY_ROUTE_COUNT) .addProperty(String.class, TripSeineDto.PROPERTY_VESSEL) .addProperty(String.class, TripSeineDto.PROPERTY_OBSERVER)), diff --git a/services-topia/src/main/java/fr/ird/observe/services/topia/service/ReferentialServiceTopia.java b/services-topia/src/main/java/fr/ird/observe/services/topia/service/ReferentialServiceTopia.java index f04a9b3..12663db 100644 --- a/services-topia/src/main/java/fr/ird/observe/services/topia/service/ReferentialServiceTopia.java +++ b/services-topia/src/main/java/fr/ird/observe/services/topia/service/ReferentialServiceTopia.java @@ -25,6 +25,7 @@ package fr.ird.observe.services.topia.service; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import fr.ird.observe.ObserveEntityEnum; import fr.ird.observe.entities.EntityMap; import fr.ird.observe.entities.constants.ReferenceStatusPersist; import fr.ird.observe.entities.referentiel.ObserveReferentialEntity; @@ -47,10 +48,12 @@ import fr.ird.observe.services.service.ReferenceSetsRequest; import fr.ird.observe.services.service.ReferentialService; import fr.ird.observe.services.topia.ObserveServiceTopia; import fr.ird.observe.services.topia.binder.referential.ReferentialBinderSupport; +import fr.ird.observe.services.topia.service.actions.synchro.referential.sql.ReplaceSqlStatementGenerator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaDao; import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; import java.util.Collection; import java.util.Collections; @@ -211,6 +214,27 @@ public class ReferentialServiceTopia extends ObserveServiceTopia implements Refe } @Override + public <E extends ReferentialDto> void replaceReference(Class<E> beanType, String idToReplace, String replaceId) { + if (log.isTraceEnabled()) { + log.trace("replaceReference(" + beanType.getName() + ", " + idToReplace + "," + replaceId + ")"); + } + Class<ObserveReferentialEntity> entityType = getReferentialEntityType(beanType); + ObserveEntityEnum entityEnum = ObserveEntityEnum.valueOf(entityType); + + TopiaMetadataModel metadataModel = serviceContext.getTopiaApplicationContext().getMetadataModel(); + + ReplaceSqlStatementGenerator<E> generator = new ReplaceSqlStatementGenerator<E>(metadataModel, entityEnum.name()); + + String sql = generator.generateSql(idToReplace, replaceId); + + if (log.isInfoEnabled()) { + log.info("Replace sql code:\n" + sql); + } + getTopiaPersistenceContext().executeSqlScript(sql.getBytes()); + + } + + @Override public <R extends ReferentialDto> ReferenceMap findAllUsages(R bean) throws DataNotFoundException { if (log.isTraceEnabled()) { log.trace("findAllUsages(" + bean.getId() + ")"); diff --git a/services/src/main/java/fr/ird/observe/services/service/ReferentialService.java b/services/src/main/java/fr/ird/observe/services/service/ReferentialService.java index 5f94e4e..0935387 100644 --- a/services/src/main/java/fr/ird/observe/services/service/ReferentialService.java +++ b/services/src/main/java/fr/ird/observe/services/service/ReferentialService.java @@ -24,8 +24,8 @@ package fr.ird.observe.services.service; import com.google.common.collect.ImmutableSet; import fr.ird.observe.services.ObserveService; -import fr.ird.observe.services.dto.ReferenceMap; import fr.ird.observe.services.dto.Form; +import fr.ird.observe.services.dto.ReferenceMap; import fr.ird.observe.services.dto.referential.ReferentialDto; import fr.ird.observe.services.dto.referential.ReferentialReference; import fr.ird.observe.services.dto.referential.ReferentialReferenceSet; @@ -36,6 +36,7 @@ import fr.ird.observe.services.spi.PostRequest; import fr.ird.observe.services.spi.ReadDataPermission; import fr.ird.observe.services.spi.ReadReferentialPermission; import fr.ird.observe.services.spi.Write; +import fr.ird.observe.services.spi.WriteDataPermission; import fr.ird.observe.services.spi.WriteReferentialPermission; import java.util.Collection; @@ -52,7 +53,7 @@ public interface ReferentialService extends ObserveService { <R extends ReferentialDto> ReferentialReferenceSet<R> getReferenceSet(Class<R> type, Date lastUpdateDate); @ReadReferentialPermission - ImmutableSet<ReferentialReferenceSet<?>> getReferentialReferenceSets(ReferenceSetsRequest request); + ImmutableSet<ReferentialReferenceSet<?>> getReferentialReferenceSets(ReferenceSetsRequest request); //FIXME charger cela dans le cache côté applicatif @ReadReferentialPermission @@ -82,6 +83,11 @@ public interface ReferentialService extends ObserveService { @DeleteRequest <R extends ReferentialDto> void delete(Class<R> type, Collection<String> ids) throws DataNotFoundException; + @WriteReferentialPermission + @WriteDataPermission + @Write + <E extends ReferentialDto> void replaceReference(Class<E> beanType, String idToReplace, String replaceId); + @ReadReferentialPermission @ReadDataPermission <R extends ReferentialDto> ReferenceMap findAllUsages(R bean) throws DataNotFoundException; @@ -89,4 +95,5 @@ public interface ReferentialService extends ObserveService { @ReadReferentialPermission @ReadDataPermission <R extends ReferentialDto> boolean exists(Class<R> type, String id); + } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.