Skip to content

Commit 94e2815

Browse files
Release/2.14.0 (#266)
2.14.0 (2021-10-27) ------------------- **Added** * Added String representing product abbreviation to ProductCategory Enum (`#266) * ProductId now provides 'From' method to be created via String representation (`#264) **Fixed** **Dependencies** **Deprecated** * ``life.qbic.datamodel.dtos.business.services.ProductType.groovy``. The abbreviation is now accessible via the ``abbreviation`` property in ``life.qbic.datamodel.dtos.business.ProductCategory`` (`#266)
1 parent a561ac0 commit 94e2815

20 files changed

+270
-101
lines changed

.github/workflows/build_docs.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

.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.13.0
7+
version: 2.14.0
88
domain: lib
99
language: groovy
1010
project_slug: data-model-lib

CHANGELOG.rst

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

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

7+
2.14.0 (2021-10-27)
8+
-------------------
9+
10+
**Added**
11+
12+
* Added String representing product abbreviation to ProductCategory Enum (`#266 <https://github.com/qbicsoftware/data-model-lib/pull/266>`_)
13+
* ProductId now provides 'From' method to be created via String representation (`#264 <https://github.com/qbicsoftware/data-model-lib/pull/264>`_)
14+
15+
**Fixed**
16+
17+
**Dependencies**
18+
19+
**Deprecated**
20+
21+
* ``life.qbic.datamodel.dtos.business.services.ProductType.groovy``. The abbreviation is now accessible via the ``abbreviation`` property in ``life.qbic.datamodel.dtos.business.ProductCategory`` (`#266 <https://github.com/qbicsoftware/data-model-lib/pull/266>`_)
22+
723
2.13.0 (2021-10-13)
824
-------------------
925

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.13.0'
58+
version = '2.14.0'
5959
# The full version, including alpha/beta/rc tags.
60-
release = '2.13.0'
60+
release = '2.14.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.13.0</version> <!-- <<QUBE_FORCE_BUMP>> -->
10+
<version>2.14.0</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.13.0
2+
current_version = 2.14.0
33

44
[bumpversion_files_whitelisted]
55
dot_qube = .qube.yml

src/main/groovy/life/qbic/datamodel/dtos/business/ProductCategory.groovy

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,28 @@ package life.qbic.datamodel.dtos.business
99
*/
1010
enum ProductCategory {
1111

12-
SEQUENCING("Sequencing"),
13-
PROJECT_MANAGEMENT("Project Management"),
14-
PRIMARY_BIOINFO("Primary Bioinformatics"),
15-
SECONDARY_BIOINFO("Secondary Bioinformatics"),
16-
DATA_STORAGE("Data Storage"),
17-
PROTEOMIC("Proteomics"),
18-
METABOLOMIC("Metabolomics"),
19-
EXTERNAL_SERVICE("External Service")
12+
SEQUENCING("Sequencing", "SE"),
13+
PROJECT_MANAGEMENT("Project Management", "PM"),
14+
PRIMARY_BIOINFO("Primary Bioinformatics", "PB"),
15+
SECONDARY_BIOINFO("Secondary Bioinformatics", "SB"),
16+
DATA_STORAGE("Data Storage", "DS"),
17+
PROTEOMIC("Proteomics", "PR"),
18+
METABOLOMIC("Metabolomics", "ME"),
19+
EXTERNAL_SERVICE("External Service", "EXT")
2020

2121
/**
2222
* Value describing the enum type with a string
2323
*/
24-
private final String value
24+
private String value
2525

26-
ProductCategory(String value) {
26+
/**
27+
* Abbreviation for the enum type name
28+
*/
29+
private String abbreviation
30+
31+
ProductCategory(String value, String abbreviation) {
2732
this.value = value
33+
this.abbreviation = abbreviation
2834
}
2935

3036
/**
@@ -35,4 +41,14 @@ enum ProductCategory {
3541
String getValue() {
3642
return value
3743
}
44+
45+
/**
46+
* Returns the abbreviation associated to the given enum
47+
* This is <em>NOT</em> the same as {@link #toString}
48+
* @return a user-friendly string value
49+
*/
50+
String getAbbreviation() {
51+
return abbreviation
52+
}
53+
3854
}

src/main/groovy/life/qbic/datamodel/dtos/business/ProductCategoryFactory.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,20 @@ class ProductCategoryFactory extends EnumFactory<ProductCategory>{
2727
}
2828
return desiredKey
2929
}
30+
31+
/**
32+
* This method returns the enum with the provided String abbreviation.
33+
*
34+
* @throws IllegalArgumentException in case the String could not be mapped
35+
* @param abbreviation the String corresponding to the abbreviation stored in the enum
36+
* @return the enum key for the provided abbreviation
37+
*/
38+
ProductCategory getForAbbreviation(String abbreviation) {
39+
ProductCategory desiredKey
40+
desiredKey = ProductCategory.values().find {it.abbreviation.equals(abbreviation.trim())}
41+
if (!desiredKey) {
42+
throw new IllegalArgumentException("Unknown abbreviation'$abbreviation' for ${ProductCategory.getSimpleName()}")
43+
}
44+
return desiredKey
45+
}
3046
}

src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class ProductId implements Comparable<ProductId>{
2727
/**
2828
* A builder for ProductId instances.
2929
*/
30+
31+
private static final ProductCategoryFactory productCategoryFactory = new ProductCategoryFactory()
32+
3033
static class Builder {
3134
private String productType
3235
private long uniqueId
@@ -113,6 +116,39 @@ class ProductId implements Comparable<ProductId>{
113116
return type
114117
}
115118

119+
/**
120+
* Returns a ProductId from a given String representation
121+
*
122+
* Expects a ProductIdString with the Format P_N
123+
* P being the one of the abbreviation values stored in {@link ProductCategory} enum
124+
* N being an Integer Number
125+
*
126+
* @param String representation of a productId
127+
* @return ProductId containing productCategory abbreviation and uniqueNumber of String representation
128+
*/
129+
static ProductId from(String productId) {
130+
if (!productId.contains("_")) {
131+
throw new IllegalArgumentException("${productId} is not a valid product identifier.")
132+
}
133+
def splitId = productId.split("_")
134+
String productCategoryString = splitId[0].trim()
135+
String runningNumberString = splitId[1].trim()
136+
Long runningNumber
137+
ProductCategory productCategory
138+
try {
139+
runningNumber = Long.parseUnsignedLong(runningNumberString)
140+
productCategory = productCategoryFactory.getForAbbreviation(productCategoryString)
141+
}
142+
catch (NumberFormatException numberFormatException) {
143+
throw new NumberFormatException("Provided productId does not have a valid uniqueID. Provided unique id: ${runningNumberString}")
144+
}
145+
catch (IllegalArgumentException illegalArgumentException) {
146+
throw new IllegalArgumentException("ProductId does not have a valid ProductCategory abbreviation. Provided abbreviation: ${productCategoryString}")
147+
148+
}
149+
return new Builder(productCategory.getAbbreviation() , runningNumber).build()
150+
}
151+
116152
/**
117153
* Returns a String representation in the format:
118154
*

src/main/groovy/life/qbic/datamodel/dtos/business/services/DataStorage.groovy

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package life.qbic.datamodel.dtos.business.services
22

33
import groovy.transform.EqualsAndHashCode
4+
import life.qbic.datamodel.dtos.business.ProductCategory
45
import life.qbic.datamodel.dtos.business.ProductId
56
import life.qbic.datamodel.dtos.business.facilities.Facility
67

@@ -20,12 +21,12 @@ class DataStorage extends PartialProduct {
2021
* @param description The description of what the product is about.
2122
* @param unitPrice The price in € per unit
2223
* @param unit The product unit
23-
* @param runningNumber Number used in conjunction with ProductType{@link life.qbic.datamodel.dtos.business.services.ProductType} to identify product
24+
* @param runningNumber Number used in conjunction with {@link ProductCategory} to identify product
2425
* @deprecated since 2.5.0
2526
*/
2627
@Deprecated
2728
DataStorage(String name, String description, double unitPrice, ProductUnit unit, String runningNumber) {
28-
super(name, description, unitPrice, unit, new ProductId(ProductType.DATA_STORAGE.toString(), runningNumber))
29+
super(name, description, unitPrice, unit, new ProductId(ProductCategory.DATA_STORAGE.getAbbreviation(), runningNumber))
2930
}
3031

3132
/**
@@ -37,13 +38,13 @@ class DataStorage extends PartialProduct {
3738
* @param description The description of what the product is about.
3839
* @param unitPrice The price in € per unit
3940
* @param unit The product unit
40-
* @param runningNumber Number used in conjunction with ProductType{@link life.qbic.datamodel.dtos.business.services.ProductType} to identify product
41+
* @param runningNumber Number used in conjunction with {@link ProductCategory} to identify product
4142
*
4243
* @deprecated 2.11.0
4344
*/
4445
@Deprecated
4546
DataStorage(String name, String description, double unitPrice, ProductUnit unit, long runningNumber) {
46-
super(name, description, unitPrice, unit, new ProductId.Builder(ProductType.DATA_STORAGE.toString(), runningNumber).build())
47+
super(name, description, unitPrice, unit, new ProductId.Builder(ProductCategory.DATA_STORAGE.getAbbreviation(), runningNumber).build())
4748
}
4849

4950
/**
@@ -56,11 +57,11 @@ class DataStorage extends PartialProduct {
5657
* @param internalUnitPrice The price in € per unit for internal customers
5758
* @param externalUnitPrice The price in € per unit for external customers
5859
* @param unit The product unit
59-
* @param runningNumber Number used in conjunction with ProductType{@link life.qbic.datamodel.dtos.business.services.ProductType} to identify product
60+
* @param runningNumber Number used in conjunction with {@link ProductCategory} to identify product
6061
*
6162
* @since 2.11.0
6263
*/
6364
DataStorage(String name, String description, double internalUnitPrice, double externalUnitPrice, ProductUnit unit, long runningNumber, Facility serviceProvider) {
64-
super(name, description, internalUnitPrice, externalUnitPrice, unit, new ProductId.Builder(ProductType.DATA_STORAGE.toString(), runningNumber).build(), serviceProvider)
65+
super(name, description, internalUnitPrice, externalUnitPrice, unit, new ProductId.Builder(ProductCategory.DATA_STORAGE.getAbbreviation(), runningNumber).build(), serviceProvider)
6566
}
6667
}

0 commit comments

Comments
 (0)