From c8d9223ca9eff1546a9245dee716df24c163cb01 Mon Sep 17 00:00:00 2001 From: labkey-jeckels Date: Mon, 5 Jan 2026 11:21:19 -0800 Subject: [PATCH] Fix transaction boundary problem with ParticipantCategoryListener --- .../study/model/ParticipantGroupManager.java | 127 ++++-------------- 1 file changed, 27 insertions(+), 100 deletions(-) diff --git a/study/src/org/labkey/study/model/ParticipantGroupManager.java b/study/src/org/labkey/study/model/ParticipantGroupManager.java index 60643f17f7e..04cf8d18ba3 100644 --- a/study/src/org/labkey/study/model/ParticipantGroupManager.java +++ b/study/src/org/labkey/study/model/ParticipantGroupManager.java @@ -443,9 +443,7 @@ private List _getParticipantCategories(Container c, Use List filtered = new ArrayList<>(); // TODO: Switch ParticipantCategoryImpl internals from arrays to lists... but not right now - categories.stream().filter(category -> category.canRead(c, user)).forEach(category -> { - filtered.add(category); - }); + categories.stream().filter(category -> category.canRead(c, user)).forEach(filtered::add); return filtered; } @@ -454,11 +452,10 @@ public ParticipantCategoryImpl setParticipantCategory(Container c, User user, Pa { DbScope scope = StudySchema.getInstance().getSchema().getScope(); + ParticipantCategoryImpl ret; try (DbScope.Transaction transaction = scope.ensureTransaction()) { - ParticipantCategoryImpl ret; boolean isUpdate = !def.isNew(); - List errors; ret = _saveParticipantCategory(c, user, def); @@ -477,33 +474,23 @@ public ParticipantCategoryImpl setParticipantCategory(Container c, User user, Pa } transaction.commit(); ParticipantGroupCache.uncache(c); + } - if (def.isNew()) - errors = fireCreatedCategory(user, ret); - else - errors = fireUpdateCategory(user, ret); + if (def.isNew()) + fireCreatedCategory(user, ret); + else + fireUpdateCategory(user, ret); - if (!errors.isEmpty()) - { - Throwable first = errors.get(0); - if (first instanceof RuntimeException) - throw (RuntimeException) first; - else - throw new RuntimeException(first); - } - return ret; - } + return ret; } public ParticipantCategoryImpl setParticipantCategory(Container c, User user, ParticipantCategoryImpl def) throws ValidationException { DbScope scope = StudySchema.getInstance().getSchema().getScope(); + ParticipantCategoryImpl ret; try (DbScope.Transaction transaction = scope.ensureTransaction()) { - ParticipantCategoryImpl ret; - List errors; - ret = _saveParticipantCategory(c, user, def); switch (ParticipantCategory.Type.valueOf(ret.getType())) @@ -515,22 +502,14 @@ public ParticipantCategoryImpl setParticipantCategory(Container c, User user, Pa } transaction.commit(); ParticipantGroupCache.uncache(c); + } - if (def.isNew()) - errors = fireCreatedCategory(user, ret); - else - errors = fireUpdateCategory(user, ret); + if (def.isNew()) + fireCreatedCategory(user, ret); + else + fireUpdateCategory(user, ret); - if (!errors.isEmpty()) - { - Throwable first = errors.get(0); - if (first instanceof RuntimeException) - throw (RuntimeException) first; - else - throw new RuntimeException(first); - } - return ret; - } + return ret; } private ParticipantCategoryImpl _saveParticipantCategory(Container c, User user, ParticipantCategoryImpl def) throws ValidationException @@ -771,9 +750,6 @@ private ParticipantCategoryImpl modifyParticipantCategory(Container c, User user try (DbScope.Transaction transaction = scope.ensureTransaction()) { - ParticipantCategoryImpl ret; - List errors; - List groups = getParticipantGroups(c, user, def); if (groups.size() != 1) throw new RuntimeException("Expected one group in category " + def.getLabel()); @@ -794,22 +770,11 @@ private ParticipantCategoryImpl modifyParticipantCategory(Container c, User user } transaction.commit(); ParticipantGroupCache.uncache(c); - - //Reselect - ret = getParticipantCategory(c, user, def.getRowId()); - - errors = fireUpdateCategory(user, ret); - - if (!errors.isEmpty()) - { - Throwable first = errors.get(0); - if (first instanceof RuntimeException) - throw (RuntimeException) first; - else - throw new RuntimeException(first); - } - return ret; } + //Reselect + ParticipantCategoryImpl ret = getParticipantCategory(c, user, def.getRowId()); + fireUpdateCategory(user, ret); + return ret; } private void addGroupParticipants(Container c, User user, ParticipantGroup group, String[] participantsToAdd) throws ValidationException @@ -1012,17 +977,9 @@ public void deleteParticipantCategory(Container c, User user, ParticipantCategor ParticipantGroupCache.uncache(c); transaction.commit(); - - List errors = fireDeleteCategory(user, def); - if (!errors.isEmpty()) - { - Throwable first = errors.get(0); - if (first instanceof RuntimeException) - throw (RuntimeException) first; - else - throw new RuntimeException(first); - } } + + fireDeleteCategory(user, def); } public void deleteParticipantGroup(Container c, User user, ParticipantGroup group) throws ValidationException @@ -1109,58 +1066,28 @@ public static void removeCategoryListener(ParticipantCategoryListener listener) _listeners.remove(listener); } - private static List fireDeleteCategory(User user, ParticipantCategoryImpl category) + private static void fireDeleteCategory(User user, ParticipantCategoryImpl category) { - List errors = new ArrayList<>(); - for (ParticipantCategoryListener l : _listeners) { - try - { - l.categoryDeleted(user, category); - } - catch (Throwable t) - { - errors.add(t); - } + l.categoryDeleted(user, category); } - return errors; } - private static List fireUpdateCategory(User user, ParticipantCategoryImpl category) + private static void fireUpdateCategory(User user, ParticipantCategoryImpl category) { - List errors = new ArrayList<>(); - for (ParticipantCategoryListener l : _listeners) { - try - { - l.categoryUpdated(user, category); - } - catch (Throwable t) - { - errors.add(t); - } + l.categoryUpdated(user, category); } - return errors; } - private static List fireCreatedCategory(User user, ParticipantCategoryImpl category) + private static void fireCreatedCategory(User user, ParticipantCategoryImpl category) { - List errors = new ArrayList<>(); - for (ParticipantCategoryListener l : _listeners) { - try - { - l.categoryCreated(user, category); - } - catch (Throwable t) - { - errors.add(t); - } + l.categoryCreated(user, category); } - return errors; } public void clearCache(Container c)