From b72b20e489f4f1c108a0127cf58c992577fdb26f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B6ger?= Date: Mon, 29 Aug 2016 15:38:35 +0200 Subject: [PATCH 01/10] Added a default status for PaymentStatus --- .../common/api/datatype/PaymentStatus.java | 70 ++++++++++--------- .../logic/impl/usecase/UcManageBillImpl.java | 27 ++++--- 2 files changed, 51 insertions(+), 46 deletions(-) diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/common/api/datatype/PaymentStatus.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/common/api/datatype/PaymentStatus.java index 9857f297c..1d8e8c5eb 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/common/api/datatype/PaymentStatus.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/common/api/datatype/PaymentStatus.java @@ -1,40 +1,46 @@ package io.oasp.gastronomy.restaurant.salesmanagement.common.api.datatype; /** - * + * * @author etomety */ public enum PaymentStatus { - /** - * This status describes a successful payment transaction. - */ - SUCCESS, - - /** - * This status describes a unsuccessful payment transaction. The input data is not correct. - */ - INPUT_DATA_ERROR, - - /** - * This status describes a unsuccessful payment transaction. The connection timed out. - */ - TIME_OUT_ERROR; - - /** - * @return {@code true}, if the {@link PaymentStatus} equals {@link PaymentStatus#SUCCESS}. - * {@code false} otherwise. - */ - public boolean isSuccessful() { - return this == SUCCESS; - } - - /** - * - * @return {@code true}, if the {@link PaymentStatus} equals {@link PaymentStatus#INPUT_DATA_ERROR} - * or {@link PaymentStatus#TIME_OUT_ERROR}. {@code false} otherwise. - */ - public boolean isUnsuccessful() { - return (this == INPUT_DATA_ERROR || this == TIME_OUT_ERROR); - } + /** + * This status describes a successful payment transaction. + */ + SUCCESS, + + /** + * This status describes a unsuccessful payment transaction. The input data is not correct. + */ + INPUT_DATA_ERROR, + + /** + * This status describes a unsuccessful payment transaction. The connection timed out. + */ + TIME_OUT_ERROR, + + /** + * This status describes an unfinished payment transaction. + */ + UNFINISHED; + + /** + * @return {@code true}, if the {@link PaymentStatus} equals {@link PaymentStatus#SUCCESS}. {@code false} otherwise. + */ + public boolean isSuccessful() { + + return this == SUCCESS; + } + + /** + * + * @return {@code true}, if the {@link PaymentStatus} equals {@link PaymentStatus#INPUT_DATA_ERROR} or + * {@link PaymentStatus#TIME_OUT_ERROR} or {@link PaymentStatus#UNFINISHED}. {@code false} otherwise. + */ + public boolean isUnsuccessful() { + + return (this == INPUT_DATA_ERROR || this == TIME_OUT_ERROR || this == UNFINISHED); + } } diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/usecase/UcManageBillImpl.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/usecase/UcManageBillImpl.java index e13455af1..0501d7497 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/usecase/UcManageBillImpl.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/usecase/UcManageBillImpl.java @@ -1,5 +1,16 @@ package io.oasp.gastronomy.restaurant.salesmanagement.logic.impl.usecase; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.annotation.security.RolesAllowed; +import javax.inject.Inject; +import javax.inject.Named; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.oasp.gastronomy.restaurant.general.common.api.constants.PermissionConstants; import io.oasp.gastronomy.restaurant.general.common.api.datatype.Money; import io.oasp.gastronomy.restaurant.general.common.api.exception.IllegalEntityStateException; @@ -19,17 +30,6 @@ import io.oasp.gastronomy.restaurant.salesmanagement.logic.impl.paymentadapter.PaymentAdapter; import io.oasp.gastronomy.restaurant.salesmanagement.logic.impl.paymentadapter.PaymentTransactionData; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -import javax.annotation.security.RolesAllowed; -import javax.inject.Inject; -import javax.inject.Named; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * Implementation of {@link UcManageBill}. * @@ -152,7 +152,7 @@ public PaymentStatus doPayment(BillEto bill) { LOG.debug("The bill with id '" + bill.getId() + "' will be marked as payed."); // Return a PaymentStatus - LOG.debug("The bill with id '" + bill.getId() + "' is succesfuly payed."); + LOG.debug("The bill with id '" + bill.getId() + "' is succesfully payed."); return PaymentStatus.SUCCESS; } @@ -160,8 +160,7 @@ public PaymentStatus doPayment(BillEto bill) { @RolesAllowed(PermissionConstants.SAVE_BILL) public PaymentStatus doPayment(BillEto bill, PaymentData paymentDataDebitor) { - // REVIEW (hohwille) Remove this hack or replace with something reasonable. - PaymentStatus status = null; + PaymentStatus status = PaymentStatus.UNFINISHED; // Creditor data: constant BankPaymentData paymentDataCreditor = new BankPaymentData(); From 12b9f2b5623874eececaa1930c763289f0519bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B6ger?= Date: Tue, 30 Aug 2016 09:22:43 +0200 Subject: [PATCH 02/10] Added JavaDoc --- .../configuration/DefaultRolesPrefixPostProcessor.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/DefaultRolesPrefixPostProcessor.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/DefaultRolesPrefixPostProcessor.java index 951f840b7..3aa011ac4 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/DefaultRolesPrefixPostProcessor.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/DefaultRolesPrefixPostProcessor.java @@ -9,18 +9,17 @@ import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter; /** - * TODO hohwille This type ... - * - * @author hohwille + * By default Spring-Security is setting the prefix "ROLE_" for all permissions/authorities. This class offers the + * possibility to change this behavior to a wanted prefix using the constructor with a string parameter. */ public class DefaultRolesPrefixPostProcessor implements BeanPostProcessor, PriorityOrdered { private final String rolePrefix; /** - * Der Konstruktor. + * The constructor. * - * @param rolePrefix das gewünschte Rollen-Präfix (z.B. der leere String). + * @param rolePrefix the role prefix to set (e.g. an empty string). */ public DefaultRolesPrefixPostProcessor(String rolePrefix) { super(); From 4ee6893f235aa63a84289b2201c5e91243be5fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B6ger?= Date: Tue, 30 Aug 2016 10:01:12 +0200 Subject: [PATCH 03/10] fixed TODO - added verification for mealState and SidedishState --- .../common/api/OrderPosition.java | 20 ++++ .../dataaccess/api/OrderPositionEntity.java | 45 ++++++-- .../logic/api/to/OrderPositionEto.java | 35 ++++-- .../usecase/UcManageOrderPositionImpl.java | 103 +++++++++++++++++- .../db/migration/V0002__R001_Master_data.sql | 10 +- .../h2/V0001__R001_Create_schema.sql | 2 + .../logic/impl/SalesManagementTest.java | 4 + .../V0001__R001_Create_schema.sql | 2 + .../V0002__R001_Master_data.sql | 41 ++++--- 9 files changed, 216 insertions(+), 46 deletions(-) diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/common/api/OrderPosition.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/common/api/OrderPosition.java index b46cdeff5..dde0bb58a 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/common/api/OrderPosition.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/common/api/OrderPosition.java @@ -72,6 +72,16 @@ public interface OrderPosition extends ApplicationEntity { @NotNull OrderPositionState getState(); + /** + * @return the current {@link ProductOrderState state}. + */ + ProductOrderState getMealState(); + + /** + * @return the current {@link ProductOrderState state}. + */ + ProductOrderState getSidedishState(); + /** * @return the current {@link ProductOrderState state}. */ @@ -82,6 +92,16 @@ public interface OrderPosition extends ApplicationEntity { */ void setState(OrderPositionState state); + /** + * @param mealState the new {@link #getMealState() state}. + */ + void setMealState(ProductOrderState mealState); + + /** + * @param sidedishState the new {@link #getSidedishState() state}. + */ + void setSidedishState(ProductOrderState sidedishState); + /** * @param drinkState the new {@link #getDrinkState() state}. */ diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/dataaccess/api/OrderPositionEntity.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/dataaccess/api/OrderPositionEntity.java index 3781adb37..64b962580 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/dataaccess/api/OrderPositionEntity.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/dataaccess/api/OrderPositionEntity.java @@ -1,11 +1,5 @@ package io.oasp.gastronomy.restaurant.salesmanagement.dataaccess.api; -import io.oasp.gastronomy.restaurant.general.common.api.datatype.Money; -import io.oasp.gastronomy.restaurant.general.dataaccess.api.ApplicationPersistenceEntity; -import io.oasp.gastronomy.restaurant.salesmanagement.common.api.OrderPosition; -import io.oasp.gastronomy.restaurant.salesmanagement.common.api.datatype.OrderPositionState; -import io.oasp.gastronomy.restaurant.salesmanagement.common.api.datatype.ProductOrderState; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -15,6 +9,12 @@ import javax.persistence.Transient; import javax.validation.constraints.NotNull; +import io.oasp.gastronomy.restaurant.general.common.api.datatype.Money; +import io.oasp.gastronomy.restaurant.general.dataaccess.api.ApplicationPersistenceEntity; +import io.oasp.gastronomy.restaurant.salesmanagement.common.api.OrderPosition; +import io.oasp.gastronomy.restaurant.salesmanagement.common.api.datatype.OrderPositionState; +import io.oasp.gastronomy.restaurant.salesmanagement.common.api.datatype.ProductOrderState; + /** * {@link ApplicationPersistenceEntity Entity} that represents a single {@link OrderPosition position} of an * {@link OrderEntity}. @@ -37,6 +37,10 @@ public class OrderPositionEntity extends ApplicationPersistenceEntity implements private OrderPositionState state; + private ProductOrderState mealState; + + private ProductOrderState sidedishState; + private ProductOrderState drinkState; private Money price; @@ -166,23 +170,40 @@ public void setComment(String comment) { this.comment = comment; } - /** - * {@inheritDoc} - */ @Override public ProductOrderState getDrinkState() { return this.drinkState; } - /** - * {@inheritDoc} - */ @Override public void setDrinkState(ProductOrderState drinkState) { this.drinkState = drinkState; + } + + @Override + public ProductOrderState getMealState() { + + return this.mealState; + } + + @Override + public void setMealState(ProductOrderState mealState) { + + this.mealState = mealState; + } + + @Override + public ProductOrderState getSidedishState() { + + return this.sidedishState; + } + + @Override + public void setSidedishState(ProductOrderState sidedishState) { + this.sidedishState = sidedishState; } } diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/api/to/OrderPositionEto.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/api/to/OrderPositionEto.java index 1a42d8089..14bddccea 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/api/to/OrderPositionEto.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/api/to/OrderPositionEto.java @@ -25,6 +25,10 @@ public class OrderPositionEto extends AbstractEto implements OrderPosition { private OrderPositionState state; + private ProductOrderState mealState; + + private ProductOrderState sidedishState; + private ProductOrderState drinkState; private Money price; @@ -134,23 +138,40 @@ public void setComment(String comment) { this.comment = comment; } - /** - * {@inheritDoc} - */ @Override public ProductOrderState getDrinkState() { return this.drinkState; - } - /** - * {@inheritDoc} - */ @Override public void setDrinkState(ProductOrderState drinkState) { this.drinkState = drinkState; + } + + @Override + public ProductOrderState getMealState() { + + return this.mealState; + } + + @Override + public void setMealState(ProductOrderState mealState) { + + this.mealState = mealState; + } + + @Override + public ProductOrderState getSidedishState() { + + return this.sidedishState; + } + + @Override + public void setSidedishState(ProductOrderState sidedishState) { + + this.sidedishState = sidedishState; } diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/usecase/UcManageOrderPositionImpl.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/usecase/UcManageOrderPositionImpl.java index a1833967f..f87395462 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/usecase/UcManageOrderPositionImpl.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/usecase/UcManageOrderPositionImpl.java @@ -133,12 +133,14 @@ private void verifyUpdate(OrderPosition currentOrderPosition, OrderPosition upda OrderPositionState currentState = currentOrderPosition.getState(); OrderPositionState newState = updateOrderPosition.getState(); ProductOrderState newDrinkState = updateOrderPosition.getDrinkState(); + ProductOrderState newMealState = updateOrderPosition.getMealState(); + ProductOrderState newSidedishState = updateOrderPosition.getSidedishState(); verifyOrderPositionStateChange(updateOrderPosition, currentState, newState); - // TODO add verification methods of other sub-states of OrderPosition (i.e. Meal and SideDish) + verifyMealStateChange(updateOrderPosition, currentState, newState, newMealState); + verifySidedishStateChange(updateOrderPosition, currentState, newState, newSidedishState); verifyDrinkStateChange(updateOrderPosition, currentState, newState, newDrinkState); - } /** @@ -184,8 +186,101 @@ private void verifyOrderPositionStateChange(OrderPosition updateOrderPosition, O } /** - * Verifies if an update of the {@link DrinkState} is legal. This verification is based on both the states of - * {@link DrinkState} and {@link OrderPositionState}. + * Verifies if an update of the {@link ProductOrderState} is legal. This verification is based on both the states of + * {@link ProductOrderState} and {@link OrderPositionState}. + * + * @param updateOrderPosition the new {@link OrderPosition} to update to. + * @param currentState the old/current {@link OrderPositionState} of the {@link OrderPosition}. + * @param newState new {@link OrderPositionState} of the {@link OrderPosition} to be updated to. + * @param newMealState new {@link ProductOrderState} of the meal of the {@link OrderPosition} to be updated to. + */ + private void verifyMealStateChange(OrderPosition updateOrderPosition, OrderPositionState currentState, + OrderPositionState newState, ProductOrderState newMealState) { + + switch (currentState) { + case CANCELLED: + if ((newState != OrderPositionState.CANCELLED) && (newState != OrderPositionState.ORDERED)) { + throw new IllegalEntityStateException(updateOrderPosition, currentState, newMealState); + } + break; + case ORDERED: + if ((newState != OrderPositionState.ORDERED) && (newState != OrderPositionState.CANCELLED) + && (newState != OrderPositionState.PREPARED) && (newMealState != ProductOrderState.ORDERED) + && (newMealState != ProductOrderState.PREPARED)) { + throw new IllegalEntityStateException(updateOrderPosition, currentState, newMealState); + } + break; + case PREPARED: + // from here we can go to any other state (back to ORDERED in case that the kitchen has to rework) + break; + case DELIVERED: + if ((newState == OrderPositionState.PREPARED) || (newState == OrderPositionState.ORDERED) + || (newMealState == ProductOrderState.PREPARED) || (newMealState == ProductOrderState.ORDERED)) { + throw new IllegalEntityStateException(updateOrderPosition, currentState, newMealState); + } + break; + case PAYED: + if (newState != OrderPositionState.PAYED) { + throw new IllegalEntityStateException(updateOrderPosition, currentState, newMealState); + } + break; + default: + LOG.error("Illegal state {}", currentState); + break; + } + + } + + /** + * Verifies if an update of the {@link ProductOrderState} is legal. This verification is based on both the states of + * {@link ProductOrderState} and {@link OrderPositionState}. + * + * @param updateOrderPosition the new {@link OrderPosition} to update to. + * @param currentState the old/current {@link OrderPositionState} of the {@link OrderPosition}. + * @param newState new {@link OrderPositionState} of the {@link OrderPosition} to be updated to. + * @param newSidedishState new {@link ProductOrderState} of the sidedish of the {@link OrderPosition} to be updated + * to. + */ + private void verifySidedishStateChange(OrderPosition updateOrderPosition, OrderPositionState currentState, + OrderPositionState newState, ProductOrderState newSidedishState) { + + switch (currentState) { + case CANCELLED: + if ((newState != OrderPositionState.CANCELLED) && (newState != OrderPositionState.ORDERED)) { + throw new IllegalEntityStateException(updateOrderPosition, currentState, newSidedishState); + } + break; + case ORDERED: + if ((newState != OrderPositionState.ORDERED) && (newState != OrderPositionState.CANCELLED) + && (newState != OrderPositionState.PREPARED) && (newSidedishState != ProductOrderState.ORDERED) + && (newSidedishState != ProductOrderState.PREPARED)) { + throw new IllegalEntityStateException(updateOrderPosition, currentState, newSidedishState); + } + break; + case PREPARED: + // from here we can go to any other state (back to ORDERED in case that the kitchen has to rework) + break; + case DELIVERED: + if ((newState == OrderPositionState.PREPARED) || (newState == OrderPositionState.ORDERED) + || (newSidedishState == ProductOrderState.PREPARED) || (newSidedishState == ProductOrderState.ORDERED)) { + throw new IllegalEntityStateException(updateOrderPosition, currentState, newSidedishState); + } + break; + case PAYED: + if (newState != OrderPositionState.PAYED) { + throw new IllegalEntityStateException(updateOrderPosition, currentState, newSidedishState); + } + break; + default: + LOG.error("Illegal state {}", currentState); + break; + } + + } + + /** + * Verifies if an update of the {@link ProductOrderState} is legal. This verification is based on both the states of + * {@link ProductOrderState} and {@link OrderPositionState}. * * @param updateOrderPosition the new {@link OrderPosition} to update to. * @param currentState the old/current {@link OrderPositionState} of the {@link OrderPosition}. diff --git a/samples/core/src/main/resources/db/migration/V0002__R001_Master_data.sql b/samples/core/src/main/resources/db/migration/V0002__R001_Master_data.sql index b8e9afc18..0576c4466 100644 --- a/samples/core/src/main/resources/db/migration/V0002__R001_Master_data.sql +++ b/samples/core/src/main/resources/db/migration/V0002__R001_Master_data.sql @@ -32,11 +32,11 @@ INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, s INSERT INTO RESTAURANTORDER (id, modificationCounter, table_id, state) VALUES (1, 1, 101, 1); -INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, drinkState, order_id, price) VALUES (1, 1, 1, 'Schnitzel-Menü', 'mit Ketschup', 2, 2, 1, 6.99); -INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, drinkState, order_id, price) VALUES (2, 1, 2, 'Goulasch-Menü', '', 2, 2, 1, 7.99); -INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, drinkState, order_id, price) VALUES (3, 1, 3, 'Pfifferlinge-Menü','', 2, 2, 1, 8.99); -INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, drinkState, order_id, price) VALUES (4, 1, 4, 'Salat-Menü', '', 2, 2, 1, 5.99); -INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, drinkState, order_id, price) VALUES (5, 1, 5, 'Cola', '', 2, 2, 1, 5.99); +INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, mealState, sidedishState, drinkState, order_id, price) VALUES (1, 1, 1, 'Schnitzel-Menü', 'mit Ketschup', 2, 2, 2, 2, 1, 6.99); +INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, mealState, sidedishState, drinkState, order_id, price) VALUES (2, 1, 2, 'Goulasch-Menü', '', 2, 2, 2, 2, 1, 7.99); +INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, mealState, sidedishState, drinkState, order_id, price) VALUES (3, 1, 3, 'Pfifferlinge-Menü','', 2, 2, 2, 2, 1, 8.99); +INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, mealState, sidedishState, drinkState, order_id, price) VALUES (4, 1, 4, 'Salat-Menü', '', 2, 2, 2, 2, 1, 5.99); +INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, mealState, sidedishState, drinkState, order_id, price) VALUES (5, 1, 5, 'Cola', '', 2, 2, 2, 2, 1, 5.99); INSERT INTO BILL (id, modificationCounter, payed, total, tip) VALUES (1, 1, true, 14.98, 1.3); INSERT INTO BILL_ORDERPOSITION (bill_id, orderpositions_id) VALUES (1,1); diff --git a/samples/core/src/main/resources/db/migration/h2/V0001__R001_Create_schema.sql b/samples/core/src/main/resources/db/migration/h2/V0001__R001_Create_schema.sql index 850ced42c..6319e2ba4 100644 --- a/samples/core/src/main/resources/db/migration/h2/V0001__R001_Create_schema.sql +++ b/samples/core/src/main/resources/db/migration/h2/V0001__R001_Create_schema.sql @@ -90,6 +90,8 @@ CREATE TABLE ORDERPOSITION( offerName VARCHAR(255), price DECIMAL(19, 2), state INTEGER, + mealState INTEGER, + sidedishState INTEGER, drinkState INTEGER, order_id BIGINT ); diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/SalesManagementTest.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/SalesManagementTest.java index 936832c70..129c2ac51 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/SalesManagementTest.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/SalesManagementTest.java @@ -77,6 +77,8 @@ public void testOrderPositionStateChange() { orderPosition = this.salesManagement.saveOrderPosition(orderPosition); assertThat(orderPosition).isNotNull(); orderPosition.setState(OrderPositionState.ORDERED); + orderPosition.setMealState(ProductOrderState.ORDERED); + orderPosition.setSidedishState(ProductOrderState.ORDERED); orderPosition.setDrinkState(ProductOrderState.ORDERED); OrderPositionEto updatedOrderPosition = this.salesManagement.saveOrderPosition(orderPosition); @@ -84,6 +86,8 @@ public void testOrderPositionStateChange() { // when updatedOrderPosition.setState(OrderPositionState.PREPARED); + updatedOrderPosition.setMealState(ProductOrderState.PREPARED); + updatedOrderPosition.setSidedishState(ProductOrderState.PREPARED); updatedOrderPosition.setDrinkState(ProductOrderState.PREPARED); updatedOrderPosition = this.salesManagement.saveOrderPosition(updatedOrderPosition); diff --git a/samples/core/src/test/resources/db/tablemanagement/V0001__R001_Create_schema.sql b/samples/core/src/test/resources/db/tablemanagement/V0001__R001_Create_schema.sql index 850ced42c..6319e2ba4 100644 --- a/samples/core/src/test/resources/db/tablemanagement/V0001__R001_Create_schema.sql +++ b/samples/core/src/test/resources/db/tablemanagement/V0001__R001_Create_schema.sql @@ -90,6 +90,8 @@ CREATE TABLE ORDERPOSITION( offerName VARCHAR(255), price DECIMAL(19, 2), state INTEGER, + mealState INTEGER, + sidedishState INTEGER, drinkState INTEGER, order_id BIGINT ); diff --git a/samples/core/src/test/resources/db/tablemanagement/V0002__R001_Master_data.sql b/samples/core/src/test/resources/db/tablemanagement/V0002__R001_Master_data.sql index e00a65ad4..0576c4466 100644 --- a/samples/core/src/test/resources/db/tablemanagement/V0002__R001_Master_data.sql +++ b/samples/core/src/test/resources/db/tablemanagement/V0002__R001_Master_data.sql @@ -8,30 +8,35 @@ INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (1, 1, INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (2, 1, 'Meal', 'Goulasch'); INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (3, 1, 'Meal', 'Pfifferlinge'); INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (4, 1, 'Meal', 'Salat'); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (5, 1, 'Meal', 'Pizza'); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (6, 1, 'Meal', 'Flammkuchen'); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (5, 1, 'SideDish', 'Pommes'); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (6, 1, 'SideDish', 'Reis'); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (7, 1, 'SideDish', 'Brot'); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (8, 1, 'SideDish', 'Knödel'); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (7, 1, 'SideDish', 'Pommes'); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (8, 1, 'SideDish', 'Reis'); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (9, 1, 'SideDish', 'Brot'); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (10, 1, 'SideDish', 'Knödel'); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (9, 1, 'Drink', 'Wasser', false); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (10, 1, 'Drink', 'Cola', false); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (11, 1, 'Drink', 'Bier', false); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (12, 1, 'Drink', 'Wein / Apfelwein', false); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (11, 1, 'Drink', 'Wasser', false); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (12, 1, 'Drink', 'Cola', false); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (13, 1, 'Drink', 'Bier', false); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (14, 1, 'Drink', 'Wein / Apfelwein', false); + +INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (1, 1, 'Schnitzel-Menü', 'Description of Schnitzel-Menü', 0, 1, 7, 12, 6.99); +INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (2, 1, 'Goulasch-Menü', 'Description of Goulasch-Menü', 0, 2, 8, 13, 7.99); +INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (3, 1, 'Pfifferlinge-Menü', 'Description of Pfifferlinge-Menü', 0, 3, 10, 14, 8.99); +INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (4, 1, 'Salat-Menü', 'Description of Salat-Menü', 0, 4, 9, 11, 5.99); +INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (5, 1, 'Cola', 'Description of Salat-Menü', 0, null, null, 12, 1.20); +INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (6, 1, 'Pizza-Menü', 'Description of Pizza-Menü', 0, 5, null, 12, 6.23); +INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (7, 1, 'Flammkuchen-Menü', 'Description of Flammkuchen-Menü', 0, 6, null, 12, 5.99); -INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (1, 1, 'Schnitzel-Menü', 'Description of Schnitzel-Menü', 0, 1, 5, 10, 6.99); -INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (2, 1, 'Goulasch-Menü', 'Description of Goulasch-Menü', 0, 2, 6, 11, 7.99); -INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (3, 1, 'Pfifferlinge-Menü', 'Description of Pfifferlinge-Menü', 0, 3, 8, 12, 8.99); -INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (4, 1, 'Salat-Menü', 'Description of Salat-Menü', 0, 4, 7, 9, 5.99); -INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (5, 1, 'Cola', 'Description of Salat-Menü', 0, null, null, 10, 1.20); INSERT INTO RESTAURANTORDER (id, modificationCounter, table_id, state) VALUES (1, 1, 101, 1); -INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, drinkState, order_id, price) VALUES (1, 1, 1, 'Schnitzel-Menü', 'mit Ketschup', 2, 2, 1, 6.99); -INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, drinkState, order_id, price) VALUES (2, 1, 2, 'Goulasch-Menü', '', 2, 2, 1, 7.99); -INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, drinkState, order_id, price) VALUES (3, 1, 3, 'Pfifferlinge-Menü','', 2, 2, 1, 8.99); -INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, drinkState, order_id, price) VALUES (4, 1, 4, 'Salat-Menü', '', 2, 2, 1, 5.99); -INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, drinkState, order_id, price) VALUES (5, 1, 5, 'Cola', '', 2, 2, 1, 5.99); +INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, mealState, sidedishState, drinkState, order_id, price) VALUES (1, 1, 1, 'Schnitzel-Menü', 'mit Ketschup', 2, 2, 2, 2, 1, 6.99); +INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, mealState, sidedishState, drinkState, order_id, price) VALUES (2, 1, 2, 'Goulasch-Menü', '', 2, 2, 2, 2, 1, 7.99); +INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, mealState, sidedishState, drinkState, order_id, price) VALUES (3, 1, 3, 'Pfifferlinge-Menü','', 2, 2, 2, 2, 1, 8.99); +INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, mealState, sidedishState, drinkState, order_id, price) VALUES (4, 1, 4, 'Salat-Menü', '', 2, 2, 2, 2, 1, 5.99); +INSERT INTO ORDERPOSITION (id, modificationCounter, offer_id, offername, comment, state, mealState, sidedishState, drinkState, order_id, price) VALUES (5, 1, 5, 'Cola', '', 2, 2, 2, 2, 1, 5.99); INSERT INTO BILL (id, modificationCounter, payed, total, tip) VALUES (1, 1, true, 14.98, 1.3); INSERT INTO BILL_ORDERPOSITION (bill_id, orderpositions_id) VALUES (1,1); From 0797d5a56ac0815efe3bbfa9a9e262e4b76a6c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B6ger?= Date: Tue, 30 Aug 2016 10:29:00 +0200 Subject: [PATCH 04/10] added negative test for changing orderPosition --- .../logic/impl/SalesManagementTest.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/SalesManagementTest.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/SalesManagementTest.java index 129c2ac51..8416ccf27 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/SalesManagementTest.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/SalesManagementTest.java @@ -17,6 +17,7 @@ import io.oasp.gastronomy.restaurant.general.common.TestUtil; import io.oasp.gastronomy.restaurant.general.common.api.constants.PermissionConstants; import io.oasp.gastronomy.restaurant.general.common.api.datatype.Money; +import io.oasp.gastronomy.restaurant.general.common.api.exception.IllegalEntityStateException; import io.oasp.gastronomy.restaurant.salesmanagement.common.api.datatype.OrderPositionState; import io.oasp.gastronomy.restaurant.salesmanagement.common.api.datatype.ProductOrderState; import io.oasp.gastronomy.restaurant.salesmanagement.logic.api.Salesmanagement; @@ -27,7 +28,6 @@ /** * This is the test-case of {@link Salesmanagement}. * - * @author hohwille, sroeger */ @SpringApplicationConfiguration(classes = { SpringBootApp.class }) @WebAppConfiguration @@ -46,7 +46,7 @@ public class SalesManagementTest extends ComponentTest { public void setUp() { TestUtil.login("waiter", PermissionConstants.FIND_ORDER_POSITION, PermissionConstants.SAVE_ORDER_POSITION, - PermissionConstants.SAVE_ORDER, PermissionConstants.FIND_OFFER); + PermissionConstants.SAVE_ORDER, PermissionConstants.FIND_OFFER, PermissionConstants.FIND_ORDER); this.dbTestHelper.setMigrationVersion("0002"); this.dbTestHelper.resetDatabase(); } @@ -109,4 +109,24 @@ public void testOrderPositionStateChange() { } + /** + * This test tries to change an {@link ProductOrderState} in a forbidden way. + */ + @Test(expected = IllegalEntityStateException.class) + public void testBadOrderPositionUpdate() { + + // given + OrderPositionEto orderPosition = this.salesManagement.findOrderPosition(1L); + assertThat(orderPosition.getMealState()).isEqualTo(ProductOrderState.DELIVERED); + orderPosition.setMealState(ProductOrderState.PREPARED); + + // when + OrderPositionEto updatedOrderPosition = this.salesManagement.saveOrderPosition(orderPosition); + + // then + assertThat(updatedOrderPosition).isNull(); + OrderPositionEto orderPositionAfterUpdate = this.salesManagement.findOrderPosition(1L); + assertThat(orderPositionAfterUpdate.getMealState()).isEqualTo(ProductOrderState.DELIVERED); + } + } From 0c2498d68aa44751fb50491d714b216754137611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B6ger?= Date: Tue, 30 Aug 2016 11:25:37 +0200 Subject: [PATCH 05/10] Small change to blob loading, to be changed --- .../service/impl/rest/OffermanagementRestServiceImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/offermanagement/service/impl/rest/OffermanagementRestServiceImpl.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/offermanagement/service/impl/rest/OffermanagementRestServiceImpl.java index b03056e98..aa910786d 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/offermanagement/service/impl/rest/OffermanagementRestServiceImpl.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/offermanagement/service/impl/rest/OffermanagementRestServiceImpl.java @@ -1,5 +1,6 @@ package io.oasp.gastronomy.restaurant.offermanagement.service.impl.rest; +import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -182,12 +183,13 @@ public MultipartBody getProductPicture(long productId) throws SQLException, IOEx Blob blob = this.offermanagement.findProductPictureBlob(productId); // REVIEW arturk88 (hohwille) we need to find another way to stream the blob without loading into heap. // https://github.com/oasp/oasp4j-sample/pull/45 - byte[] data = IOUtils.readBytesFromStream(blob.getBinaryStream()); + // byte[] data = IOUtils.readBytesFromStream(blob.getBinaryStream()); + InputStream data = blob.getBinaryStream(); List atts = new LinkedList<>(); atts.add(new Attachment("binaryObjectEto", MediaType.APPLICATION_JSON, this.offermanagement.findProductPicture(productId))); - atts.add(new Attachment("blob", MediaType.APPLICATION_OCTET_STREAM, new ByteArrayInputStream(data))); + atts.add(new Attachment("blob", MediaType.APPLICATION_OCTET_STREAM, new BufferedInputStream(data))); return new MultipartBody(atts, true); } From 8f857c7c67a1335a70f660947d8045bb8a6c93a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B6ger?= Date: Tue, 30 Aug 2016 15:36:03 +0200 Subject: [PATCH 06/10] Clean up javadoc and todo --- .../restaurant/general/common/api/UserProfile.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/common/api/UserProfile.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/common/api/UserProfile.java index 60d25a223..cf2326be5 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/common/api/UserProfile.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/common/api/UserProfile.java @@ -1,17 +1,12 @@ package io.oasp.gastronomy.restaurant.general.common.api; -import io.oasp.gastronomy.restaurant.general.common.api.datatype.Role; - import java.security.Principal; +import io.oasp.gastronomy.restaurant.general.common.api.datatype.Role; + /** - * This is the interface for the profile of a user interacting with this application. Currently this can only be a - * {@link io.oasp.gastronomy.restaurant.staffmanagement.dataaccess.api.StaffMemberEntity} however in the future a - * customer may login and make a reservation, etc.
- * TODO: Also an external system may access the application via some service. Then there would be no user profile or it - * would be empty... + * This is the interface for the profile of a user interacting with this application. * - * @author agreul */ public interface UserProfile extends Principal { /** @@ -22,6 +17,7 @@ public interface UserProfile extends Principal { /** * @return the unique login of the user for authentication and identification. */ + @Override String getName(); /** From 25eb3ddc840240228d22c2862a024011c2474489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B6ger?= Date: Wed, 31 Aug 2016 13:39:10 +0200 Subject: [PATCH 07/10] Refined test, added javadoc to builders --- .../common/builders/BillEntityBuilder.java | 75 +++++++---- .../common/builders/DrinkEntityBuilder.java | 55 ++++++-- .../common/builders/OrderEtoBuilder.java | 31 ++++- .../builders/OrderPositionEtoBuilder.java | 118 +++++++++++++++--- .../restaurant/common/builders/P.java | 8 ++ .../common/builders/TableEtoBuilder.java | 54 +++++--- .../logic/impl/SalesManagementTest.java | 21 ++-- 7 files changed, 280 insertions(+), 82 deletions(-) diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/BillEntityBuilder.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/BillEntityBuilder.java index 668c7be59..8372626ba 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/BillEntityBuilder.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/BillEntityBuilder.java @@ -7,20 +7,44 @@ import io.oasp.gastronomy.restaurant.salesmanagement.dataaccess.api.BillEntity; import io.oasp.gastronomy.restaurant.salesmanagement.dataaccess.api.OrderPositionEntity; +/** + * Test data builder for BillEntity generated with cobigen. + */ public class BillEntityBuilder { private List> parameterToBeApplied; + /** + * The constructor. + */ public BillEntityBuilder() { - parameterToBeApplied = new LinkedList>(); + this.parameterToBeApplied = new LinkedList<>(); fillMandatoryFields(); fillMandatoryFields_custom(); } + /** + * Might be enriched to users needs (will not be overwritten) + */ + private void fillMandatoryFields_custom() { + + } + + /** + * Fills all mandatory fields by default. (will be overwritten on re-generation) + */ + private void fillMandatoryFields() { + + } + + /** + * @param orderPositions the orderPositions to add. + * @return the builder for fluent population of fields. + */ public BillEntityBuilder orderPositions(final List orderPositions) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(BillEntity target) { @@ -30,9 +54,13 @@ public void apply(BillEntity target) { return this; } + /** + * @param total the total to add. + * @return the builder for fluent population of fields. + */ public BillEntityBuilder total(final Money total) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(BillEntity target) { @@ -42,9 +70,13 @@ public void apply(BillEntity target) { return this; } + /** + * @param tip the tip to add. + * @return the builder for fluent population of fields. + */ public BillEntityBuilder tip(final Money tip) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(BillEntity target) { @@ -54,9 +86,13 @@ public void apply(BillEntity target) { return this; } + /** + * @param payed the payed to add. + * @return the builder for fluent population of fields. + */ public BillEntityBuilder payed(final boolean payed) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(BillEntity target) { @@ -66,9 +102,13 @@ public void apply(BillEntity target) { return this; } + /** + * @param revision the revision to add. + * @return the builder for fluent population of fields. + */ public BillEntityBuilder revision(final Number revision) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(BillEntity target) { @@ -78,9 +118,13 @@ public void apply(BillEntity target) { return this; } + /** + * @param orderPositionIds the orderPositionIds to add. + * @return the builder for fluent population of fields. + */ public BillEntityBuilder orderPositionIds(final List orderPositionIds) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(BillEntity target) { @@ -90,6 +134,9 @@ public void apply(BillEntity target) { return this; } + /** + * @return the populated BillEntity. + */ public BillEntity createNew() { BillEntity billentity = new BillEntity(); @@ -99,18 +146,4 @@ public BillEntity createNew() { return billentity; } - /** - * Might be enrichted to users needs (will not be overwritten) - */ - private void fillMandatoryFields_custom() { - - } - - /** - * Fills all mandatory fields by default. (will be overwritten on re-generation) - */ - private void fillMandatoryFields() { - - } - } diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/DrinkEntityBuilder.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/DrinkEntityBuilder.java index d8c910641..35f7e43d9 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/DrinkEntityBuilder.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/DrinkEntityBuilder.java @@ -5,24 +5,23 @@ import io.oasp.gastronomy.restaurant.offermanagement.dataaccess.api.DrinkEntity; +/** + * Test data builder for DrinkEntity generated with cobigen. + */ public class DrinkEntityBuilder { private List> parameterToBeApplied; + /** + * The constructor. + */ public DrinkEntityBuilder() { - parameterToBeApplied = new LinkedList>(); + this.parameterToBeApplied = new LinkedList<>(); fillMandatoryFields(); fillMandatoryFields_custom(); } - /** - * Might be enrichted to users needs (will not be overwritten) - */ - private void fillMandatoryFields_custom() { - - } - /** * Fills all mandatory fields by default. (will be overwritten on re-generation) */ @@ -30,9 +29,13 @@ private void fillMandatoryFields() { } + /** + * @param alcoholic the alcoholic to add. + * @return the builder for fluent population of fields. + */ public DrinkEntityBuilder alcoholic(final boolean alcoholic) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(DrinkEntity target) { @@ -42,9 +45,13 @@ public void apply(DrinkEntity target) { return this; } + /** + * @param pictureId the pictureId to add. + * @return the builder for fluent population of fields. + */ public DrinkEntityBuilder pictureId(final Long pictureId) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(DrinkEntity target) { @@ -54,9 +61,13 @@ public void apply(DrinkEntity target) { return this; } + /** + * @param name the name to add. + * @return the builder for fluent population of fields. + */ public DrinkEntityBuilder name(final String name) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(DrinkEntity target) { @@ -66,9 +77,13 @@ public void apply(DrinkEntity target) { return this; } + /** + * @param description the description to add. + * @return the builder for fluent population of fields. + */ public DrinkEntityBuilder description(final String description) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(DrinkEntity target) { @@ -78,9 +93,13 @@ public void apply(DrinkEntity target) { return this; } + /** + * @param revision the revision to add. + * @return the builder for fluent population of fields. + */ public DrinkEntityBuilder revision(final Number revision) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(DrinkEntity target) { @@ -90,6 +109,9 @@ public void apply(DrinkEntity target) { return this; } + /** + * @return the populated DrinkEntity. + */ public DrinkEntity createNew() { DrinkEntity drinkentity = new DrinkEntity(); @@ -99,4 +121,11 @@ public DrinkEntity createNew() { return drinkentity; } + /** + * Might be enriched to users needs (will not be overwritten) + */ + private void fillMandatoryFields_custom() { + + } + } diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/OrderEtoBuilder.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/OrderEtoBuilder.java index 875746bc1..d2dab34d1 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/OrderEtoBuilder.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/OrderEtoBuilder.java @@ -6,20 +6,30 @@ import io.oasp.gastronomy.restaurant.salesmanagement.common.api.datatype.OrderState; import io.oasp.gastronomy.restaurant.salesmanagement.logic.api.to.OrderEto; +/** + * Test data builder for OrderEto generated with cobigen. + */ public class OrderEtoBuilder { private List> parameterToBeApplied; + /** + * The constructor. + */ public OrderEtoBuilder() { - parameterToBeApplied = new LinkedList>(); + this.parameterToBeApplied = new LinkedList<>(); fillMandatoryFields(); fillMandatoryFields_custom(); } + /** + * @param tableId the tableId to add. + * @return the builder for fluent population of fields. + */ public OrderEtoBuilder tableId(final long tableId) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(OrderEto target) { @@ -29,9 +39,13 @@ public void apply(OrderEto target) { return this; } + /** + * @param state the state to add. + * @return the builder for fluent population of fields. + */ public OrderEtoBuilder state(final OrderState state) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(OrderEto target) { @@ -41,9 +55,13 @@ public void apply(OrderEto target) { return this; } + /** + * @param revision the revision to add. + * @return the builder for fluent population of fields. + */ public OrderEtoBuilder revision(final Number revision) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(OrderEto target) { @@ -53,6 +71,9 @@ public void apply(OrderEto target) { return this; } + /** + * @return the populated OrderEto. + */ public OrderEto createNew() { OrderEto ordereto = new OrderEto(); @@ -70,7 +91,7 @@ private void fillMandatoryFields() { } /** - * Might be enrichted to users needs (will not be overwritten) + * Might be enriched to users needs (will not be overwritten) */ private void fillMandatoryFields_custom() { diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/OrderPositionEtoBuilder.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/OrderPositionEtoBuilder.java index 4e21a15fa..c17a0f968 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/OrderPositionEtoBuilder.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/OrderPositionEtoBuilder.java @@ -8,34 +8,37 @@ import io.oasp.gastronomy.restaurant.salesmanagement.common.api.datatype.ProductOrderState; import io.oasp.gastronomy.restaurant.salesmanagement.logic.api.to.OrderPositionEto; +/** + * Test data builder for OrderPositionEto generated with cobigen. + */ public class OrderPositionEtoBuilder { private List> parameterToBeApplied; + /** + * The constructor. + */ public OrderPositionEtoBuilder() { - parameterToBeApplied = new LinkedList>(); + this.parameterToBeApplied = new LinkedList<>(); fillMandatoryFields(); fillMandatoryFields_custom(); } /** - * Fills all mandatory fields by default. (will be overwritten on re-generation) + * Might be enriched to users needs (will not be overwritten) */ - private void fillMandatoryFields() { + private void fillMandatoryFields_custom() { } /** - * Might be enrichted to users needs (will not be overwritten) + * @param orderId the orderId to add. + * @return the builder for fluent population of fields. */ - private void fillMandatoryFields_custom() { - - } - public OrderPositionEtoBuilder orderId(final Long orderId) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(OrderPositionEto target) { @@ -45,9 +48,13 @@ public void apply(OrderPositionEto target) { return this; } + /** + * @param cookId the cookId to add. + * @return the builder for fluent population of fields. + */ public OrderPositionEtoBuilder cookId(final Long cookId) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(OrderPositionEto target) { @@ -57,9 +64,13 @@ public void apply(OrderPositionEto target) { return this; } + /** + * @param offerId the offerId to add. + * @return the builder for fluent population of fields. + */ public OrderPositionEtoBuilder offerId(final Long offerId) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(OrderPositionEto target) { @@ -69,9 +80,13 @@ public void apply(OrderPositionEto target) { return this; } + /** + * @param offerName the offerName to add. + * @return the builder for fluent population of fields. + */ public OrderPositionEtoBuilder offerName(final String offerName) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(OrderPositionEto target) { @@ -81,9 +96,13 @@ public void apply(OrderPositionEto target) { return this; } + /** + * @param state the state to add. + * @return the builder for fluent population of fields. + */ public OrderPositionEtoBuilder state(final OrderPositionState state) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(OrderPositionEto target) { @@ -93,9 +112,13 @@ public void apply(OrderPositionEto target) { return this; } + /** + * @param price the price to add. + * @return the builder for fluent population of fields. + */ public OrderPositionEtoBuilder price(final Money price) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(OrderPositionEto target) { @@ -105,9 +128,13 @@ public void apply(OrderPositionEto target) { return this; } + /** + * @param comment the comment to add. + * @return the builder for fluent population of fields. + */ public OrderPositionEtoBuilder comment(final String comment) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(OrderPositionEto target) { @@ -117,9 +144,13 @@ public void apply(OrderPositionEto target) { return this; } + /** + * @param drinkState the drinkState to add. + * @return the builder for fluent population of fields. + */ public OrderPositionEtoBuilder drinkState(final ProductOrderState drinkState) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(OrderPositionEto target) { @@ -129,9 +160,45 @@ public void apply(OrderPositionEto target) { return this; } + /** + * @param mealState the mealState to add. + * @return the builder for fluent population of fields. + */ + public OrderPositionEtoBuilder mealState(final ProductOrderState mealState) { + + this.parameterToBeApplied.add(new P() { + @Override + public void apply(OrderPositionEto target) { + + target.setMealState(mealState); + } + }); + return this; + } + + /** + * @param sidedishState the sidedishState to add. + * @return the builder for fluent population of fields. + */ + public OrderPositionEtoBuilder sidedishState(final ProductOrderState sidedishState) { + + this.parameterToBeApplied.add(new P() { + @Override + public void apply(OrderPositionEto target) { + + target.setSidedishState(sidedishState); + } + }); + return this; + } + + /** + * @param revision the revision to add. + * @return the builder for fluent population of fields. + */ public OrderPositionEtoBuilder revision(final Number revision) { - parameterToBeApplied.add(new P() { + this.parameterToBeApplied.add(new P() { @Override public void apply(OrderPositionEto target) { @@ -141,13 +208,28 @@ public void apply(OrderPositionEto target) { return this; } + /** + * @return the populated OrderPositionEto. + */ public OrderPositionEto createNew() { OrderPositionEto orderpositioneto = new OrderPositionEto(); - for (P parameter : parameterToBeApplied) { + // default values + orderpositioneto.setState(OrderPositionState.ORDERED); + orderpositioneto.setMealState(ProductOrderState.ORDERED); + orderpositioneto.setSidedishState(ProductOrderState.ORDERED); + orderpositioneto.setDrinkState(ProductOrderState.ORDERED); + for (P parameter : this.parameterToBeApplied) { parameter.apply(orderpositioneto); } return orderpositioneto; } + /** + * Fills all mandatory fields by default. (will be overwritten on re-generation) + */ + private void fillMandatoryFields() { + + } + } diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/P.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/P.java index ed4a68974..910290eb2 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/P.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/P.java @@ -1,6 +1,14 @@ package io.oasp.gastronomy.restaurant.common.builders; +/** + * Helper interface for usage of test data builders. + * + * @param the parameter + */ public interface P { + /** + * @param target the target to apply + */ public void apply(T target); } \ No newline at end of file diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/TableEtoBuilder.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/TableEtoBuilder.java index 49e4573d5..d0eda8a65 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/TableEtoBuilder.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/TableEtoBuilder.java @@ -6,31 +6,27 @@ import io.oasp.gastronomy.restaurant.tablemanagement.common.api.datatype.TableState; import io.oasp.gastronomy.restaurant.tablemanagement.logic.api.to.TableEto; +/** + * Test data builder for TableEto generated with cobigen. + */ public class TableEtoBuilder { private List> parameterToBeApplied; + /** + * The constructor. + */ public TableEtoBuilder() { - this.parameterToBeApplied = new LinkedList>(); + this.parameterToBeApplied = new LinkedList<>(); fillMandatoryFields(); fillMandatoryFields_custom(); } /** - * Might be enrichted to users needs (will not be overwritten) - */ - private void fillMandatoryFields_custom() { - - } - - /** - * Fills all mandatory fields by default. (will be overwritten on re-generation) + * @param number the number to add. + * @return the builder for fluent population of fields. */ - private void fillMandatoryFields() { - - } - public TableEtoBuilder number(final Long number) { this.parameterToBeApplied.add(new P() { @@ -43,6 +39,10 @@ public void apply(TableEto target) { return this; } + /** + * @param waiterId the waiterId to add. + * @return the builder for fluent population of fields. + */ public TableEtoBuilder waiterId(final Long waiterId) { this.parameterToBeApplied.add(new P() { @@ -55,6 +55,10 @@ public void apply(TableEto target) { return this; } + /** + * @param state the state to add. + * @return the builder for fluent population of fields. + */ public TableEtoBuilder state(final TableState state) { this.parameterToBeApplied.add(new P() { @@ -67,6 +71,10 @@ public void apply(TableEto target) { return this; } + /** + * @param revision the revision to add. + * @return the builder for fluent population of fields. + */ public TableEtoBuilder revision(final Number revision) { this.parameterToBeApplied.add(new P() { @@ -79,14 +87,30 @@ public void apply(TableEto target) { return this; } + /** + * @return the populated TableEto. + */ public TableEto createNew() { TableEto tableeto = new TableEto(); - tableeto.setState(TableState.FREE); - for (P parameter : this.parameterToBeApplied) { + for (P parameter : parameterToBeApplied) { parameter.apply(tableeto); } return tableeto; } + /** + * Fills all mandatory fields by default. (will be overwritten on re-generation) + */ + private void fillMandatoryFields() { + + } + + /** + * Might be enriched to users needs (will not be overwritten) + */ + private void fillMandatoryFields_custom() { + + } + } diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/SalesManagementTest.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/SalesManagementTest.java index 8416ccf27..ca4f37afb 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/SalesManagementTest.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/logic/impl/SalesManagementTest.java @@ -74,14 +74,8 @@ public void testOrderPositionStateChange() { order = this.salesManagement.saveOrder(order); OrderPositionEto orderPosition = new OrderPositionEtoBuilder().offerId(5L).orderId(order.getId()) .offerName("Cola").price(new Money(1.2)).createNew(); - orderPosition = this.salesManagement.saveOrderPosition(orderPosition); - assertThat(orderPosition).isNotNull(); - orderPosition.setState(OrderPositionState.ORDERED); - orderPosition.setMealState(ProductOrderState.ORDERED); - orderPosition.setSidedishState(ProductOrderState.ORDERED); - orderPosition.setDrinkState(ProductOrderState.ORDERED); - OrderPositionEto updatedOrderPosition = this.salesManagement.saveOrderPosition(orderPosition); + assertThat(updatedOrderPosition).isNotNull(); assertThat(updatedOrderPosition.getState()).isEqualTo(OrderPositionState.ORDERED); // when @@ -110,14 +104,21 @@ public void testOrderPositionStateChange() { } /** - * This test tries to change an {@link ProductOrderState} in a forbidden way. + * This test tries to change an {@link ProductOrderState} and save the appropriate orderposition in a forbidden way. */ @Test(expected = IllegalEntityStateException.class) public void testBadOrderPositionUpdate() { // given - OrderPositionEto orderPosition = this.salesManagement.findOrderPosition(1L); + OrderEto order = new OrderEtoBuilder().tableId(1L).createNew(); + order = this.salesManagement.saveOrder(order); + OrderPositionEto orderPosition = new OrderPositionEtoBuilder().offerId(5L).orderId(order.getId()) + .mealState(ProductOrderState.DELIVERED).sidedishState(ProductOrderState.DELIVERED) + .drinkState(ProductOrderState.DELIVERED).state(OrderPositionState.DELIVERED).createNew(); + orderPosition = this.salesManagement.saveOrderPosition(orderPosition); + assertThat(orderPosition).isNotNull(); assertThat(orderPosition.getMealState()).isEqualTo(ProductOrderState.DELIVERED); + orderPosition.setMealState(ProductOrderState.PREPARED); // when @@ -125,7 +126,7 @@ public void testBadOrderPositionUpdate() { // then assertThat(updatedOrderPosition).isNull(); - OrderPositionEto orderPositionAfterUpdate = this.salesManagement.findOrderPosition(1L); + OrderPositionEto orderPositionAfterUpdate = this.salesManagement.findOrderPosition(5L); assertThat(orderPositionAfterUpdate.getMealState()).isEqualTo(ProductOrderState.DELIVERED); } From a8beb93900e1ad726e841b18ba3f1a8a8daef2c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B6ger?= Date: Thu, 1 Sep 2016 08:21:04 +0200 Subject: [PATCH 08/10] Removed REVIEW in code and opened issue --- .../SalesmanagementHttpRestServiceTest.java | 2 +- .../rest/SalesmanagementRestServiceTest.java | 4 +-- .../V0002__R001_Master_data.sql | 35 ++++++++----------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementHttpRestServiceTest.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementHttpRestServiceTest.java index af499935d..26074076d 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementHttpRestServiceTest.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementHttpRestServiceTest.java @@ -246,7 +246,7 @@ public void getAllOrderPositions() { int numberOfOrderPositionsToSave = NUMBER_OF_SAMPLE_ORDER_POSITIONS; OrderPositionEto sampleOrderPositionEto; - ArrayList savedOrderPositionEtos = new ArrayList(); + ArrayList savedOrderPositionEtos = new ArrayList<>(); for (int i = 0; i < numberOfOrderPositionsToSave; ++i) { sampleOrderPositionEto = new OrderPositionEtoBuilder().orderId(responseOrderCto.getOrder().getId()) .offerId(SAMPLE_OFFER_ID).createNew(); diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementRestServiceTest.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementRestServiceTest.java index 31b548edd..916be0bdf 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementRestServiceTest.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementRestServiceTest.java @@ -111,7 +111,7 @@ public void findAllOrders() { OrderCto sampleOrderCto; OrderCto responseOrderCto; - ArrayList savedOrderCtos = new ArrayList(); + ArrayList savedOrderCtos = new ArrayList<>(); for (int i = 0; i < NUMBER_OF_SAMPLE_ORDERS; ++i) { sampleOrderCto = this.helper.createSampleOrderCto(SAMPLE_TABLE_ID); @@ -231,7 +231,7 @@ public void findAllOrderPositions() { OrderPositionEto sampleOrderPositionEto; OrderPositionEto responseOrderPositionEto; - ArrayList savedOrderPositionEtos = new ArrayList(); + ArrayList savedOrderPositionEtos = new ArrayList<>(); for (int i = 0; i < NUMBER_OF_SAMPLE_ORDER_POSITIONS; ++i) { sampleOrderPositionEto = new OrderPositionEto(); sampleOrderPositionEto.setOrderId(responseOrderCto.getOrder().getId()); diff --git a/samples/core/src/test/resources/db/tablemanagement/V0002__R001_Master_data.sql b/samples/core/src/test/resources/db/tablemanagement/V0002__R001_Master_data.sql index 0576c4466..bda3c15d9 100644 --- a/samples/core/src/test/resources/db/tablemanagement/V0002__R001_Master_data.sql +++ b/samples/core/src/test/resources/db/tablemanagement/V0002__R001_Master_data.sql @@ -8,27 +8,22 @@ INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (1, 1, INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (2, 1, 'Meal', 'Goulasch'); INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (3, 1, 'Meal', 'Pfifferlinge'); INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (4, 1, 'Meal', 'Salat'); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (5, 1, 'Meal', 'Pizza'); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (6, 1, 'Meal', 'Flammkuchen'); - -INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (7, 1, 'SideDish', 'Pommes'); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (8, 1, 'SideDish', 'Reis'); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (9, 1, 'SideDish', 'Brot'); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (10, 1, 'SideDish', 'Knödel'); - -INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (11, 1, 'Drink', 'Wasser', false); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (12, 1, 'Drink', 'Cola', false); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (13, 1, 'Drink', 'Bier', false); -INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (14, 1, 'Drink', 'Wein / Apfelwein', false); - -INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (1, 1, 'Schnitzel-Menü', 'Description of Schnitzel-Menü', 0, 1, 7, 12, 6.99); -INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (2, 1, 'Goulasch-Menü', 'Description of Goulasch-Menü', 0, 2, 8, 13, 7.99); -INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (3, 1, 'Pfifferlinge-Menü', 'Description of Pfifferlinge-Menü', 0, 3, 10, 14, 8.99); -INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (4, 1, 'Salat-Menü', 'Description of Salat-Menü', 0, 4, 9, 11, 5.99); -INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (5, 1, 'Cola', 'Description of Salat-Menü', 0, null, null, 12, 1.20); -INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (6, 1, 'Pizza-Menü', 'Description of Pizza-Menü', 0, 5, null, 12, 6.23); -INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (7, 1, 'Flammkuchen-Menü', 'Description of Flammkuchen-Menü', 0, 6, null, 12, 5.99); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (5, 1, 'SideDish', 'Pommes'); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (6, 1, 'SideDish', 'Reis'); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (7, 1, 'SideDish', 'Brot'); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description) VALUES (8, 1, 'SideDish', 'Knödel'); + +INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (9, 1, 'Drink', 'Wasser', false); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (10, 1, 'Drink', 'Cola', false); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (11, 1, 'Drink', 'Bier', false); +INSERT INTO PRODUCT (id, modificationCounter, dtype, description, alcoholic) VALUES (12, 1, 'Drink', 'Wein / Apfelwein', false); + +INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (1, 1, 'Schnitzel-Menü', 'Description of Schnitzel-Menü', 0, 1, 5, 10, 6.99); +INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (2, 1, 'Goulasch-Menü', 'Description of Goulasch-Menü', 0, 2, 6, 11, 7.99); +INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (3, 1, 'Pfifferlinge-Menü', 'Description of Pfifferlinge-Menü', 0, 3, 8, 12, 8.99); +INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (4, 1, 'Salat-Menü', 'Description of Salat-Menü', 0, 4, 7, 9, 5.99); +INSERT INTO OFFER (id, modificationCounter, name, description, state, meal_id, sidedish_id, drink_id, price) VALUES (5, 1, 'Cola', 'Description of Salat-Menü', 0, null, null, 10, 1.20); INSERT INTO RESTAURANTORDER (id, modificationCounter, table_id, state) VALUES (1, 1, 101, 1); From 13a74e1b210fa14d40ef95f7e7f69c8e932a6faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B6ger?= Date: Thu, 1 Sep 2016 09:25:57 +0200 Subject: [PATCH 09/10] Added JavaDoc, fixing Java Problems --- .../gastronomy/restaurant/SpringBootApp.java | 5 +++- .../restaurant/SpringBootBatchApp.java | 16 ++++++------ .../configuration/BaseWebSecurityConfig.java | 10 +++++-- .../BeansDozerConfiguration.java | 3 +++ .../configuration/ServiceConfiguration.java | 26 +++++++++++++++++++ .../rest/OffermanagementRestServiceImpl.java | 3 +-- .../websocket/config/WebSocketConfig.java | 3 +++ .../common/builders/BillEntityBuilder.java | 4 +-- .../AbstractSpringBatchIntegrationTest.java | 14 +++++++--- .../configuration/BeansJpaConfiguration.java | 13 ++++++---- .../configuration/TestWebSecurityConfig.java | 4 +++ .../logic/impl/OffermanagementImplTest.java | 3 +++ .../SalesmanagementHttpRestServiceTest.java | 4 --- .../rest/SalesmanagementRestServiceTest.java | 4 --- 14 files changed, 81 insertions(+), 31 deletions(-) diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/SpringBootApp.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/SpringBootApp.java index cbd4f9b41..221085130 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/SpringBootApp.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/SpringBootApp.java @@ -9,13 +9,16 @@ import io.oasp.module.jpa.dataaccess.api.AdvancedRevisionEntity; //@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, SecurityFilterAutoConfiguration.class }) +/** + * Class containing main method as an entry point for spring-boot based app. + */ @SpringBootApplication(exclude = { EndpointAutoConfiguration.class }) @EntityScan(basePackages = { "io.oasp.gastronomy.restaurant" }, basePackageClasses = { AdvancedRevisionEntity.class }) @EnableGlobalMethodSecurity(jsr250Enabled = true) public class SpringBootApp { /** - * Entry point for spring-boot based app + * Entry point for spring-boot based app. * * @param args - arguments */ diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/SpringBootBatchApp.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/SpringBootBatchApp.java index d867c13bf..3ecb0595f 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/SpringBootBatchApp.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/SpringBootBatchApp.java @@ -10,11 +10,11 @@ import io.oasp.module.jpa.dataaccess.api.AdvancedRevisionEntity; -@SpringBootApplication(exclude = { - EndpointAutoConfiguration.class, - SecurityAutoConfiguration.class, - SecurityFilterAutoConfiguration.class, - }) +/** + * Class containing main method as an entry point for spring-boot based app. + */ +@SpringBootApplication(exclude = { EndpointAutoConfiguration.class, SecurityAutoConfiguration.class, +SecurityFilterAutoConfiguration.class, }) @EntityScan(basePackages = { "io.oasp.gastronomy.restaurant" }, basePackageClasses = { AdvancedRevisionEntity.class }) @EnableGlobalMethodSecurity(jsr250Enabled = false) public class SpringBootBatchApp { @@ -24,8 +24,8 @@ public class SpringBootBatchApp { * * @param args - arguments */ - public static void main(String[] args) { + public static void main(String[] args) { - SpringApplication.run(SpringBootApp.class, args); - } + SpringApplication.run(SpringBootApp.class, args); + } } diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/BaseWebSecurityConfig.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/BaseWebSecurityConfig.java index 218e73bef..284e5e32c 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/BaseWebSecurityConfig.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/BaseWebSecurityConfig.java @@ -38,9 +38,15 @@ public abstract class BaseWebSecurityConfig extends WebSecurityConfigurerAdapter @Value("${security.cors.enabled}") boolean corsEnabled = false; + /** + * The {@link AuthenticationManagerBuilder} to inject. + */ @Inject protected AuthenticationManagerBuilder authenticationManagerBuilder; + /** + * The {@link ApplicationAuthenticationProvider} to inject. + */ @Inject protected ApplicationAuthenticationProvider authenticationProvider; @@ -124,7 +130,7 @@ protected Filter getSimpleRestLogoutFilter() { * status 200 instead of redirect after login. * * @return the AuthenticationFilter - * @throws Exception + * @throws Exception to pass over. */ protected JsonUsernamePasswordAuthenticationFilter getSimpleRestAuthenticationFilter() throws Exception { @@ -143,7 +149,7 @@ protected JsonUsernamePasswordAuthenticationFilter getSimpleRestAuthenticationFi /** * Init the authenticationManager and simply set users and roles here (to keep things as simplistic as possible). * - * @throws Exception + * @throws Exception to pass over. */ @PostConstruct public void init() throws Exception { diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/BeansDozerConfiguration.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/BeansDozerConfiguration.java index 9d5e70705..4e2da87d0 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/BeansDozerConfiguration.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/BeansDozerConfiguration.java @@ -20,6 +20,9 @@ public class BeansDozerConfiguration { private static final String DOZER_MAPPING_XML = "config/app/common/dozer-mapping.xml"; + /** + * @return an instance of {@link DozerBeanMapper}. + */ @Bean public Mapper getDozer() { diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/ServiceConfiguration.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/ServiceConfiguration.java index df3be66ef..20af4a3ee 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/ServiceConfiguration.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/general/configuration/ServiceConfiguration.java @@ -32,6 +32,9 @@ import io.oasp.module.rest.service.impl.RestServiceExceptionFacade; import io.oasp.module.rest.service.impl.json.ObjectMapperFactory; +/** + * This configuration type registers various beans related to rest and web services. + */ @Configuration @EnableWs @ImportResource({ "classpath:META-INF/cxf/cxf.xml" /* , "classpath:META-INF/cxf/cxf-servlet.xml" */ }) @@ -40,14 +43,19 @@ public class ServiceConfiguration extends WsConfigurerAdapter { /** Logger instance. */ private static final Logger LOG = LoggerFactory.getLogger(ServiceConfiguration.class); + @SuppressWarnings("javadoc") public static final String URL_PATH_SERVICES = "/services"; + @SuppressWarnings("javadoc") public static final String URL_FOLDER_REST = "/rest"; + @SuppressWarnings("javadoc") public static final String URL_FOLDER_WEB_SERVICES = "/ws"; + @SuppressWarnings("javadoc") public static final String URL_PATH_REST_SERVICES = URL_PATH_SERVICES + URL_FOLDER_REST; + @SuppressWarnings("javadoc") public static final String URL_PATH_WEB_SERVICES = URL_PATH_SERVICES + URL_FOLDER_WEB_SERVICES; @Value("${security.expose.error.details}") @@ -59,18 +67,27 @@ public class ServiceConfiguration extends WsConfigurerAdapter { @Inject private ObjectMapperFactory objectMapperFactory; + /** + * @return a {@link SpringBus} instance as bean with name "cxf". + */ @Bean(name = "cxf") public SpringBus springBus() { return new SpringBus(); } + /** + * @return the {@link JacksonJsonProvider}. + */ @Bean public JacksonJsonProvider jacksonJsonProvider() { return new JacksonJsonProvider(this.objectMapperFactory.createInstance()); } + /** + * @return the configured {@link ServletRegistrationBean}. + */ @Bean public ServletRegistrationBean servletRegistrationBean() { @@ -79,6 +96,9 @@ public ServletRegistrationBean servletRegistrationBean() { return servletRegistration; } + /** + * @return a configured JAX RS {@link Server}. + */ @Bean public Server jaxRsServer() { @@ -106,6 +126,9 @@ private Collection findRestServices() { return this.applicationContext.getBeansWithAnnotation(Path.class).values(); } + /** + * @return the {@link RestServiceExceptionFacade}. + */ @Bean public RestServiceExceptionFacade restServiceExceptionFacade() { @@ -115,6 +138,9 @@ public RestServiceExceptionFacade restServiceExceptionFacade() { } // BEGIN ARCHETYPE SKIP + /** + * @return an {@link Endpoint} at /TablemanagementWebService. + */ @Bean public Endpoint tableManagement() { diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/offermanagement/service/impl/rest/OffermanagementRestServiceImpl.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/offermanagement/service/impl/rest/OffermanagementRestServiceImpl.java index aa910786d..4396f47f9 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/offermanagement/service/impl/rest/OffermanagementRestServiceImpl.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/offermanagement/service/impl/rest/OffermanagementRestServiceImpl.java @@ -181,8 +181,7 @@ public void updateProductPicture(long productId, BinaryObjectEto binaryObjectEto public MultipartBody getProductPicture(long productId) throws SQLException, IOException { Blob blob = this.offermanagement.findProductPictureBlob(productId); - // REVIEW arturk88 (hohwille) we need to find another way to stream the blob without loading into heap. - // https://github.com/oasp/oasp4j-sample/pull/45 + // byte[] data = IOUtils.readBytesFromStream(blob.getBinaryStream()); InputStream data = blob.getBinaryStream(); diff --git a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/websocket/config/WebSocketConfig.java b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/websocket/config/WebSocketConfig.java index fd4a4aca7..54cf66160 100644 --- a/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/websocket/config/WebSocketConfig.java +++ b/samples/core/src/main/java/io/oasp/gastronomy/restaurant/salesmanagement/websocket/config/WebSocketConfig.java @@ -6,6 +6,9 @@ import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; import org.springframework.web.socket.config.annotation.StompEndpointRegistry; +/** + * Configuration class overriding two Spring methods from {@link AbstractWebSocketMessageBrokerConfigurer}. + */ @Configuration @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/BillEntityBuilder.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/BillEntityBuilder.java index 8372626ba..a10b39110 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/BillEntityBuilder.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/common/builders/BillEntityBuilder.java @@ -122,7 +122,7 @@ public void apply(BillEntity target) { * @param orderPositionIds the orderPositionIds to add. * @return the builder for fluent population of fields. */ - public BillEntityBuilder orderPositionIds(final List orderPositionIds) { + public BillEntityBuilder orderPositionIds(final List orderPositionIds) { this.parameterToBeApplied.add(new P() { @Override @@ -140,7 +140,7 @@ public void apply(BillEntity target) { public BillEntity createNew() { BillEntity billentity = new BillEntity(); - for (P parameter : parameterToBeApplied) { + for (P parameter : this.parameterToBeApplied) { parameter.apply(billentity); } return billentity; diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/general/common/AbstractSpringBatchIntegrationTest.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/general/common/AbstractSpringBatchIntegrationTest.java index 647dbc877..c334ff6b8 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/general/common/AbstractSpringBatchIntegrationTest.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/general/common/AbstractSpringBatchIntegrationTest.java @@ -39,10 +39,15 @@ public abstract class AbstractSpringBatchIntegrationTest extends ComponentTest { /** scripts for all tests db setup */ private static final String ALL_TESTS_DB_SETUP_DIR = "classpath:AllTests/setup/db"; + /** + * @param login the login. + * @param password the password. + * @param permissions the permissions. + */ protected static void login(String login, String password, String... permissions) { - + Set groups = new HashSet<>(Arrays.asList(permissions)); - + Set authorities = new HashSet<>(); for (String permission : groups) { authorities.add(new AccessControlGrantedAuthority(new AccessControlPermission(permission))); @@ -51,8 +56,11 @@ protected static void login(String login, String password, String... permissions new UsernamePasswordAuthenticationToken(new UserData(login, password, authorities), password)); } + /** + * Log out utility. + */ public static void logout() { - + SecurityContextHolder.getContext().setAuthentication(null); } diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/general/configuration/BeansJpaConfiguration.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/general/configuration/BeansJpaConfiguration.java index 33e3bed64..cec1dff87 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/general/configuration/BeansJpaConfiguration.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/general/configuration/BeansJpaConfiguration.java @@ -1,9 +1,6 @@ package io.oasp.gastronomy.restaurant.general.configuration; -import io.oasp.gastronomy.restaurant.general.dataaccess.base.DatabaseMigrator; - import javax.annotation.PostConstruct; -import javax.persistence.EntityManagerFactory; import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; @@ -11,6 +8,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import io.oasp.gastronomy.restaurant.general.dataaccess.base.DatabaseMigrator; + /** * Java configuration for JPA * @@ -20,8 +19,6 @@ // @EnableTransactionManagement public class BeansJpaConfiguration { - private @Autowired EntityManagerFactory entityManagerFactory; - private @Autowired DataSource appDataSource; @Value("${database.migration.auto}") @@ -33,6 +30,9 @@ public class BeansJpaConfiguration { @Value("${database.migration.clean}") private Boolean clean; + /** + * @return the configured {@link DatabaseMigrator}. + */ @Bean public DatabaseMigrator getFlyway() { @@ -45,6 +45,9 @@ public DatabaseMigrator getFlyway() { } + /** + * Migration operation. + */ @PostConstruct public void migrate() { diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/general/configuration/TestWebSecurityConfig.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/general/configuration/TestWebSecurityConfig.java index 36d203ba7..61837c61a 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/general/configuration/TestWebSecurityConfig.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/general/configuration/TestWebSecurityConfig.java @@ -42,6 +42,10 @@ public void configure(HttpSecurity http) throws Exception { LOG.debug("used non static class"); } + /** + * @return the {@link BasicAuthenticationFilter}. + * @throws Exception to pass over. + */ @Bean protected BasicAuthenticationFilter basicAuthenticationFilter() throws Exception { diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/offermanagement/logic/impl/OffermanagementImplTest.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/offermanagement/logic/impl/OffermanagementImplTest.java index 8d9e270ba..e428d63e7 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/offermanagement/logic/impl/OffermanagementImplTest.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/offermanagement/logic/impl/OffermanagementImplTest.java @@ -35,6 +35,9 @@ public class OffermanagementImplTest extends ModuleTest { private OffermanagementImpl offerManagementImpl; + /** + * Mockito rule to enable mockito features. + */ @Rule public MockitoRule rule = MockitoJUnit.rule(); diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementHttpRestServiceTest.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementHttpRestServiceTest.java index 26074076d..d362de9f8 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementHttpRestServiceTest.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementHttpRestServiceTest.java @@ -29,8 +29,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.skyscreamer.jsonassert.JSONAssert; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -64,8 +62,6 @@ public class SalesmanagementHttpRestServiceTest extends AbstractRestServiceTest private final HttpHeaders AUTHENTIFICATED_HEADERS = getAuthentificatedHeaders(); - private static Logger LOG = LoggerFactory.getLogger(SalesmanagementHttpRestServiceTest.class); - private SalesmanagementRestService service; @Inject diff --git a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementRestServiceTest.java b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementRestServiceTest.java index 916be0bdf..1317e929b 100644 --- a/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementRestServiceTest.java +++ b/samples/core/src/test/java/io/oasp/gastronomy/restaurant/salesmanagement/service/impl/rest/SalesmanagementRestServiceTest.java @@ -19,8 +19,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -49,8 +47,6 @@ public class SalesmanagementRestServiceTest extends AbstractRestServiceTest { - private static Logger LOG = LoggerFactory.getLogger(SalesmanagementRestServiceTest.class); - private SalesmanagementRestService service; @Inject From 2eba388314412cefd3e093835046ad4aeb251b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B6ger?= Date: Thu, 1 Sep 2016 09:39:08 +0200 Subject: [PATCH 10/10] Added JavaDoc, fixing Java Problems --- .../base/SpringBootBatchCommandLine.java | 464 +++++++++--------- .../common/impl/ChunkLoggingListener.java | 10 +- ...nUsernamePasswordAuthenticationFilter.java | 7 +- .../web/common/base/ToggleFilterWrapper.java | 12 +- 4 files changed, 243 insertions(+), 250 deletions(-) diff --git a/modules/batch/src/main/java/io/oasp/module/batch/common/base/SpringBootBatchCommandLine.java b/modules/batch/src/main/java/io/oasp/module/batch/common/base/SpringBootBatchCommandLine.java index c934c1b28..5f7c17452 100644 --- a/modules/batch/src/main/java/io/oasp/module/batch/common/base/SpringBootBatchCommandLine.java +++ b/modules/batch/src/main/java/io/oasp/module/batch/common/base/SpringBootBatchCommandLine.java @@ -25,29 +25,24 @@ import org.springframework.util.StringUtils; /** - * Launcher for launching batch jobs from the command line when Spring Boot is - * used. Similar to the {@link CommandLineJobRunner}, which does not work very - * well with Spring Boot. + * Launcher for launching batch jobs from the command line when Spring Boot is used. Similar to the + * {@link CommandLineJobRunner}, which does not work very well with Spring Boot. *

* Do not use this class if Spring Boot is not used! *

- * It expects the full class name of the Spring Boot configuration class to be - * used as first argument, the class/XML file for configuring the job as second - * argument and the job name as third.
- * Moreover parameters can be specified as further arguments (convention: - * key1=value1 key2=value2 ...). + * It expects the full class name of the Spring Boot configuration class to be used as first argument, the class/XML + * file for configuring the job as second argument and the job name as third.
+ * Moreover parameters can be specified as further arguments (convention: key1=value1 key2=value2 ...). *

* Example:
- * java io.oasp.module.batch.common.base.SpringBootBatchCommandLine - * io.oasp.gastronomy.restaurant.SpringBootBatchApp - * classpath:config/app/batch/beans-productimport.xml productImportJob - * drinks.file=file:import/drinks.csv date(date)=2015/12/20 + * java io.oasp.module.batch.common.base.SpringBootBatchCommandLine io.oasp.gastronomy.restaurant.SpringBootBatchApp + * classpath:config/app/batch/beans-productimport.xml productImportJob drinks.file=file:import/drinks.csv + * date(date)=2015/12/20 *

* For stopping all running executions of a job, use the -stop option. *

* Example:
- * java io.oasp.module.batch.common.base.SpringBootBatchCommandLine - * io.oasp.gastronomy.restaurant.SpringBootBatchApp + * java io.oasp.module.batch.common.base.SpringBootBatchCommandLine io.oasp.gastronomy.restaurant.SpringBootBatchApp * classpath:config/app/batch/beans-productimport.xml productImportJob -stop * * @author Ludger Overbeck @@ -55,272 +50,265 @@ */ public class SpringBootBatchCommandLine { - private static final Logger LOG = LoggerFactory - .getLogger(SpringBootBatchCommandLine.class); + private static final Logger LOG = LoggerFactory.getLogger(SpringBootBatchCommandLine.class); - private ResourceLoader resourceLoader = new DefaultResourceLoader(); + private ResourceLoader resourceLoader = new DefaultResourceLoader(); - public static enum Operation { - START, STOP - }; + /** + * Possible operation values. + */ + public static enum Operation { + /** + * Enum representing start. + */ + START, + /** + * Enum representing stop. + */ + STOP + }; - private JobLauncher launcher; + private JobLauncher launcher; - private JobLocator locator; + private JobLocator locator; - private JobParametersConverter parametersConverter; + private JobParametersConverter parametersConverter; - private JobOperator operator; + private JobOperator operator; - public static void main(String[] args) throws Exception { + /** + * @param args - arguments + * @throws Exception if errors occur. + */ + public static void main(String[] args) throws Exception { - if (args.length < 3) { + if (args.length < 3) { - handleIncorrectParameters(); - return; - } + handleIncorrectParameters(); + return; + } - List configurations = new ArrayList(2); - configurations.add(args[0]); - configurations.add(args[1]); + List configurations = new ArrayList<>(2); + configurations.add(args[0]); + configurations.add(args[1]); - List parameters = new ArrayList(); + List parameters = new ArrayList<>(); - Operation op = Operation.START; - if (args.length > 3 && args[3].equalsIgnoreCase("-stop")) { + Operation op = Operation.START; + if (args.length > 3 && args[3].equalsIgnoreCase("-stop")) { - if (args.length > 4) { + if (args.length > 4) { - handleIncorrectParameters(); - return; - } + handleIncorrectParameters(); + return; + } - op = Operation.STOP; - } else { + op = Operation.STOP; + } else { - for (int i = 3; i < args.length; i++) { + for (int i = 3; i < args.length; i++) { - parameters.add(args[i]); - } - } + parameters.add(args[i]); + } + } - new SpringBootBatchCommandLine().execute(op, configurations, args[2], - parameters); - } + new SpringBootBatchCommandLine().execute(op, configurations, args[2], parameters); + } - private static void handleIncorrectParameters() { + private static void handleIncorrectParameters() { - LOG.error("Incorrect parameters."); - LOG.info("Usage:"); - LOG.info("java io.oasp.module.batch.common.base.SpringBootBatchCommandLine" - + " " - + " param1=value1 param2=value2 ..."); - LOG.info("For stopping all running executions of a batch job:"); - LOG.info("java io.oasp.module.batch.common.base.BatchCommandLine" - + " " - + " -stop"); - LOG.info("Example:"); - LOG.info("java io.oasp.module.batch.common.base.SpringBootBatchCommandLine" - + " io.oasp.gastronomy.restaurant.SpringBootBatchApp" - + " classpath:config/app/batch/beans-productimport.xml" - + " productImportJob drinks.file=file:import/drinks.csv" - + " date(date)=2015/12/20"); - } + LOG.error("Incorrect parameters."); + LOG.info("Usage:"); + LOG.info("java io.oasp.module.batch.common.base.SpringBootBatchCommandLine" + + " " + " param1=value1 param2=value2 ..."); + LOG.info("For stopping all running executions of a batch job:"); + LOG.info("java io.oasp.module.batch.common.base.BatchCommandLine" + + " " + " -stop"); + LOG.info("Example:"); + LOG.info("java io.oasp.module.batch.common.base.SpringBootBatchCommandLine" + + " io.oasp.gastronomy.restaurant.SpringBootBatchApp" + " classpath:config/app/batch/beans-productimport.xml" + + " productImportJob drinks.file=file:import/drinks.csv" + " date(date)=2015/12/20"); + } - protected int getReturnCode(JobExecution jobExecution) { + /** + * @param jobExecution the {@link JobExecution} to use. + * @return the return code 0 if completed, 1 else. + */ + protected int getReturnCode(JobExecution jobExecution) { - if (jobExecution.getStatus() != null - && jobExecution.getStatus() == BatchStatus.COMPLETED) - return 0; - else - return 1; - } + if (jobExecution.getStatus() != null && jobExecution.getStatus() == BatchStatus.COMPLETED) + return 0; + else + return 1; + } - private Object getConfiguration(String stringRepresentation) { + private Object getConfiguration(String stringRepresentation) { - // try to load a source of Spring bean definitions: - // 1. try to load it as a (JavaConfig) class - // 2. if that fails: try to load it as XML resource + // try to load a source of Spring bean definitions: + // 1. try to load it as a (JavaConfig) class + // 2. if that fails: try to load it as XML resource - try { + try { - return Class.forName(stringRepresentation); - } catch (ClassNotFoundException e) { + return Class.forName(stringRepresentation); + } catch (ClassNotFoundException e) { - return resourceLoader.getResource(stringRepresentation); - } - } + return this.resourceLoader.getResource(stringRepresentation); + } + } - private void findBeans(ConfigurableApplicationContext ctx) { + private void findBeans(ConfigurableApplicationContext ctx) { - launcher = ctx.getBean(JobLauncher.class); - locator = ctx.getBean(JobLocator.class); // supertype of JobRegistry - operator = ctx.getBean(JobOperator.class); - try { + this.launcher = ctx.getBean(JobLauncher.class); + this.locator = ctx.getBean(JobLocator.class); // supertype of JobRegistry + this.operator = ctx.getBean(JobOperator.class); + try { - parametersConverter = ctx.getBean(JobParametersConverter.class); - } catch (NoSuchBeanDefinitionException e) { + this.parametersConverter = ctx.getBean(JobParametersConverter.class); + } catch (NoSuchBeanDefinitionException e) { - parametersConverter = new DefaultJobParametersConverter(); - } - } + this.parametersConverter = new DefaultJobParametersConverter(); + } + } - /** - * Initialize the application context and execute the operation. - *

- * The application context is closed after the operation has finished. - * - * @param operation - * The operation to start. - * @param configurations - * The sources of bean configurations (either JavaConfig classes - * or XML files). - * @param jobName - * The name of the job to launch/stop. - * @param parameters - * The parameters (key=value). - * @throws Exception - */ - public void execute(Operation operation, List configurations, - String jobName, List parameters) throws Exception { - - // get sources of configuration - Object[] configurationObjects = new Object[configurations.size()]; - for (int i = 0; i < configurations.size(); i++) { - - configurationObjects[i] = getConfiguration(configurations.get(i)); - } - - SpringApplication app = new SpringApplication(configurationObjects); - - // no (web) server needed - app.setWebEnvironment(false); - - // start the application - ConfigurableApplicationContext ctx = app.run(new String[0]); - - switch (operation) { - case START: - startBatch(ctx, jobName, parameters); - break; - case STOP: - stopBatch(ctx, jobName); - break; - default: - throw new RuntimeException("Unknown operation: " + operation); - } - - } - - private void startBatch(ConfigurableApplicationContext ctx, String jobName, - List parameters) throws Exception { - - JobExecution jobExecution = null; - try { - - findBeans(ctx); - - JobParameters params = parametersConverter - .getJobParameters(StringUtils - .splitArrayElementsIntoProperties( - parameters.toArray(new String[] {}), "=")); - - // execute the batch - // the JobOperator would require special logic for a restart, so we - // are using the JobLauncher directly here - jobExecution = launcher.run(locator.getJob(jobName), params); - - } finally { - - // evaluate the outcome - final int returnCode = (jobExecution == null) ? 1 - : getReturnCode(jobExecution); - if (jobExecution == null) { - - LOG.error("Batch Status: Batch could not be started."); - } else { - - LOG.info("Batch start time: {}", - jobExecution.getStartTime() == null ? "null" - : jobExecution.getStartTime()); - LOG.info("Batch end time: {}", - jobExecution.getEndTime() == null ? "null" - : jobExecution.getEndTime()); - - if (returnCode == 0) { - - LOG.info("Batch Status: {}", - jobExecution.getStatus() == null ? "null" - : jobExecution.getStatus()); - } else { - - LOG.error("Batch Status: {}", - jobExecution.getStatus() == null ? "null" - : jobExecution.getStatus()); - } - } - LOG.info("Return Code: {}", returnCode); - - SpringApplication.exit(ctx, new ExitCodeGenerator() { - - @Override - public int getExitCode() { - return returnCode; - } - }); - } - } - - private void stopBatch(ConfigurableApplicationContext ctx, String jobName) - throws Exception { - - int returnCode = 0; - try { + /** + * Initialize the application context and execute the operation. + *

+ * The application context is closed after the operation has finished. + * + * @param operation The operation to start. + * @param configurations The sources of bean configurations (either JavaConfig classes or XML files). + * @param jobName The name of the job to launch/stop. + * @param parameters The parameters (key=value). + * @throws Exception to pass over. + */ + public void execute(Operation operation, List configurations, String jobName, List parameters) + throws Exception { - findBeans(ctx); + // get sources of configuration + Object[] configurationObjects = new Object[configurations.size()]; + for (int i = 0; i < configurations.size(); i++) { - Set runningJobExecutionIDs = operator - .getRunningExecutions(jobName); - if (runningJobExecutionIDs.isEmpty()) { + configurationObjects[i] = getConfiguration(configurations.get(i)); + } - throw new JobExecutionNotRunningException("Batch job " - + jobName + " is currently not being executed."); - } + SpringApplication app = new SpringApplication(configurationObjects); - LOG.debug("Found {} executions to be stopped (potentially" - + " already in state stopping).", - runningJobExecutionIDs.size()); + // no (web) server needed + app.setWebEnvironment(false); - int stoppedCount = 0; - for (Long id : runningJobExecutionIDs) { + // start the application + ConfigurableApplicationContext ctx = app.run(new String[0]); - try { + switch (operation) { + case START: + startBatch(ctx, jobName, parameters); + break; + case STOP: + stopBatch(ctx, jobName); + break; + default: + throw new RuntimeException("Unknown operation: " + operation); + } - operator.stop(id); - stoppedCount++; - } catch (JobExecutionNotRunningException e) { - - // might have finished at this point - // or was in state stopping already - } - } + } - LOG.info("Actually stopped {} batch executions.", stoppedCount); + private void startBatch(ConfigurableApplicationContext ctx, String jobName, List parameters) + throws Exception { - } catch (Exception e) { + JobExecution jobExecution = null; + try { - returnCode = 1; - throw e; - } finally { + findBeans(ctx); - final int returnCodeResult = returnCode; - SpringApplication.exit(ctx, new ExitCodeGenerator() { + JobParameters params = this.parametersConverter + .getJobParameters(StringUtils.splitArrayElementsIntoProperties(parameters.toArray(new String[] {}), "=")); - @Override - public int getExitCode() { - return returnCodeResult; - } - }); - } - } + // execute the batch + // the JobOperator would require special logic for a restart, so we + // are using the JobLauncher directly here + jobExecution = this.launcher.run(this.locator.getJob(jobName), params); + + } finally { + + // evaluate the outcome + final int returnCode = (jobExecution == null) ? 1 : getReturnCode(jobExecution); + if (jobExecution == null) { + + LOG.error("Batch Status: Batch could not be started."); + } else { + + LOG.info("Batch start time: {}", jobExecution.getStartTime() == null ? "null" : jobExecution.getStartTime()); + LOG.info("Batch end time: {}", jobExecution.getEndTime() == null ? "null" : jobExecution.getEndTime()); + + if (returnCode == 0) { + + LOG.info("Batch Status: {}", jobExecution.getStatus() == null ? "null" : jobExecution.getStatus()); + } else { + + LOG.error("Batch Status: {}", jobExecution.getStatus() == null ? "null" : jobExecution.getStatus()); + } + } + LOG.info("Return Code: {}", returnCode); + + SpringApplication.exit(ctx, new ExitCodeGenerator() { + + @Override + public int getExitCode() { + + return returnCode; + } + }); + } + } + + private void stopBatch(ConfigurableApplicationContext ctx, String jobName) throws Exception { + + int returnCode = 0; + try { + + findBeans(ctx); + + Set runningJobExecutionIDs = this.operator.getRunningExecutions(jobName); + if (runningJobExecutionIDs.isEmpty()) { + + throw new JobExecutionNotRunningException("Batch job " + jobName + " is currently not being executed."); + } + + LOG.debug("Found {} executions to be stopped (potentially" + " already in state stopping).", + runningJobExecutionIDs.size()); + + int stoppedCount = 0; + for (Long id : runningJobExecutionIDs) { + + try { + + this.operator.stop(id); + stoppedCount++; + } catch (JobExecutionNotRunningException e) { + + // might have finished at this point + // or was in state stopping already + } + } + + LOG.info("Actually stopped {} batch executions.", stoppedCount); + + } catch (Exception e) { + + returnCode = 1; + throw e; + } finally { + + final int returnCodeResult = returnCode; + SpringApplication.exit(ctx, new ExitCodeGenerator() { + + @Override + public int getExitCode() { + + return returnCodeResult; + } + }); + } + } } diff --git a/modules/batch/src/main/java/io/oasp/module/batch/common/impl/ChunkLoggingListener.java b/modules/batch/src/main/java/io/oasp/module/batch/common/impl/ChunkLoggingListener.java index 16008e079..fbaf5a635 100644 --- a/modules/batch/src/main/java/io/oasp/module/batch/common/impl/ChunkLoggingListener.java +++ b/modules/batch/src/main/java/io/oasp/module/batch/common/impl/ChunkLoggingListener.java @@ -14,12 +14,18 @@ * occurred. * * @author Ludger Overbeck + * @param generic item. + * @param generic item. */ -public class ChunkLoggingListener implements SkipListener, ItemReadListener, ItemProcessListener, - ItemWriteListener { +public class ChunkLoggingListener + implements SkipListener, ItemReadListener, ItemProcessListener, ItemWriteListener { private static final Logger LOG = LoggerFactory.getLogger(ChunkLoggingListener.class); + /** + * @param item the object to use. + * @return the string representation of the input. + */ protected String itemToString(Object item) { return item.toString(); diff --git a/modules/security/src/main/java/io/oasp/module/security/common/impl/rest/JsonUsernamePasswordAuthenticationFilter.java b/modules/security/src/main/java/io/oasp/module/security/common/impl/rest/JsonUsernamePasswordAuthenticationFilter.java index 9f2d44e9b..fde07a30c 100644 --- a/modules/security/src/main/java/io/oasp/module/security/common/impl/rest/JsonUsernamePasswordAuthenticationFilter.java +++ b/modules/security/src/main/java/io/oasp/module/security/common/impl/rest/JsonUsernamePasswordAuthenticationFilter.java @@ -63,8 +63,6 @@ public class JsonUsernamePasswordAuthenticationFilter extends AbstractAuthentica private boolean postOnly = true; - // REVIEW may-bee (hohwille) We have a centralized and custom-configured object mapper as spring bean. IMHO we should - // inject that instance here. private ObjectMapper objectMapper = new ObjectMapper(); /** @@ -88,9 +86,8 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ final UsernameAndPasswordParser usernameAndPasswordParser = new UsernameAndPasswordParser(request); usernameAndPasswordParser.parse(); - UsernamePasswordAuthenticationToken authRequest = - new UsernamePasswordAuthenticationToken(usernameAndPasswordParser.getTrimmedUsername(), - usernameAndPasswordParser.getPassword()); + UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken( + usernameAndPasswordParser.getTrimmedUsername(), usernameAndPasswordParser.getPassword()); // authRequest.setDetails(this.authenticationDetailsSource.buildDetails(request)); return getAuthenticationManager().authenticate(authRequest); } diff --git a/modules/web/src/main/java/io/oasp/module/web/common/base/ToggleFilterWrapper.java b/modules/web/src/main/java/io/oasp/module/web/common/base/ToggleFilterWrapper.java index f991d7e44..451fe6ede 100644 --- a/modules/web/src/main/java/io/oasp/module/web/common/base/ToggleFilterWrapper.java +++ b/modules/web/src/main/java/io/oasp/module/web/common/base/ToggleFilterWrapper.java @@ -50,13 +50,15 @@ public void init(FilterConfig filterConfig) throws ServletException { } + /** + * Initialization, for development mode only. + */ @PostConstruct public void initialize() { if (!this.enabled) { - String message = - "****** FILTER " + this.delegateFilter - + " HAS BEEN DISABLED! THIS FEATURE SHOULD ONLY BE USED IN DEVELOPMENT MODE ******"; + String message = "****** FILTER " + this.delegateFilter + + " HAS BEEN DISABLED! THIS FEATURE SHOULD ONLY BE USED IN DEVELOPMENT MODE ******"; LOG.warn(message); // CHECKSTYLE:OFF (for development only) System.err.println(message); @@ -65,8 +67,8 @@ public void initialize() { } @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, - ServletException { + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException { if (this.enabled) { this.delegateFilter.doFilter(request, response, chain);