Skip to content

Commit 85b310f

Browse files
authored
Release 2.12.0
Release 2.12.0
2 parents ad49fc8 + 479ab64 commit 85b310f

File tree

11 files changed

+170
-21
lines changed

11 files changed

+170
-21
lines changed

.qube.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ email: sven.fillinger@qbic.uni-tuebingen.de
44
project_name: data-model-lib
55
project_short_description: "Data models. A collection of QBiC's central data models\
66
\ and DTOs. "
7-
version: 2.11.0
7+
version: 2.12.0
88
domain: lib
99
language: groovy
1010
project_slug: data-model-lib

CHANGELOG.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ Changelog
44

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

7+
2.12.0 (2021-09-10)
8+
-------------------
9+
10+
**Added**
11+
12+
* Add ``life.qbic.datamodel.validation.*`` for project code validation. (`#254 <https://github.com/qbicsoftware/data-model-lib/pull/254>`_)
13+
14+
* ``life.qbic.datamodel.dtos.business.facilities.Facility`` can provide a shorthand label now (`#255 <https://github.com/qbicsoftware/data-model-lib/pull/255>`_)
15+
16+
**Fixed**
17+
18+
**Dependencies**
19+
20+
**Deprecated**
21+
722
2.11.0 (2021-08-03)
823
----------------------------
924

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
# the built documents.
5656
#
5757
# The short X.Y version.
58-
version = '2.11.0'
58+
version = '2.12.0'
5959
# The full version, including alpha/beta/rc tags.
60-
release = '2.11.0'
60+
release = '2.12.0'
6161

6262
# The language for content autogenerated by Sphinx. Refer to documentation
6363
# for a list of supported languages.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<groupId>life.qbic</groupId>
99
<artifactId>data-model-lib</artifactId>
10-
<version>2.11.0</version> <!-- <<QUBE_FORCE_BUMP>> -->
10+
<version>2.12.0-SNAPSHOT</version> <!-- <<QUBE_FORCE_BUMP>> -->
1111
<name>data-model-lib</name>
1212
<url>http://github.com/qbicsoftware/data-model-lib</url>
1313
<description>Data models. A collection of QBiC's central data models and DTOs. </description>

qube.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.11.0
2+
current_version = 2.12.0
33

44
[bumpversion_files_whitelisted]
55
dot_qube = .qube.yml

src/main/groovy/life/qbic/datamodel/dtos/business/facilities/Facility.groovy

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,26 @@ package life.qbic.datamodel.dtos.business.facilities
1717
*/
1818
enum Facility {
1919

20-
CFMB("Core Facility for Medical Bioanalytics"),
21-
IMGAG("Institute for Medical Genetics and Applied Genomics"),
22-
MGM("Institute for Medical Microbiology and Hygiene"),
23-
QBIC("Quantitative Biology Center"),
24-
PCT("Proteome Center Tübingen")
20+
CFMB("Core Facility for Medical Bioanalytics", "CFMB"),
21+
IMGAG("Institute for Medical Genetics and Applied Genomics", "IMGAG"),
22+
MGM("Institute for Medical Microbiology and Hygiene", "MGM"),
23+
QBIC("Quantitative Biology Center", "QBIC"),
24+
CFMB_PCT("Proteomics Facility Tübingen", "Proteomics Facility")
2525

2626
private final String fullName
27+
private final String label
2728

2829
/**
29-
* Creates an instance of a facility enum
30-
* @param fullName The full name representation of the enum
30+
* Creates an instance of a facility enum with shorthand label
31+
* @param fullName The full name representation of the facility
32+
* @param label The shorthand label of the facility
3133
*/
32-
Facility(String fullName) {
34+
Facility(String fullName, String label) {
3335
this.fullName = fullName
36+
this.label = label
3437
}
3538

39+
3640
/**
3741
* Returns to the full name representation of the facility
3842
* @return
@@ -41,6 +45,14 @@ enum Facility {
4145
return this.fullName
4246
}
4347

48+
/**
49+
* Returns the short representation form of the facility
50+
* @return
51+
*/
52+
String getLabel() {
53+
return this.label
54+
}
55+
4456
/**
4557
* Returns a String representation of the facility enum.
4658
*

src/main/groovy/life/qbic/datamodel/dtos/projectmanagement/ProjectCode.groovy

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package life.qbic.datamodel.dtos.projectmanagement
22

3+
import life.qbic.datamodel.validation.ValidationException
4+
import life.qbic.datamodel.validation.projectmanagement.ProjectCodeValidator
5+
36
/**
47
* Describes the project code, that identifies the project within a project space.
58
*
@@ -13,7 +16,7 @@ class ProjectCode {
1316

1417
final String code
1518

16-
private static final def REGEX = ~'Q[A-X0-9]{4}'
19+
private static final ProjectCodeValidator projectCodeValidator = new ProjectCodeValidator()
1720

1821
/**
1922
* Constructs a project code instance based on the given code string.
@@ -22,14 +25,13 @@ class ProjectCode {
2225
*/
2326
ProjectCode(String code) throws IllegalArgumentException {
2427
Objects.requireNonNull(code, "Code must not be null")
25-
this.code = code.trim()
26-
validateCode()
27-
}
28-
29-
private void validateCode() {
30-
if(! REGEX.matcher(code).matches()) {
31-
throw new IllegalArgumentException("${code} is not a valid project code.")
28+
String projectCode = code.trim()
29+
try {
30+
projectCodeValidator.accept(projectCode)
31+
} catch (ValidationException validationException) {
32+
throw new IllegalArgumentException(validationException.message)
3233
}
34+
this.code = projectCode
3335
}
3436

3537
@Override
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package life.qbic.datamodel.validation
2+
3+
/**
4+
* <p>Should be thrown in case a validation failed</p>
5+
*
6+
* @since 2.12.0
7+
*/
8+
class ValidationException extends RuntimeException {
9+
/** Constructs a new runtime exception with the specified detail message.
10+
* The cause is not initialized, and may subsequently be initialized by a
11+
* call to {@link #initCause}.
12+
*
13+
* @param message the detail message. The detail message is saved for
14+
* later retrieval by the {@link #getMessage()} method.
15+
* @since 2.12.0
16+
*/
17+
ValidationException(String message) {
18+
super(message)
19+
}
20+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package life.qbic.datamodel.validation.projectmanagement
2+
3+
import life.qbic.datamodel.validation.ValidationException
4+
5+
import java.util.function.Consumer
6+
import java.util.function.Predicate
7+
import java.util.regex.Pattern
8+
9+
/**
10+
* <b>Project Code Validator</b>
11+
*
12+
* <p>Consumes a project code and throws a {@link ValidationException} in case it is not valid.</p>
13+
*
14+
* @since 2.12.0
15+
*/
16+
class ProjectCodeValidator implements Consumer<String> {
17+
private static final Predicate<String> IS_VALID_PROJECT_CODE = Pattern.compile("^Q[A-X0-9]{4}\$").asPredicate()
18+
19+
/**
20+
* Consumes the project code and throws a {@link ValidationException} in case of invalidity.
21+
*
22+
* @param projectCode the project code to validate
23+
* @throws ValidationException in case of validation failure
24+
* @since 2.12.0
25+
*/
26+
@Override
27+
void accept(String projectCode) throws ValidationException {
28+
ValidationException validationException = new ValidationException("'${projectCode}' is not a valid project code.")
29+
if (!projectCode) {
30+
throw validationException
31+
}
32+
if (!IS_VALID_PROJECT_CODE.test(projectCode)) {
33+
throw validationException
34+
}
35+
}
36+
37+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package life.qbic.datamodel.dtos.business.facilities
2+
3+
import spock.lang.Specification
4+
5+
/**
6+
* Tests for the {@link Facility} enum class
7+
*
8+
* @since 2.12.0
9+
*/
10+
class FacilitySpec extends Specification {
11+
12+
def "given an enum, calling the label function returns the right label"() {
13+
14+
when:
15+
String result = facility.label
16+
17+
then:
18+
result == expectedLabel
19+
20+
where:
21+
facility | expectedLabel
22+
Facility.CFMB | "CFMB"
23+
Facility.CFMB_PCT | "Proteomics Facility"
24+
Facility.IMGAG | "IMGAG"
25+
Facility.MGM | "MGM"
26+
Facility.QBIC | "QBIC"
27+
}
28+
29+
}

0 commit comments

Comments
 (0)