branch hotfix/3.1.5 created (now e157d377)
This is an automated email from the git hooks/post-receive script. New change to branch hotfix/3.1.5 in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git at e157d377 ref #213 : Correction sur les modifications concurentes d'un sondage This branch includes the following new commits: new e157d377 ref #213 : Correction sur les modifications concurentes d'un sondage 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 e157d37707a0614c6bff1b7d4252590682dbd338 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Fri Jun 1 14:48:19 2018 +0200 ref #213 : Correction sur les modifications concurentes d'un sondage -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch hotfix/3.1.5 in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit e157d37707a0614c6bff1b7d4252590682dbd338 Author: Sylvain Bavencoff <bavencoff@codelutin.com> Date: Fri Jun 1 14:48:19 2018 +0200 ref #213 : Correction sur les modifications concurentes d'un sondage --- .../pollen/services/service/ChoiceService.java | 30 ++++++---- .../pollen/services/service/PollService.java | 69 +++++++++++++--------- .../services/service/PollenServiceSupport.java | 8 +++ 3 files changed, 66 insertions(+), 41 deletions(-) diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java index 6dc46811..b701fac7 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/ChoiceService.java @@ -127,24 +127,30 @@ public class ChoiceService extends PollenServiceSupport { checkNotNull(choice); checkIsNotPersisted(choice); - Poll poll = getPollService().getPoll0(pollId); - checkPermission(PollenPermissions.addChoice(poll)); + // FIXME 01/06/2018 SBavencoff Evite les modifications concurantes en BD du sondage + synchronized (getLock(pollId)) { - List<Choice> existingChoices = getChoiceDao().findAll(poll); + Poll poll = getPollService().getPoll0(pollId); + checkPermission(PollenPermissions.addChoice(poll)); - ErrorMap errorMap = checkChoice(existingChoices, choice); - errorMap.failIfNotEmpty(); + List<Choice> existingChoices = getChoiceDao().findAll(poll); - // set the choice order - choice.setChoiceOrder(existingChoices.size()); + ErrorMap errorMap = checkChoice(existingChoices, choice); + errorMap.failIfNotEmpty(); - Choice result = saveChoice(poll, choice); - commit(); + // set the choice order + choice.setChoiceOrder(existingChoices.size()); + + Choice result = saveChoice(poll, choice); + commit(); + + getNotificationService().onChoiceAdded(poll, result); + getFeedService().onChoiceAdded(poll, result); - getNotificationService().onChoiceAdded(poll, result); - getFeedService().onChoiceAdded(poll, result); + return PollenEntityRef.of(result); + + } - return PollenEntityRef.of(result); } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java index 1e48cad2..ba9da016 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollService.java @@ -336,28 +336,32 @@ public class PollService extends PollenServiceSupport { checkNotNull(poll); checkIsPersisted(poll); - Poll pollDb = getPoll0(poll.getEntityId()); - checkPermission(PollenPermissions.edit(pollDb)); - ErrorMap errorMap = checkPoll(poll); - errorMap.failIfNotEmpty(); - Set<String> newParticipants = Sets.newHashSet(); - if (PollType.FREE.equals(poll.getPollType()) ) { - newParticipants.addAll(Sets.newHashSet(poll.getParticipants())); - String participantsDb = pollDb.getParticipants(); - if (participantsDb != null) { - newParticipants.removeAll(Sets.newHashSet(participantsDb.split("\\s+"))); + // FIXME 01/06/2018 SBavencoff Evite les modifications concurantes en BD du sondage + synchronized (getLock(poll.getEntityId())) { + Poll pollDb = getPoll0(poll.getEntityId()); + checkPermission(PollenPermissions.edit(pollDb)); + + ErrorMap errorMap = checkPoll(poll); + errorMap.failIfNotEmpty(); + Set<String> newParticipants = Sets.newHashSet(); + if (PollType.FREE.equals(poll.getPollType())) { + newParticipants.addAll(Sets.newHashSet(poll.getParticipants())); + String participantsDb = pollDb.getParticipants(); + if (participantsDb != null) { + newParticipants.removeAll(Sets.newHashSet(participantsDb.split("\\s+"))); + } } - } - Poll savedPoll = savePoll(poll, null); + Poll savedPoll = savePoll(poll, null); - commit(); + commit(); - getNotificationService().onPollEdited(savedPoll, newParticipants); - getFeedService().onPollEdited(savedPoll, newParticipants); + getNotificationService().onPollEdited(savedPoll, newParticipants); + getFeedService().onPollEdited(savedPoll, newParticipants); - return toPollBean(savedPoll); + return toPollBean(savedPoll); + } } @@ -420,17 +424,21 @@ public class PollService extends PollenServiceSupport { checkNotNull(pollId); - Poll poll = getPoll0(pollId); - checkPermission(PollenPermissions.close(poll)); + // FIXME 01/06/2018 SBavencoff Evite les modifications concurantes en BD du sondage + synchronized (getLock(pollId)) { - poll.setEndDate(getNow()); + Poll poll = getPoll0(pollId); + checkPermission(PollenPermissions.close(poll)); - commit(); + poll.setEndDate(getNow()); + + commit(); - getNotificationService().onPollClosed(poll); - getFeedService().onPollClosed(poll); + getNotificationService().onPollClosed(poll); + getFeedService().onPollClosed(poll); - return poll.getEndDate(); + return poll.getEndDate(); + } } public void reopenPoll(String pollId) { @@ -438,15 +446,18 @@ public class PollService extends PollenServiceSupport { checkNotNull(pollId); - Poll poll = getPoll0(pollId); - checkPermission(PollenPermissions.close(poll)); + // FIXME 01/06/2018 SBavencoff Evite les modifications concurantes en BD du sondage + synchronized (getLock(pollId)) { + Poll poll = getPoll0(pollId); + checkPermission(PollenPermissions.close(poll)); - poll.setEndDate(null); + poll.setEndDate(null); - commit(); + commit(); - getNotificationService().onPollReopened(poll); - getFeedService().onPollReopened(poll); + getNotificationService().onPollReopened(poll); + getFeedService().onPollReopened(poll); + } } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java index d46beb01..38f28d83 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/PollenServiceSupport.java @@ -24,6 +24,7 @@ package org.chorem.pollen.services.service; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -71,6 +72,7 @@ import org.nuiton.util.pagination.PaginationResult; import java.util.Collection; import java.util.Date; import java.util.Locale; +import java.util.Map; import java.util.function.Function; /** @@ -83,6 +85,12 @@ public abstract class PollenServiceSupport implements PollenService { public static final int PAGE_SIZE_DEFAULT = 10; + private static Map<String, Object> ENTITY_LOCK_BY_ID = Maps.newHashMap(); + + public static synchronized Object getLock(String id) { + return ENTITY_LOCK_BY_ID. computeIfAbsent(id, id2 -> new Object()); + } + // -- PollenServiceSupport -- // protected PollenServiceContext serviceContext; -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm