From 64aa4b036717c32222d9b3be0433ed695d102af4 Mon Sep 17 00:00:00 2001 From: Binal Patel Date: Thu, 14 Nov 2024 14:33:04 -0800 Subject: [PATCH] Bug fix, cleanup, add comment --- .../study/controllers/StudyController.java | 19 ++++++++++--------- .../labkey/study/view/manageAlternateIds.jsp | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/study/src/org/labkey/study/controllers/StudyController.java b/study/src/org/labkey/study/controllers/StudyController.java index cdd28dd8b8f..41f99e8f419 100644 --- a/study/src/org/labkey/study/controllers/StudyController.java +++ b/study/src/org/labkey/study/controllers/StudyController.java @@ -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; @@ -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(); @@ -1562,22 +1561,24 @@ private void deleteParticipantRows(TableInfo ti, List> 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); diff --git a/study/src/org/labkey/study/view/manageAlternateIds.jsp b/study/src/org/labkey/study/view/manageAlternateIds.jsp index 8fa18a168ed..9f27ce44c43 100644 --- a/study/src/org/labkey/study/view/manageAlternateIds.jsp +++ b/study/src/org/labkey/study/view/manageAlternateIds.jsp @@ -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',