Skip to content

Commit

Permalink
#328 - Renamed …Manager types to …Management.
Browse files Browse the repository at this point in the history
Removed deprecations and quite a few cleanups in test cases.
  • Loading branch information
odrotbohm committed Sep 24, 2020
1 parent 6755f77 commit ff9d072
Show file tree
Hide file tree
Showing 31 changed files with 295 additions and 376 deletions.
1 change: 1 addition & 0 deletions lombok.config
@@ -1,3 +1,4 @@
lombok.nonNull.exceptionType = IllegalArgumentException
lombok.log.fieldName = LOG
lombok.addLombokGeneratedAnnotation = true
lombok.accessors.chain=true
6 changes: 3 additions & 3 deletions src/main/asciidoc/salespoint-reference.adoc
Expand Up @@ -394,11 +394,11 @@ Completed -> Cancelled : cancel()
These events are then used by other business modules to act on them.
Currently, the following events are exposed:

* `OrderPaid` -- the event being thrown if the order gets paid, usually through a call to `OrderManager.pay(…)`. The <<modules.accountancy>> module makes use of those events as described in <<modules.accountancy.events>>.
* `OrderCompleted` -- the event being thrown when the `Order` is about to be completed, usually through a call to `OrderManager.completeOrder(…)`.
* `OrderPaid` -- the event being thrown if the order gets paid, usually through a call to `OrderManagement.pay(…)`. The <<modules.accountancy>> module makes use of those events as described in <<modules.accountancy.events>>.
* `OrderCompleted` -- the event being thrown when the `Order` is about to be completed, usually through a call to `OrderManagement.completeOrder(…)`.
The <<modules.inventory>> module ships with a listener for the `OrderCompleted` event to update the inventory and reduce the stock of ordered items.
See <<modules.inventory.events>> for details.
* `OrderCancelled` -- the event being thrown when an `Order` was cancelled, usually through `OrderManager.cancelOrder(…)`. <<modules.accountancy>> will react by creating a new `AccountancyEntry` that compensates for the revenue entry created for the `OrderPaid` event. <<modules.inventory>> will restore the previously subtracted stock if the order had been cancelled already.
* `OrderCanceled` -- the event being thrown when an `Order` was canceled, usually through `OrderManagement.cancelOrder(…)`. <<modules.accountancy>> will react by creating a new `AccountancyEntry` that compensates for the revenue entry created for the `OrderPaid` event. <<modules.inventory>> will restore the previously subtracted stock if the order had been cancelled already.

[[modules.order.handling-events]]
==== Handling events
Expand Down
Expand Up @@ -19,7 +19,7 @@
import lombok.RequiredArgsConstructor;

import org.salespointframework.order.Order;
import org.salespointframework.order.Order.OrderCancelled;
import org.salespointframework.order.Order.OrderCanceled;
import org.salespointframework.order.Order.OrderCompleted;
import org.salespointframework.order.Order.OrderPaid;
import org.springframework.context.ApplicationListener;
Expand Down Expand Up @@ -59,7 +59,7 @@ public void on(OrderPaid event) {
* @since 7.1
*/
@EventListener
public void on(OrderCancelled event) {
public void on(OrderCanceled event) {

Order order = event.getOrder();

Expand Down
Expand Up @@ -25,7 +25,7 @@

import org.salespointframework.catalog.Product;
import org.salespointframework.order.Order;
import org.salespointframework.order.Order.OrderCancelled;
import org.salespointframework.order.Order.OrderCanceled;
import org.salespointframework.order.Order.OrderCompleted;
import org.salespointframework.order.OrderCompletionFailure;
import org.salespointframework.order.OrderCompletionReport;
Expand Down Expand Up @@ -87,7 +87,7 @@ public void on(OrderCompleted event) throws OrderCompletionFailure {
* @param event must not be {@literal null}.
*/
@EventListener
public void on(OrderCancelled event) {
public void on(OrderCanceled event) {

var order = event.getOrder();

Expand Down
24 changes: 12 additions & 12 deletions src/main/java/org/salespointframework/order/Cart.java
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2020 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.
Expand Down Expand Up @@ -44,7 +44,7 @@ public class Cart implements Streamable<CartItem>, Priced {
* Creates a {@link CartItem} for the given {@link Product} and {@link Quantity}. If a {@link CartItem} for the given
* {@link Product} already exists the {@link Cart} will be updated to reflect the combined {@link Quantity} for the
* backing {@link CartItem}.
*
*
* @param product must not be {@literal null}
* @param quantity must not be {@literal null}
* @return The created {@link CartItem}.
Expand All @@ -64,7 +64,7 @@ public CartItem addOrUpdateItem(Product product, Quantity quantity) {
* Creates a {@link CartItem} for the given {@link Product} and amount. If a {@link CartItem} for the given
* {@link Product} already exists the {@link Cart} will be updated to reflect the combined {@link Quantity} for the
* backing {@link CartItem}.
*
*
* @param product must not be {@literal null}.
* @param amount must not be {@literal null}.
* @return
Expand All @@ -77,7 +77,7 @@ public CartItem addOrUpdateItem(Product product, long amount) {
* Creates a {@link CartItem} for the given {@link Product} and amount. If a {@link CartItem} for the given
* {@link Product} already exists the {@link Cart} will be updated to reflect the combined {@link Quantity} for the
* backing {@link CartItem}.
*
*
* @param product must not be {@literal null}.
* @param amount must not be {@literal null}.
* @return
Expand All @@ -88,7 +88,7 @@ public CartItem addOrUpdateItem(Product product, double amount) {

/**
* Removes the {@link CartItem} with the given identifier.
*
*
* @param identifier must not be {@literal null}.
* @return
*/
Expand All @@ -102,7 +102,7 @@ public Optional<CartItem> removeItem(String identifier) {

/**
* Returns the CartItem for the given identifier.
*
*
* @param identifier must not be {@literal null}.
* @return
*/
Expand All @@ -124,7 +124,7 @@ public void clear() {

/**
* Returns whether the {@link Cart} is currently empty.
*
*
* @return
*/
public boolean isEmpty() {
Expand All @@ -133,7 +133,7 @@ public boolean isEmpty() {

/**
* Turns the current state of the cart into an {@link Order}.
*
*
* @param order must not be {@literal null}.
* @return the {@link Order} which all items in the card have been added to.
* @throws IllegalStateException if the given Order is not {@link OrderStatus#OPEN} anymore.
Expand All @@ -142,14 +142,14 @@ public Order addItemsTo(Order order) {

Assert.notNull(order, "Order must not be null!");

items.values().forEach(item -> order.add(item.toOrderLine()));
items.values().forEach(item -> order.addOrderLine(item.getProduct(), item.getQuantity()));

return order;
}

/**
* Creates a new Order for the given {@link UserAccount} from the current {@link Cart}.
*
*
* @param user must not be {@literal null}.
* @return a new Order for the current {@link Cart} and given {@link UserAccount}.
*/
Expand All @@ -160,7 +160,7 @@ public Order createOrderFor(UserAccount user) {
return addItemsTo(new Order(user));
}

/*
/*
* (non-Javadoc)
* @see org.salespointframework.order.Priced#getPrice()
*/
Expand All @@ -173,7 +173,7 @@ public MonetaryAmount getPrice() {
.orElse(Money.of(0, Currencies.EURO));
}

/*
/*
* (non-Javadoc)
* @see java.lang.Iterable#iterator()
*/
Expand Down
58 changes: 6 additions & 52 deletions src/main/java/org/salespointframework/order/Order.java
Expand Up @@ -198,41 +198,6 @@ public MonetaryAmount getTotal() {
return getOrderLines().getTotal().add(getAllChargeLines().getTotal());
}

/**
* Returns the total price of the {@link Order}.
*
* @return
* @deprecated since 7.1, use {@link #getTotal()} instead.
*/
@Deprecated
public MonetaryAmount getTotalPrice() {
return getTotal();
}

/**
* Returns the total of all {@link OrderLine}s.
*
* @return
* @deprecated since 7.1, use {@link #getOrderLines()} and call {@link Totalable#getTotal()} on the result.
*/
@Deprecated
public MonetaryAmount getOrderedLinesPrice() {
return Priced.sumUp(orderLines);
}

/**
* Returns the total of all charge lines registered with the order and order lines.
*
* @return
* @deprecated since 7.1, prefer {@link #getChargeLines()}, {@link #getAllChargeLines()} and call
* {@link PricedTotalable#getTotal()} on the result for fine grained control over which
* {@link ChargeLine}s to calculate the total for.
*/
@Deprecated
public MonetaryAmount getChargeLinesPrice() {
return Priced.sumUp(getAllChargeLines());
}

/**
* Adds an {@link OrderLine} to the {@link Order}, the {@link OrderStatus} must be OPEN.
*
Expand All @@ -242,7 +207,7 @@ public MonetaryAmount getChargeLinesPrice() {
* @deprecated since 7.1, use {@link #addOrderLine(Product, Quantity)} instead.
*/
@Deprecated
public OrderLine add(OrderLine orderLine) {
OrderLine add(OrderLine orderLine) {

Assert.notNull(orderLine, "OrderLine must not be null!");
assertOrderIsOpen();
Expand Down Expand Up @@ -294,7 +259,7 @@ public void remove(OrderLine orderLine) {
* @deprecated since 7.1, use {@link #addChargeLine(MonetaryAmount, String)} instead
*/
@Deprecated
public ChargeLine add(ChargeLine chargeLine) {
ChargeLine add(ChargeLine chargeLine) {

Assert.notNull(chargeLine, "ChargeLine must not be null!");
assertOrderIsOpen();
Expand Down Expand Up @@ -469,18 +434,7 @@ Order complete() {
}

/**
* Cancels the current {@link Order}.
*
* @return
* @deprecated since 7.1, use {@link #cancel(String)} instead.
*/
@Deprecated
Order cancel() {
return cancel(\\_(ツ)_/¯");
}

/**
* Cancels the current {@link Order} with the given reason. Will publish an {@link OrderCancelled} even
* Cancels the current {@link Order} with the given reason. Will publish an {@link OrderCanceled} even
*
* @param reason must not be {@literal null}.
* @return
Expand All @@ -495,7 +449,7 @@ Order cancel(String reason) {

this.orderStatus = OrderStatus.CANCELLED;

registerEvent(OrderCancelled.of(this, reason));
registerEvent(OrderCanceled.of(this, reason));

return this;
}
Expand Down Expand Up @@ -572,7 +526,7 @@ public String toString() {
}

@Value(staticConstructor = "of")
public static class OrderCancelled implements DomainEvent {
public static class OrderCanceled implements DomainEvent {

Order order;
String reason;
Expand All @@ -583,7 +537,7 @@ public static class OrderCancelled implements DomainEvent {
*/
@Override
public String toString() {
return "OrderCancelled: " + reason;
return "OrderCanceled: " + reason;
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-2020 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.
Expand All @@ -17,7 +17,7 @@

import java.util.Optional;

import org.salespointframework.order.Order.OrderCancelled;
import org.salespointframework.order.Order.OrderCanceled;
import org.salespointframework.order.Order.OrderCompleted;
import org.salespointframework.order.Order.OrderPaid;
import org.salespointframework.payment.PaymentMethod;
Expand All @@ -36,7 +36,7 @@
* @author Oliver Gierke
*/
@Service
public interface OrderManager<T extends Order> {
public interface OrderManagement<T extends Order> {

/**
* Saves the given {@link Order} or persists changes to it.
Expand All @@ -55,7 +55,7 @@ public interface OrderManager<T extends Order> {
Optional<T> get(OrderIdentifier orderIdentifier);

/**
* Checks if this {@link OrderManager} contains an order.
* Checks if this {@link OrderManagement} contains an order.
*
* @param orderIdentifier the {@link OrderIdentifier} of the {@link Order}, must not be {@literal null}.
* @return {@literal true} if the OrderManager contains the order, {@literal false} otherwise.
Expand Down Expand Up @@ -125,7 +125,7 @@ public interface OrderManager<T extends Order> {
* @param order the order to be canceled, must not be {@literal null}.
* @param reason the reason the order was cancelled.
* @return true if the order could be canceled
* @see OrderCancelled
* @see OrderCanceled
*/
boolean cancelOrder(T order, String reason);

Expand Down

0 comments on commit ff9d072

Please sign in to comment.