JAVA-16264: review module names (#13136)
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
package com.baeldung.dddcontexts.shippingcontext.model;
|
||||
|
||||
public class PackageItem {
|
||||
private int productId;
|
||||
private float weight;
|
||||
private float estimatedValue;
|
||||
|
||||
public PackageItem(int productId, float weight, float estimatedValue) {
|
||||
this.productId = productId;
|
||||
this.weight = weight;
|
||||
this.estimatedValue = estimatedValue;
|
||||
}
|
||||
|
||||
public int getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(int productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public float getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(float weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public float getEstimatedValue() {
|
||||
return estimatedValue;
|
||||
}
|
||||
|
||||
public void setEstimatedValue(float estimatedValue) {
|
||||
this.estimatedValue = estimatedValue;
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.baeldung.dddcontexts.shippingcontext.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Parcel {
|
||||
private int orderId;
|
||||
private String address;
|
||||
private String trackingId;
|
||||
private List<PackageItem> packageItems;
|
||||
|
||||
public Parcel(int orderId, String address, List<PackageItem> packageItems) {
|
||||
this.orderId = orderId;
|
||||
this.address = address;
|
||||
this.packageItems = packageItems;
|
||||
}
|
||||
|
||||
public float calculateTotalWeight() {
|
||||
return packageItems.stream().map(PackageItem::getWeight)
|
||||
.reduce(0F, Float::sum);
|
||||
}
|
||||
|
||||
public boolean isTaxable() {
|
||||
return calculateEstimatedValue() > 100;
|
||||
}
|
||||
|
||||
public float calculateEstimatedValue() {
|
||||
return packageItems.stream().map(PackageItem::getWeight)
|
||||
.reduce(0F, Float::sum);
|
||||
}
|
||||
|
||||
public int getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(int orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public String getTrackingId() {
|
||||
return trackingId;
|
||||
}
|
||||
|
||||
public void setTrackingId(String trackingId) {
|
||||
this.trackingId = trackingId;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package com.baeldung.dddcontexts.shippingcontext.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ShippableOrder {
|
||||
private int orderId;
|
||||
private String address;
|
||||
private List<PackageItem> packageItems;
|
||||
|
||||
public ShippableOrder(int orderId, List<PackageItem> packageItems) {
|
||||
this.orderId = orderId;
|
||||
this.packageItems = packageItems;
|
||||
}
|
||||
|
||||
public int getOrderId() {
|
||||
return orderId;
|
||||
}
|
||||
|
||||
public void setOrderId(int orderId) {
|
||||
this.orderId = orderId;
|
||||
}
|
||||
|
||||
public List<PackageItem> getPackageItems() {
|
||||
return packageItems;
|
||||
}
|
||||
|
||||
public void setPackageItems(List<PackageItem> packageItems) {
|
||||
this.packageItems = packageItems;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.dddcontexts.shippingcontext.repository;
|
||||
|
||||
import com.baeldung.dddcontexts.shippingcontext.model.ShippableOrder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ShippingOrderRepository {
|
||||
Optional<ShippableOrder> findShippableOrder(int orderId);
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.baeldung.dddcontexts.shippingcontext.service;
|
||||
|
||||
import com.baeldung.dddcontexts.sharedkernel.events.ApplicationEvent;
|
||||
import com.baeldung.dddcontexts.sharedkernel.events.EventBus;
|
||||
import com.baeldung.dddcontexts.sharedkernel.events.EventSubscriber;
|
||||
import com.baeldung.dddcontexts.shippingcontext.model.Parcel;
|
||||
import com.baeldung.dddcontexts.shippingcontext.model.ShippableOrder;
|
||||
import com.baeldung.dddcontexts.shippingcontext.repository.ShippingOrderRepository;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ParcelShippingService implements ShippingService {
|
||||
public static final String EVENT_ORDER_READY_FOR_SHIPMENT = "OrderReadyForShipmentEvent";
|
||||
private ShippingOrderRepository orderRepository;
|
||||
private EventBus eventBus;
|
||||
private Map<Integer, Parcel> shippedParcels = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void shipOrder(int orderId) {
|
||||
Optional<ShippableOrder> order = this.orderRepository.findShippableOrder(orderId);
|
||||
order.ifPresent(completedOrder -> {
|
||||
Parcel parcel = new Parcel(completedOrder.getOrderId(), completedOrder.getAddress(), completedOrder.getPackageItems());
|
||||
if (parcel.isTaxable()) {
|
||||
// Calculate additional taxes
|
||||
}
|
||||
// Ship parcel
|
||||
this.shippedParcels.put(completedOrder.getOrderId(), parcel);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listenToOrderEvents() {
|
||||
this.eventBus.subscribe(EVENT_ORDER_READY_FOR_SHIPMENT, new EventSubscriber() {
|
||||
@Override
|
||||
public <E extends ApplicationEvent> void onEvent(E event) {
|
||||
shipOrder(Integer.parseInt(event.getPayloadValue("order_id")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Parcel> getParcelByOrderId(int orderId) {
|
||||
return Optional.ofNullable(this.shippedParcels.get(orderId));
|
||||
}
|
||||
|
||||
public void setOrderRepository(ShippingOrderRepository orderRepository) {
|
||||
this.orderRepository = orderRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventBus getEventBus() {
|
||||
return eventBus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEventBus(EventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.baeldung.dddcontexts.shippingcontext.service;
|
||||
|
||||
import com.baeldung.dddcontexts.sharedkernel.service.ApplicationService;
|
||||
import com.baeldung.dddcontexts.shippingcontext.model.Parcel;
|
||||
import com.baeldung.dddcontexts.shippingcontext.repository.ShippingOrderRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ShippingService extends ApplicationService {
|
||||
void shipOrder(int orderId);
|
||||
|
||||
void listenToOrderEvents();
|
||||
|
||||
Optional<Parcel> getParcelByOrderId(int orderId);
|
||||
|
||||
void setOrderRepository(ShippingOrderRepository orderRepository);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
module com.baeldung.dddcontexts.shippingcontext {
|
||||
requires com.baeldung.dddcontexts.sharedkernel;
|
||||
exports com.baeldung.dddcontexts.shippingcontext.service;
|
||||
exports com.baeldung.dddcontexts.shippingcontext.model;
|
||||
exports com.baeldung.dddcontexts.shippingcontext.repository;
|
||||
provides com.baeldung.dddcontexts.shippingcontext.service.ShippingService
|
||||
with com.baeldung.dddcontexts.shippingcontext.service.ParcelShippingService;
|
||||
}
|
||||
Reference in New Issue
Block a user