From f2cebf3eb5ae0e160adc4f3f48d852625fa87bce Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Wed, 1 Dec 2021 21:59:44 +0100 Subject: [PATCH] #377 - Improved identifier arrangements for entities. We now use simple Identifier implementations for identifiers. Moved the identifiers into the corresponding entities. --- pom.xml | 25 +++++- .../accountancy/Accountancy.java | 1 + .../accountancy/AccountancyEntry.java | 43 +++++++++- .../AccountancyEntryIdentifier.java | 53 ------------ .../AccountancyEntryRepository.java | 1 + .../accountancy/PersistentAccountancy.java | 1 + .../accountancy/ProductPaymentEntry.java | 12 +-- .../salespointframework/catalog/Catalog.java | 1 + .../salespointframework/catalog/Product.java | 47 +++++++++-- .../catalog/ProductIdentifier.java | 53 ------------ .../core/AbstractAggregateRoot.java | 3 +- .../core/AbstractEntity.java | 3 +- .../core/SalespointIdentifier.java | 60 -------------- .../core/SalespointRepository.java | 3 +- .../inventory/Inventory.java | 2 +- .../inventory/InventoryEvents.java | 2 +- .../inventory/InventoryItem.java | 46 +++++++++-- .../inventory/InventoryItemIdentifier.java | 51 ------------ .../inventory/LineItemFilter.java | 1 + .../inventory/MultiInventory.java | 3 +- .../inventory/UniqueInventory.java | 3 +- .../salespointframework/order/ChargeLine.java | 42 +++++++--- .../order/ChargeLineIdentifier.java | 50 ----------- .../org/salespointframework/order/Order.java | 41 +++++++++- .../order/OrderIdentifier.java | 52 ------------ .../salespointframework/order/OrderLine.java | 74 ++++++++++++----- .../order/OrderLineIdentifier.java | 53 ------------ .../order/OrderManagement.java | 1 + .../order/OrderRepository.java | 1 + .../order/PersistentOrderManagement.java | 1 + .../support/JpaEntityConverter.java | 29 +++++-- .../SalespointIdentifierConverter.java | 75 ----------------- .../PersistentUserAccountManagement.java | 5 +- ...pringSecurityAuthenticationManagement.java | 5 +- .../useraccount/UserAccount.java | 49 +++++++++-- .../useraccount/UserAccountIdentifier.java | 54 ------------ .../useraccount/UserAccountManagement.java | 1 + .../useraccount/UserAccountRepository.java | 1 + .../EnableSalespointIntegrationTests.java | 2 +- ...pointWebApplicationConfigurationTests.java | 2 +- .../accountancy/AccountancyPeriodTests.java | 2 +- .../JpaEntityConverterIntegrationTests.java | 4 +- ...alespointIdentifierConverterUnitTests.java | 82 ------------------- ...ecurityAuthenticationManagerUnitTests.java | 6 +- ...UserAccountRepositoryIntegrationTests.java | 5 +- .../useraccount/UserAccountTestUtils.java | 3 +- 46 files changed, 375 insertions(+), 679 deletions(-) delete mode 100755 src/main/java/org/salespointframework/accountancy/AccountancyEntryIdentifier.java delete mode 100755 src/main/java/org/salespointframework/catalog/ProductIdentifier.java delete mode 100755 src/main/java/org/salespointframework/core/SalespointIdentifier.java delete mode 100755 src/main/java/org/salespointframework/inventory/InventoryItemIdentifier.java delete mode 100755 src/main/java/org/salespointframework/order/ChargeLineIdentifier.java delete mode 100755 src/main/java/org/salespointframework/order/OrderIdentifier.java delete mode 100755 src/main/java/org/salespointframework/order/OrderLineIdentifier.java delete mode 100644 src/main/java/org/salespointframework/support/SalespointIdentifierConverter.java delete mode 100755 src/main/java/org/salespointframework/useraccount/UserAccountIdentifier.java delete mode 100644 src/test/java/org/salespointframework/support/SalespointIdentifierConverterUnitTests.java diff --git a/pom.xml b/pom.xml index 69956146..74f9e24a 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ /dev 11 - 1.3.0 + 2021.1.0 1.2.1 ${project.build.directory}/refdocs @@ -153,6 +153,18 @@ + + + + + org.jmolecules + jmolecules-bom + ${jmolecules.version} + import + pom + + + @@ -276,10 +288,19 @@ test + + org.jmolecules + jmolecules-ddd + + org.jmolecules jmolecules-events - ${jmolecules.version} + + + + org.jmolecules.integrations + jmolecules-spring diff --git a/src/main/java/org/salespointframework/accountancy/Accountancy.java b/src/main/java/org/salespointframework/accountancy/Accountancy.java index 33feca8e..ec9f7217 100755 --- a/src/main/java/org/salespointframework/accountancy/Accountancy.java +++ b/src/main/java/org/salespointframework/accountancy/Accountancy.java @@ -22,6 +22,7 @@ import javax.money.MonetaryAmount; +import org.salespointframework.accountancy.AccountancyEntry.AccountancyEntryIdentifier; import org.salespointframework.time.BusinessTime; import org.salespointframework.time.Interval; import org.springframework.data.util.Streamable; diff --git a/src/main/java/org/salespointframework/accountancy/AccountancyEntry.java b/src/main/java/org/salespointframework/accountancy/AccountancyEntry.java index af219f29..210a763f 100755 --- a/src/main/java/org/salespointframework/accountancy/AccountancyEntry.java +++ b/src/main/java/org/salespointframework/accountancy/AccountancyEntry.java @@ -16,22 +16,28 @@ package org.salespointframework.accountancy; 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.Date; +import java.util.Map; import java.util.Optional; +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.PrePersist; +import org.jmolecules.ddd.types.Identifier; +import org.salespointframework.accountancy.AccountancyEntry.AccountancyEntryIdentifier; import org.salespointframework.core.AbstractEntity; import org.springframework.util.Assert; @@ -47,8 +53,8 @@ @NoArgsConstructor(force = true, access = AccessLevel.PROTECTED, onConstructor = @__(@Deprecated)) public class AccountancyEntry extends AbstractEntity { - @EmbeddedId @AttributeOverride(name = "id", column = @Column(name = "ENTRY_ID", nullable = false)) // - private AccountancyEntryIdentifier accountancyEntryIdentifier = new AccountancyEntryIdentifier(); + private @EmbeddedId AccountancyEntryIdentifier accountancyEntryIdentifier = AccountancyEntryIdentifier + .of(UUID.randomUUID().toString()); private @Getter MonetaryAmount value; private @Setter(AccessLevel.PACKAGE) LocalDateTime date = null; @@ -132,4 +138,33 @@ void verifyConstraints() { Assert.state(value != null, "No value set! Make sure you have created the accountancy entry by calling a non-default constructor!"); } + + /** + * {@link AccountancyEntryIdentifier} serves as an identifier type for {@link AccountancyEntry} objects. The main + * reason for its existence is type safety for identifier across the Salespoint Framework.
+ * {@link AccountancyEntryIdentifier} instances serve as primary key attribute in {@link PersistentAccountancyEntry} , + * 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 AccountancyEntryIdentifier implements Identifier, Serializable { + + private static final long serialVersionUID = -7802218428666489137L; + + private final String accountancyEntryId; + + /* + * (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return accountancyEntryId; + } + } } diff --git a/src/main/java/org/salespointframework/accountancy/AccountancyEntryIdentifier.java b/src/main/java/org/salespointframework/accountancy/AccountancyEntryIdentifier.java deleted file mode 100755 index 1ff56cef..00000000 --- a/src/main/java/org/salespointframework/accountancy/AccountancyEntryIdentifier.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.accountancy; - -import java.util.Map; - -import javax.persistence.Embeddable; - -import org.salespointframework.core.SalespointIdentifier; - -/** - * {@link AccountancyEntryIdentifier} serves as an identifier type for {@link AccountancyEntry} objects. The main reason - * for its existence is type safety for identifier across the Salespoint Framework.
- * {@link AccountancyEntryIdentifier} instances serve as primary key attribute in {@link PersistentAccountancyEntry} , - * 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 AccountancyEntryIdentifier extends SalespointIdentifier { - - private static final long serialVersionUID = 1767274605223942263L; - - /** - * Creates a new unique identifier for accountancy entries. - */ - AccountancyEntryIdentifier() { - super(); - } - - /** - * Only needed for property editor, shouldn't be used otherwise. - * - * @param identifier The string representation of the identifier. - */ - AccountancyEntryIdentifier(String identifier) { - super(identifier); - } -} diff --git a/src/main/java/org/salespointframework/accountancy/AccountancyEntryRepository.java b/src/main/java/org/salespointframework/accountancy/AccountancyEntryRepository.java index 78896b36..ae7d1557 100644 --- a/src/main/java/org/salespointframework/accountancy/AccountancyEntryRepository.java +++ b/src/main/java/org/salespointframework/accountancy/AccountancyEntryRepository.java @@ -17,6 +17,7 @@ import java.time.LocalDateTime; +import org.salespointframework.accountancy.AccountancyEntry.AccountancyEntryIdentifier; import org.salespointframework.core.SalespointRepository; import org.salespointframework.time.Interval; import org.springframework.data.util.Streamable; diff --git a/src/main/java/org/salespointframework/accountancy/PersistentAccountancy.java b/src/main/java/org/salespointframework/accountancy/PersistentAccountancy.java index cad03ec6..3645fc52 100755 --- a/src/main/java/org/salespointframework/accountancy/PersistentAccountancy.java +++ b/src/main/java/org/salespointframework/accountancy/PersistentAccountancy.java @@ -29,6 +29,7 @@ import javax.money.MonetaryAmount; import org.javamoney.moneta.Money; +import org.salespointframework.accountancy.AccountancyEntry.AccountancyEntryIdentifier; import org.salespointframework.core.Currencies; import org.salespointframework.time.BusinessTime; import org.salespointframework.time.Interval; diff --git a/src/main/java/org/salespointframework/accountancy/ProductPaymentEntry.java b/src/main/java/org/salespointframework/accountancy/ProductPaymentEntry.java index 1419cb08..b75103f7 100755 --- a/src/main/java/org/salespointframework/accountancy/ProductPaymentEntry.java +++ b/src/main/java/org/salespointframework/accountancy/ProductPaymentEntry.java @@ -30,15 +30,15 @@ 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.PaymentMethod; import org.salespointframework.useraccount.UserAccount; -import org.salespointframework.useraccount.UserAccountIdentifier; +import org.salespointframework.useraccount.UserAccount.UserAccountIdentifier; import org.springframework.util.Assert; /** * A {@link ProductPaymentEntry} is used to store information of payments of orders. - * + * * @author Hannes Weisbach * @author Thomas Dedek * @author Oliver Gierke @@ -75,7 +75,7 @@ public static ProductPaymentEntry of(Order order, String description) { /** * Creates a new {@link ProductPaymentEntry} that rolls back the payment for the given {@link Order}. - * + * * @param order must not be {@literal null}. * @param description must not be {@literal null}. * @return @@ -95,7 +95,7 @@ public static ProductPaymentEntry rollback(Order order, String description) { /** * A {@code ProductPaymentEntry} is constructed for a specific {@link OrderIdentifier} attached to it. This entry * saves also the {@link UserAccountIdentifier} and the specified amount that was paid. - * + * * @param orderIdentifier the {@link OrderIdentifier} to which this {@link ProductPaymentEntry} will refer to, must * not be {@literal null}. * @param userAccount the {@link UserAccount} to which this {@link ProductPaymentEntry} will refer to, must not be @@ -120,7 +120,7 @@ public ProductPaymentEntry(OrderIdentifier orderIdentifier, UserAccount userAcco /** * Returns whether the {@link ProductPaymentEntry} belongs to the given {@link Order}. - * + * * @param order must not be {@literal null}. * @return */ diff --git a/src/main/java/org/salespointframework/catalog/Catalog.java b/src/main/java/org/salespointframework/catalog/Catalog.java index 92877df5..925d8764 100644 --- a/src/main/java/org/salespointframework/catalog/Catalog.java +++ b/src/main/java/org/salespointframework/catalog/Catalog.java @@ -18,6 +18,7 @@ import java.util.Arrays; import java.util.Collection; +import org.salespointframework.catalog.Product.ProductIdentifier; import org.salespointframework.core.SalespointRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.util.Streamable; diff --git a/src/main/java/org/salespointframework/catalog/Product.java b/src/main/java/org/salespointframework/catalog/Product.java index 00243c4a..82e2971b 100755 --- a/src/main/java/org/salespointframework/catalog/Product.java +++ b/src/main/java/org/salespointframework/catalog/Product.java @@ -16,24 +16,30 @@ package org.salespointframework.catalog; import lombok.AccessLevel; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.NonNull; +import lombok.RequiredArgsConstructor; import lombok.Setter; +import java.io.Serializable; import java.util.Collections; import java.util.HashSet; +import java.util.Map; import java.util.Set; +import java.util.UUID; import javax.money.MonetaryAmount; -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.salespointframework.catalog.Product.ProductIdentifier; import org.salespointframework.core.AbstractAggregateRoot; import org.salespointframework.quantity.Metric; import org.salespointframework.quantity.MetricMismatchException; @@ -53,9 +59,7 @@ public class Product extends AbstractAggregateRoot implements private static final String INVALID_METRIC = "Product %s does not support quantity %s using metric %s!"; - @EmbeddedId // - @AttributeOverride(name = "id", column = @Column(name = "PRODUCT_ID")) // - private ProductIdentifier productIdentifier = new ProductIdentifier(); + private @EmbeddedId ProductIdentifier id = ProductIdentifier.of(UUID.randomUUID().toString()); private @NonNull @Getter @Setter String name; private @NonNull @Getter @Setter MonetaryAmount price; private @ElementCollection(fetch = FetchType.EAGER) Set categories = new HashSet(); @@ -95,7 +99,7 @@ public Product(String name, MonetaryAmount price, Metric metric) { */ @Override public ProductIdentifier getId() { - return productIdentifier; + return id; } /** @@ -185,7 +189,7 @@ public int compareTo(Product other) { */ @Override public String toString() { - return String.format("%s, %s, %s, handled in %s", name, productIdentifier, price, metric); + return String.format("%s, %s, %s, handled in %s", name, id, price, metric); } /** @@ -198,4 +202,33 @@ void verifyConstraints() { Assert.state(metric != null, "No metric set! Make sure you have created the product by calling a non-default constructor!"); } + + /** + * {link ProductIdentifier} serves as an identifier type for {@link Product} objects. The main reason for its + * existence is type safety for identifier across the Salespoint Framework.
+ * {@link ProductIdentifier} instances serve as primary key attribute in {@link Product}, but can also be used as a + * key for non-persistent, {@link Map}-based implementations. + * + * @author Paul Henke + * @author Oliver Gierke + */ + @Embeddable + @EqualsAndHashCode + @RequiredArgsConstructor(staticName = "of") + @NoArgsConstructor(force = true, access = AccessLevel.PRIVATE) + public static class ProductIdentifier implements Identifier, Serializable { + + private static final long serialVersionUID = 67875667760921725L; + + private final String productId; + + /* + * (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return productId; + } + } } diff --git a/src/main/java/org/salespointframework/catalog/ProductIdentifier.java b/src/main/java/org/salespointframework/catalog/ProductIdentifier.java deleted file mode 100755 index 5240e2a9..00000000 --- a/src/main/java/org/salespointframework/catalog/ProductIdentifier.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.catalog; - -import java.util.Map; - -import javax.persistence.Embeddable; - -import org.salespointframework.core.SalespointIdentifier; - -/** - * {link ProductIdentifier} serves as an identifier type for {@link Product} objects. The main reason for its existence - * is type safety for identifier across the Salespoint Framework.
- * {@link ProductIdentifier} instances serve as primary key attribute in {@link Product}, but can also be used as a key - * for non-persistent, {@link Map}-based implementations. - * - * @author Paul Henke - * @author Oliver Gierke - */ -@Embeddable -public final class ProductIdentifier extends SalespointIdentifier { - - private static final long serialVersionUID = 7740660930809051850L; - - /** - * Creates a new unique identifier for {@link Product}s. - */ - ProductIdentifier() { - super(); - } - - /** - * Only needed for property editor, shouldn't be used otherwise. - * - * @param productIdentifier The string representation of the identifier. - */ - ProductIdentifier(String productIdentifier) { - super(productIdentifier); - } -} diff --git a/src/main/java/org/salespointframework/core/AbstractAggregateRoot.java b/src/main/java/org/salespointframework/core/AbstractAggregateRoot.java index f8fc533e..71c8c03f 100644 --- a/src/main/java/org/salespointframework/core/AbstractAggregateRoot.java +++ b/src/main/java/org/salespointframework/core/AbstractAggregateRoot.java @@ -21,6 +21,7 @@ import javax.persistence.MappedSuperclass; +import org.jmolecules.ddd.types.Identifier; import org.springframework.data.domain.AfterDomainEventPublication; import org.springframework.data.domain.DomainEvents; import org.springframework.data.repository.CrudRepository; @@ -38,7 +39,7 @@ * @soundtrack Dave Matthews Band - #41 (Live at Hollywood Bowl) */ @MappedSuperclass -public abstract class AbstractAggregateRoot extends AbstractEntity { +public abstract class AbstractAggregateRoot extends AbstractEntity { private transient final Collection events = new ArrayList<>(); diff --git a/src/main/java/org/salespointframework/core/AbstractEntity.java b/src/main/java/org/salespointframework/core/AbstractEntity.java index 07c685ef..e9b14349 100644 --- a/src/main/java/org/salespointframework/core/AbstractEntity.java +++ b/src/main/java/org/salespointframework/core/AbstractEntity.java @@ -20,6 +20,7 @@ import javax.persistence.PrePersist; import javax.persistence.Transient; +import org.jmolecules.ddd.types.Identifier; import org.springframework.data.domain.Persistable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -30,7 +31,7 @@ * @author Oliver Gierke */ @MappedSuperclass -public abstract class AbstractEntity implements Persistable { +public abstract class AbstractEntity implements Persistable { private @Transient boolean isNew = true; diff --git a/src/main/java/org/salespointframework/core/SalespointIdentifier.java b/src/main/java/org/salespointframework/core/SalespointIdentifier.java deleted file mode 100755 index 24bb8a4f..00000000 --- a/src/main/java/org/salespointframework/core/SalespointIdentifier.java +++ /dev/null @@ -1,60 +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.core; - -import lombok.EqualsAndHashCode; -import lombok.RequiredArgsConstructor; - -import java.io.Serializable; -import java.util.UUID; - -import javax.persistence.Access; -import javax.persistence.AccessType; -import javax.persistence.Column; -import javax.persistence.MappedSuperclass; - -/** - * @author Hannes Weisbach - * @author Thomas Dedek - * @author Oliver Gierke - */ -@MappedSuperclass -@Access(AccessType.FIELD) -@RequiredArgsConstructor -@EqualsAndHashCode -public class SalespointIdentifier implements Serializable { - - private static final long serialVersionUID = -859038278950680970L; - - private final @Column(unique = true) String id; - - public SalespointIdentifier() { - this.id = UUID.randomUUID().toString(); - } - - public String getIdentifier() { - return id; - } - - /* - * (non-Javadoc) - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return id; - } -} diff --git a/src/main/java/org/salespointframework/core/SalespointRepository.java b/src/main/java/org/salespointframework/core/SalespointRepository.java index 28ab77ca..262eae3d 100644 --- a/src/main/java/org/salespointframework/core/SalespointRepository.java +++ b/src/main/java/org/salespointframework/core/SalespointRepository.java @@ -15,6 +15,7 @@ */ package org.salespointframework.core; +import org.jmolecules.ddd.types.Identifier; import org.springframework.data.domain.Sort; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.NoRepositoryBean; @@ -29,7 +30,7 @@ * @since 7.3 */ @NoRepositoryBean -public interface SalespointRepository extends PagingAndSortingRepository { +public interface SalespointRepository extends PagingAndSortingRepository { /** * Re-declaration of {@link CrudRepository#findAll()} to return {@link Streamable} instead of {@link Iterable} for diff --git a/src/main/java/org/salespointframework/inventory/Inventory.java b/src/main/java/org/salespointframework/inventory/Inventory.java index e911f737..0b46e155 100644 --- a/src/main/java/org/salespointframework/inventory/Inventory.java +++ b/src/main/java/org/salespointframework/inventory/Inventory.java @@ -16,7 +16,7 @@ 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.quantity.Quantity; import org.springframework.data.jpa.repository.Query; diff --git a/src/main/java/org/salespointframework/inventory/InventoryEvents.java b/src/main/java/org/salespointframework/inventory/InventoryEvents.java index d9c2747c..bf594cb1 100644 --- a/src/main/java/org/salespointframework/inventory/InventoryEvents.java +++ b/src/main/java/org/salespointframework/inventory/InventoryEvents.java @@ -22,7 +22,7 @@ import org.jmolecules.event.types.DomainEvent; import org.salespointframework.catalog.Product; -import org.salespointframework.catalog.ProductIdentifier; +import org.salespointframework.catalog.Product.ProductIdentifier; import org.salespointframework.quantity.Quantity; /** diff --git a/src/main/java/org/salespointframework/inventory/InventoryItem.java b/src/main/java/org/salespointframework/inventory/InventoryItem.java index e5907b53..c5d82ba6 100644 --- a/src/main/java/org/salespointframework/inventory/InventoryItem.java +++ b/src/main/java/org/salespointframework/inventory/InventoryItem.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,19 +16,25 @@ package org.salespointframework.inventory; import lombok.AccessLevel; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.RequiredArgsConstructor; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; +import java.io.Serializable; +import java.util.UUID; + +import javax.persistence.Embeddable; import javax.persistence.EmbeddedId; import javax.persistence.EntityListeners; import javax.persistence.MappedSuperclass; import javax.persistence.PrePersist; +import org.jmolecules.ddd.types.Identifier; import org.salespointframework.catalog.Product; import org.salespointframework.core.AbstractAggregateRoot; import org.salespointframework.inventory.InventoryEvents.QuantityReduced; +import org.salespointframework.inventory.InventoryItem.InventoryItemIdentifier; import org.salespointframework.quantity.Quantity; import org.springframework.util.Assert; @@ -48,9 +54,8 @@ @EntityListeners(InventoryItemCreationListener.class) public abstract class InventoryItem> extends AbstractAggregateRoot { - @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); } }