Skip to content

Commit ec57e1c

Browse files
committed
Fix notification settings creation
Signed-off-by: Andrea Lamparelli <[email protected]>
1 parent 8e3caa0 commit ec57e1c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

horreum-backend/src/main/java/io/hyperfoil/tools/horreum/svc/NotificationServiceImpl.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
@Startup
4141
public class NotificationServiceImpl implements NotificationService {
4242
private static final Logger log = Logger.getLogger(NotificationServiceImpl.class);
43-
//@formatter:off
44-
private static final String GET_NOTIFICATIONS = """
43+
//@formatter:off
44+
private static final String GET_NOTIFICATIONS = """
4545
WITH ens AS (
4646
SELECT ns.*, watch_id FROM notificationsettings ns
4747
JOIN watch_users wu ON NOT ns.isteam AND ns.name = wu.users
@@ -60,7 +60,7 @@ WITH ens AS (
6060
WHERE testid = ?
6161
AND name NOT IN (SELECT optout FROM watch_optout WHERE ens.watch_id = watch_optout.watch_id)
6262
""";
63-
//@formatter:on
63+
//@formatter:on
6464
public final Map<String, NotificationPlugin> plugins = new HashMap<>();
6565

6666
@Inject
@@ -147,6 +147,7 @@ public List<NotificationSettings> settings(String name, boolean team) {
147147
@RolesAllowed({ Roles.VIEWER, Roles.TESTER, Roles.ADMIN })
148148
@Transactional
149149
@Override
150+
// remove and re-create the settings for the user
150151
public void updateSettings(String name, boolean team, NotificationSettings[] settings) {
151152
NotificationSettingsDAO.delete("name = ?1 AND isTeam = ?2", name, team);
152153
Arrays.stream(settings).map(NotificationSettingsMapper::to).forEach(ns -> {
@@ -158,9 +159,11 @@ public void updateSettings(String name, boolean team, NotificationSettings[] set
158159
}
159160
throw ServiceException.badRequest("Invalid method " + ns.method);
160161
}
162+
// reset the id
163+
ns.id = null;
161164
ns.name = name;
162165
ns.isTeam = team;
163-
em.merge(ns);
166+
ns.persist();
164167
});
165168
}
166169

0 commit comments

Comments
 (0)