Skip to content

Commit

Permalink
Bug fix, cleanup, add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-bpatel committed Nov 14, 2024
1 parent 896355b commit 64aa4b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions study/src/org/labkey/study/controllers/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@
import org.labkey.study.model.DateDatasetDomainKind;
import org.labkey.study.model.Participant;
import org.labkey.study.model.ParticipantCategoryImpl;
import org.labkey.study.model.ParticipantGroupCache;
import org.labkey.study.model.ParticipantGroupManager;
import org.labkey.study.model.QCStateSet;
import org.labkey.study.model.SecurityType;
Expand Down Expand Up @@ -1517,9 +1516,9 @@ public Object execute(DeleteParticipantForm deleteParticipantForm, BindException
{
TableSelector ts = new TableSelector(participantGroupMapTable, Set.of(participantIdColumnName, "GroupId"), new SimpleFilter(FieldKey.fromString(participantIdColumnName), participantId), null);
ParticipantGroupManager.ParticipantGroupMap[] pgm = ts.getArray(ParticipantGroupManager.ParticipantGroupMap.class);
if (pgm.length == 1)
if (pgm.length == 1) //a participant is associated with only one group, so there should be only one row
{
deleteFromParticipantGroupMapTable(participantGroupMapTable, participantId, participantGroupMapTable.getName(), pgm[0].getGroupId(), errors);
deleteFromParticipantGroupMapTable(participantGroupMapTable, participantId, participantIdColumnName, pgm[0].getGroupId(), errors);
}
}
transaction.commit();
Expand Down Expand Up @@ -1562,22 +1561,24 @@ private void deleteParticipantRows(TableInfo ti, List<Map<String, Object>> keys,
}
catch (InvalidKeyException | BatchValidationException | QueryUpdateServiceException | SQLException e)
{
_log.error("Failed to delete from dataset {}", ti.getName(), e);
errors.reject(ERROR_MSG, "Error deleting from dataset " + ti.getName() + ": " + e.getMessage());
String msg = "Failed to delete participant rows from " + ti.getName();
_log.error(msg, e);
errors.reject(ERROR_MSG, msg + ": " + e.getMessage());
}
}

private void deleteFromParticipantGroupMapTable(TableInfo ti, String participantId, String tableName, Integer groupId, BindException errors)
private void deleteFromParticipantGroupMapTable(TableInfo ti, String participantId, String participantColName, Integer groupId, BindException errors)
{
try
{
SQLFragment sql = new SQLFragment("DELETE FROM " + ti.getSchema().getName() + "." + tableName + " WHERE participantid = ?", participantId);
SQLFragment sql = new SQLFragment("DELETE FROM study.participantgroupmap WHERE participantid = ?", participantId);
new SqlExecutor(ti.getSchema()).execute(sql);
}
catch (Exception e)
{
_log.error("Failed to delete participant from ParticipantGroupMap for ID: " + participantId, e);
errors.reject(ERROR_MSG, "Failed to delete participant from " + ti.getSchema().getName() + "." + tableName + ": " + e.getMessage());
String msg = "Failed to delete row from " + ti.getSchema().getName() + "." + ti.getName() + " for " + participantColName + " '" + participantId + "'";
_log.error(msg, e);
errors.reject(ERROR_MSG, msg + " :" + e.getMessage());
}

ParticipantGroupAuditProvider.ParticipantGroupAuditEvent event = ParticipantGroupAuditProvider.EventFactory.participantDeleted(participantId, getContainer(), groupId);
Expand Down
2 changes: 1 addition & 1 deletion study/src/org/labkey/study/view/manageAlternateIds.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
reader: {
type: 'json',
rootProperty: 'rows',
totalProperty: 'total' // Assuming the total count is in the 'total' property for paging
totalProperty: 'rowCount'
},
extraParams: {
schemaName: 'study',
Expand Down

0 comments on commit 64aa4b0

Please sign in to comment.