We are using dspace 3.2 and added our own authentication class. This authentication class is called whenever a session is spawned by the first time user. Inside the code, we lookup for the user and add them to the group if they don't belong to that group.
EPerson eperson = EPerson.findByEmail(context, email);
if (eperson != null) {
for (Group group : Group.findAll(context, Group.ID)) {
if (!group.isMember(eperson)) {
group.addMember(eperson);
group.update();
context.commit();
}
}
}
The problem comes in when there are multiple sessions running concurrently and adding the person to the group. This causes a duplicate row entry in the epersongroup2eperson table
dspace=> select * from epersongroup2eperson;
id | eperson_group_id | eperson_id
-----+------------------+------------
1 | 3 | 10
2 | 3 | 10
Is this a known bug in dspace?
I tried putting a
synchronized
code block around the code above, but the duplicate rows still happens. So I added a constraint in the table to make the columns unique.