From 9c5b0e741159c764c81243d83a14171f9335b1aa Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Mon, 17 Apr 2023 19:12:05 -0400 Subject: [PATCH] Add Potential Trust Mdoe (CO-2534) --- app/resources/locales/en_US/default.po | 3 ++ app/src/Lib/Enum/TrustModeEnum.php | 1 + app/src/Lib/Match/MatchService.php | 37 +++++++++++++++++++++-- app/src/View/Helper/FieldHelper.php | 9 +++++- app/templates/SystemsOfRecord/columns.inc | 4 +++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/app/resources/locales/en_US/default.po b/app/resources/locales/en_US/default.po index 2ebe2f156..b3a9fc8a1 100644 --- a/app/resources/locales/en_US/default.po +++ b/app/resources/locales/en_US/default.po @@ -275,6 +275,9 @@ msgstr "Suspended" msgid "match.en.StatusEnum.S.badge" msgstr "Danger" +msgid "match.en.TrustModeEnum.P" +msgstr "Potential" + msgid "match.en.TrustModeEnum.S" msgstr "Standard" diff --git a/app/src/Lib/Enum/TrustModeEnum.php b/app/src/Lib/Enum/TrustModeEnum.php index 1b150edce..8544a7f5b 100644 --- a/app/src/Lib/Enum/TrustModeEnum.php +++ b/app/src/Lib/Enum/TrustModeEnum.php @@ -30,6 +30,7 @@ namespace App\Lib\Enum; class TrustModeEnum extends StandardEnum { + const Potential = 'P'; const Standard = 'S'; const Trust = 'T'; } \ No newline at end of file diff --git a/app/src/Lib/Match/MatchService.php b/app/src/Lib/Match/MatchService.php index e1025aa60..30ef97728 100644 --- a/app/src/Lib/Match/MatchService.php +++ b/app/src/Lib/Match/MatchService.php @@ -834,6 +834,7 @@ public function searchReferenceId(string $sor, string $sorid, AttributeManager $ $SystemsOfRecord = TableRegistry::getTableLocator()->get('SystemsOfRecord'); $trustMode = $SystemsOfRecord->getTrustMode($this->mgConfig->id, $sor); + $sorMatch = null; // Only used if TrustMode == Potential if($trustMode == TrustModeEnum::Trust) { Log::write('debug', $sor . "/" . $sorid . " Trust Mode enabled, ignoring existing records in the same SOR"); @@ -850,8 +851,33 @@ public function searchReferenceId(string $sor, string $sorid, AttributeManager $ switch($canonicalMatches->count()) { case 1: - // Exact match, return - return $canonicalMatches; + if($trustMode != TrustModeEnum::Potential) { + // Exact match, return + return $canonicalMatches; + } + + // Handling Potential mode is a bit more complicated. First, get the + // raw results. Even though count() was 1, $results may have more than + // one entry since we're getting the per-row matches. Check to see if + // _any_ row matched the SOR. + + $results = $canonicalMatches->getRawResults(); + + foreach($results as $rowId => $attrs) { + if($attrs['sor'] == $sor) { + $sorMatch = $attrs; + break; + } + } + + if(!$sorMatch) { + // We matched against a _different_ SOR, so return a canonical match + + return $canonicalMatches; + } + + Log::write('debug', $sor . "/" . $sorid . " Trust Mode downgrading result to Potential"); + break; case 0: // Fall through and try potential matches @@ -873,6 +899,13 @@ public function searchReferenceId(string $sor, string $sorid, AttributeManager $ attributes: $attributes, skipSor: $trustMode == TrustModeEnum::Trust ); + + // Add in the potential match from above, if configured + + if($sorMatch) { + // We use a psuedo-rule name + $potentialMatches->add($sorMatch, "_trustmode"); + } // The calling code generally checks to see if any rules successfully ran, // since if there were no valid attributes or rules we treat that as an error. diff --git a/app/src/View/Helper/FieldHelper.php b/app/src/View/Helper/FieldHelper.php index 0350e50ae..9509da7e5 100644 --- a/app/src/View/Helper/FieldHelper.php +++ b/app/src/View/Helper/FieldHelper.php @@ -72,7 +72,14 @@ public function control(string $fieldName, // Get the field type from the map of fields (e.g. 'boolean', 'string', 'timestamp') $fieldMap = $this->getView()->get('vv_field_types'); - $fieldType = $fieldMap[$fieldName]; + + // $vv_field_types holds the table schema as introspected by Cake. + // For viewing Matchgrid Records (/match/matchgrid-records/edit/X), + // $fieldName is the API label, but $labelText is the database column + // name, so we have to check both locations. + $fieldType = (!empty($fieldMap[$fieldName]) + ? $fieldMap[$fieldName] + : (!empty($fieldMap[$labelText]) ? $fieldMap[$labelText] : "")); if($labelText) { $label = $labelText; diff --git a/app/templates/SystemsOfRecord/columns.inc b/app/templates/SystemsOfRecord/columns.inc index ae9da8f7e..edc9a7119 100644 --- a/app/templates/SystemsOfRecord/columns.inc +++ b/app/templates/SystemsOfRecord/columns.inc @@ -33,5 +33,9 @@ $indexColumns = [ 'resolution_mode' => [ 'type' => 'enum', 'class' => 'ResolutionModeEnum' + ], + 'trust_mode' => [ + 'type' => 'enum', + 'class' => 'TrustModeEnum' ] ]; \ No newline at end of file