#502 Replaced usages of System.out with logger.
This commit is contained in:
@ -30,6 +30,8 @@ import com.iluwatar.hexagonal.domain.LotteryService;
|
||||
import com.iluwatar.hexagonal.module.LotteryModule;
|
||||
import com.iluwatar.hexagonal.mongo.MongoConnectionPropertiesLoader;
|
||||
import com.iluwatar.hexagonal.sampledata.SampleData;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
@ -38,6 +40,8 @@ import java.util.Scanner;
|
||||
*/
|
||||
public class ConsoleAdministration {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConsoleAdministration.class);
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
*/
|
||||
@ -53,29 +57,29 @@ public class ConsoleAdministration {
|
||||
printMainMenu();
|
||||
String cmd = readString(scanner);
|
||||
if (cmd.equals("1")) {
|
||||
administartion.getAllSubmittedTickets().forEach((k,v)->System.out.println("Key: " + k + " Value: " + v));
|
||||
administartion.getAllSubmittedTickets().forEach((k,v)->LOGGER.info("Key: {}, Value: {}", k, v));
|
||||
} else if (cmd.equals("2")) {
|
||||
LotteryNumbers numbers = administartion.performLottery();
|
||||
System.out.println("The winning numbers: " + numbers.getNumbersAsString());
|
||||
System.out.println("Time to reset the database for next round, eh?");
|
||||
LOGGER.info("The winning numbers: {}", numbers.getNumbersAsString());
|
||||
LOGGER.info("Time to reset the database for next round, eh?");
|
||||
} else if (cmd.equals("3")) {
|
||||
administartion.resetLottery();
|
||||
System.out.println("The lottery ticket database was cleared.");
|
||||
LOGGER.info("The lottery ticket database was cleared.");
|
||||
} else if (cmd.equals("4")) {
|
||||
exit = true;
|
||||
} else {
|
||||
System.out.println("Unknown command: " + cmd);
|
||||
LOGGER.info("Unknown command: {}", cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void printMainMenu() {
|
||||
System.out.println("");
|
||||
System.out.println("### Lottery Administration Console ###");
|
||||
System.out.println("(1) Show all submitted tickets");
|
||||
System.out.println("(2) Perform lottery draw");
|
||||
System.out.println("(3) Reset lottery ticket database");
|
||||
System.out.println("(4) Exit");
|
||||
LOGGER.info("");
|
||||
LOGGER.info("### Lottery Administration Console ###");
|
||||
LOGGER.info("(1) Show all submitted tickets");
|
||||
LOGGER.info("(2) Perform lottery draw");
|
||||
LOGGER.info("(3) Reset lottery ticket database");
|
||||
LOGGER.info("(4) Exit");
|
||||
}
|
||||
|
||||
private static String readString(Scanner scanner) {
|
||||
|
@ -23,42 +23,42 @@
|
||||
package com.iluwatar.hexagonal.eventlog;
|
||||
|
||||
import com.iluwatar.hexagonal.domain.PlayerDetails;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Standard output event log
|
||||
*/
|
||||
public class StdOutEventLog implements LotteryEventLog {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(StdOutEventLog.class);
|
||||
|
||||
@Override
|
||||
public void ticketSubmitted(PlayerDetails details) {
|
||||
System.out.println(String.format("Lottery ticket for %s was submitted. Bank account %s was charged for 3 credits.",
|
||||
details.getEmail(), details.getBankAccount()));
|
||||
LOGGER.info("Lottery ticket for {} was submitted. Bank account {} was charged for 3 credits.",
|
||||
details.getEmail(), details.getBankAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ticketDidNotWin(PlayerDetails details) {
|
||||
System.out.println(String.format("Lottery ticket for %s was checked and unfortunately did not win this time.",
|
||||
details.getEmail()));
|
||||
LOGGER.info("Lottery ticket for {} was checked and unfortunately did not win this time.", details.getEmail());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ticketWon(PlayerDetails details, int prizeAmount) {
|
||||
System.out
|
||||
.println(String.format("Lottery ticket for %s has won! The bank account %s was deposited with %d credits.",
|
||||
details.getEmail(), details.getBankAccount(), prizeAmount));
|
||||
LOGGER.info("Lottery ticket for {} has won! The bank account {} was deposited with {} credits.",
|
||||
details.getEmail(), details.getBankAccount(), prizeAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prizeError(PlayerDetails details, int prizeAmount) {
|
||||
System.out
|
||||
.println(String.format("Lottery ticket for %s has won! Unfortunately the bank credit transfer of %d failed.",
|
||||
details.getEmail(), prizeAmount));
|
||||
LOGGER.error("Lottery ticket for {} has won! Unfortunately the bank credit transfer of {} failed.",
|
||||
details.getEmail(), prizeAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ticketSubmitError(PlayerDetails details) {
|
||||
System.out.println(
|
||||
String.format("Lottery ticket for %s could not be submitted because the credit transfer of 3 credits failed.",
|
||||
details.getEmail()));
|
||||
LOGGER.error("Lottery ticket for {} could not be submitted because the credit transfer of 3 credits failed.",
|
||||
details.getEmail());
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ package com.iluwatar.hexagonal.service;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.iluwatar.hexagonal.administration.ConsoleAdministration;
|
||||
import com.iluwatar.hexagonal.banking.WireTransfers;
|
||||
import com.iluwatar.hexagonal.domain.LotteryNumbers;
|
||||
import com.iluwatar.hexagonal.domain.LotteryService;
|
||||
@ -33,6 +34,8 @@ import com.iluwatar.hexagonal.domain.LotteryTicketId;
|
||||
import com.iluwatar.hexagonal.domain.PlayerDetails;
|
||||
import com.iluwatar.hexagonal.module.LotteryModule;
|
||||
import com.iluwatar.hexagonal.mongo.MongoConnectionPropertiesLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
@ -44,6 +47,7 @@ import java.util.Set;
|
||||
*/
|
||||
public class ConsoleLottery {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConsoleLottery.class);
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
@ -59,25 +63,25 @@ public class ConsoleLottery {
|
||||
printMainMenu();
|
||||
String cmd = readString(scanner);
|
||||
if (cmd.equals("1")) {
|
||||
System.out.println("What is the account number?");
|
||||
LOGGER.info("What is the account number?");
|
||||
String account = readString(scanner);
|
||||
System.out.println(String.format("The account %s has %d credits.", account, bank.getFunds(account)));
|
||||
LOGGER.info("The account {} has {} credits.", account, bank.getFunds(account));
|
||||
} else if (cmd.equals("2")) {
|
||||
System.out.println("What is the account number?");
|
||||
LOGGER.info("What is the account number?");
|
||||
String account = readString(scanner);
|
||||
System.out.println("How many credits do you want to deposit?");
|
||||
LOGGER.info("How many credits do you want to deposit?");
|
||||
String amount = readString(scanner);
|
||||
bank.setFunds(account, Integer.parseInt(amount));
|
||||
System.out.println(String.format("The account %s now has %d credits.", account, bank.getFunds(account)));
|
||||
LOGGER.info("The account {} now has {} credits.", account, bank.getFunds(account));
|
||||
} else if (cmd.equals("3")) {
|
||||
System.out.println("What is your email address?");
|
||||
LOGGER.info("What is your email address?");
|
||||
String email = readString(scanner);
|
||||
System.out.println("What is your bank account number?");
|
||||
LOGGER.info("What is your bank account number?");
|
||||
String account = readString(scanner);
|
||||
System.out.println("What is your phone number?");
|
||||
LOGGER.info("What is your phone number?");
|
||||
String phone = readString(scanner);
|
||||
PlayerDetails details = new PlayerDetails(email, account, phone);
|
||||
System.out.println("Give 4 comma separated lottery numbers?");
|
||||
LOGGER.info("Give 4 comma separated lottery numbers?");
|
||||
String numbers = readString(scanner);
|
||||
try {
|
||||
String[] parts = numbers.split(",");
|
||||
@ -89,17 +93,17 @@ public class ConsoleLottery {
|
||||
LotteryTicket lotteryTicket = new LotteryTicket(new LotteryTicketId(), details, lotteryNumbers);
|
||||
Optional<LotteryTicketId> id = service.submitTicket(lotteryTicket);
|
||||
if (id.isPresent()) {
|
||||
System.out.println("Submitted lottery ticket with id: " + id.get());
|
||||
LOGGER.info("Submitted lottery ticket with id: {}", id.get());
|
||||
} else {
|
||||
System.out.println("Failed submitting lottery ticket - please try again.");
|
||||
LOGGER.info("Failed submitting lottery ticket - please try again.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed submitting lottery ticket - please try again.");
|
||||
LOGGER.info("Failed submitting lottery ticket - please try again.");
|
||||
}
|
||||
} else if (cmd.equals("4")) {
|
||||
System.out.println("What is the ID of the lottery ticket?");
|
||||
LOGGER.info("What is the ID of the lottery ticket?");
|
||||
String id = readString(scanner);
|
||||
System.out.println("Give the 4 comma separated winning numbers?");
|
||||
LOGGER.info("Give the 4 comma separated winning numbers?");
|
||||
String numbers = readString(scanner);
|
||||
try {
|
||||
String[] parts = numbers.split(",");
|
||||
@ -110,31 +114,31 @@ public class ConsoleLottery {
|
||||
LotteryTicketCheckResult result = service.checkTicketForPrize(
|
||||
new LotteryTicketId(Integer.parseInt(id)), LotteryNumbers.create(winningNumbers));
|
||||
if (result.getResult().equals(LotteryTicketCheckResult.CheckResult.WIN_PRIZE)) {
|
||||
System.out.println("Congratulations! The lottery ticket has won!");
|
||||
LOGGER.info("Congratulations! The lottery ticket has won!");
|
||||
} else if (result.getResult().equals(LotteryTicketCheckResult.CheckResult.NO_PRIZE)) {
|
||||
System.out.println("Unfortunately the lottery ticket did not win.");
|
||||
LOGGER.info("Unfortunately the lottery ticket did not win.");
|
||||
} else {
|
||||
System.out.println("Such lottery ticket has not been submitted.");
|
||||
LOGGER.info("Such lottery ticket has not been submitted.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Failed checking the lottery ticket - please try again.");
|
||||
LOGGER.info("Failed checking the lottery ticket - please try again.");
|
||||
}
|
||||
} else if (cmd.equals("5")) {
|
||||
exit = true;
|
||||
} else {
|
||||
System.out.println("Unknown command");
|
||||
LOGGER.info("Unknown command");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void printMainMenu() {
|
||||
System.out.println("");
|
||||
System.out.println("### Lottery Service Console ###");
|
||||
System.out.println("(1) Query lottery account funds");
|
||||
System.out.println("(2) Add funds to lottery account");
|
||||
System.out.println("(3) Submit ticket");
|
||||
System.out.println("(4) Check ticket");
|
||||
System.out.println("(5) Exit");
|
||||
LOGGER.info("");
|
||||
LOGGER.info("### Lottery Service Console ###");
|
||||
LOGGER.info("(1) Query lottery account funds");
|
||||
LOGGER.info("(2) Add funds to lottery account");
|
||||
LOGGER.info("(3) Submit ticket");
|
||||
LOGGER.info("(4) Check ticket");
|
||||
LOGGER.info("(5) Exit");
|
||||
}
|
||||
|
||||
private static String readString(Scanner scanner) {
|
||||
|
Reference in New Issue
Block a user