Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add Potential Trust Mdoe (CO-2534)
Benn Oshrin committed Apr 17, 2023
1 parent 8f9c05a commit 9c5b0e7
Showing 5 changed files with 51 additions and 3 deletions.
3 changes: 3 additions & 0 deletions 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"

1 change: 1 addition & 0 deletions 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';
}
37 changes: 35 additions & 2 deletions 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.
9 changes: 8 additions & 1 deletion 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;
4 changes: 4 additions & 0 deletions app/templates/SystemsOfRecord/columns.inc
@@ -33,5 +33,9 @@ $indexColumns = [
'resolution_mode' => [
'type' => 'enum',
'class' => 'ResolutionModeEnum'
],
'trust_mode' => [
'type' => 'enum',
'class' => 'TrustModeEnum'
]
];

0 comments on commit 9c5b0e7

Please sign in to comment.