Skip to content

Commit

Permalink
Fix creation of reference ID on request with no attributes (CO-1690)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Jun 23, 2019
1 parent ab4b5b7 commit 778cba1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/src/Controller/TierApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 20 additions & 1 deletion app/src/Lib/Match/ResultManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,24 @@ 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.
*
* @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;
}
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 778cba1

Please sign in to comment.