Skip to content

Commit 455eabc

Browse files
Add ids to offermanager dtos (#310)
* add database id field to builder generated DTOs * add dedicated constructors to products * add missing @EqualsAndHashCode annotation * FacilityFactory searches in label, fullName and enum name * Bump dependencies Co-authored-by: Tobias Koch <tobias.koch@qbic.uni-tuebingen.de> Co-authored-by: Tobias Koch <KochTobi@users.noreply.github.com>
1 parent 2593ead commit 455eabc

21 files changed

+339
-12
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
<dependency>
9292
<groupId>org.codehaus.groovy</groupId>
9393
<artifactId>groovy-all</artifactId>
94-
<version>3.0.9</version>
94+
<version>3.0.10</version>
9595
<type>pom</type>
9696
<scope>${osgi.scope}</scope>
9797
</dependency>
@@ -144,7 +144,7 @@
144144
<dependency>
145145
<groupId>org.spockframework</groupId>
146146
<artifactId>spock-core</artifactId>
147-
<version>2.0-groovy-3.0</version>
147+
<version>2.1-groovy-3.0</version>
148148
<scope>test</scope>
149149
</dependency>
150150
</dependencies>

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import groovy.transform.EqualsAndHashCode
1111
@EqualsAndHashCode
1212
final class Affiliation {
1313

14+
/**
15+
* The database id of an affiliation.
16+
*
17+
* For example "1"
18+
*/
19+
final int id
20+
1421
/**
1522
* The organisation label of an affiliation.
1623
*
@@ -61,6 +68,8 @@ final class Affiliation {
6168

6269
static class Builder {
6370

71+
int id
72+
6473
String organisation
6574

6675
String addressAddition
@@ -78,6 +87,7 @@ final class Affiliation {
7887
AffiliationLabel label
7988

8089
Builder(String organisation, String street, String postalCode, String city) {
90+
this.id = id
8191
this.organisation = organisation
8292
this.street = street
8393
this.postalCode = postalCode
@@ -88,6 +98,11 @@ final class Affiliation {
8898
this.label = AffiliationLabel.MNF
8999
}
90100

101+
Builder id(int id){
102+
this.id = id
103+
return this
104+
}
105+
91106
/**
92107
* Sets an address addition
93108
* @param addressAddition
@@ -121,6 +136,7 @@ final class Affiliation {
121136
}
122137

123138
private Affiliation(Builder builder) {
139+
this.id = builder.id
124140
this.addressAddition = builder.addressAddition
125141
this.organisation = builder.organisation
126142
this.street = builder.street

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ import life.qbic.datamodel.dtos.projectmanagement.ProjectIdentifier
1313
@EqualsAndHashCode
1414
class Offer {
1515

16+
17+
/**
18+
* database id of an offer
19+
*/
20+
final int id
21+
1622
/**
1723
* The checksum of the offer
1824
*/
@@ -111,6 +117,7 @@ class Offer {
111117

112118
static class Builder {
113119

120+
int id
114121
/*
115122
Overall offer describing properties
116123
*/
@@ -189,6 +196,11 @@ class Offer {
189196
this.projectDescription = Objects.requireNonNull(projectObjective, "Project Objective must not be null")
190197
}
191198

199+
Builder id(int id) {
200+
this.id = id
201+
return this
202+
}
203+
192204
Builder checksum(String checksum) {
193205
this.checksum = checksum
194206
return this
@@ -280,6 +292,9 @@ class Offer {
280292
}
281293

282294
private Offer(Builder builder) {
295+
296+
this.id = builder.id
297+
283298
/*
284299
Offer Related Properties
285300
*/

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import life.qbic.datamodel.dtos.business.services.Product
1313
@EqualsAndHashCode
1414
class ProductItem {
1515

16+
/**
17+
* The database of an id of a ProductItem
18+
*
19+
* For example "1"
20+
*/
21+
final int id
22+
1623
/**
1724
* Describes the amount of a given item
1825
*/
@@ -55,6 +62,13 @@ class ProductItem {
5562
this.quantityDiscount = quantityDiscount
5663
}
5764

65+
ProductItem(int id, double quantity, Product product, double totalPrice, double quantityDiscount) {
66+
this.id = id
67+
this.quantity = quantity
68+
this.product = product
69+
this.totalPrice = totalPrice
70+
this.quantityDiscount = quantityDiscount
71+
}
5872

5973

6074
}

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

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

3-
import life.qbic.datamodel.dtos.business.Customer
4-
import life.qbic.datamodel.dtos.business.OfferId
5-
import life.qbic.datamodel.dtos.business.ProjectManager
3+
import groovy.transform.EqualsAndHashCode
64
import life.qbic.datamodel.dtos.projectmanagement.ProjectCode
75
import life.qbic.datamodel.dtos.projectmanagement.ProjectSpace
86

@@ -19,6 +17,7 @@ import life.qbic.datamodel.dtos.projectmanagement.ProjectSpace
1917
*
2018
* @since 2.3.0
2119
*/
20+
@EqualsAndHashCode
2221
class ProjectApplication {
2322

2423
/**

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@ class FacilityFactory extends EnumFactory<Facility> {
2121
*/
2222
@Override
2323
Facility getForString(String value) {
24-
Facility desiredKey
25-
desiredKey = Facility.values().find {it.fullName.equals(value.trim())}
26-
if (!desiredKey) {
27-
throw new IllegalArgumentException("Invalid value '$value' for ${Facility.getSimpleName()}")
28-
}
29-
return desiredKey
24+
Optional<Facility> matchingFullName = Arrays.stream(Facility.values())
25+
.filter(it -> it.fullName == value)
26+
.findFirst()
27+
Optional<Facility> matchingLabel = Arrays.stream(Facility.values())
28+
.filter(it -> it.label == value)
29+
.findFirst()
30+
Optional<Facility> matchingEnumValue = Arrays.stream(Facility.values())
31+
.filter(it -> it.name() == value)
32+
.findFirst()
33+
34+
return matchingFullName
35+
.orElse( matchingLabel
36+
.orElse(matchingEnumValue
37+
.orElseThrow(() ->
38+
new IllegalArgumentException("Invalid value '$value' for ${Facility.getSimpleName()}"))))
3039
}
3140
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,24 @@ class AtomicProduct extends Product {
5050
AtomicProduct(String name, String description, double internalUnitPrice, double externalUnitPrice, ProductUnit unit, ProductId productId, Facility serviceProvider) {
5151
super(name, description, internalUnitPrice, externalUnitPrice, unit, productId, serviceProvider)
5252
}
53+
54+
/**
55+
* Basic product constructor with id.
56+
*
57+
* Checks that all passed arguments except id are not null.
58+
*
59+
* @paran id the id of the product
60+
* @param name The name of the product.
61+
* @param description The description of what the product is about.
62+
* @param internalUnitPrice The price in € per unit for internal customers
63+
* @param externalUnitPrice The price in € per unit for external customers
64+
* @param unit The product unit
65+
* @param productId The product identifier
66+
* @param serviceProvider The facility providing the service product
67+
*
68+
* @since 2.17.0
69+
*/
70+
AtomicProduct(int id, String name, String description, double internalUnitPrice, double externalUnitPrice, ProductUnit unit, ProductId productId, Facility serviceProvider) {
71+
super(id, name, description, internalUnitPrice, externalUnitPrice, unit, productId, serviceProvider)
72+
}
5373
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,25 @@ class DataStorage extends PartialProduct {
6464
DataStorage(String name, String description, double internalUnitPrice, double externalUnitPrice, ProductUnit unit, long runningNumber, Facility serviceProvider) {
6565
super(name, description, internalUnitPrice, externalUnitPrice, unit, new ProductId.Builder(ProductCategory.DATA_STORAGE.getAbbreviation(), runningNumber).build(), serviceProvider)
6666
}
67+
68+
/**
69+
* Basic product constructor.
70+
*
71+
* Checks that all passed arguments except id are not null.
72+
*
73+
* @param id The id of the product.
74+
* @param name The name of the product.
75+
* @param description The description of what the product is about.
76+
* @param internalUnitPrice The price in € per unit for internal customers
77+
* @param externalUnitPrice The price in € per unit for external customers
78+
* @param unit The product unit
79+
* @param runningNumber Number used in conjunction with {@link ProductCategory} to identify product
80+
*
81+
* @since 2.17.0
82+
*/
83+
DataStorage(int id, String name, String description, double internalUnitPrice, double externalUnitPrice, ProductUnit unit, long runningNumber, Facility serviceProvider) {
84+
super(id, name, description, internalUnitPrice, externalUnitPrice, unit, new ProductId.Builder(ProductCategory.DATA_STORAGE.getAbbreviation(), runningNumber).build(), serviceProvider)
85+
}
86+
87+
6788
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,20 @@ class ExternalServiceProduct extends PartialProduct {
2828
super(name, description, internalUnitPrice, externalUnitPrice, unit, new ProductId.Builder(
2929
ProductCategory.EXTERNAL_SERVICE.getAbbreviation(), runningNumber).build(), serviceProvider)
3030
}
31+
32+
/**
33+
* Creates an instance of an {@link ExternalServiceProduct}.
34+
* @param id the id of the product
35+
* @param name The name of the product
36+
* @param description A product description
37+
* @param internalUnitPrice The net internal unit price of the product
38+
* @param externalUnitPrice The net external unit price of the product
39+
* @param unit The unit of the product
40+
* @param productId A product id, uniquely identifying the product in the offer environment
41+
* @param serviceProvider The service provider
42+
*/
43+
ExternalServiceProduct(int id, String name, String description, double internalUnitPrice, double externalUnitPrice, ProductUnit unit, long runningNumber, Facility serviceProvider) {
44+
super(id, name, description, internalUnitPrice, externalUnitPrice, unit, new ProductId.Builder(
45+
ProductCategory.EXTERNAL_SERVICE.getAbbreviation(), runningNumber).build(), serviceProvider)
46+
}
3147
}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,24 @@ class MetabolomicAnalysis extends AtomicProduct {
6565
MetabolomicAnalysis(String name, String description, double internalUnitPrice, double externalUnitPrice, ProductUnit unit, long runningNumber, Facility serviceProvider) {
6666
super(name, description, internalUnitPrice, externalUnitPrice, unit, new ProductId.Builder(ProductCategory.METABOLOMIC.getAbbreviation(), runningNumber).build(), serviceProvider)
6767
}
68-
}
6968

69+
/**
70+
* Basic product constructor with id.
71+
*
72+
* Checks that all passed arguments except id are not null.
73+
*
74+
* @paran id the id of the product.
75+
* @param name The name of the product.
76+
* @param description The description of what the product is about.
77+
* @param internalUnitPrice The price in € per unit for internal customers
78+
* @param externalUnitPrice The price in € per unit for external customers
79+
* @param unit The product unit
80+
* @param runningNumber Number used in conjunction with {@link ProductCategory} to identify product
81+
* @param serviceProvider The facility providing the service product
82+
*
83+
* @since 2.17.0
84+
*/
85+
MetabolomicAnalysis(int id, String name, String description, double internalUnitPrice, double externalUnitPrice, ProductUnit unit, long runningNumber, Facility serviceProvider) {
86+
super(id, name, description, internalUnitPrice, externalUnitPrice, unit, new ProductId.Builder(ProductCategory.METABOLOMIC.getAbbreviation(), runningNumber).build(), serviceProvider)
87+
}
88+
}

0 commit comments

Comments
 (0)