From 778cba14b56e535e1a9590876f848620c4540374 Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Sun, 23 Jun 2019 05:47:06 -0400 Subject: [PATCH] Fix creation of reference ID on request with no attributes (CO-1690) --- app/src/Controller/TierApiController.php | 6 ++++++ app/src/Lib/Match/ResultManager.php | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/Controller/TierApiController.php b/app/src/Controller/TierApiController.php index 68d0bb585..4003384df 100644 --- a/app/src/Controller/TierApiController.php +++ b/app/src/Controller/TierApiController.php @@ -246,6 +246,12 @@ protected function doMatchRequest(bool $searchOnly=false) { // Perform a search, and insert or update if not Search Only $results = $MatchService->searchReferenceId($sor, $sorid, $AttributeManager); + // Did any rules run succesffully? If not (eg: no attributes provided in the + // request, no rules defined) then throw an error. + if(empty($results->getSuccessfulRules())) { + throw new \RuntimeException(__('match.er.rules.unsuccessful')); + } + if($results->count() == 0) { // No match diff --git a/app/src/Lib/Match/ResultManager.php b/app/src/Lib/Match/ResultManager.php index 94fc5263f..11a11ef30 100644 --- a/app/src/Lib/Match/ResultManager.php +++ b/app/src/Lib/Match/ResultManager.php @@ -45,6 +45,8 @@ class ResultManager { // "canonical" or "potential" protected $confidenceMode = null; protected $attrconfig = []; + // We track which rules ran successfully as a way of validating the inbound request + protected $successfulRules = []; /** * Add a Matchgrid result. @@ -52,10 +54,15 @@ class ResultManager { * @since COmanage Match v1.0.0 * @param string $referenceId Reference ID * @param array $attributes Array of matchgrid attributes + * @param string $rule Rule that generated this result * @throws RuntimeException */ - public function add(array $attributes) { + public function add(array $attributes, string $rule=null) { + if($rule) { + $successfulRules[] = $rule; + } + if(empty($attributes)) { return; } @@ -248,6 +255,18 @@ public function getResultsForJson($mode="search") { return $ret; } + /** + * Obtain an array of successfully executed rules as reported to the ResultManager. + * Note that successful rules may have generated no matches. + * + * @since COmanage Match v1.0.0 + * @return Array Reference IDs + */ + + public function getSuccessfulRules() { + return $this->successfulRules; + } + /** * Set the Confidence Mode for this set of results. *