Skip to content

Commit

Permalink
#377 - Improved identifier arrangements for entities.
Browse files Browse the repository at this point in the history
We now use simple Identifier implementations for identifiers. Moved the identifiers into the corresponding entities.
  • Loading branch information
odrotbohm committed Dec 1, 2021
1 parent dbe5cd1 commit f2cebf3
Show file tree
Hide file tree
Showing 46 changed files with 375 additions and 679 deletions.
25 changes: 23 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<properties>
<dev>/dev</dev>
<java.version>11</java.version>
<jmolecules.version>1.3.0</jmolecules.version>
<jmolecules.version>2021.1.0</jmolecules.version>
<moduliths.version>1.2.1</moduliths.version>
<refdocs.dir>${project.build.directory}/refdocs</refdocs.dir>
</properties>
Expand Down Expand Up @@ -153,6 +153,18 @@
</build>
</profile>
</profiles>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>jmolecules-bom</artifactId>
<version>${jmolecules.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

Expand Down Expand Up @@ -276,10 +288,19 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>jmolecules-ddd</artifactId>
</dependency>

<dependency>
<groupId>org.jmolecules</groupId>
<artifactId>jmolecules-events</artifactId>
<version>${jmolecules.version}</version>
</dependency>

<dependency>
<groupId>org.jmolecules.integrations</groupId>
<artifactId>jmolecules-spring</artifactId>
</dependency>

<!-- Documentation -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -47,8 +53,8 @@
@NoArgsConstructor(force = true, access = AccessLevel.PROTECTED, onConstructor = @__(@Deprecated))
public class AccountancyEntry extends AbstractEntity<AccountancyEntryIdentifier> {

@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;
Expand Down Expand Up @@ -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. <br />
* {@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;
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/salespointframework/catalog/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
47 changes: 40 additions & 7 deletions src/main/java/org/salespointframework/catalog/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,9 +59,7 @@ public class Product extends AbstractAggregateRoot<ProductIdentifier> 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<String> categories = new HashSet<String>();
Expand Down Expand Up @@ -95,7 +99,7 @@ public Product(String name, MonetaryAmount price, Metric metric) {
*/
@Override
public ProductIdentifier getId() {
return productIdentifier;
return id;
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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. <br />
* {@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;
}
}
}
Loading

0 comments on commit f2cebf3

Please sign in to comment.