From 073bd89cbd09c4a3f14d6f303193d35261d079ce Mon Sep 17 00:00:00 2001 From: Matthew Bellew Date: Wed, 18 Nov 2020 10:33:07 -0800 Subject: [PATCH 1/4] avoid parameters markers to implement modules table avoid old sqlserver parameter limit --- .../labkey/core/query/ModulesTableInfo.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/core/src/org/labkey/core/query/ModulesTableInfo.java b/core/src/org/labkey/core/query/ModulesTableInfo.java index 0885d56ea92..ede1ccab16a 100644 --- a/core/src/org/labkey/core/query/ModulesTableInfo.java +++ b/core/src/org/labkey/core/query/ModulesTableInfo.java @@ -27,6 +27,7 @@ import org.labkey.api.data.RenderContext; import org.labkey.api.data.SQLFragment; import org.labkey.api.data.Table; +import org.labkey.api.data.dialect.DialectStringHandler; import org.labkey.api.module.Module; import org.labkey.api.module.ModuleContext; import org.labkey.api.module.ModuleLoader; @@ -135,10 +136,21 @@ public ModulesTableInfo init() return (ModulesTableInfo) super.init(); } + private void appendStringLiteral(DialectStringHandler h, SQLFragment sql, String sep, String s) + { + sql.append(sep); + s = StringUtils.trimToNull(s); + if (null == s) + sql.append("NULL"); + else + sql.append(h.quoteStringLiteral(s)); + } + @NotNull @Override public SQLFragment getFromSQL(String alias) { + var h = getSqlDialect().getStringHandler(); SQLFragment ret = new SQLFragment(); // select in-memory modules @@ -150,21 +162,20 @@ public SQLFragment getFromSQL(String alias) { cte.append(sep); sep = ",\n"; - cte.append("("); - cte.append("?").add(module.getName()); - cte.append(",?").add(StringUtils.trimToNull(module.getReleaseVersion())); - cte.append(",?").add(StringUtils.trimToNull(module.getLabel())); - cte.append(",?").add(StringUtils.trimToNull(module.getDescription())); - cte.append(",?").add(StringUtils.trimToNull(module.getUrl())); - cte.append(",?").add(StringUtils.trimToNull(module.getAuthor())); - cte.append(",?").add(StringUtils.trimToNull(module.getMaintainer())); - cte.append(",?").add(StringUtils.trimToNull(module.getOrganization())); - cte.append(",?").add(StringUtils.trimToNull(module.getOrganizationUrl())); - cte.append(",?").add(StringUtils.trimToNull(module.getLicense())); - cte.append(",?").add(StringUtils.trimToNull(module.getLicenseUrl())); - cte.append(",?").add(StringUtils.trimToNull(module.getVcsRevision())); - cte.append(",?").add(StringUtils.trimToNull(module.getVcsUrl())); - cte.append(",?").add(StringUtils.join(module.getModuleDependenciesAsSet(), ", ")); + appendStringLiteral(h, cte,"(",module.getName()); + appendStringLiteral(h, cte,",",module.getReleaseVersion()); + appendStringLiteral(h, cte,",",module.getLabel()); + appendStringLiteral(h, cte,",",module.getDescription()); + appendStringLiteral(h, cte,",",module.getUrl()); + appendStringLiteral(h, cte,",",module.getAuthor()); + appendStringLiteral(h, cte,",",module.getMaintainer()); + appendStringLiteral(h, cte,",",module.getOrganization()); + appendStringLiteral(h, cte,",",module.getOrganizationUrl()); + appendStringLiteral(h, cte,",",module.getLicense()); + appendStringLiteral(h, cte,",",module.getLicenseUrl()); + appendStringLiteral(h, cte,",",module.getVcsRevision()); + appendStringLiteral(h, cte,",",module.getVcsUrl()); + appendStringLiteral(h, cte,",",StringUtils.join(module.getModuleDependenciesAsSet(), ", ")); cte.append(")"); } cte.append(") AS T ("); From 39744d7680df47a572d21d10fe1bbdfdf3248e2f Mon Sep 17 00:00:00 2001 From: Matthew Bellew Date: Thu, 10 Dec 2020 13:43:21 -0800 Subject: [PATCH 2/4] allow controlling whether session participant group message shows up in dataregion (and client grid) --- .../ParticipantGroupController.java | 17 ++++++-- .../study/model/ParticipantGroupManager.java | 14 ++++++- .../labkey/study/query/DatasetQueryView.java | 41 ++++++++++--------- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/study/src/org/labkey/study/controllers/ParticipantGroupController.java b/study/src/org/labkey/study/controllers/ParticipantGroupController.java index 3fa5470a6c1..2e05e2a1f13 100644 --- a/study/src/org/labkey/study/controllers/ParticipantGroupController.java +++ b/study/src/org/labkey/study/controllers/ParticipantGroupController.java @@ -1128,6 +1128,7 @@ private static class UpdateParticipantGroupForm private String[] _participantIds; private String[] _ensureParticipantIds; private String[] _deleteParticipantIds; + private boolean _showDataRegionMessage = true; public int getRowId() { @@ -1198,6 +1199,16 @@ public void setDeleteParticipantIds(String[] deleteParticipantIds) { _deleteParticipantIds = deleteParticipantIds; } + + public boolean isShowDataRegionMessage() + { + return _showDataRegionMessage; + } + + public void setShowDataRegionMessage(boolean showDataRegionMessage) + { + _showDataRegionMessage = showDataRegionMessage; + } } @RequiresPermission(ReadPermission.class) @RequiresLogin @@ -1425,7 +1436,7 @@ public Object execute(UpdateParticipantGroupForm form, BindException errors) if (existing == null) throw new NotFoundException("Could not find participant group with rowId " + form.getRowId()); - ParticipantGroupManager.getInstance().setSessionParticipantGroup(getContainer(), getUser(), getViewContext().getRequest(), existing.getRowId()); + ParticipantGroupManager.getInstance().setSessionParticipantGroup(getContainer(), getUser(), getViewContext().getRequest(), existing.getRowId(), form.isShowDataRegionMessage()); return success(existing); } else @@ -1453,7 +1464,7 @@ else if (!group.isSession()) copy.setModified(copy.getModified()); copy.setModifiedBy(copy.getModifiedBy()); group = copy; - ParticipantGroupManager.getInstance().setSessionParticipantGroup(getContainer(), getUser(), getViewContext().getRequest(), group); + ParticipantGroupManager.getInstance().setSessionParticipantGroup(getContainer(), getUser(), getViewContext().getRequest(), group, form.isShowDataRegionMessage()); } Set participantIds = new HashSet<>(Arrays.asList(form.getParticipantIds() == null ? group.getParticipantIds() : form.getParticipantIds())); @@ -1473,7 +1484,7 @@ else if (!group.isSession()) if (form.getFilters() != null) group.setFilters(form.getFilters()); - group = ParticipantGroupManager.getInstance().setSessionParticipantGroup(getContainer(), getUser(), getViewContext().getRequest(), group); + group = ParticipantGroupManager.getInstance().setSessionParticipantGroup(getContainer(), getUser(), getViewContext().getRequest(), group, form.isShowDataRegionMessage()); return success(group); } } diff --git a/study/src/org/labkey/study/model/ParticipantGroupManager.java b/study/src/org/labkey/study/model/ParticipantGroupManager.java index 581acee37c6..8bec2ef3657 100644 --- a/study/src/org/labkey/study/model/ParticipantGroupManager.java +++ b/study/src/org/labkey/study/model/ParticipantGroupManager.java @@ -55,6 +55,7 @@ import org.labkey.api.util.MemTracker; import org.labkey.api.util.PageFlowUtil; import org.labkey.api.util.Pair; +import org.labkey.api.util.SessionHelper; import org.labkey.api.view.ActionURL; import org.labkey.api.view.NavTree; import org.labkey.api.view.ViewContext; @@ -659,16 +660,17 @@ private Map getParticipantIdMap(Container c, User user, Particip return participantIdMap; } - public void setSessionParticipantGroup(Container c, User user, HttpServletRequest request, Integer groupRowId) + public void setSessionParticipantGroup(Container c, User user, HttpServletRequest request, Integer groupRowId, boolean showDataRegionMessage) { HttpSession session = request.getSession(true); if (session == null) return; session.setAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId(), groupRowId); + session.setAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId() + ".showMessage", showDataRegionMessage); } - public ParticipantGroup setSessionParticipantGroup(Container c, User user, HttpServletRequest request, ParticipantGroup group) + public ParticipantGroup setSessionParticipantGroup(Container c, User user, HttpServletRequest request, ParticipantGroup group, boolean showDataRegionMessage) { assert group.isSession(); HttpSession session = request.getSession(true); @@ -676,11 +678,18 @@ public ParticipantGroup setSessionParticipantGroup(Container c, User user, HttpS return null; session.setAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId(), group); + session.setAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId() + "showMessage", showDataRegionMessage); // don't MemTrack track this one, since it's going in session MemTracker.get().remove(group); return group; } + public boolean getSessionParticipantGroupShowMessage(Container c, HttpServletRequest request) + { + Boolean b = (Boolean)SessionHelper.getAttribute(request, PARTICIPANT_GROUP_SESSION_KEY + c.getRowId() + "showMessage", false); + return b == Boolean.TRUE; + } + public ParticipantGroup getSessionParticipantGroup(Container c, User user, HttpServletRequest request) { HttpSession session = request.getSession(true); @@ -703,6 +712,7 @@ public void deleteSessionParticipantGroup(Container c, User user, HttpServletReq return; session.removeAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId()); + session.removeAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId() + ".showMessage"); } diff --git a/study/src/org/labkey/study/query/DatasetQueryView.java b/study/src/org/labkey/study/query/DatasetQueryView.java index a22c1cac2c9..2efc5ea5c76 100644 --- a/study/src/org/labkey/study/query/DatasetQueryView.java +++ b/study/src/org/labkey/study/query/DatasetQueryView.java @@ -696,29 +696,32 @@ protected void addHeaderMessage(StringBuilder headerMessage, RenderContext ctx) } } - ParticipantGroup sessionGroup = ParticipantGroupManager.getInstance().getSessionParticipantGroup(dqs.getContainer(), dqs.getUser(), ctx.getViewContext().getRequest()); - if (sessionGroup != null) + if (ParticipantGroupManager.getInstance().getSessionParticipantGroupShowMessage(dqs.getContainer(), ctx.getViewContext().getRequest())) { - if (msg.length() > 0) - msg.append("  "); - msg.append("Selected " + PageFlowUtil.filter(dqs.getStudy().getSubjectNounPlural()) + ": "); - msg.append(sessionGroup.getParticipantIds().length); - } + ParticipantGroup sessionGroup = ParticipantGroupManager.getInstance().getSessionParticipantGroup(dqs.getContainer(), dqs.getUser(), ctx.getViewContext().getRequest()); + if (sessionGroup != null) + { + if (msg.length() > 0) + msg.append("  "); + msg.append("Selected " + PageFlowUtil.filter(dqs.getStudy().getSubjectNounPlural()) + ": "); + msg.append(sessionGroup.getParticipantIds().length); + } - if (msg.length() == 0) - return; + if (msg.length() != 0) + { + // HACK -- link to immport/studyFinder.view + Module immport = ModuleLoader.getInstance().getModule("immport"); + Container project = ctx.getContainer().getProject(); + if (immport != null && project != null && project.getActiveModules().contains(immport)) + { + ActionURL finderURL = new ActionURL("immport", "dataFinderRedirect.view", project); + msg.append("  ").append(PageFlowUtil.button("Edit").href(finderURL.toString())); + } + msg.append(""); - // HACK -- link to immport/studyFinder.view - Module immport = ModuleLoader.getInstance().getModule("immport"); - Container project = ctx.getContainer().getProject(); - if (immport != null && project != null && project.getActiveModules().contains(immport)) - { - ActionURL finderURL = new ActionURL("immport", "dataFinderRedirect.view", project); - msg.append("  ").append(PageFlowUtil.button("Edit").href(finderURL.toString())); + headerMessage.append(msg); + } } - msg.append(""); - - headerMessage.append(msg); } } From efce504a5ddd08a7c56070d1f47c2fb3930958a1 Mon Sep 17 00:00:00 2001 From: labkey-matthewb Date: Fri, 11 Dec 2020 09:26:56 -0800 Subject: [PATCH 3/4] Update study/src/org/labkey/study/model/ParticipantGroupManager.java Co-authored-by: Kevin Krouse --- study/src/org/labkey/study/model/ParticipantGroupManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/study/src/org/labkey/study/model/ParticipantGroupManager.java b/study/src/org/labkey/study/model/ParticipantGroupManager.java index 8bec2ef3657..066b8695c90 100644 --- a/study/src/org/labkey/study/model/ParticipantGroupManager.java +++ b/study/src/org/labkey/study/model/ParticipantGroupManager.java @@ -678,7 +678,8 @@ public ParticipantGroup setSessionParticipantGroup(Container c, User user, HttpS return null; session.setAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId(), group); - session.setAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId() + "showMessage", showDataRegionMessage); + session.setAttribute(PARTICIPANT_GROUP_SESSION_KEY + c.getRowId() + ".showMessage", showDataRegionMessage); + // don't MemTrack track this one, since it's going in session MemTracker.get().remove(group); return group; From f6cdf90ffd052397d8eb1c7727212cb5dda621eb Mon Sep 17 00:00:00 2001 From: labkey-matthewb Date: Fri, 11 Dec 2020 09:27:05 -0800 Subject: [PATCH 4/4] Update study/src/org/labkey/study/model/ParticipantGroupManager.java Co-authored-by: Kevin Krouse --- study/src/org/labkey/study/model/ParticipantGroupManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/study/src/org/labkey/study/model/ParticipantGroupManager.java b/study/src/org/labkey/study/model/ParticipantGroupManager.java index 066b8695c90..969867945a6 100644 --- a/study/src/org/labkey/study/model/ParticipantGroupManager.java +++ b/study/src/org/labkey/study/model/ParticipantGroupManager.java @@ -687,7 +687,8 @@ public ParticipantGroup setSessionParticipantGroup(Container c, User user, HttpS public boolean getSessionParticipantGroupShowMessage(Container c, HttpServletRequest request) { - Boolean b = (Boolean)SessionHelper.getAttribute(request, PARTICIPANT_GROUP_SESSION_KEY + c.getRowId() + "showMessage", false); + Boolean b = (Boolean)SessionHelper.getAttribute(request, PARTICIPANT_GROUP_SESSION_KEY + c.getRowId() + ".showMessage", false); + return b == Boolean.TRUE; }