Refactor POS PurchaseOrder application domain model class to include an identifyAs(:Long) builder method to set the ID of a PurchaseOrder instance.
Annotate the PurchaseOrder class with Jackson's JsonTypeInfo annotation. Include statically defined Array and Map instance members for test purposes.
This commit is contained in:
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* The {@link PurchaseOrder} class models an actual purchase agreement for {@link Product products}
|
||||
@@ -43,17 +44,37 @@ import lombok.Getter;
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
@Region("PurchaseOrders")
|
||||
//@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@type")
|
||||
@SuppressWarnings("unused")
|
||||
public class PurchaseOrder implements Iterable<LineItem> {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
//@Getter(AccessLevel.PROTECTED) // Ideally! However, Jackson ObjectMapper does not handle protected correctly!
|
||||
/*
|
||||
private LineItem[] lineItemArray = {
|
||||
LineItem.newLineItem(Product.newProduct("Test Product")
|
||||
.in(Product.Category.SPECIALTY)
|
||||
.havingPrice(BigDecimal.valueOf(99.99)))
|
||||
.withQuantity(2)
|
||||
};
|
||||
*/
|
||||
|
||||
//@Getter(AccessLevel.PROTECTED)
|
||||
// Ideally! However, Jackson ObjectMapper does not handle protected correctly!
|
||||
// In fact, ideally, no getter at all; why can't Jackson's ObjectMapper handle field mapping(?); argh!
|
||||
private List<LineItem> lineItems = new ArrayList<>();
|
||||
|
||||
/*
|
||||
private Map<Object, LineItem> lineItemMap = Collections.singletonMap("MockProduct",
|
||||
LineItem.newLineItem(Product.newProduct("Mock Product")
|
||||
.in(Product.Category.SPECIALTY)
|
||||
.havingPrice(BigDecimal.valueOf(100.00)))
|
||||
.withQuantity(2));
|
||||
*/
|
||||
|
||||
public Optional<LineItem> findBy(String productName) {
|
||||
|
||||
return StreamSupport.stream(this.spliterator(), false)
|
||||
@@ -78,6 +99,11 @@ public class PurchaseOrder implements Iterable<LineItem> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public PurchaseOrder identifiedAs(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull @Override
|
||||
public Iterator<LineItem> iterator() {
|
||||
return Collections.unmodifiableList(this.lineItems).iterator();
|
||||
|
||||
Reference in New Issue
Block a user