{
- @EmbeddedId //
- @AttributeOverride(name = "id", column = @Column(name = "ITEM_ID")) //
- private final InventoryItemIdentifier inventoryItemIdentifier = new InventoryItemIdentifier();
+ private final @EmbeddedId InventoryItemIdentifier inventoryItemIdentifier = InventoryItemIdentifier
+ .of(UUID.randomUUID().toString());
@Getter //
private Quantity quantity;
@@ -175,4 +180,33 @@ public String toString() {
return String.format("%s(%s) for Product(%s, \"%s\") with quantity %s", //
getClass().getSimpleName(), getId(), product.getId(), product.getName(), getQuantity());
}
+
+ /**
+ * {@code InventoryItemIdentifier} serves as an identifier type for {@link UniqueInventoryItem} objects. The main
+ * reason for its existence is type safety for identifier across the Salespoint Framework.
+ * {@code InventoryItemIdentifier} instances serve as primary key attribute in {@link UniqueInventoryItem}, but can
+ * also be used as a key for non-persistent, Map
-based implementations.
+ *
+ * @author Paul Henke
+ * @author Oliver Gierke
+ */
+ @Embeddable
+ @EqualsAndHashCode
+ @RequiredArgsConstructor(staticName = "of")
+ @NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
+ public static class InventoryItemIdentifier implements Identifier, Serializable {
+
+ private static final long serialVersionUID = -3309444549353766703L;
+
+ private final String inventoryItemId;
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return inventoryItemId;
+ }
+ }
}
diff --git a/src/main/java/org/salespointframework/inventory/InventoryItemIdentifier.java b/src/main/java/org/salespointframework/inventory/InventoryItemIdentifier.java
deleted file mode 100755
index 02c22cfd..00000000
--- a/src/main/java/org/salespointframework/inventory/InventoryItemIdentifier.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2017-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.salespointframework.inventory;
-
-import javax.persistence.Embeddable;
-
-import org.salespointframework.core.SalespointIdentifier;
-
-/**
- * {@code InventoryItemIdentifier} serves as an identifier type for {@link UniqueInventoryItem} objects. The main reason for
- * its existence is type safety for identifier across the Salespoint Framework.
- * {@code InventoryItemIdentifier} instances serve as primary key attribute in {@link UniqueInventoryItem}, but can also be
- * used as a key for non-persistent, Map
-based implementations.
- *
- * @author Paul Henke
- * @author Oliver Gierke
- */
-@Embeddable
-public class InventoryItemIdentifier extends SalespointIdentifier {
-
- private static final long serialVersionUID = -5195493076944614L;
-
- /**
- * Creates a new unique identifier for {@link UniqueInventoryItem}s.
- */
- InventoryItemIdentifier() {
- super();
- }
-
- /**
- * Only needed for property editor, shouldn't be used otherwise.
- *
- * @param inventoryItemIdentifier The string representation of the identifier.
- */
- InventoryItemIdentifier(String inventoryItemIdentifier) {
- super(inventoryItemIdentifier);
- }
-}
diff --git a/src/main/java/org/salespointframework/inventory/LineItemFilter.java b/src/main/java/org/salespointframework/inventory/LineItemFilter.java
index 9dafdc25..ce78b134 100644
--- a/src/main/java/org/salespointframework/inventory/LineItemFilter.java
+++ b/src/main/java/org/salespointframework/inventory/LineItemFilter.java
@@ -18,6 +18,7 @@
import java.util.Collection;
import java.util.function.Predicate;
+import org.salespointframework.inventory.InventoryListeners.InventoryOrderEventListener;
import org.salespointframework.order.OrderLine;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
diff --git a/src/main/java/org/salespointframework/inventory/MultiInventory.java b/src/main/java/org/salespointframework/inventory/MultiInventory.java
index 018ac3ef..1f5c6c3a 100644
--- a/src/main/java/org/salespointframework/inventory/MultiInventory.java
+++ b/src/main/java/org/salespointframework/inventory/MultiInventory.java
@@ -16,8 +16,9 @@
package org.salespointframework.inventory;
import org.salespointframework.catalog.Product;
-import org.salespointframework.catalog.ProductIdentifier;
+import org.salespointframework.catalog.Product.ProductIdentifier;
import org.salespointframework.core.SalespointRepository;
+import org.salespointframework.inventory.InventoryItem.InventoryItemIdentifier;
import org.springframework.data.jpa.repository.Query;
import org.springframework.util.Assert;
diff --git a/src/main/java/org/salespointframework/inventory/UniqueInventory.java b/src/main/java/org/salespointframework/inventory/UniqueInventory.java
index 6d857880..b0560690 100644
--- a/src/main/java/org/salespointframework/inventory/UniqueInventory.java
+++ b/src/main/java/org/salespointframework/inventory/UniqueInventory.java
@@ -18,8 +18,9 @@
import java.util.Optional;
import org.salespointframework.catalog.Product;
-import org.salespointframework.catalog.ProductIdentifier;
+import org.salespointframework.catalog.Product.ProductIdentifier;
import org.salespointframework.core.SalespointRepository;
+import org.salespointframework.inventory.InventoryItem.InventoryItemIdentifier;
import org.salespointframework.order.Order;
import org.salespointframework.quantity.Quantity;
import org.springframework.data.jpa.repository.Query;
diff --git a/src/main/java/org/salespointframework/order/ChargeLine.java b/src/main/java/org/salespointframework/order/ChargeLine.java
index c632aabb..42d633ff 100755
--- a/src/main/java/org/salespointframework/order/ChargeLine.java
+++ b/src/main/java/org/salespointframework/order/ChargeLine.java
@@ -21,26 +21,30 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
+import lombok.Value;
+
+import java.io.Serializable;
+import java.util.UUID;
import javax.money.MonetaryAmount;
-import javax.persistence.AttributeOverride;
-import javax.persistence.Column;
+import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
+import org.jmolecules.ddd.types.Identifier;
import org.salespointframework.core.AbstractEntity;
+import org.salespointframework.order.ChargeLine.ChargeLineIdentifier;
import org.springframework.util.Assert;
/**
- * A charge line represents extra expenses, such as shipping, for an
- * {@link Order} as a whole. Expenses for an individual {@link OrderLine} can be
- * modeled using the {@link AttachedChargeLine} sub-class.
+ * A charge line represents extra expenses, such as shipping, for an {@link Order} as a whole. Expenses for an
+ * individual {@link OrderLine} can be modeled using the {@link AttachedChargeLine} sub-class.
*
* This class is immutable.
- *
+ *
* @see AttachedChargeLine
* @see OrderLine
* @author Thomas Dedek
@@ -55,9 +59,7 @@
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class ChargeLine extends AbstractEntity implements Priced {
- @EmbeddedId //
- @AttributeOverride(name = "id", column = @Column(name = "CHARGELINE_ID")) //
- private ChargeLineIdentifier chargeLineIdentifier = new ChargeLineIdentifier();
+ private @EmbeddedId ChargeLineIdentifier chargeLineIdentifier = ChargeLineIdentifier.of(UUID.randomUUID().toString());
private final @NonNull MonetaryAmount price;
private final @NonNull String description;
@@ -70,6 +72,24 @@ public ChargeLineIdentifier getId() {
return chargeLineIdentifier;
}
+ /**
+ * {@link ChargeLineIdentifier} serves as an identifier type for {@link ChargeLine} objects. The main reason for its
+ * existence is type safety for identifier across the Salespoint Framework.
+ *
+ * @author Paul Henke
+ * @author Oliver Gierke
+ */
+ @Embeddable
+ @Value
+ @RequiredArgsConstructor(staticName = "of")
+ @NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
+ public static class ChargeLineIdentifier implements Identifier, Serializable {
+
+ private static final long serialVersionUID = -2971693909958003661L;
+
+ String id;
+ }
+
/**
* A {@link ChargeLine} that's attached to an {@link OrderLine}. Create via
* {@link Order#addChargeLine(MonetaryAmount, String, int)} or
@@ -87,7 +107,7 @@ public static class AttachedChargeLine extends ChargeLine {
/**
* Creates a new {@link AttachedChargeLine} for the given price, description and {@link OrderLine}.
- *
+ *
* @param price must not be {@literal null}.
* @param description must not be {@literal null}.
* @param orderLine must not be {@literal null}.
@@ -103,7 +123,7 @@ public static class AttachedChargeLine extends ChargeLine {
/**
* Returns whether the {@link AttachedChargeLine} belongs to the given {@link OrderLine}.
- *
+ *
* @param oderLine must not be {@literal null}.
* @return
*/
diff --git a/src/main/java/org/salespointframework/order/ChargeLineIdentifier.java b/src/main/java/org/salespointframework/order/ChargeLineIdentifier.java
deleted file mode 100755
index e7a6585d..00000000
--- a/src/main/java/org/salespointframework/order/ChargeLineIdentifier.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2017-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.salespointframework.order;
-
-import javax.persistence.Embeddable;
-
-import org.salespointframework.core.SalespointIdentifier;
-
-/**
- * {@link ChargeLineIdentifier} serves as an identifier type for {@link ChargeLine} objects. The main reason for its
- * existence is type safety for identifier across the Salespoint Framework.
- *
- * @author Paul Henke
- * @author Oliver Gierke
- */
-@Embeddable
-class ChargeLineIdentifier extends SalespointIdentifier {
-
- private static final long serialVersionUID = 3953538683490057901L;
-
- /**
- * Creates a new unique identifier for {@link ChargeLine}s.
- */
- ChargeLineIdentifier() {
- super();
- }
-
- /**
- * Only needed for property editor, shouldn't be used otherwise.
- *
- * @param chargeLineIdentifier The string representation of the identifier.
- */
-
- ChargeLineIdentifier(String chargeLineIdentifier) {
- super(chargeLineIdentifier);
- }
-}
diff --git a/src/main/java/org/salespointframework/order/Order.java b/src/main/java/org/salespointframework/order/Order.java
index dbbc532a..eb1f2369 100755
--- a/src/main/java/org/salespointframework/order/Order.java
+++ b/src/main/java/org/salespointframework/order/Order.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2019 the original author or authors.
+ * Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,21 +16,28 @@
package org.salespointframework.order;
import lombok.AccessLevel;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
+import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
+import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.UUID;
import javax.money.MonetaryAmount;
import javax.persistence.*;
+import org.jmolecules.ddd.types.Identifier;
import org.salespointframework.catalog.Product;
import org.salespointframework.core.AbstractAggregateRoot;
import org.salespointframework.order.ChargeLine.AttachedChargeLine;
+import org.salespointframework.order.Order.OrderIdentifier;
import org.salespointframework.order.OrderEvents.OrderCanceled;
import org.salespointframework.order.OrderEvents.OrderCompleted;
import org.salespointframework.order.OrderEvents.OrderPaid;
@@ -53,9 +60,7 @@
@NoArgsConstructor(force = true, access = AccessLevel.PROTECTED, onConstructor = @__(@Deprecated))
public class Order extends AbstractAggregateRoot {
- @EmbeddedId //
- @AttributeOverride(name = "id", column = @Column(name = "ORDER_ID")) //
- private OrderIdentifier orderIdentifier = new OrderIdentifier();
+ private @EmbeddedId OrderIdentifier orderIdentifier = OrderIdentifier.of(UUID.randomUUID().toString());
private @Lob @Getter PaymentMethod paymentMethod;
@@ -505,4 +510,32 @@ private OrderLine getRequiredOrderLineByIndex(int index) {
return this.orderLines.get(index);
}
+
+ /**
+ * {@link OrderIdentifier} serves as an identifier type for {@link Order} objects. The main reason for its existence
+ * is type safety for identifier across the Salespoint Framework.
+ * {@link OrderIdentifier} instances serve as primary key attribute in {@link Order}, but can also be used as a key
+ * for non-persistent, {@link Map}-based implementations.
+ *
+ * @author Thomas Dedek
+ */
+ @Embeddable
+ @EqualsAndHashCode
+ @RequiredArgsConstructor(staticName = "of")
+ @NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
+ public static class OrderIdentifier implements Identifier, Serializable {
+
+ private static final long serialVersionUID = 7243092788875480705L;
+
+ private final String orderId;
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return orderId;
+ }
+ }
}
diff --git a/src/main/java/org/salespointframework/order/OrderIdentifier.java b/src/main/java/org/salespointframework/order/OrderIdentifier.java
deleted file mode 100755
index a2897b38..00000000
--- a/src/main/java/org/salespointframework/order/OrderIdentifier.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2017-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.salespointframework.order;
-
-import java.util.Map;
-
-import javax.persistence.Embeddable;
-
-import org.salespointframework.core.SalespointIdentifier;
-
-/**
- * {@link OrderIdentifier} serves as an identifier type for {@link Order} objects. The main reason for its existence is
- * type safety for identifier across the Salespoint Framework.
- * {@link OrderIdentifier} instances serve as primary key attribute in {@link Order}, but can also be used as a key for
- * non-persistent, {@link Map}-based implementations.
- *
- * @author Thomas Dedek
- */
-@Embeddable
-public final class OrderIdentifier extends SalespointIdentifier {
-
- private static final long serialVersionUID = -5109304499529387062L;
-
- /**
- * Creates a new unique identifier for {@link Order}.
- */
- OrderIdentifier() {
- super();
- }
-
- /**
- * Only needed for property editor, shouldn't be used otherwise.
- *
- * @param orderIdentifier The string representation of the identifier.
- */
- OrderIdentifier(String orderIdentifier) {
- super(orderIdentifier);
- }
-}
diff --git a/src/main/java/org/salespointframework/order/OrderLine.java b/src/main/java/org/salespointframework/order/OrderLine.java
index 3faed9ba..f60c15dc 100755
--- a/src/main/java/org/salespointframework/order/OrderLine.java
+++ b/src/main/java/org/salespointframework/order/OrderLine.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2020 the original author or authors.
+ * Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,34 +16,40 @@
package org.salespointframework.order;
import lombok.AccessLevel;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
+import lombok.RequiredArgsConstructor;
import lombok.ToString;
+import java.io.Serializable;
+import java.util.Map;
+import java.util.UUID;
+
import javax.money.MonetaryAmount;
-import javax.persistence.AttributeOverride;
-import javax.persistence.Column;
-import javax.persistence.Embedded;
+import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
+import org.jmolecules.ddd.types.Identifier;
import org.salespointframework.catalog.Product;
-import org.salespointframework.catalog.ProductIdentifier;
+import org.salespointframework.catalog.Product.ProductIdentifier;
import org.salespointframework.core.AbstractEntity;
+import org.salespointframework.order.OrderLine.OrderLineIdentifier;
import org.salespointframework.quantity.MetricMismatchException;
import org.salespointframework.quantity.Quantity;
import org.springframework.util.Assert;
/**
- * An order line represents the price and the {@link Quantity} of a
- * {@link Product} that is intended to be purchased as part of an {@link Order}.
+ * An order line represents the price and the {@link Quantity} of a {@link Product} that is intended to be purchased as
+ * part of an {@link Order}.
*
- * Order lines should not be used to represent expenses for services, such as
- * shipping. For this purpose, {@link ChargeLine} should be used instead.
+ * Order lines should not be used to represent expenses for services, such as shipping. For this purpose,
+ * {@link ChargeLine} should be used instead.
*
- * Note that the constructor of this class creates a copy of the product's name
- * and price, so that changes to those attributes do not affect existing orders.
- *
+ * Note that the constructor of this class creates a copy of the product's name and price, so that changes to those
+ * attributes do not affect existing orders.
+ *
* @see ChargeLine
* @author Paul Henke
* @author Oliver Gierke
@@ -53,21 +59,16 @@
@NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
public class OrderLine extends AbstractEntity implements Priced {
- @EmbeddedId //
- @AttributeOverride(name = "id", column = @Column(name = "ORDERLINE_ID")) //
- private OrderLineIdentifier orderLineIdentifier = new OrderLineIdentifier();
+ private @EmbeddedId OrderLineIdentifier orderLineIdentifier = OrderLineIdentifier.of(UUID.randomUUID().toString());
- @Embedded //
- @AttributeOverride(name = "id", column = @Column(name = "PRODUCT_ID")) //
private @Getter ProductIdentifier productIdentifier;
-
private @Getter MonetaryAmount price;
private @Getter Quantity quantity;
private @Getter String productName;
/**
* Creates a new {@link OrderLine} for the given {@link Product} and {@link Quantity}.
- *
+ *
* @param product must not be {@literal null}.
* @param quantity must not be {@literal null}.
*/
@@ -86,7 +87,7 @@ public class OrderLine extends AbstractEntity implements Pr
this.productName = product.getName();
}
- /*
+ /*
* (non-Javadoc)
* @see org.springframework.data.domain.Persistable#getId()
*/
@@ -97,7 +98,7 @@ public OrderLineIdentifier getId() {
/**
* Returns whether the {@link OrderLine} refers to the given {@link Product}.
- *
+ *
* @param product must not be {@literal null}.
* @return
* @since 7.1
@@ -111,7 +112,7 @@ public boolean refersTo(Product product) {
/**
* Returns whether the {@link OrderLine} refers to the {@link Product} with the given identifier.
- *
+ *
* @param identifier must not be {@literal null}.
* @return
* @since 7.1
@@ -122,4 +123,33 @@ public boolean refersTo(ProductIdentifier identifier) {
return this.productIdentifier.equals(identifier);
}
+
+ /**
+ * {@link OrderLineIdentifier} serves as an identifier type for {@link OrderLine} objects. The main reason for its
+ * existence is type safety for identifier across the Salespoint Framework.
+ * {@link OrderLineIdentifier} instances serve as primary key attribute in {@link OrderLine}, but can also be used as
+ * a key for non-persistent, {@link Map}-based implementations.
+ *
+ * @author Thomas Dedek
+ * @author Oliver Gierke
+ */
+ @Embeddable
+ @EqualsAndHashCode
+ @RequiredArgsConstructor(staticName = "of")
+ @NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
+ static class OrderLineIdentifier implements Identifier, Serializable {
+
+ private static final long serialVersionUID = 2978461586574769497L;
+
+ private final String orderLineId;
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return orderLineId;
+ }
+ }
}
diff --git a/src/main/java/org/salespointframework/order/OrderLineIdentifier.java b/src/main/java/org/salespointframework/order/OrderLineIdentifier.java
deleted file mode 100755
index 1a9f9591..00000000
--- a/src/main/java/org/salespointframework/order/OrderLineIdentifier.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2017-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.salespointframework.order;
-
-import java.util.Map;
-
-import javax.persistence.Embeddable;
-
-import org.salespointframework.core.SalespointIdentifier;
-
-/**
- * {@link OrderLineIdentifier} serves as an identifier type for {@link OrderLine} objects. The main reason for its
- * existence is type safety for identifier across the Salespoint Framework.
- * {@link OrderLineIdentifier} instances serve as primary key attribute in {@link OrderLine}, but can also be used as a
- * key for non-persistent, {@link Map}-based implementations.
- *
- * @author Thomas Dedek
- * @author Oliver Gierke
- */
-@Embeddable
-final class OrderLineIdentifier extends SalespointIdentifier {
-
- private static final long serialVersionUID = 8245571681642563326L;
-
- /**
- * Creates a new unique identifier for {@link OrderLine}s
- */
- OrderLineIdentifier() {
- super();
- }
-
- /**
- * Only needed for property editor, shouldn't be used otherwise.
- *
- * @param orderLineIdentifier The string representation of the identifier.
- */
- OrderLineIdentifier(String orderLineIdentifier) {
- super(orderLineIdentifier);
- }
-}
diff --git a/src/main/java/org/salespointframework/order/OrderManagement.java b/src/main/java/org/salespointframework/order/OrderManagement.java
index 2ab1fef6..4f572636 100755
--- a/src/main/java/org/salespointframework/order/OrderManagement.java
+++ b/src/main/java/org/salespointframework/order/OrderManagement.java
@@ -17,6 +17,7 @@
import java.util.Optional;
+import org.salespointframework.order.Order.OrderIdentifier;
import org.salespointframework.order.OrderEvents.OrderCanceled;
import org.salespointframework.order.OrderEvents.OrderCompleted;
import org.salespointframework.order.OrderEvents.OrderPaid;
diff --git a/src/main/java/org/salespointframework/order/OrderRepository.java b/src/main/java/org/salespointframework/order/OrderRepository.java
index 13b42984..15d9947a 100644
--- a/src/main/java/org/salespointframework/order/OrderRepository.java
+++ b/src/main/java/org/salespointframework/order/OrderRepository.java
@@ -17,6 +17,7 @@
import java.time.LocalDateTime;
+import org.salespointframework.order.Order.OrderIdentifier;
import org.salespointframework.useraccount.UserAccount;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
diff --git a/src/main/java/org/salespointframework/order/PersistentOrderManagement.java b/src/main/java/org/salespointframework/order/PersistentOrderManagement.java
index 9d90c03b..8256b23a 100755
--- a/src/main/java/org/salespointframework/order/PersistentOrderManagement.java
+++ b/src/main/java/org/salespointframework/order/PersistentOrderManagement.java
@@ -20,6 +20,7 @@
import java.util.Optional;
+import org.salespointframework.order.Order.OrderIdentifier;
import org.salespointframework.time.BusinessTime;
import org.salespointframework.time.Interval;
import org.salespointframework.useraccount.UserAccount;
diff --git a/src/main/java/org/salespointframework/support/JpaEntityConverter.java b/src/main/java/org/salespointframework/support/JpaEntityConverter.java
index a2638b7e..41a1d12d 100644
--- a/src/main/java/org/salespointframework/support/JpaEntityConverter.java
+++ b/src/main/java/org/salespointframework/support/JpaEntityConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017-2019 the original author or authors.
+ * Copyright 2017-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package org.salespointframework.support;
import lombok.NonNull;
-import lombok.RequiredArgsConstructor;
import java.util.Collections;
import java.util.Set;
@@ -24,24 +23,42 @@
import javax.persistence.EntityManager;
import javax.persistence.metamodel.EntityType;
+import org.jmolecules.spring.PrimitivesToIdentifierConverter;
+import org.springframework.beans.factory.ObjectFactory;
+import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
+import org.springframework.util.Assert;
/**
* {@link Converter} that can convert {@link String}s into JPA managed domain types. We expect the identifier types to
* have a constructor that takes a {@link String} as arguments.
- *
+ *
* @author Oliver Gierke
*/
@Component
-@RequiredArgsConstructor
class JpaEntityConverter implements ConditionalGenericConverter {
- private final @NonNull SalespointIdentifierConverter identifierConverter;
+ private final @NonNull PrimitivesToIdentifierConverter identifierConverter;
private final @NonNull EntityManager em;
+ /**
+ * Creates a new {@link JpaEntityConverter} for the given {@link EntityManager} and {@link ConversionService}.
+ *
+ * @param em must not be {@literal null}.
+ * @param conversionService must not be {@literal null}.
+ */
+ public JpaEntityConverter(EntityManager em, ObjectFactory conversionService) {
+
+ Assert.notNull(conversionService, "EntityManager must not be null!");
+ Assert.notNull(conversionService, "ConversionService must not be null!");
+
+ this.em = em;
+ this.identifierConverter = new PrimitivesToIdentifierConverter(() -> conversionService.getObject());
+ }
+
/*
* (non-Javadoc)
* @see org.springframework.core.convert.converter.GenericConverter#getConvertibleTypes()
@@ -64,7 +81,7 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
}
}
- /*
+ /*
* (non-Javadoc)
* @see org.springframework.core.convert.converter.GenericConverter#convert(java.lang.Object, org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
*/
diff --git a/src/main/java/org/salespointframework/support/SalespointIdentifierConverter.java b/src/main/java/org/salespointframework/support/SalespointIdentifierConverter.java
deleted file mode 100644
index 54d1ba6d..00000000
--- a/src/main/java/org/salespointframework/support/SalespointIdentifierConverter.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2017-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.salespointframework.support;
-
-import java.lang.reflect.Constructor;
-import java.util.Collections;
-import java.util.Set;
-
-import org.salespointframework.core.SalespointIdentifier;
-import org.springframework.beans.BeanUtils;
-import org.springframework.core.convert.ConversionFailedException;
-import org.springframework.core.convert.TypeDescriptor;
-import org.springframework.core.convert.converter.ConditionalGenericConverter;
-import org.springframework.stereotype.Component;
-
-/**
- * @author Oliver Gierke
- */
-@Component
-class SalespointIdentifierConverter implements ConditionalGenericConverter {
-
- private static final TypeDescriptor STRING_DESCRIPTOR = TypeDescriptor.valueOf(String.class);
- private static final TypeDescriptor IDENTIFIER_DESCRIPTOR = TypeDescriptor.valueOf(SalespointIdentifier.class);
-
- /*
- * (non-Javadoc)
- * @see org.springframework.core.convert.converter.GenericConverter#getConvertibleTypes()
- */
- @Override
- public Set getConvertibleTypes() {
- return Collections.singleton(new ConvertiblePair(String.class, SalespointIdentifier.class));
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.core.convert.converter.ConditionalConverter#matches(org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
- */
- @Override
- public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
- return sourceType.isAssignableTo(STRING_DESCRIPTOR) && targetType.isAssignableTo(IDENTIFIER_DESCRIPTOR);
- }
-
- /*
- * (non-Javadoc)
- * @see org.springframework.core.convert.converter.GenericConverter#convert(java.lang.Object, org.springframework.core.convert.TypeDescriptor, org.springframework.core.convert.TypeDescriptor)
- */
- @Override
- public SalespointIdentifier convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
-
- Class> targetClass = targetType.getType();
-
- try {
-
- Constructor> constructor = targetClass.getDeclaredConstructor(String.class);
- return (SalespointIdentifier) BeanUtils.instantiateClass(constructor, source);
-
- } catch (NoSuchMethodException | SecurityException o_O) {
- throw new ConversionFailedException(TypeDescriptor.forObject(source), TypeDescriptor.valueOf(targetClass), source,
- o_O);
- }
- }
-}
diff --git a/src/main/java/org/salespointframework/useraccount/PersistentUserAccountManagement.java b/src/main/java/org/salespointframework/useraccount/PersistentUserAccountManagement.java
index 2953c9ab..9ef3eae5 100644
--- a/src/main/java/org/salespointframework/useraccount/PersistentUserAccountManagement.java
+++ b/src/main/java/org/salespointframework/useraccount/PersistentUserAccountManagement.java
@@ -23,6 +23,7 @@
import org.salespointframework.useraccount.Password.EncryptedPassword;
import org.salespointframework.useraccount.Password.UnencryptedPassword;
+import org.salespointframework.useraccount.UserAccount.UserAccountIdentifier;
import org.springframework.data.util.Streamable;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
@@ -96,7 +97,7 @@ public UserAccount create(String userName, UnencryptedPassword password, String
});
EncryptedPassword encryptedPassword = encrypt(password);
- UserAccount account = new UserAccount(new UserAccountIdentifier(userName), encryptedPassword, roles);
+ UserAccount account = new UserAccount(UserAccountIdentifier.of(userName), encryptedPassword, roles);
account.setEmail(EMAIL_PLACEHOLDER.equals(emailAddress) ? null : emailAddress);
return save(account);
@@ -228,7 +229,7 @@ public Streamable findDisabled() {
public Optional findByUsername(String username) {
Assert.hasText(username, "Username must not be null or empty!");
- return repository.findById(new UserAccountIdentifier(username));
+ return repository.findById(UserAccountIdentifier.of(username));
}
/*
diff --git a/src/main/java/org/salespointframework/useraccount/SpringSecurityAuthenticationManagement.java b/src/main/java/org/salespointframework/useraccount/SpringSecurityAuthenticationManagement.java
index f275440c..09504faf 100644
--- a/src/main/java/org/salespointframework/useraccount/SpringSecurityAuthenticationManagement.java
+++ b/src/main/java/org/salespointframework/useraccount/SpringSecurityAuthenticationManagement.java
@@ -26,6 +26,7 @@
import org.salespointframework.useraccount.Password.EncryptedPassword;
import org.salespointframework.useraccount.Password.UnencryptedPassword;
+import org.salespointframework.useraccount.UserAccount.UserAccountIdentifier;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
@@ -60,7 +61,7 @@ public Optional getCurrentUser() {
return Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication()) //
.map(Authentication::getName) //
- .map(UserAccountIdentifier::new) //
+ .map(UserAccountIdentifier::of) //
.flatMap(repository::findById);
}
@@ -87,7 +88,7 @@ public UserDetails loadUserByUsername(String name) throws UsernameNotFoundExcept
Optional candidate = config.isLoginViaEmail() //
? repository.findByEmail(name) //
- : repository.findById(new UserAccountIdentifier(name));
+ : repository.findById(UserAccountIdentifier.of(name));
return new UserAccountDetails(
candidate.orElseThrow(() -> new UsernameNotFoundException("Useraccount: " + name + "not found")));
diff --git a/src/main/java/org/salespointframework/useraccount/UserAccount.java b/src/main/java/org/salespointframework/useraccount/UserAccount.java
index 881d8934..c39e5561 100644
--- a/src/main/java/org/salespointframework/useraccount/UserAccount.java
+++ b/src/main/java/org/salespointframework/useraccount/UserAccount.java
@@ -16,26 +16,32 @@
package org.salespointframework.useraccount;
import lombok.AccessLevel;
+import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
+import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.Value;
+import java.io.Serializable;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
-import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
+import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.PrePersist;
+import org.jmolecules.ddd.types.Identifier;
import org.jmolecules.event.types.DomainEvent;
import org.salespointframework.core.AbstractAggregateRoot;
import org.salespointframework.useraccount.Password.EncryptedPassword;
+import org.salespointframework.useraccount.UserAccount.UserAccountIdentifier;
import org.springframework.data.util.Streamable;
import org.springframework.util.Assert;
@@ -49,9 +55,7 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class UserAccount extends AbstractAggregateRoot {
- @EmbeddedId //
- @AttributeOverride(name = "id", column = @Column(name = "USERACCOUNT_ID")) //
- private UserAccountIdentifier userAccountIdentifier;
+ private @EmbeddedId UserAccountIdentifier id;
@Getter //
@Setter(AccessLevel.PACKAGE) //
@@ -83,7 +87,7 @@ public class UserAccount extends AbstractAggregateRoot {
Assert.notNull(roles, "Roles must not be null");
this.enabled = true;
- this.userAccountIdentifier = userAccountIdentifier;
+ this.id = userAccountIdentifier;
this.password = password;
this.firstname = firstname;
this.lastname = lastname;
@@ -98,7 +102,7 @@ public class UserAccount extends AbstractAggregateRoot {
*/
@Override
public UserAccountIdentifier getId() {
- return userAccountIdentifier;
+ return id;
}
/**
@@ -107,7 +111,7 @@ public UserAccountIdentifier getId() {
* @return will never be {@literal null}.
*/
public String getUsername() {
- return userAccountIdentifier.getIdentifier();
+ return id.toString();
}
/**
@@ -161,7 +165,36 @@ void onCreate() {
*/
@Override
public String toString() {
- return String.format("UserAccount(\"%s\")", userAccountIdentifier.getIdentifier());
+ return String.format("UserAccount(\"%s\")", id);
+ }
+
+ /**
+ * {@link UserAccountIdentifier} serves as an identifier type for {@link UserAccount} objects. The main reason for its
+ * existence is type safety for identifier across the Salespoint Framework.
+ * {@link UserAccountIdentifier} instances serve as primary key attribute in {@link UserAccount}, but can also be used
+ * as a key for non-persistent, {@link Map}-based implementations.
+ *
+ * @author Hannes Weisbach
+ * @author Oliver Gierke
+ */
+ @Embeddable
+ @EqualsAndHashCode
+ @RequiredArgsConstructor(staticName = "of")
+ @NoArgsConstructor(force = true, access = AccessLevel.PRIVATE)
+ public static class UserAccountIdentifier implements Identifier, Serializable {
+
+ private static final long serialVersionUID = -3010760283726584012L;
+
+ private final String userAccountId;
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return userAccountId;
+ }
}
@Value(staticConstructor = "of")
diff --git a/src/main/java/org/salespointframework/useraccount/UserAccountIdentifier.java b/src/main/java/org/salespointframework/useraccount/UserAccountIdentifier.java
deleted file mode 100755
index e8529d4a..00000000
--- a/src/main/java/org/salespointframework/useraccount/UserAccountIdentifier.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2017-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.salespointframework.useraccount;
-
-import java.util.Map;
-
-import javax.persistence.Embeddable;
-
-import org.salespointframework.core.SalespointIdentifier;
-
-/**
- * {@link UserAccountIdentifier} serves as an identifier type for {@link UserAccount} objects. The main reason for its
- * existence is type safety for identifier across the Salespoint Framework.
- * {@link UserAccountIdentifier} instances serve as primary key attribute in {@link UserAccount}, but can also be used
- * as a key for non-persistent, {@link Map}-based implementations.
- *
- * @author Hannes Weisbach
- * @author Oliver Gierke
- */
-@Embeddable
-public final class UserAccountIdentifier extends SalespointIdentifier {
-
- private static final long serialVersionUID = -5156469313158894803L;
-
- /**
- * Creates a new unique identifier for {@link UserAccount}s.
- */
- UserAccountIdentifier() {
- super();
- }
-
- /**
- * Creates a new identifier for {@link UserAccount}s. This self defined identifier is not guaranteed to be unique. But
- * you can provide a human readable value.
- *
- * @param userIdentifier The value of this identifier. Will not be checked to be unique.
- */
- UserAccountIdentifier(String userIdentifier) {
- super(userIdentifier);
- }
-}
diff --git a/src/main/java/org/salespointframework/useraccount/UserAccountManagement.java b/src/main/java/org/salespointframework/useraccount/UserAccountManagement.java
index 3e2f40b5..283b2a7a 100644
--- a/src/main/java/org/salespointframework/useraccount/UserAccountManagement.java
+++ b/src/main/java/org/salespointframework/useraccount/UserAccountManagement.java
@@ -18,6 +18,7 @@
import java.util.Optional;
import org.salespointframework.useraccount.Password.UnencryptedPassword;
+import org.salespointframework.useraccount.UserAccount.UserAccountIdentifier;
import org.springframework.data.util.Streamable;
import org.springframework.stereotype.Service;
diff --git a/src/main/java/org/salespointframework/useraccount/UserAccountRepository.java b/src/main/java/org/salespointframework/useraccount/UserAccountRepository.java
index 1a79d832..ffba5318 100644
--- a/src/main/java/org/salespointframework/useraccount/UserAccountRepository.java
+++ b/src/main/java/org/salespointframework/useraccount/UserAccountRepository.java
@@ -18,6 +18,7 @@
import java.util.Optional;
import org.salespointframework.core.SalespointRepository;
+import org.salespointframework.useraccount.UserAccount.UserAccountIdentifier;
import org.springframework.data.util.Streamable;
/**
diff --git a/src/test/java/example/EnableSalespointIntegrationTests.java b/src/test/java/example/EnableSalespointIntegrationTests.java
index 7840848c..06c64c51 100644
--- a/src/test/java/example/EnableSalespointIntegrationTests.java
+++ b/src/test/java/example/EnableSalespointIntegrationTests.java
@@ -23,7 +23,7 @@
import org.salespointframework.EnableSalespoint;
import org.salespointframework.catalog.Catalog;
import org.salespointframework.catalog.Product;
-import org.salespointframework.catalog.ProductIdentifier;
+import org.salespointframework.catalog.Product.ProductIdentifier;
import org.salespointframework.order.OrderLine;
import org.salespointframework.quantity.Quantity;
import org.salespointframework.useraccount.web.UserAccountWebTestUtils;
diff --git a/src/test/java/org/salespointframework/SalespointWebApplicationConfigurationTests.java b/src/test/java/org/salespointframework/SalespointWebApplicationConfigurationTests.java
index 5fa7ae26..90878a8b 100644
--- a/src/test/java/org/salespointframework/SalespointWebApplicationConfigurationTests.java
+++ b/src/test/java/org/salespointframework/SalespointWebApplicationConfigurationTests.java
@@ -19,7 +19,7 @@
import static org.hamcrest.junit.MatcherAssert.*;
import org.junit.jupiter.api.Test;
-import org.salespointframework.catalog.ProductIdentifier;
+import org.salespointframework.catalog.Product.ProductIdentifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.core.convert.ConversionService;
diff --git a/src/test/java/org/salespointframework/accountancy/AccountancyPeriodTests.java b/src/test/java/org/salespointframework/accountancy/AccountancyPeriodTests.java
index 00ae7e49..7782ddaf 100644
--- a/src/test/java/org/salespointframework/accountancy/AccountancyPeriodTests.java
+++ b/src/test/java/org/salespointframework/accountancy/AccountancyPeriodTests.java
@@ -24,7 +24,7 @@
import org.salespointframework.AbstractIntegrationTests;
import org.salespointframework.core.Currencies;
import org.salespointframework.order.Order;
-import org.salespointframework.order.OrderIdentifier;
+import org.salespointframework.order.Order.OrderIdentifier;
import org.salespointframework.payment.Cash;
import org.salespointframework.time.Interval;
import org.salespointframework.useraccount.UserAccount;
diff --git a/src/test/java/org/salespointframework/support/JpaEntityConverterIntegrationTests.java b/src/test/java/org/salespointframework/support/JpaEntityConverterIntegrationTests.java
index e83818f2..372a94fc 100644
--- a/src/test/java/org/salespointframework/support/JpaEntityConverterIntegrationTests.java
+++ b/src/test/java/org/salespointframework/support/JpaEntityConverterIntegrationTests.java
@@ -25,6 +25,7 @@
import org.salespointframework.catalog.Product;
import org.salespointframework.core.Currencies;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.transaction.annotation.Transactional;
@@ -42,12 +43,13 @@ class JpaEntityConverterIntegrationTests {
@Autowired JpaEntityConverter converter;
@Autowired Catalog catalog;
+ @Autowired ApplicationContext context;
@Test
void convertsStringIdToProduct() {
Product product = catalog.save(new Product("iPad", Money.of(400, Currencies.EURO)));
- String identifier = product.getId().getIdentifier();
+ String identifier = product.getId().toString();
assertThat(converter.convert(identifier, STRING_TYPE, PRODUCT_TYPE), is((Object) product));
}
diff --git a/src/test/java/org/salespointframework/support/SalespointIdentifierConverterUnitTests.java b/src/test/java/org/salespointframework/support/SalespointIdentifierConverterUnitTests.java
deleted file mode 100644
index af1db522..00000000
--- a/src/test/java/org/salespointframework/support/SalespointIdentifierConverterUnitTests.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2017-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.salespointframework.support;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.hamcrest.junit.MatcherAssert.*;
-
-import org.junit.jupiter.api.Test;
-import org.salespointframework.catalog.ProductIdentifier;
-import org.salespointframework.core.SalespointIdentifier;
-import org.springframework.core.convert.TypeDescriptor;
-
-/**
- * Units tests for {@link SalespointIdentifierConverter}.
- *
- * @author Oliver Gierke
- */
-class SalespointIdentifierConverterUnitTests {
-
- private static final TypeDescriptor PRODUCT_IDENTIFIER_DESCRIPTOR = TypeDescriptor.valueOf(ProductIdentifier.class);
- private static final TypeDescriptor STRING_DESCRIPTOR = TypeDescriptor.valueOf(String.class);
- private static final TypeDescriptor OBJECT_DESCRIPTOR = TypeDescriptor.valueOf(Object.class);
-
- SalespointIdentifierConverter converter = new SalespointIdentifierConverter();
-
- @Test
- void matchesForStringSourceSalespointIdentifierTarget() {
- assertThat(converter.matches(STRING_DESCRIPTOR, PRODUCT_IDENTIFIER_DESCRIPTOR), is(true));
- }
-
- @Test
- void doesNotMatchForNonStringSource() {
- assertThat(converter.matches(OBJECT_DESCRIPTOR, PRODUCT_IDENTIFIER_DESCRIPTOR), is(false));
- }
-
- @Test
- void doesNotMatchForNonSalespointIdentifierTarget() {
- assertThat(converter.matches(STRING_DESCRIPTOR, OBJECT_DESCRIPTOR), is(false));
- }
-
- @Test
- void convertsStringToProductIdentifier() {
-
- SalespointIdentifier result = converter.convert("5", STRING_DESCRIPTOR, PRODUCT_IDENTIFIER_DESCRIPTOR);
-
- assertThat(result, is(instanceOf(ProductIdentifier.class)));
- assertThat(result.getIdentifier(), is("5"));
- }
-
- @Test // #46
- void createsIdentifierInstanceFromPrivateConstructor() {
-
- Object result = converter.convert("5", STRING_DESCRIPTOR, TypeDescriptor.valueOf(MySalespointIdentifier.class));
- assertThat(result, is(instanceOf(MySalespointIdentifier.class)));
- }
-
- static class MySalespointIdentifier extends SalespointIdentifier {
-
- private static final long serialVersionUID = 1419011598975206455L;
-
- MySalespointIdentifier() {
- super();
- }
-
- MySalespointIdentifier(String id) {
- super(id);
- }
- }
-}
diff --git a/src/test/java/org/salespointframework/useraccount/SpringSecurityAuthenticationManagerUnitTests.java b/src/test/java/org/salespointframework/useraccount/SpringSecurityAuthenticationManagerUnitTests.java
index 203fed1d..709f515e 100644
--- a/src/test/java/org/salespointframework/useraccount/SpringSecurityAuthenticationManagerUnitTests.java
+++ b/src/test/java/org/salespointframework/useraccount/SpringSecurityAuthenticationManagerUnitTests.java
@@ -33,6 +33,7 @@
import org.salespointframework.useraccount.Password.EncryptedPassword;
import org.salespointframework.useraccount.Password.UnencryptedPassword;
import org.salespointframework.useraccount.SpringSecurityAuthenticationManagement.UserAccountDetails;
+import org.salespointframework.useraccount.UserAccount.UserAccountIdentifier;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
@@ -101,7 +102,8 @@ void delegatesPasswordMatchCorrectly() {
@Test // #222
void usesByEmailLookupIfConfigured() {
- SpringSecurityAuthenticationManagement authenticationManager = new SpringSecurityAuthenticationManagement(repository,
+ SpringSecurityAuthenticationManagement authenticationManager = new SpringSecurityAuthenticationManagement(
+ repository,
passwordEncoder, new AuthenticationProperties(true));
doReturn(Optional.of(account)).when(repository).findByEmail(any());
@@ -118,7 +120,7 @@ void exposesRolesAsRoleUnderscorePrefixedAuthorities() {
Role customerRole = Role.of("CUSTOMER");
Role adminRole = Role.of("ROLE_ADMIN");
- UserAccountIdentifier identifier = new UserAccountIdentifier("4711");
+ UserAccountIdentifier identifier = UserAccountIdentifier.of("4711");
var userAccount = new UserAccount(identifier, EncryptedPassword.of("encrypted"), customerRole, adminRole);
doReturn(Optional.of(userAccount)).when(repository).findById(identifier);
diff --git a/src/test/java/org/salespointframework/useraccount/UserAccountRepositoryIntegrationTests.java b/src/test/java/org/salespointframework/useraccount/UserAccountRepositoryIntegrationTests.java
index 772bd1a6..b7515d14 100644
--- a/src/test/java/org/salespointframework/useraccount/UserAccountRepositoryIntegrationTests.java
+++ b/src/test/java/org/salespointframework/useraccount/UserAccountRepositoryIntegrationTests.java
@@ -23,6 +23,7 @@
import org.junit.jupiter.api.Test;
import org.moduliths.test.ModuleTest;
import org.salespointframework.useraccount.Password.EncryptedPassword;
+import org.salespointframework.useraccount.UserAccount.UserAccountIdentifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.transaction.annotation.Transactional;
@@ -75,7 +76,7 @@ void rejectsUserAccountWithSameUsername() {
@Test // #222
void looksUpUserViaEmail() {
- UserAccount account = new UserAccount(new UserAccountIdentifier("username"), PASSWORD);
+ UserAccount account = new UserAccount(UserAccountIdentifier.of("username"), PASSWORD);
account.setEmail("foo@bar.com");
UserAccount reference = repository.save(account);
@@ -113,7 +114,7 @@ static UserAccount createAccount() {
static UserAccount createAccount(EncryptedPassword encryptedPassword) {
- UserAccountIdentifier identifier = new UserAccountIdentifier(UUID.randomUUID().toString());
+ UserAccountIdentifier identifier = UserAccountIdentifier.of(UUID.randomUUID().toString());
return new UserAccount(identifier, encryptedPassword, Role.of("USER"));
}
}
diff --git a/src/test/java/org/salespointframework/useraccount/UserAccountTestUtils.java b/src/test/java/org/salespointframework/useraccount/UserAccountTestUtils.java
index 62b70402..a9d55d50 100644
--- a/src/test/java/org/salespointframework/useraccount/UserAccountTestUtils.java
+++ b/src/test/java/org/salespointframework/useraccount/UserAccountTestUtils.java
@@ -19,6 +19,7 @@
import org.salespointframework.useraccount.Password.EncryptedPassword;
import org.salespointframework.useraccount.Password.UnencryptedPassword;
+import org.salespointframework.useraccount.UserAccount.UserAccountIdentifier;
/**
* Testing utilities when working with {@link UserAccount}s.
@@ -39,6 +40,6 @@ public class UserAccountTestUtils {
* @return
*/
public static UserAccount createUserAccount() {
- return new UserAccount(new UserAccountIdentifier(), ENCRYPTED_PASSWORD);
+ return new UserAccount(UserAccountIdentifier.of("4711"), ENCRYPTED_PASSWORD);
}
}