From 1363a295c94df8f2c0ec42ffe2e7f9c1619090a9 Mon Sep 17 00:00:00 2001 From: Konrad Lang Date: Wed, 1 Feb 2023 17:22:06 +0100 Subject: [PATCH] Fix to add userID for selected queries; add queries for owners without queryID to allow acting on behalf of Biobank; --- .../control/owner/OwnerQueriesDetailBean.java | 11 +++++++---- .../researcher/ResearcherQueriesDetailBean.java | 3 ++- .../samply/bbmri/negotiator/db/util/DbUtil.java | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/samply/bbmri/negotiator/control/owner/OwnerQueriesDetailBean.java b/src/main/java/de/samply/bbmri/negotiator/control/owner/OwnerQueriesDetailBean.java index 27dd23d9..5f79291f 100644 --- a/src/main/java/de/samply/bbmri/negotiator/control/owner/OwnerQueriesDetailBean.java +++ b/src/main/java/de/samply/bbmri/negotiator/control/owner/OwnerQueriesDetailBean.java @@ -265,11 +265,14 @@ public String initialize() { * Get the selected(clicked on) query from the list of queries for the owner */ // TODO: implement loading of the selected query and setting the comments - selectedQuery = DbUtil.getSelectedQuery( config, queryId); + selectedQuery = DbUtil.getSelectedQueryForUserId( config, queryId, userBean.getUserId()); + //selectedQuery = DbUtil.getSelectedQuery( config, queryId); + // TODO: Get the query for type ownerQueryStatsDTO //setCommentCountAndUreadCommentCount(ownerQueryStatsDTO); - /** - * Get the selected(clicked on) query from the list of queries for the owner + + // Get the selected(clicked on) query from the list of queries for the owner + // Needs to be optimized! for(OwnerQueryStatsDTO ownerQueryStatsDTO : getQueries()) { if(ownerQueryStatsDTO.getQuery().getId() == queryId) { @@ -277,7 +280,7 @@ public String initialize() { setCommentCountAndUreadCommentCount(ownerQueryStatsDTO); } } - */ + if(selectedQuery != null) { try { diff --git a/src/main/java/de/samply/bbmri/negotiator/control/researcher/ResearcherQueriesDetailBean.java b/src/main/java/de/samply/bbmri/negotiator/control/researcher/ResearcherQueriesDetailBean.java index 223c8c4a..92cd6c74 100644 --- a/src/main/java/de/samply/bbmri/negotiator/control/researcher/ResearcherQueriesDetailBean.java +++ b/src/main/java/de/samply/bbmri/negotiator/control/researcher/ResearcherQueriesDetailBean.java @@ -304,7 +304,8 @@ public String loadSelectedQueryDetails() { * Get the selected(clicked on) query from the list of queries for the owner */ // TODO: implement loading of the selected query and setting the comments - selectedQuery = DbUtil.getSelectedQuery( config, queryId); + selectedQuery = DbUtil.getSelectedQueryForUserId( config, queryId, userBean.getUserId()); + //selectedQuery = DbUtil.getSelectedQuery( config, queryId); logger.debug("loadSelectedQueryDetails-17: " + LocalDateTime.now()); /* for (QueryStatsDTO query : getQueries()) { diff --git a/src/main/java/de/samply/bbmri/negotiator/db/util/DbUtil.java b/src/main/java/de/samply/bbmri/negotiator/db/util/DbUtil.java index 5e320c83..63a437ae 100644 --- a/src/main/java/de/samply/bbmri/negotiator/db/util/DbUtil.java +++ b/src/main/java/de/samply/bbmri/negotiator/db/util/DbUtil.java @@ -580,6 +580,22 @@ public static de.samply.bbmri.negotiator.jooq.tables.pojos.Query getSelectedQuer //.fetchOne( Tables.QUERY.as(fetchedQuery)); //.getResult(); } + + /** + * Get the JSON query from the database for a specific userID. + * @param config JOOQ configuration + * @param queryId the query ID + * @param userId the user ID for this query + * @return JSON string + */ + public static de.samply.bbmri.negotiator.jooq.tables.pojos.Query getSelectedQueryForUserId( Config config, Integer queryId, int userId) { + Condition condition = Tables.QUERY.RESEARCHER_ID.eq(userId); + + return (de.samply.bbmri.negotiator.jooq.tables.pojos.Query) config.dsl().selectFrom(Tables.QUERY) + .where(condition).and(Tables.QUERY.ID.eq(queryId)) + .fetchOneInto( de.samply.bbmri.negotiator.jooq.tables.pojos.Query.class); + } + /** * Get the JSON query from the database. * @param config JOOQ configuration