From 721701eba4d30d6ec55c994d7520c30cf70505f5 Mon Sep 17 00:00:00 2001 From: Tobias Koch Date: Tue, 3 Aug 2021 11:15:47 +0200 Subject: [PATCH 1/5] Sync Release 2.11.0 to development (#252) --- .qube.yml | 2 +- CHANGELOG.rst | 2 +- docs/conf.py | 4 ++-- pom.xml | 2 +- qube.cfg | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.qube.yml b/.qube.yml index 5c0e12586..16c8c2b91 100644 --- a/.qube.yml +++ b/.qube.yml @@ -4,7 +4,7 @@ email: sven.fillinger@qbic.uni-tuebingen.de project_name: data-model-lib project_short_description: "Data models. A collection of QBiC's central data models\ \ and DTOs. " -version: 2.11.0-SNAPSHOT +version: 2.11.0 domain: lib language: groovy project_slug: data-model-lib diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 14d421119..da1c1a871 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,7 +4,7 @@ Changelog This project adheres to `Semantic Versioning `_. -2.11.0-SNAPSHOT +2.11.0 (2021-08-03) ---------------------------- **Added** diff --git a/docs/conf.py b/docs/conf.py index 773caa191..f52e8af91 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,9 +55,9 @@ # the built documents. # # The short X.Y version. -version = '2.11.0-SNAPSHOT' +version = '2.11.0' # The full version, including alpha/beta/rc tags. -release = '2.11.0-SNAPSHOT' +release = '2.11.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/pom.xml b/pom.xml index 1883929ce..ef655aaee 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ life.qbic data-model-lib - 2.11.0-SNAPSHOT + 2.11.0 data-model-lib http://github.com/qbicsoftware/data-model-lib Data models. A collection of QBiC's central data models and DTOs. diff --git a/qube.cfg b/qube.cfg index 1b451da82..12aac7923 100644 --- a/qube.cfg +++ b/qube.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.11.0-SNAPSHOT +current_version = 2.11.0 [bumpversion_files_whitelisted] dot_qube = .qube.yml From 4ebba8e7cb3c1eb5e7b27a7a46f602b923c6506c Mon Sep 17 00:00:00 2001 From: Tobias Koch Date: Fri, 3 Sep 2021 10:06:45 +0200 Subject: [PATCH 2/5] Extract project code validation (#254) * Extract project code validation * Bump version from 2.11.0 to 2.12.0-SNAPSHOT * Update CHANGELOG.rst * Correct Regex Co-authored-by: Sven Fillinger * Add tests Co-authored-by: Sven Fillinger --- .qube.yml | 2 +- CHANGELOG.rst | 14 +++++++ docs/conf.py | 4 +- pom.xml | 2 +- qube.cfg | 2 +- .../dtos/projectmanagement/ProjectCode.groovy | 18 +++++---- .../validation/ValidationException.groovy | 20 ++++++++++ .../ProjectCodeValidator.groovy | 37 +++++++++++++++++++ .../ProjectCodeValidatorSpec.groovy | 34 +++++++++++++++++ 9 files changed, 120 insertions(+), 13 deletions(-) create mode 100644 src/main/groovy/life/qbic/datamodel/validation/ValidationException.groovy create mode 100644 src/main/groovy/life/qbic/datamodel/validation/projectmanagement/ProjectCodeValidator.groovy create mode 100644 src/test/groovy/life/qbic/datamodel/validation/projectmanagement/ProjectCodeValidatorSpec.groovy diff --git a/.qube.yml b/.qube.yml index 16c8c2b91..dfb051172 100644 --- a/.qube.yml +++ b/.qube.yml @@ -4,7 +4,7 @@ email: sven.fillinger@qbic.uni-tuebingen.de project_name: data-model-lib project_short_description: "Data models. A collection of QBiC's central data models\ \ and DTOs. " -version: 2.11.0 +version: 2.12.0-SNAPSHOT domain: lib language: groovy project_slug: data-model-lib diff --git a/CHANGELOG.rst b/CHANGELOG.rst index da1c1a871..52f352524 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,20 @@ Changelog This project adheres to `Semantic Versioning `_. +2.12.0-SNAPSHOT (2021-09-03) +---------------------------- + +**Added** + +* Add ``life.qbic.datamodel.validation.*`` for project code validation. (`#254 `_) + +**Fixed** + +**Dependencies** + +**Deprecated** + + 2.11.0 (2021-08-03) ---------------------------- diff --git a/docs/conf.py b/docs/conf.py index f52e8af91..d292421b4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,9 +55,9 @@ # the built documents. # # The short X.Y version. -version = '2.11.0' +version = '2.12.0-SNAPSHOT' # The full version, including alpha/beta/rc tags. -release = '2.11.0' +release = '2.12.0-SNAPSHOT' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/pom.xml b/pom.xml index ef655aaee..198e4d90e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ life.qbic data-model-lib - 2.11.0 + 2.12.0-SNAPSHOT data-model-lib http://github.com/qbicsoftware/data-model-lib Data models. A collection of QBiC's central data models and DTOs. diff --git a/qube.cfg b/qube.cfg index 12aac7923..a862a4c3d 100644 --- a/qube.cfg +++ b/qube.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.11.0 +current_version = 2.12.0-SNAPSHOT [bumpversion_files_whitelisted] dot_qube = .qube.yml diff --git a/src/main/groovy/life/qbic/datamodel/dtos/projectmanagement/ProjectCode.groovy b/src/main/groovy/life/qbic/datamodel/dtos/projectmanagement/ProjectCode.groovy index 34d93efa8..6644e8037 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/projectmanagement/ProjectCode.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/projectmanagement/ProjectCode.groovy @@ -1,5 +1,8 @@ package life.qbic.datamodel.dtos.projectmanagement +import life.qbic.datamodel.validation.ValidationException +import life.qbic.datamodel.validation.projectmanagement.ProjectCodeValidator + /** * Describes the project code, that identifies the project within a project space. * @@ -13,7 +16,7 @@ class ProjectCode { final String code - private static final def REGEX = ~'Q[A-X0-9]{4}' + private static final ProjectCodeValidator projectCodeValidator = new ProjectCodeValidator() /** * Constructs a project code instance based on the given code string. @@ -22,14 +25,13 @@ class ProjectCode { */ ProjectCode(String code) throws IllegalArgumentException { Objects.requireNonNull(code, "Code must not be null") - this.code = code.trim() - validateCode() - } - - private void validateCode() { - if(! REGEX.matcher(code).matches()) { - throw new IllegalArgumentException("${code} is not a valid project code.") + String projectCode = code.trim() + try { + projectCodeValidator.accept(projectCode) + } catch (ValidationException validationException) { + throw new IllegalArgumentException(validationException.message) } + this.code = projectCode } @Override diff --git a/src/main/groovy/life/qbic/datamodel/validation/ValidationException.groovy b/src/main/groovy/life/qbic/datamodel/validation/ValidationException.groovy new file mode 100644 index 000000000..5f18d5998 --- /dev/null +++ b/src/main/groovy/life/qbic/datamodel/validation/ValidationException.groovy @@ -0,0 +1,20 @@ +package life.qbic.datamodel.validation + +/** + *

Should be thrown in case a validation failed

+ * + * @since 2.12.0 + */ +class ValidationException extends RuntimeException { + /** Constructs a new runtime exception with the specified detail message. + * The cause is not initialized, and may subsequently be initialized by a + * call to {@link #initCause}. + * + * @param message the detail message. The detail message is saved for + * later retrieval by the {@link #getMessage()} method. + * @since 2.12.0 + */ + ValidationException(String message) { + super(message) + } +} diff --git a/src/main/groovy/life/qbic/datamodel/validation/projectmanagement/ProjectCodeValidator.groovy b/src/main/groovy/life/qbic/datamodel/validation/projectmanagement/ProjectCodeValidator.groovy new file mode 100644 index 000000000..2b1522ff2 --- /dev/null +++ b/src/main/groovy/life/qbic/datamodel/validation/projectmanagement/ProjectCodeValidator.groovy @@ -0,0 +1,37 @@ +package life.qbic.datamodel.validation.projectmanagement + +import life.qbic.datamodel.validation.ValidationException + +import java.util.function.Consumer +import java.util.function.Predicate +import java.util.regex.Pattern + +/** + * Project Code Validator + * + *

Consumes a project code and throws a {@link ValidationException} in case it is not valid.

+ * + * @since 2.12.0 + */ +class ProjectCodeValidator implements Consumer { + private static final Predicate IS_VALID_PROJECT_CODE = Pattern.compile("^Q[A-X0-9]{4}\$").asPredicate() + + /** + * Consumes the project code and throws a {@link ValidationException} in case of invalidity. + * + * @param projectCode the project code to validate + * @throws ValidationException in case of validation failure + * @since 2.12.0 + */ + @Override + void accept(String projectCode) throws ValidationException { + ValidationException validationException = new ValidationException("'${projectCode}' is not a valid project code.") + if (!projectCode) { + throw validationException + } + if (!IS_VALID_PROJECT_CODE.test(projectCode)) { + throw validationException + } + } + +} diff --git a/src/test/groovy/life/qbic/datamodel/validation/projectmanagement/ProjectCodeValidatorSpec.groovy b/src/test/groovy/life/qbic/datamodel/validation/projectmanagement/ProjectCodeValidatorSpec.groovy new file mode 100644 index 000000000..0ebb8911f --- /dev/null +++ b/src/test/groovy/life/qbic/datamodel/validation/projectmanagement/ProjectCodeValidatorSpec.groovy @@ -0,0 +1,34 @@ +package life.qbic.datamodel.validation.projectmanagement + +import life.qbic.datamodel.validation.ValidationException +import spock.lang.Specification +import spock.lang.Unroll + +/** + *

Tests the ProjectCodeValidator

+ * + * @since 2.12.0 + */ +class ProjectCodeValidatorSpec extends Specification { + ProjectCodeValidator validator = new ProjectCodeValidator() + + @Unroll + def "Accept throws no exception for valid project code: #validProjectCode"() { + when: + validator.accept(validProjectCode) + then: + noExceptionThrown() + where: + validProjectCode << ["QABCD", "QBBBA", "QPPEO", "QQQQQ", "Q0000", "Q00A0"] + } + + @Unroll + def "Accept throws ValidationException for invalid project code: #invalidProjectCode"() { + when: + validator.accept(invalidProjectCode) + then: + thrown(ValidationException) + where: + invalidProjectCode << [null, "", "testQABCD", "QABCD0000", "YABCD", "ZABCD", "QZZBA"] + } +} From a730c3de5f33813e18afa661c63f515a9cac443c Mon Sep 17 00:00:00 2001 From: Sven F Date: Fri, 10 Sep 2021 11:17:30 +0200 Subject: [PATCH 3/5] Shorthand label for Facility enum (#255) --- CHANGELOG.rst | 2 ++ .../dtos/business/facilities/Facility.groovy | 28 +++++++++++++----- .../business/facilities/FacilitySpec.groovy | 29 +++++++++++++++++++ 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 src/test/groovy/life/qbic/datamodel/dtos/business/facilities/FacilitySpec.groovy diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 52f352524..6f51ac18b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,8 @@ This project adheres to `Semantic Versioning `_. * Add ``life.qbic.datamodel.validation.*`` for project code validation. (`#254 `_) +* ``life.qbic.datamodel.dtos.business.facilities.Facility`` can provide a shorthand label now (`#255 `_) + **Fixed** **Dependencies** diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/facilities/Facility.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/facilities/Facility.groovy index 86b124a96..dec6fb9ce 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/facilities/Facility.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/facilities/Facility.groovy @@ -17,22 +17,26 @@ package life.qbic.datamodel.dtos.business.facilities */ enum Facility { - CFMB("Core Facility for Medical Bioanalytics"), - IMGAG("Institute for Medical Genetics and Applied Genomics"), - MGM("Institute for Medical Microbiology and Hygiene"), - QBIC("Quantitative Biology Center"), - PCT("Proteome Center Tübingen") + CFMB("Core Facility for Medical Bioanalytics", "CFMB"), + IMGAG("Institute for Medical Genetics and Applied Genomics", "IMGAG"), + MGM("Institute for Medical Microbiology and Hygiene", "MGM"), + QBIC("Quantitative Biology Center", "QBIC"), + CFMB_PCT("Proteomics Facility Tübingen", "Proteomics Facility") private final String fullName + private final String label /** - * Creates an instance of a facility enum - * @param fullName The full name representation of the enum + * Creates an instance of a facility enum with shorthand label + * @param fullName The full name representation of the facility + * @param label The shorthand label of the facility */ - Facility(String fullName) { + Facility(String fullName, String label) { this.fullName = fullName + this.label = label } + /** * Returns to the full name representation of the facility * @return @@ -41,6 +45,14 @@ enum Facility { return this.fullName } + /** + * Returns the short representation form of the facility + * @return + */ + String getLabel() { + return this.label + } + /** * Returns a String representation of the facility enum. * diff --git a/src/test/groovy/life/qbic/datamodel/dtos/business/facilities/FacilitySpec.groovy b/src/test/groovy/life/qbic/datamodel/dtos/business/facilities/FacilitySpec.groovy new file mode 100644 index 000000000..0ac8f1c1d --- /dev/null +++ b/src/test/groovy/life/qbic/datamodel/dtos/business/facilities/FacilitySpec.groovy @@ -0,0 +1,29 @@ +package life.qbic.datamodel.dtos.business.facilities + +import spock.lang.Specification + +/** + * Tests for the {@link Facility} enum class + * + * @since 2.12.0 + */ +class FacilitySpec extends Specification { + + def "given an enum, calling the label function returns the right label"() { + + when: + String result = facility.label + + then: + result == expectedLabel + + where: + facility | expectedLabel + Facility.CFMB | "CFMB" + Facility.CFMB_PCT | "Proteomics Facility" + Facility.IMGAG | "IMGAG" + Facility.MGM | "MGM" + Facility.QBIC | "QBIC" + } + +} From 97d66bade9b2214a3d135c2df3208e9d36462099 Mon Sep 17 00:00:00 2001 From: Sven Fillinger Date: Fri, 10 Sep 2021 14:47:16 +0200 Subject: [PATCH 4/5] Update CL --- CHANGELOG.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6f51ac18b..cf6e52742 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,8 +4,8 @@ Changelog This project adheres to `Semantic Versioning `_. -2.12.0-SNAPSHOT (2021-09-03) ----------------------------- +2.12.0 (2021-09-10) +------------------- **Added** From 479ab64fbb357b23702df713e6542726718697b3 Mon Sep 17 00:00:00 2001 From: Sven F Date: Fri, 10 Sep 2021 14:57:16 +0200 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: jnnfr --- .qube.yml | 2 +- docs/conf.py | 4 ++-- qube.cfg | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.qube.yml b/.qube.yml index dfb051172..344a9ac1d 100644 --- a/.qube.yml +++ b/.qube.yml @@ -4,7 +4,7 @@ email: sven.fillinger@qbic.uni-tuebingen.de project_name: data-model-lib project_short_description: "Data models. A collection of QBiC's central data models\ \ and DTOs. " -version: 2.12.0-SNAPSHOT +version: 2.12.0 domain: lib language: groovy project_slug: data-model-lib diff --git a/docs/conf.py b/docs/conf.py index d292421b4..51f279066 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,9 +55,9 @@ # the built documents. # # The short X.Y version. -version = '2.12.0-SNAPSHOT' +version = '2.12.0' # The full version, including alpha/beta/rc tags. -release = '2.12.0-SNAPSHOT' +release = '2.12.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/qube.cfg b/qube.cfg index a862a4c3d..9d6c9d633 100644 --- a/qube.cfg +++ b/qube.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.12.0-SNAPSHOT +current_version = 2.12.0 [bumpversion_files_whitelisted] dot_qube = .qube.yml