From 33458ab4bede2103e9ee5f7063d761e0ae9fdeda Mon Sep 17 00:00:00 2001 From: John Blum Date: Fri, 8 May 2020 01:42:56 -0700 Subject: [PATCH] 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. --- .../example/app/pos/model/PurchaseOrder.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/spring-geode/src/test/java/example/app/pos/model/PurchaseOrder.java b/spring-geode/src/test/java/example/app/pos/model/PurchaseOrder.java index 7b5d5399..9f6dbb36 100644 --- a/spring-geode/src/test/java/example/app/pos/model/PurchaseOrder.java +++ b/spring-geode/src/test/java/example/app/pos/model/PurchaseOrder.java @@ -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 { @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 lineItems = new ArrayList<>(); + /* + private Map lineItemMap = Collections.singletonMap("MockProduct", + LineItem.newLineItem(Product.newProduct("Mock Product") + .in(Product.Category.SPECIALTY) + .havingPrice(BigDecimal.valueOf(100.00))) + .withQuantity(2)); + */ + public Optional findBy(String productName) { return StreamSupport.stream(this.spliterator(), false) @@ -78,6 +99,11 @@ public class PurchaseOrder implements Iterable { return this; } + public PurchaseOrder identifiedAs(Long id) { + this.id = id; + return this; + } + @NotNull @Override public Iterator iterator() { return Collections.unmodifiableList(this.lineItems).iterator();