Skip to content

Commit

Permalink
Release 2.12.0
Browse files Browse the repository at this point in the history
Release 2.12.0
  • Loading branch information
sven1103 authored Sep 10, 2021
2 parents ad49fc8 + 479ab64 commit 85b310f
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .qube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ email: [email protected]
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
domain: lib
language: groovy
project_slug: data-model-lib
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ Changelog

This project adheres to `Semantic Versioning <https://semver.org/>`_.

2.12.0 (2021-09-10)
-------------------

**Added**

* Add ``life.qbic.datamodel.validation.*`` for project code validation. (`#254 <https://github.com/qbicsoftware/data-model-lib/pull/254>`_)

* ``life.qbic.datamodel.dtos.business.facilities.Facility`` can provide a shorthand label now (`#255 <https://github.com/qbicsoftware/data-model-lib/pull/255>`_)

**Fixed**

**Dependencies**

**Deprecated**

2.11.0 (2021-08-03)
----------------------------

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
# the built documents.
#
# The short X.Y version.
version = '2.11.0'
version = '2.12.0'
# The full version, including alpha/beta/rc tags.
release = '2.11.0'
release = '2.12.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>life.qbic</groupId>
<artifactId>data-model-lib</artifactId>
<version>2.11.0</version> <!-- <<QUBE_FORCE_BUMP>> -->
<version>2.12.0-SNAPSHOT</version> <!-- <<QUBE_FORCE_BUMP>> -->
<name>data-model-lib</name>
<url>http://github.com/qbicsoftware/data-model-lib</url>
<description>Data models. A collection of QBiC's central data models and DTOs. </description>
Expand Down
2 changes: 1 addition & 1 deletion qube.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.11.0
current_version = 2.12.0

[bumpversion_files_whitelisted]
dot_qube = .qube.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package life.qbic.datamodel.validation

/**
* <p>Should be thrown in case a validation failed</p>
*
* @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)
}
}
Original file line number Diff line number Diff line change
@@ -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

/**
* <b>Project Code Validator</b>
*
* <p>Consumes a project code and throws a {@link ValidationException} in case it is not valid.</p>
*
* @since 2.12.0
*/
class ProjectCodeValidator implements Consumer<String> {
private static final Predicate<String> 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
}
}

}
Original file line number Diff line number Diff line change
@@ -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"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package life.qbic.datamodel.validation.projectmanagement

import life.qbic.datamodel.validation.ValidationException
import spock.lang.Specification
import spock.lang.Unroll

/**
* <p>Tests the ProjectCodeValidator</p>
*
* @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"]
}
}

0 comments on commit 85b310f

Please sign in to comment.