From e2c4912b3ebab8678120e741bab72e47f03e76b6 Mon Sep 17 00:00:00 2001 From: Tobias Koch Date: Fri, 12 Mar 2021 16:51:10 +0100 Subject: [PATCH 1/4] Prepare product id refactor --- .../datamodel/dtos/business/ProductId.groovy | 73 +++++++++++++++++-- 1 file changed, 66 insertions(+), 7 deletions(-) diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy index 0bf3c417f..fbcddfd71 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy @@ -23,27 +23,86 @@ class ProductId { /** * Identifying number used in conjunction with the type */ - private final String identifier + private final long uniqueId + + /** + * A builder for ProductId instances. + */ + static class Builder { + private String productType + private long uniqueId + + /** + * + * @param productType + * @param identifier the unique id - will be interpreted as unsigned long + */ + Builder(String productType, String identifier) { + Builder(productType, Long.parseUnsignedLong(identifier)) + } + + /** + * + * @param productType + * @param uniqueId the unique id - will be interpreted as unsigned long + */ + Builder(String productType, long uniqueId) { + this.productType = Objects.requireNonNull(productType) + this.uniqueId = Objects.requireNonNull(uniqueId) + } + + Builder productType(String productType) { + this.productType = productType + return this + } + + Builder identifier(long identifier) { + this.identifier = identifier + return this + } + /** + * Constructs a product identifier based on the configuration of the builder + * @return + */ + ProductId build() { + return new ProductId(this) + } + } /** * Creates an identifier object with the * * @param type describing the type of the underlying identifier * @param identifier describes the identifying running number + * @deprecated please use {@link ProductId.Builder} */ - + @Deprecated ProductId(String type, String identifier){ - this.type = Objects.requireNonNull(type, "type must not be null") - this.identifier= Objects.requireNonNull(identifier, "version must not be null") + Builder builder = new Builder(type, identifier) + ProductId(builder) + } + private ProductId(Builder builder) { + this.type = builder.productType + this.identifier = builder.identifier } /** * Returns the identifying running number - * @return + * @return the identifier + * @deprecated please use {@link ProductId#getUniqueId()} */ + @Deprecated String getIdentifier() { - return identifier + return uniqueId.toString() + } + + /** + * Returns the identifying running number + * @return the identifier + */ + Long getUniqueId() { + return uniqueId } /** * Returns the type of the identifier @@ -62,6 +121,6 @@ class ProductId { */ @Override String toString() { - return type + "_" + identifier + return "${type}_${uniqueId}" } } \ No newline at end of file From 7c4144c78d7f74fd961dd9d7b48d957f30b9e699 Mon Sep 17 00:00:00 2001 From: Tobias Koch Date: Fri, 12 Mar 2021 16:52:51 +0100 Subject: [PATCH 2/4] Fix field rename --- .../groovy/life/qbic/datamodel/dtos/business/ProductId.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy index fbcddfd71..8c9cb8ba9 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy @@ -57,7 +57,7 @@ class ProductId { } Builder identifier(long identifier) { - this.identifier = identifier + this.uniqueId = identifier return this } /** @@ -84,7 +84,7 @@ class ProductId { private ProductId(Builder builder) { this.type = builder.productType - this.identifier = builder.identifier + this.uniqueId = builder.uniqueId } /** From 1f1bcf7c8fc37c38faa3356264feb097db07d55c Mon Sep 17 00:00:00 2001 From: Tobias Koch Date: Mon, 15 Mar 2021 09:29:03 +0100 Subject: [PATCH 3/4] Rename builder method --- .../groovy/life/qbic/datamodel/dtos/business/ProductId.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy index 8c9cb8ba9..1ddc301ab 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy @@ -56,7 +56,7 @@ class ProductId { return this } - Builder identifier(long identifier) { + Builder uniqueId(long identifier) { this.uniqueId = identifier return this } From 54b467e25fb6656f90f5510e67316ddd63fe32e9 Mon Sep 17 00:00:00 2001 From: Tobias Koch Date: Mon, 15 Mar 2021 13:21:23 +0100 Subject: [PATCH 4/4] Fix compilation error --- .../life/qbic/datamodel/dtos/business/ProductId.groovy | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy b/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy index 1ddc301ab..fbf17f95e 100644 --- a/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy +++ b/src/main/groovy/life/qbic/datamodel/dtos/business/ProductId.groovy @@ -38,7 +38,8 @@ class ProductId { * @param identifier the unique id - will be interpreted as unsigned long */ Builder(String productType, String identifier) { - Builder(productType, Long.parseUnsignedLong(identifier)) + this.productType = Objects.requireNonNull(productType) + this.uniqueId = Objects.requireNonNull(Long.parseUnsignedLong(identifier)) } /** @@ -79,7 +80,8 @@ class ProductId { @Deprecated ProductId(String type, String identifier){ Builder builder = new Builder(type, identifier) - ProductId(builder) + this.type = builder.productType + this.uniqueId = builder.uniqueId } private ProductId(Builder builder) {