diff --git a/app/config/schema/schema.xml b/app/config/schema/schema.xml index 93742884a..6d12b2485 100644 --- a/app/config/schema/schema.xml +++ b/app/config/schema/schema.xml @@ -43,9 +43,9 @@ - + diff --git a/app/src/Lib/Identifier/ReferenceIdService.php b/app/src/Lib/Identifier/ReferenceIdService.php index 4b82cb5f0..f9abd80b6 100644 --- a/app/src/Lib/Identifier/ReferenceIdService.php +++ b/app/src/Lib/Identifier/ReferenceIdService.php @@ -30,5 +30,15 @@ namespace App\Lib\Identifier; abstract class ReferenceIdService { - abstract public function generate(); + /** + * Generate a Reference Identifier. + * + * @since COmanage Match v1.0.0 + * @param Matchgrid $mgConfig Matchgrid Configuration + * @param ADOConnection $dbc ADODB Database Connection Handle + * @return string Reference Identifier + * @throws RuntimeException + */ + + abstract public function generate(\App\Model\Entity\Matchgrid $mgConfig, \ADOConnection $dbc); } \ No newline at end of file diff --git a/app/src/Lib/Identifier/Sequence.php b/app/src/Lib/Identifier/Sequence.php index 5b1e5383c..926d70881 100644 --- a/app/src/Lib/Identifier/Sequence.php +++ b/app/src/Lib/Identifier/Sequence.php @@ -30,10 +30,25 @@ namespace App\Lib\Identifier; class Sequence extends ReferenceIdService { - public function generate() { - // XXX we need access to the database config + /** + * Generate a Reference Identifier. + * + * @since COmanage Match v1.0.0 + * @param Matchgrid $mgConfig Matchgrid Configuration + * @param ADOConnection $dbc ADODB Database Connection Handle + * @return string Reference Identifier + * @throws RuntimeException + */ + + public function generate(\App\Model\Entity\Matchgrid $mgConfig, \ADOConnection $dbc) { + // We'll use the matchgrid ID rather than name in the sequence name to avoid + // issues if the matchgrid is renamed for some reason. -// Use ADOdb genId() to create/read from sequence http://adodb.org/dokuwiki/doku.php?id=v5:reference:connection:genid - // genId('matchgrid__sequence') or something + $seq = "mg_seq_" . (string)$mgConfig->id; + $prefix = $mgConfig->referenceid_prefix ?: ""; + + $refId = $prefix . (string)$dbc->genId($seq, $mgConfig->referenceid_start); + + return $refId; } } \ No newline at end of file diff --git a/app/src/Lib/Identifier/Uuid.php b/app/src/Lib/Identifier/Uuid.php index 6ec1eaa75..e276eb53e 100644 --- a/app/src/Lib/Identifier/Uuid.php +++ b/app/src/Lib/Identifier/Uuid.php @@ -30,7 +30,17 @@ namespace App\Lib\Identifier; class Uuid extends ReferenceIdService { - public function generate() { + /** + * Generate a Reference Identifier. + * + * @since COmanage Match v1.0.0 + * @param Matchgrid $mgConfig Matchgrid Configuration + * @param ADOConnection $dbc ADODB Database Connection Handle + * @return string Reference Identifier + * @throws RuntimeException + */ + + public function generate(\App\Model\Entity\Matchgrid $mgConfig, \ADOConnection $dbc) { // GUID generation based on https://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid // could use openssl_random_pseudo_bytes(16) diff --git a/app/src/Lib/Match/MatchService.php b/app/src/Lib/Match/MatchService.php index 02820c309..e3c9aaf09 100644 --- a/app/src/Lib/Match/MatchService.php +++ b/app/src/Lib/Match/MatchService.php @@ -36,6 +36,7 @@ use Cake\Utility\Xml; use \App\Lib\Enum\ConfidenceModeEnum; +use \App\Lib\Enum\ReferenceIdEnum; use \App\Lib\Enum\SearchTypeEnum; require(ROOT . DS . "vendor" . DS . "adodb" . DS . "adodb-php" . DS . "adodb-xmlschema03.inc.php"); @@ -103,16 +104,13 @@ public function attachReferenceId(string $sor, string $sorid, AttributeManager $ */ protected function generateReferenceId() { -// XXX read the matchgrid config and instantiate the appropriate backend -// need to pass database config/connection to Sequence (or maybe to all, and they -// can ignore it if not needed, eg UUID) -// Note $this->dbc is available via PostgresService -// We could also recreate matchgrid with reference_id column type uuid (supported by postgres) -// Should we build matchgrid with the appropriate column type (int or uuid) and then make it not-changeable? - - $IdService = new \App\Lib\Identifier\Uuid; + if($this->mgConfig->referenceid_method == ReferenceIdEnum::Sequence) { + $IdService = new \App\Lib\Identifier\Sequence; + } else { + $IdService = new \App\Lib\Identifier\Uuid; + } - return $IdService->generate(); + return $IdService->generate($this->mgConfig, $this->dbc); } /** diff --git a/app/src/Locale/en_US/default.po b/app/src/Locale/en_US/default.po index a01d436f3..313c8ec48 100644 --- a/app/src/Locale/en_US/default.po +++ b/app/src/Locale/en_US/default.po @@ -258,6 +258,12 @@ msgstr "Reference ID" msgid "match.fd.referenceid_method" msgstr "Reference ID Assignment Method" +msgid "match.fd.referenceid_prefix" +msgstr "Reference ID Prefix" + +msgid "match.fd.referenceid_prefix.desc" +msgstr "For sequence based Reference IDs, the prefix to prepend to the assigned integer" + msgid "match.fd.referenceid_start" msgstr "Reference ID Initial Value" diff --git a/app/src/Model/Table/MatchgridsTable.php b/app/src/Model/Table/MatchgridsTable.php index 0a28d8e3f..9b0606096 100644 --- a/app/src/Model/Table/MatchgridsTable.php +++ b/app/src/Model/Table/MatchgridsTable.php @@ -205,6 +205,13 @@ public function validationDefault(Validator $validator) { ); $validator->allowEmpty('referenceid_start'); + $validator->add( + 'referenceid_prefix', + 'content', + [ 'rule' => [ 'maxLength', 32 ] ] + ); + $validator->allowEmpty('referenceid_start'); + return $validator; } } \ No newline at end of file diff --git a/app/src/Template/Matchgrids/fields.inc b/app/src/Template/Matchgrids/fields.inc index ff4f0d600..d39a8e65b 100644 --- a/app/src/Template/Matchgrids/fields.inc +++ b/app/src/Template/Matchgrids/fields.inc @@ -36,8 +36,10 @@ use \App\Lib\Enum\ReferenceIdEnum; var method = document.getElementById('referenceid-method').value; if(method == '') { + $("#referenceid-prefix").closest('li').show('fade'); $("#referenceid-start").closest('li').show('fade'); } else { + $("#referenceid-prefix").closest('li').hide(); $("#referenceid-start").closest('li').hide(); } } @@ -62,4 +64,8 @@ if($action == 'add' || $action == 'edit') { print $this->Field->control('referenceid_start', ['default' => 1001]); + + print $this->Field->control('referenceid_prefix', + [], + false); }