From 38a3728efd1e4200c3505521f6a19ea294e5b8d8 Mon Sep 17 00:00:00 2001 From: Allan England Date: Wed, 12 Feb 2025 13:29:40 +0000 Subject: [PATCH] Find submitted proposal in a cycle by source(related) proposal id --- .../rest/SubmittedProposalResource.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/orph2020/pst/apiimpl/rest/SubmittedProposalResource.java b/src/main/java/org/orph2020/pst/apiimpl/rest/SubmittedProposalResource.java index 9f81e86..560d70e 100644 --- a/src/main/java/org/orph2020/pst/apiimpl/rest/SubmittedProposalResource.java +++ b/src/main/java/org/orph2020/pst/apiimpl/rest/SubmittedProposalResource.java @@ -33,21 +33,44 @@ public class SubmittedProposalResource extends ObjectResourceBase{ ProposalDocumentStore proposalDocumentStore; @GET - @Operation(summary = "get the identifiers for the SubmittedProposals in the ProposalCycle") + @Operation(summary = "get the identifiers for the SubmittedProposals in the ProposalCycle, note optional use of sourceProposalId overrides title and investigatorName") public List getSubmittedProposals( @PathParam("cycleCode") Long cycleCode, @RestQuery String title, - @RestQuery String investigatorName + @RestQuery String investigatorName, + @RestQuery Long sourceProposalId ) { - String qlString = getQlString(cycleCode, title, investigatorName); - Query query = em.createQuery(qlString); + if (sourceProposalId != null) { + String qlString = getQlString(cycleCode); + Query query = em.createQuery(qlString); + query.setParameter("sourceProposalId", sourceProposalId); + return getObjectIdentifiersAlt(query); - if (investigatorName != null) query.setParameter("investigatorName", investigatorName); - if (title != null) query.setParameter("title", title); + } else { - return getObjectIdentifiersAlt(query); + String qlString = getQlString(cycleCode, title, investigatorName); + Query query = em.createQuery(qlString); + if (investigatorName != null) query.setParameter("investigatorName", investigatorName); + if (title != null) query.setParameter("title", title); + return getObjectIdentifiersAlt(query); + + } + + } + + private String getQlString(Long cycleCode) { + String baseStr = "select distinct s._id,cast(s.submissionDate as string),s.title " + + "from ProposalCycle c " + + "inner join c.submittedProposals s " + + "inner join s.relatedProposals r " + + "where c._id=" + cycleCode + " " + + "and r.proposal._id = :sourceProposalId "; + + String orderByStr = "order by s._id"; + + return baseStr + orderByStr; } private static String getQlString(Long cycleCode, String title, String investigatorName) {