Skip to content

Commit

Permalink
join and query the contract_stakeholders table for party-set membership
Browse files Browse the repository at this point in the history
- restoring a few elements removed by 3e66611 (#9484)
  • Loading branch information
S11001001 committed Jun 16, 2021
1 parent 05be01f commit 00b8969
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -693,16 +693,19 @@ private object OracleQueries extends Queries {
fr" OR ",
)
}
val quotedParties = parties.toVector.map(p => s""""$p"""").mkString(", ")
val partiesQuery = oracleShortPathEscape(
'$' -: ("[*]?(@ in (": Cord) :+ quotedParties :+ "))"
)
val q =
sql"""SELECT c.contract_id contract_id, $tpid template_id, key, payload, signatories, observers, agreement_text
import Queries.CompatImplicits.catsReducibleFromFoldable1
val outerSelectList =
sql"""contract_id, template_id, key, payload,
signatories, observers, agreement_text"""
val dupQ =
sql"""SELECT c.contract_id contract_id, $tpid template_id, key, payload,
signatories, observers, agreement_text,
row_number() over (PARTITION BY c.contract_id ORDER BY c.contract_id) AS rownumber
FROM contract c
WHERE (JSON_EXISTS(signatories, $partiesQuery)
OR JSON_EXISTS(observers, $partiesQuery))
AND $queriesCondition"""
LEFT JOIN contract_stakeholders cst ON (c.contract_id = cst.contract_id)
WHERE (${Fragments.in(fr"cst.stakeholder", parties)})
AND ($queriesCondition)"""
val q = sql"SELECT $outerSelectList FROM ($dupQ) WHERE rownumber = 1"
q.query[
(String, Mark0, JsValue, JsValue, JsValue, JsValue, Option[String])
].map { case (cid, tpid, key, payload, signatories, observers, agreement) =>
Expand Down

0 comments on commit 00b8969

Please sign in to comment.