diff --git a/app/plugins/CoreAssigner/resources/locales/en_US/core_assigner.po b/app/plugins/CoreAssigner/resources/locales/en_US/core_assigner.po index 68dbb5f33..7a3608bb4 100644 --- a/app/plugins/CoreAssigner/resources/locales/en_US/core_assigner.po +++ b/app/plugins/CoreAssigner/resources/locales/en_US/core_assigner.po @@ -76,6 +76,9 @@ msgstr "Minimum Collision Value" msgid "field.FormatAssigners.minimum.desc" msgstr "The minimum value for randomly generated collision numbers, or the starting value for sequences" +msgid "field.FormatAssigners.minimum_length" +msgstr "Minimum Length" + msgid "field.FormatAssigners.permitted_characters" msgstr "Permitted Characters" diff --git a/app/plugins/CoreAssigner/src/Model/Table/FormatAssignersTable.php b/app/plugins/CoreAssigner/src/Model/Table/FormatAssignersTable.php index d41ba294a..08b2f7dbc 100644 --- a/app/plugins/CoreAssigner/src/Model/Table/FormatAssignersTable.php +++ b/app/plugins/CoreAssigner/src/Model/Table/FormatAssignersTable.php @@ -152,7 +152,11 @@ public function assign($ia, $entity): string { if(!in_array($candidate, $tested) // Also check that we didn't get an empty string - && trim($candidate) != false) { + && trim($candidate) != false + // Or that the candidate is too short + && (empty($ia->format_assigner->minimum_length) + || ($ia->format_assigner->minimum_length > 0 + && strlen($candidate) >= $ia->format_assigner->minimum_length))) { // We have a new candidate (ie: one that wasn't generated on a previous loop), // so let's see if it is already in use. @@ -398,13 +402,17 @@ protected function substituteParameters( switch($format[$i]) { case 'f': - $base .= sprintf("%.".$width."s", - preg_replace($charregex, '', strtolower($entity->primary_name->family))); - break; + if(!empty($entity->primary_name->family)) { + $base .= sprintf("%.".$width."s", + preg_replace($charregex, '', strtolower($entity->primary_name->family))); + break; + } case 'F': - $base .= sprintf("%.".$width."s", - preg_replace($charregex, '', $entity->primary_name->family)); - break; + if(!empty($entity->primary_name->family)) { + $base .= sprintf("%.".$width."s", + preg_replace($charregex, '', $entity->primary_name->family)); + break; + } case 'g': $base .= sprintf("%.".$width."s", preg_replace($charregex, '', strtolower($entity->primary_name->given))); @@ -465,12 +473,16 @@ protected function substituteParameters( } break; case 'm': - $base .= sprintf("%.".$width."s", - preg_replace($charregex, '', strtolower( $entity->primary_name->middle))); + if(!empty($entity->primary_name->middle)) { + $base .= sprintf("%.".$width."s", + preg_replace($charregex, '', strtolower($entity->primary_name->middle))); + } break; case 'M': - $base .= sprintf("%.".$width."s", - preg_replace($charregex, '', $entity->primary_name->middle)); + if(!empty($entity->primary_name->middle)) { + $base .= sprintf("%.".$width."s", + preg_replace($charregex, '', $entity->primary_name->middle)); + } break; case 'n': $base .= sprintf("%.".$width."s", @@ -524,6 +536,11 @@ public function validationDefault(Validator $validator): Validator { $this->registerStringValidation($validator, $schema, 'format', true); + $validator->add('minimum_length', [ + 'content' => ['rule' => 'isInteger'] + ]); + $validator->allowEmptyString('minimum_length'); + $validator->add('minimum', [ 'content' => ['rule' => 'isInteger'] ]); diff --git a/app/plugins/CoreAssigner/src/config/plugin.json b/app/plugins/CoreAssigner/src/config/plugin.json index 0ea282c32..882dbad71 100644 --- a/app/plugins/CoreAssigner/src/config/plugin.json +++ b/app/plugins/CoreAssigner/src/config/plugin.json @@ -12,6 +12,7 @@ "id": {}, "identifier_assignment_id": {}, "format": { "type": "string", "size": 256 }, + "minimum_length": { "type": "integer" }, "minimum": { "type": "integer" }, "maximum": { "type": "integer" }, "collision_mode": { "type": "string", "size": 2 }, diff --git a/app/plugins/CoreAssigner/templates/FormatAssigners/fields.inc b/app/plugins/CoreAssigner/templates/FormatAssigners/fields.inc index d9df04f8a..0e824547c 100644 --- a/app/plugins/CoreAssigner/templates/FormatAssigners/fields.inc +++ b/app/plugins/CoreAssigner/templates/FormatAssigners/fields.inc @@ -64,6 +64,7 @@ if($vv_action == 'edit') { foreach([ 'permitted_characters', + 'minimum_length', 'minimum', 'maximum', ] as $field) { diff --git a/app/plugins/CoreServer/src/Model/Table/HttpServersTable.php b/app/plugins/CoreServer/src/Model/Table/HttpServersTable.php index c92c92d04..06802e7d1 100644 --- a/app/plugins/CoreServer/src/Model/Table/HttpServersTable.php +++ b/app/plugins/CoreServer/src/Model/Table/HttpServersTable.php @@ -21,7 +21,7 @@ * * @link https://www.internet2.edu/comanage COmanage Project * @package registry-plugins - * @since COmanage Registry v5.2.0 + * @since COmanage Registry v5.1.0 * @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) */ @@ -49,7 +49,7 @@ class HttpServersTable extends Table { /** * Perform Cake Model initialization. * - * @since COmanage Registry v5.2.0 + * @since COmanage Registry v5.1.0 * @param array $config Configuration options passed to constructor */ @@ -96,7 +96,7 @@ public function initialize(array $config): void { /** * Create an HTTP Client from the HttpServer configuration. * - * @since COmanage Registry v5.2.0 + * @since COmanage Registry v5.1.0 * @param int $id HttpServer ID * @return Client Cake Http Client */ @@ -131,7 +131,7 @@ public function createHttpClient(int $id): Client { /** * Set validation rules. * - * @since COmanage Registry v5.2.0 + * @since COmanage Registry v5.1.0 * @param Validator $validator Validator * @return Validator Validator */ diff --git a/app/plugins/CoreServer/src/Model/Table/MatchServersTable.php b/app/plugins/CoreServer/src/Model/Table/MatchServersTable.php index 833cca9e7..6b095d270 100644 --- a/app/plugins/CoreServer/src/Model/Table/MatchServersTable.php +++ b/app/plugins/CoreServer/src/Model/Table/MatchServersTable.php @@ -21,7 +21,7 @@ * * @link https://www.internet2.edu/comanage COmanage Project * @package registry-plugins - * @since COmanage Registry v5.2.0 + * @since COmanage Registry v5.1.0 * @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) */ @@ -40,7 +40,7 @@ class MatchServersTable extends HttpServersTable { /** * Perform Cake Model initialization. * - * @since COmanage Registry v5.2.0 + * @since COmanage Registry v5.1.0 * @param array $config Configuration options passed to constructor */ @@ -80,7 +80,7 @@ public function initialize(array $config): void { /** * Set validation rules. * - * @since COmanage Registry v5.2.0 + * @since COmanage Registry v5.1.0 * @param Validator $validator Validator * @return Validator Validator */ diff --git a/app/plugins/CoreServer/src/Model/Table/SqlServersTable.php b/app/plugins/CoreServer/src/Model/Table/SqlServersTable.php index 546717899..8030d5d4c 100644 --- a/app/plugins/CoreServer/src/Model/Table/SqlServersTable.php +++ b/app/plugins/CoreServer/src/Model/Table/SqlServersTable.php @@ -35,8 +35,6 @@ use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; - -// Even though CoreServer is a plugin, it should always be enabled use CoreServer\Lib\Enum\RdbmsTypeEnum; class SqlServersTable extends Table { diff --git a/app/src/Lib/Enum/RequiredEnum.php b/app/src/Lib/Enum/RequiredEnum.php new file mode 100644 index 000000000..784d027fd --- /dev/null +++ b/app/src/Lib/Enum/RequiredEnum.php @@ -0,0 +1,36 @@ +