* #496 Add pipeline module to parent pom ✨ * #496: Add main application class and test for pipeline * #496: Checkstyle format and add log messages on pipeline stages 🎨 * #496: Fill readme sections of pipeline ✨ * #496: Javadocs and checkstyle formatting 🎨 * #496: Follow PMD checks and add more explanation as block comment on App.java * #496: Apply requested PR changes by iluwatar 🎨 * #970: Replace log4j usage on commander pattern to Slf4j API 🎨 * #970: Replace log4j usage on dao pattern to Slf4j API 🎨 * #970: Replace log4j usage on data mapper pattern to Slf4j API 🎨 * #970: Remove log4j dependency on data transfer object pom 🔥 * #970: Replace log4j usage on module pattern to Slf4j API 🎨 * #970: Replace log4j usage on serverless pattern to Slf4j API 🎨 This also removes the aws log4j dependency * #970: Remove unnecessary gitignore line for log4j.xml 🔥 * #970: Remove remaining remnants of log4j 🔥 * #970: Replace System.out logging with appropriate logging methods 🎨 * #970: Replace System.out method references to Logger::info 🎨
This commit is contained in:
committed by
Ilkka Seppälä
parent
72b174619f
commit
cfdfedbd2e
@ -23,7 +23,6 @@
|
||||
package com.iluwatar.commander;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.apache.log4j.Logger;
|
||||
import com.iluwatar.commander.employeehandle.EmployeeHandle;
|
||||
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
|
||||
import com.iluwatar.commander.exceptions.ItemUnavailableException;
|
||||
@ -37,6 +36,8 @@ import com.iluwatar.commander.queue.QueueDatabase;
|
||||
import com.iluwatar.commander.queue.QueueTask;
|
||||
import com.iluwatar.commander.queue.QueueTask.TaskType;
|
||||
import com.iluwatar.commander.shippingservice.ShippingService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*<p>Commander pattern is used to handle all issues that can come up while making a
|
||||
@ -86,7 +87,7 @@ public class Commander {
|
||||
private final long messageTime;
|
||||
private final long employeeTime;
|
||||
private boolean finalSiteMsgShown;
|
||||
static final Logger LOG = Logger.getLogger(Commander.class);
|
||||
static final Logger LOG = LoggerFactory.getLogger(Commander.class);
|
||||
//we could also have another db where it stores all orders
|
||||
|
||||
Commander(EmployeeHandle empDb, PaymentService pService, ShippingService sService,
|
||||
@ -125,27 +126,27 @@ public class Commander {
|
||||
String transactionId = shippingService.receiveRequest(order.item, order.user.address);
|
||||
//could save this transaction id in a db too
|
||||
LOG.info("Order " + order.id + ": Shipping placed successfully, transaction id: " + transactionId);
|
||||
System.out.println("Order has been placed and will be shipped to you. Please wait while we make your"
|
||||
LOG.info("Order has been placed and will be shipped to you. Please wait while we make your"
|
||||
+ " payment... ");
|
||||
sendPaymentRequest(order);
|
||||
return;
|
||||
};
|
||||
Retry.HandleErrorIssue<Order> handleError = (o,err) -> {
|
||||
if (ShippingNotPossibleException.class.isAssignableFrom(err.getClass())) {
|
||||
System.out.println("Shipping is currently not possible to your address. We are working on the problem "
|
||||
LOG.info("Shipping is currently not possible to your address. We are working on the problem "
|
||||
+ "and will get back to you asap.");
|
||||
finalSiteMsgShown = true;
|
||||
LOG.info("Order " + order.id + ": Shipping not possible to address, trying to add problem to employee db..");
|
||||
employeeHandleIssue(o);
|
||||
} else if (ItemUnavailableException.class.isAssignableFrom(err.getClass())) {
|
||||
System.out.println("This item is currently unavailable. We will inform you as soon as the item becomes "
|
||||
LOG.info("This item is currently unavailable. We will inform you as soon as the item becomes "
|
||||
+ "available again.");
|
||||
finalSiteMsgShown = true;
|
||||
LOG.info("Order " + order.id + ": Item " + order.item + " unavailable, trying to add problem to employee "
|
||||
+ "handle..");
|
||||
employeeHandleIssue(o);
|
||||
} else {
|
||||
System.out.println("Sorry, there was a problem in creating your order. Please try later.");
|
||||
LOG.info("Sorry, there was a problem in creating your order. Please try later.");
|
||||
LOG.error("Order " + order.id + ": Shipping service unavailable, order not placed..");
|
||||
finalSiteMsgShown = true;
|
||||
}
|
||||
@ -183,7 +184,7 @@ public class Commander {
|
||||
order.paid = PaymentStatus.Done;
|
||||
LOG.info("Order " + order.id + ": Payment successful, transaction Id: " + transactionId);
|
||||
if (!finalSiteMsgShown) {
|
||||
System.out.println("Payment made successfully, thank you for shopping with us!!");
|
||||
LOG.info("Payment made successfully, thank you for shopping with us!!");
|
||||
finalSiteMsgShown = true;
|
||||
}
|
||||
sendSuccessMessage(order);
|
||||
@ -193,7 +194,7 @@ public class Commander {
|
||||
Retry.HandleErrorIssue<Order> handleError = (o,err) -> {
|
||||
if (PaymentDetailsErrorException.class.isAssignableFrom(err.getClass())) {
|
||||
if (!finalSiteMsgShown) {
|
||||
System.out.println("There was an error in payment. Your account/card details may have been incorrect. "
|
||||
LOG.info("There was an error in payment. Your account/card details may have been incorrect. "
|
||||
+ "Meanwhile, your order has been converted to COD and will be shipped.");
|
||||
finalSiteMsgShown = true;
|
||||
}
|
||||
@ -204,7 +205,7 @@ public class Commander {
|
||||
try {
|
||||
if (o.messageSent.equals(MessageSent.NoneSent)) {
|
||||
if (!finalSiteMsgShown) {
|
||||
System.out.println("There was an error in payment. We are on it, and will get back to you "
|
||||
LOG.info("There was an error in payment. We are on it, and will get back to you "
|
||||
+ "asap. Don't worry, your order has been placed and will be shipped.");
|
||||
finalSiteMsgShown = true;
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ package com.iluwatar.commander.messagingservice;
|
||||
|
||||
import com.iluwatar.commander.Service;
|
||||
import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The MessagingService is used to send messages to user regarding their order and
|
||||
@ -32,6 +34,7 @@ import com.iluwatar.commander.exceptions.DatabaseUnavailableException;
|
||||
*/
|
||||
|
||||
public class MessagingService extends Service {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MessagingService.class);
|
||||
|
||||
enum MessageToSend {
|
||||
PaymentFail, PaymentTrying, PaymentSuccessful
|
||||
@ -74,7 +77,7 @@ public class MessagingService extends Service {
|
||||
MessageRequest req = (MessageRequest) parameters[0];
|
||||
if (this.database.get(req.reqId) == null) { //idempotence, in case db fails here
|
||||
database.add(req); //if successful:
|
||||
System.out.println(sendMessage(req.msg));
|
||||
LOGGER.info(sendMessage(req.msg));
|
||||
return req.reqId;
|
||||
}
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user