mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-18 00:59:37 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -58,9 +58,7 @@ import com.iluwatar.hexagonal.sampledata.SampleData;
|
||||
*/
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*/
|
||||
/** Program entry point. */
|
||||
public static void main(String[] args) {
|
||||
|
||||
var injector = Guice.createInjector(new LotteryTestingModule());
|
||||
|
||||
+2
-6
@@ -33,15 +33,11 @@ import com.iluwatar.hexagonal.sampledata.SampleData;
|
||||
import java.util.Scanner;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Console interface for lottery administration.
|
||||
*/
|
||||
/** Console interface for lottery administration. */
|
||||
@Slf4j
|
||||
public class ConsoleAdministration {
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*/
|
||||
/** Program entry point. */
|
||||
public static void main(String[] args) {
|
||||
MongoConnectionPropertiesLoader.load();
|
||||
var injector = Guice.createInjector(new LotteryModule());
|
||||
|
||||
+4
-12
@@ -24,23 +24,15 @@
|
||||
*/
|
||||
package com.iluwatar.hexagonal.administration;
|
||||
|
||||
/**
|
||||
* Console interface for lottery administration.
|
||||
*/
|
||||
/** Console interface for lottery administration. */
|
||||
public interface ConsoleAdministrationSrv {
|
||||
|
||||
/**
|
||||
* Get all submitted tickets.
|
||||
*/
|
||||
/** Get all submitted tickets. */
|
||||
void getAllSubmittedTickets();
|
||||
|
||||
/**
|
||||
* Draw lottery numbers.
|
||||
*/
|
||||
/** Draw lottery numbers. */
|
||||
void performLottery();
|
||||
|
||||
/**
|
||||
* Begin new lottery round.
|
||||
*/
|
||||
/** Begin new lottery round. */
|
||||
void resetLottery();
|
||||
}
|
||||
|
||||
+4
-7
@@ -27,16 +27,12 @@ package com.iluwatar.hexagonal.administration;
|
||||
import com.iluwatar.hexagonal.domain.LotteryAdministration;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* Console implementation for lottery administration.
|
||||
*/
|
||||
/** Console implementation for lottery administration. */
|
||||
public class ConsoleAdministrationSrvImpl implements ConsoleAdministrationSrv {
|
||||
private final LotteryAdministration administration;
|
||||
private final Logger logger;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
/** Constructor. */
|
||||
public ConsoleAdministrationSrvImpl(LotteryAdministration administration, Logger logger) {
|
||||
this.administration = administration;
|
||||
this.logger = logger;
|
||||
@@ -44,7 +40,8 @@ public class ConsoleAdministrationSrvImpl implements ConsoleAdministrationSrv {
|
||||
|
||||
@Override
|
||||
public void getAllSubmittedTickets() {
|
||||
administration.getAllSubmittedTickets()
|
||||
administration
|
||||
.getAllSubmittedTickets()
|
||||
.forEach((k, v) -> logger.info("Key: {}, Value: {}", k, v));
|
||||
}
|
||||
|
||||
|
||||
+3
-5
@@ -28,16 +28,14 @@ import com.iluwatar.hexagonal.domain.LotteryConstants;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Banking implementation.
|
||||
*/
|
||||
/** Banking implementation. */
|
||||
public class InMemoryBank implements WireTransfers {
|
||||
|
||||
private static final Map<String, Integer> accounts = new HashMap<>();
|
||||
|
||||
static {
|
||||
accounts
|
||||
.put(LotteryConstants.SERVICE_BANK_ACCOUNT, LotteryConstants.SERVICE_BANK_ACCOUNT_BALANCE);
|
||||
accounts.put(
|
||||
LotteryConstants.SERVICE_BANK_ACCOUNT, LotteryConstants.SERVICE_BANK_ACCOUNT_BALANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+11
-23
@@ -32,51 +32,39 @@ import java.util.ArrayList;
|
||||
import lombok.Getter;
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
* Mongo based banking adapter.
|
||||
*/
|
||||
/** Mongo based banking adapter. */
|
||||
public class MongoBank implements WireTransfers {
|
||||
|
||||
private static final String DEFAULT_DB = "lotteryDB";
|
||||
private static final String DEFAULT_ACCOUNTS_COLLECTION = "accounts";
|
||||
|
||||
@Getter
|
||||
private MongoClient mongoClient;
|
||||
@Getter
|
||||
private MongoDatabase database;
|
||||
@Getter
|
||||
private MongoCollection<Document> accountsCollection;
|
||||
@Getter private MongoClient mongoClient;
|
||||
@Getter private MongoDatabase database;
|
||||
@Getter private MongoCollection<Document> accountsCollection;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
/** Constructor. */
|
||||
public MongoBank() {
|
||||
connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor accepting parameters.
|
||||
*/
|
||||
/** Constructor accepting parameters. */
|
||||
public MongoBank(String dbName, String accountsCollectionName) {
|
||||
connect(dbName, accountsCollectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to database with default parameters.
|
||||
*/
|
||||
/** Connect to database with default parameters. */
|
||||
public void connect() {
|
||||
connect(DEFAULT_DB, DEFAULT_ACCOUNTS_COLLECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to database with given parameters.
|
||||
*/
|
||||
/** Connect to database with given parameters. */
|
||||
public void connect(String dbName, String accountsCollectionName) {
|
||||
if (mongoClient != null) {
|
||||
mongoClient.close();
|
||||
}
|
||||
mongoClient = new MongoClient(System.getProperty("mongo-host"),
|
||||
Integer.parseInt(System.getProperty("mongo-port")));
|
||||
mongoClient =
|
||||
new MongoClient(
|
||||
System.getProperty("mongo-host"), Integer.parseInt(System.getProperty("mongo-port")));
|
||||
database = mongoClient.getDatabase(dbName);
|
||||
accountsCollection = database.getCollection(accountsCollectionName);
|
||||
}
|
||||
|
||||
+4
-13
@@ -24,24 +24,15 @@
|
||||
*/
|
||||
package com.iluwatar.hexagonal.banking;
|
||||
|
||||
/**
|
||||
* Interface to bank accounts.
|
||||
*/
|
||||
/** Interface to bank accounts. */
|
||||
public interface WireTransfers {
|
||||
|
||||
/**
|
||||
* Set amount of funds for bank account.
|
||||
*/
|
||||
/** Set amount of funds for bank account. */
|
||||
void setFunds(String bankAccount, int amount);
|
||||
|
||||
/**
|
||||
* Get amount of funds for bank account.
|
||||
*/
|
||||
/** Get amount of funds for bank account. */
|
||||
int getFunds(String bankAccount);
|
||||
|
||||
/**
|
||||
* Transfer funds from one bank account to another.
|
||||
*/
|
||||
/** Transfer funds from one bank account to another. */
|
||||
boolean transferFunds(int amount, String sourceBackAccount, String destinationBankAccount);
|
||||
|
||||
}
|
||||
|
||||
+1
-3
@@ -30,9 +30,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Mock database for lottery tickets.
|
||||
*/
|
||||
/** Mock database for lottery tickets. */
|
||||
public class InMemoryTicketRepository implements LotteryTicketRepository {
|
||||
|
||||
private static final Map<LotteryTicketId, LotteryTicket> tickets = new HashMap<>();
|
||||
|
||||
+5
-16
@@ -29,29 +29,18 @@ import com.iluwatar.hexagonal.domain.LotteryTicketId;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Interface for accessing lottery tickets in database.
|
||||
*/
|
||||
/** Interface for accessing lottery tickets in database. */
|
||||
public interface LotteryTicketRepository {
|
||||
|
||||
/**
|
||||
* Find lottery ticket by id.
|
||||
*/
|
||||
/** Find lottery ticket by id. */
|
||||
Optional<LotteryTicket> findById(LotteryTicketId id);
|
||||
|
||||
/**
|
||||
* Save lottery ticket.
|
||||
*/
|
||||
/** Save lottery ticket. */
|
||||
Optional<LotteryTicketId> save(LotteryTicket ticket);
|
||||
|
||||
/**
|
||||
* Get all lottery tickets.
|
||||
*/
|
||||
/** Get all lottery tickets. */
|
||||
Map<LotteryTicketId, LotteryTicket> findAll();
|
||||
|
||||
/**
|
||||
* Delete all lottery tickets.
|
||||
*/
|
||||
/** Delete all lottery tickets. */
|
||||
void deleteAll();
|
||||
|
||||
}
|
||||
|
||||
+20
-34
@@ -40,9 +40,7 @@ import java.util.stream.Collectors;
|
||||
import lombok.Getter;
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
* Mongo lottery ticket database.
|
||||
*/
|
||||
/** Mongo lottery ticket database. */
|
||||
public class MongoTicketRepository implements LotteryTicketRepository {
|
||||
|
||||
private static final String DEFAULT_DB = "lotteryDB";
|
||||
@@ -52,43 +50,33 @@ public class MongoTicketRepository implements LotteryTicketRepository {
|
||||
|
||||
private MongoClient mongoClient;
|
||||
private MongoDatabase database;
|
||||
@Getter
|
||||
private MongoCollection<Document> ticketsCollection;
|
||||
@Getter
|
||||
private MongoCollection<Document> countersCollection;
|
||||
@Getter private MongoCollection<Document> ticketsCollection;
|
||||
@Getter private MongoCollection<Document> countersCollection;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
/** Constructor. */
|
||||
public MongoTicketRepository() {
|
||||
connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor accepting parameters.
|
||||
*/
|
||||
public MongoTicketRepository(String dbName, String ticketsCollectionName,
|
||||
String countersCollectionName) {
|
||||
/** Constructor accepting parameters. */
|
||||
public MongoTicketRepository(
|
||||
String dbName, String ticketsCollectionName, String countersCollectionName) {
|
||||
connect(dbName, ticketsCollectionName, countersCollectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to database with default parameters.
|
||||
*/
|
||||
/** Connect to database with default parameters. */
|
||||
public void connect() {
|
||||
connect(DEFAULT_DB, DEFAULT_TICKETS_COLLECTION, DEFAULT_COUNTERS_COLLECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to database with given parameters.
|
||||
*/
|
||||
public void connect(String dbName, String ticketsCollectionName,
|
||||
String countersCollectionName) {
|
||||
/** Connect to database with given parameters. */
|
||||
public void connect(String dbName, String ticketsCollectionName, String countersCollectionName) {
|
||||
if (mongoClient != null) {
|
||||
mongoClient.close();
|
||||
}
|
||||
mongoClient = new MongoClient(System.getProperty("mongo-host"),
|
||||
Integer.parseInt(System.getProperty("mongo-port")));
|
||||
mongoClient =
|
||||
new MongoClient(
|
||||
System.getProperty("mongo-host"), Integer.parseInt(System.getProperty("mongo-port")));
|
||||
database = mongoClient.getDatabase(dbName);
|
||||
ticketsCollection = database.getCollection(ticketsCollectionName);
|
||||
countersCollection = database.getCollection(countersCollectionName);
|
||||
@@ -140,10 +128,7 @@ public class MongoTicketRepository implements LotteryTicketRepository {
|
||||
|
||||
@Override
|
||||
public Map<LotteryTicketId, LotteryTicket> findAll() {
|
||||
return ticketsCollection
|
||||
.find(new Document())
|
||||
.into(new ArrayList<>())
|
||||
.stream()
|
||||
return ticketsCollection.find(new Document()).into(new ArrayList<>()).stream()
|
||||
.map(this::docToTicket)
|
||||
.collect(Collectors.toMap(LotteryTicket::id, Function.identity()));
|
||||
}
|
||||
@@ -154,11 +139,12 @@ public class MongoTicketRepository implements LotteryTicketRepository {
|
||||
}
|
||||
|
||||
private LotteryTicket docToTicket(Document doc) {
|
||||
var playerDetails = new PlayerDetails(doc.getString("email"), doc.getString("bank"),
|
||||
doc.getString("phone"));
|
||||
var numbers = Arrays.stream(doc.getString("numbers").split(","))
|
||||
.map(Integer::parseInt)
|
||||
.collect(Collectors.toSet());
|
||||
var playerDetails =
|
||||
new PlayerDetails(doc.getString("email"), doc.getString("bank"), doc.getString("phone"));
|
||||
var numbers =
|
||||
Arrays.stream(doc.getString("numbers").split(","))
|
||||
.map(Integer::parseInt)
|
||||
.collect(Collectors.toSet());
|
||||
var lotteryNumbers = LotteryNumbers.create(numbers);
|
||||
var ticketId = new LotteryTicketId(doc.getInteger(TICKET_ID));
|
||||
return new LotteryTicket(ticketId, playerDetails, lotteryNumbers);
|
||||
|
||||
+9
-17
@@ -33,36 +33,30 @@ import com.iluwatar.hexagonal.database.LotteryTicketRepository;
|
||||
import com.iluwatar.hexagonal.eventlog.LotteryEventLog;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Lottery administration implementation.
|
||||
*/
|
||||
/** Lottery administration implementation. */
|
||||
public class LotteryAdministration {
|
||||
|
||||
private final LotteryTicketRepository repository;
|
||||
private final LotteryEventLog notifications;
|
||||
private final WireTransfers wireTransfers;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
/** Constructor. */
|
||||
@Inject
|
||||
public LotteryAdministration(LotteryTicketRepository repository, LotteryEventLog notifications,
|
||||
WireTransfers wireTransfers) {
|
||||
public LotteryAdministration(
|
||||
LotteryTicketRepository repository,
|
||||
LotteryEventLog notifications,
|
||||
WireTransfers wireTransfers) {
|
||||
this.repository = repository;
|
||||
this.notifications = notifications;
|
||||
this.wireTransfers = wireTransfers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the lottery tickets submitted for lottery.
|
||||
*/
|
||||
/** Get all the lottery tickets submitted for lottery. */
|
||||
public Map<LotteryTicketId, LotteryTicket> getAllSubmittedTickets() {
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw lottery numbers.
|
||||
*/
|
||||
/** Draw lottery numbers. */
|
||||
public LotteryNumbers performLottery() {
|
||||
var numbers = LotteryNumbers.createRandom();
|
||||
var tickets = getAllSubmittedTickets();
|
||||
@@ -84,9 +78,7 @@ public class LotteryAdministration {
|
||||
return numbers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin new lottery round.
|
||||
*/
|
||||
/** Begin new lottery round. */
|
||||
public void resetLottery() {
|
||||
repository.deleteAll();
|
||||
}
|
||||
|
||||
+2
-6
@@ -24,18 +24,14 @@
|
||||
*/
|
||||
package com.iluwatar.hexagonal.domain;
|
||||
|
||||
/**
|
||||
* Lottery domain constants.
|
||||
*/
|
||||
/** Lottery domain constants. */
|
||||
public class LotteryConstants {
|
||||
|
||||
private LotteryConstants() {
|
||||
}
|
||||
private LotteryConstants() {}
|
||||
|
||||
public static final int PRIZE_AMOUNT = 100000;
|
||||
public static final String SERVICE_BANK_ACCOUNT = "123-123";
|
||||
public static final int TICKET_PRIZE = 3;
|
||||
public static final int SERVICE_BANK_ACCOUNT_BALANCE = 150000;
|
||||
public static final int PLAYER_MAX_BALANCE = 100;
|
||||
|
||||
}
|
||||
|
||||
+4
-13
@@ -47,17 +47,13 @@ public class LotteryNumbers {
|
||||
public static final int MAX_NUMBER = 20;
|
||||
public static final int NUM_NUMBERS = 4;
|
||||
|
||||
/**
|
||||
* Constructor. Creates random lottery numbers.
|
||||
*/
|
||||
/** Constructor. Creates random lottery numbers. */
|
||||
private LotteryNumbers() {
|
||||
numbers = new HashSet<>();
|
||||
generateRandomNumbers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor. Uses given numbers.
|
||||
*/
|
||||
/** Constructor. Uses given numbers. */
|
||||
private LotteryNumbers(Set<Integer> givenNumbers) {
|
||||
numbers = new HashSet<>();
|
||||
numbers.addAll(givenNumbers);
|
||||
@@ -99,9 +95,7 @@ public class LotteryNumbers {
|
||||
return Joiner.on(',').join(numbers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates 4 unique random numbers between 1-20 into numbers set.
|
||||
*/
|
||||
/** Generates 4 unique random numbers between 1-20 into numbers set. */
|
||||
private void generateRandomNumbers() {
|
||||
numbers.clear();
|
||||
var generator = new RandomNumberGenerator(MIN_NUMBER, MAX_NUMBER);
|
||||
@@ -111,9 +105,7 @@ public class LotteryNumbers {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper class for generating random numbers.
|
||||
*/
|
||||
/** Helper class for generating random numbers. */
|
||||
private static class RandomNumberGenerator {
|
||||
|
||||
private final PrimitiveIterator.OfInt randomIterator;
|
||||
@@ -138,5 +130,4 @@ public class LotteryNumbers {
|
||||
return randomIterator.nextInt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-17
@@ -33,29 +33,25 @@ import com.iluwatar.hexagonal.database.LotteryTicketRepository;
|
||||
import com.iluwatar.hexagonal.eventlog.LotteryEventLog;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Implementation for lottery service.
|
||||
*/
|
||||
/** Implementation for lottery service. */
|
||||
public class LotteryService {
|
||||
|
||||
private final LotteryTicketRepository repository;
|
||||
private final LotteryEventLog notifications;
|
||||
private final WireTransfers wireTransfers;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
/** Constructor. */
|
||||
@Inject
|
||||
public LotteryService(LotteryTicketRepository repository, LotteryEventLog notifications,
|
||||
WireTransfers wireTransfers) {
|
||||
public LotteryService(
|
||||
LotteryTicketRepository repository,
|
||||
LotteryEventLog notifications,
|
||||
WireTransfers wireTransfers) {
|
||||
this.repository = repository;
|
||||
this.notifications = notifications;
|
||||
this.wireTransfers = wireTransfers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit lottery ticket to participate in the lottery.
|
||||
*/
|
||||
/** Submit lottery ticket to participate in the lottery. */
|
||||
public Optional<LotteryTicketId> submitTicket(LotteryTicket ticket) {
|
||||
var playerDetails = ticket.playerDetails();
|
||||
var playerAccount = playerDetails.bankAccount();
|
||||
@@ -71,13 +67,9 @@ public class LotteryService {
|
||||
return optional;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if lottery ticket has won.
|
||||
*/
|
||||
/** Check if lottery ticket has won. */
|
||||
public LotteryTicketCheckResult checkTicketForPrize(
|
||||
LotteryTicketId id,
|
||||
LotteryNumbers winningNumbers
|
||||
) {
|
||||
LotteryTicketId id, LotteryNumbers winningNumbers) {
|
||||
return LotteryUtils.checkTicketForPrize(repository, id, winningNumbers);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-4
@@ -24,10 +24,9 @@
|
||||
*/
|
||||
package com.iluwatar.hexagonal.domain;
|
||||
|
||||
/**
|
||||
* Immutable value object representing lottery ticket.
|
||||
*/
|
||||
public record LotteryTicket(LotteryTicketId id, PlayerDetails playerDetails, LotteryNumbers lotteryNumbers) {
|
||||
/** Immutable value object representing lottery ticket. */
|
||||
public record LotteryTicket(
|
||||
LotteryTicketId id, PlayerDetails playerDetails, LotteryNumbers lotteryNumbers) {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
+3
-10
@@ -28,17 +28,13 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Represents lottery ticket check result.
|
||||
*/
|
||||
/** Represents lottery ticket check result. */
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@RequiredArgsConstructor
|
||||
public class LotteryTicketCheckResult {
|
||||
|
||||
/**
|
||||
* Enumeration of Type of Outcomes of a Lottery.
|
||||
*/
|
||||
/** Enumeration of Type of Outcomes of a Lottery. */
|
||||
public enum CheckResult {
|
||||
WIN_PRIZE,
|
||||
NO_PRIZE,
|
||||
@@ -48,12 +44,9 @@ public class LotteryTicketCheckResult {
|
||||
private final CheckResult result;
|
||||
private final int prizeAmount;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
/** Constructor. */
|
||||
public LotteryTicketCheckResult(CheckResult result) {
|
||||
this.result = result;
|
||||
prizeAmount = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-4
@@ -29,9 +29,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Lottery ticked id.
|
||||
*/
|
||||
/** Lottery ticked id. */
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
@RequiredArgsConstructor
|
||||
@@ -48,5 +46,4 @@ public class LotteryTicketId {
|
||||
public String toString() {
|
||||
return String.format("%d", id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-12
@@ -27,22 +27,14 @@ package com.iluwatar.hexagonal.domain;
|
||||
import com.iluwatar.hexagonal.database.LotteryTicketRepository;
|
||||
import com.iluwatar.hexagonal.domain.LotteryTicketCheckResult.CheckResult;
|
||||
|
||||
/**
|
||||
* Lottery utilities.
|
||||
*/
|
||||
/** Lottery utilities. */
|
||||
public class LotteryUtils {
|
||||
|
||||
private LotteryUtils() {
|
||||
}
|
||||
private LotteryUtils() {}
|
||||
|
||||
/**
|
||||
* Checks if lottery ticket has won.
|
||||
*/
|
||||
/** Checks if lottery ticket has won. */
|
||||
public static LotteryTicketCheckResult checkTicketForPrize(
|
||||
LotteryTicketRepository repository,
|
||||
LotteryTicketId id,
|
||||
LotteryNumbers winningNumbers
|
||||
) {
|
||||
LotteryTicketRepository repository, LotteryTicketId id, LotteryNumbers winningNumbers) {
|
||||
var optional = repository.findById(id);
|
||||
if (optional.isPresent()) {
|
||||
if (optional.get().lotteryNumbers().equals(winningNumbers)) {
|
||||
|
||||
+1
-3
@@ -24,7 +24,5 @@
|
||||
*/
|
||||
package com.iluwatar.hexagonal.domain;
|
||||
|
||||
/**
|
||||
* Immutable value object containing lottery player details.
|
||||
*/
|
||||
/** Immutable value object containing lottery player details. */
|
||||
public record PlayerDetails(String email, String bankAccount, String phoneNumber) {}
|
||||
|
||||
+6
-19
@@ -26,34 +26,21 @@ package com.iluwatar.hexagonal.eventlog;
|
||||
|
||||
import com.iluwatar.hexagonal.domain.PlayerDetails;
|
||||
|
||||
/**
|
||||
* Event log for lottery events.
|
||||
*/
|
||||
/** Event log for lottery events. */
|
||||
public interface LotteryEventLog {
|
||||
|
||||
/**
|
||||
* lottery ticket submitted.
|
||||
*/
|
||||
/** lottery ticket submitted. */
|
||||
void ticketSubmitted(PlayerDetails details);
|
||||
|
||||
/**
|
||||
* error submitting lottery ticket.
|
||||
*/
|
||||
/** error submitting lottery ticket. */
|
||||
void ticketSubmitError(PlayerDetails details);
|
||||
|
||||
/**
|
||||
* lottery ticket did not win.
|
||||
*/
|
||||
/** lottery ticket did not win. */
|
||||
void ticketDidNotWin(PlayerDetails details);
|
||||
|
||||
/**
|
||||
* lottery ticket won.
|
||||
*/
|
||||
/** lottery ticket won. */
|
||||
void ticketWon(PlayerDetails details, int prizeAmount);
|
||||
|
||||
/**
|
||||
* error paying the prize.
|
||||
*/
|
||||
/** error paying the prize. */
|
||||
void prizeError(PlayerDetails details, int prizeAmount);
|
||||
|
||||
}
|
||||
|
||||
+21
-30
@@ -31,9 +31,7 @@ import com.mongodb.client.MongoDatabase;
|
||||
import lombok.Getter;
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
* Mongo based event log.
|
||||
*/
|
||||
/** Mongo based event log. */
|
||||
public class MongoEventLog implements LotteryEventLog {
|
||||
|
||||
private static final String DEFAULT_DB = "lotteryDB";
|
||||
@@ -42,45 +40,35 @@ public class MongoEventLog implements LotteryEventLog {
|
||||
private static final String PHONE = "phone";
|
||||
public static final String MESSAGE = "message";
|
||||
|
||||
@Getter
|
||||
private MongoClient mongoClient;
|
||||
@Getter
|
||||
private MongoDatabase database;
|
||||
@Getter
|
||||
private MongoCollection<Document> eventsCollection;
|
||||
@Getter private MongoClient mongoClient;
|
||||
@Getter private MongoDatabase database;
|
||||
@Getter private MongoCollection<Document> eventsCollection;
|
||||
|
||||
private final StdOutEventLog stdOutEventLog = new StdOutEventLog();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
/** Constructor. */
|
||||
public MongoEventLog() {
|
||||
connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor accepting parameters.
|
||||
*/
|
||||
/** Constructor accepting parameters. */
|
||||
public MongoEventLog(String dbName, String eventsCollectionName) {
|
||||
connect(dbName, eventsCollectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to database with default parameters.
|
||||
*/
|
||||
/** Connect to database with default parameters. */
|
||||
public void connect() {
|
||||
connect(DEFAULT_DB, DEFAULT_EVENTS_COLLECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to database with given parameters.
|
||||
*/
|
||||
/** Connect to database with given parameters. */
|
||||
public void connect(String dbName, String eventsCollectionName) {
|
||||
if (mongoClient != null) {
|
||||
mongoClient.close();
|
||||
}
|
||||
mongoClient = new MongoClient(System.getProperty("mongo-host"),
|
||||
Integer.parseInt(System.getProperty("mongo-port")));
|
||||
mongoClient =
|
||||
new MongoClient(
|
||||
System.getProperty("mongo-host"), Integer.parseInt(System.getProperty("mongo-port")));
|
||||
database = mongoClient.getDatabase(dbName);
|
||||
eventsCollection = database.getCollection(eventsCollectionName);
|
||||
}
|
||||
@@ -90,8 +78,8 @@ public class MongoEventLog implements LotteryEventLog {
|
||||
var document = new Document(EMAIL, details.email());
|
||||
document.put(PHONE, details.phoneNumber());
|
||||
document.put("bank", details.bankAccount());
|
||||
document
|
||||
.put(MESSAGE, "Lottery ticket was submitted and bank account was charged for 3 credits.");
|
||||
document.put(
|
||||
MESSAGE, "Lottery ticket was submitted and bank account was charged for 3 credits.");
|
||||
eventsCollection.insertOne(document);
|
||||
stdOutEventLog.ticketSubmitted(details);
|
||||
}
|
||||
@@ -121,9 +109,10 @@ public class MongoEventLog implements LotteryEventLog {
|
||||
var document = new Document(EMAIL, details.email());
|
||||
document.put(PHONE, details.phoneNumber());
|
||||
document.put("bank", details.bankAccount());
|
||||
document.put(MESSAGE, String
|
||||
.format("Lottery ticket won! The bank account was deposited with %d credits.",
|
||||
prizeAmount));
|
||||
document.put(
|
||||
MESSAGE,
|
||||
String.format(
|
||||
"Lottery ticket won! The bank account was deposited with %d credits.", prizeAmount));
|
||||
eventsCollection.insertOne(document);
|
||||
stdOutEventLog.ticketWon(details, prizeAmount);
|
||||
}
|
||||
@@ -133,8 +122,10 @@ public class MongoEventLog implements LotteryEventLog {
|
||||
var document = new Document(EMAIL, details.email());
|
||||
document.put(PHONE, details.phoneNumber());
|
||||
document.put("bank", details.bankAccount());
|
||||
document.put(MESSAGE, String
|
||||
.format("Lottery ticket won! Unfortunately the bank credit transfer of %d failed.",
|
||||
document.put(
|
||||
MESSAGE,
|
||||
String.format(
|
||||
"Lottery ticket won! Unfortunately the bank credit transfer of %d failed.",
|
||||
prizeAmount));
|
||||
eventsCollection.insertOne(document);
|
||||
stdOutEventLog.prizeError(details, prizeAmount);
|
||||
|
||||
+20
-12
@@ -27,39 +27,47 @@ package com.iluwatar.hexagonal.eventlog;
|
||||
import com.iluwatar.hexagonal.domain.PlayerDetails;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Standard output event log.
|
||||
*/
|
||||
/** Standard output event log. */
|
||||
@Slf4j
|
||||
public class StdOutEventLog implements LotteryEventLog {
|
||||
|
||||
@Override
|
||||
public void ticketSubmitted(PlayerDetails details) {
|
||||
LOGGER.info("Lottery ticket for {} was submitted. Bank account {} was charged for 3 credits.",
|
||||
details.email(), details.bankAccount());
|
||||
LOGGER.info(
|
||||
"Lottery ticket for {} was submitted. Bank account {} was charged for 3 credits.",
|
||||
details.email(),
|
||||
details.bankAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ticketDidNotWin(PlayerDetails details) {
|
||||
LOGGER.info("Lottery ticket for {} was checked and unfortunately did not win this time.",
|
||||
LOGGER.info(
|
||||
"Lottery ticket for {} was checked and unfortunately did not win this time.",
|
||||
details.email());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ticketWon(PlayerDetails details, int prizeAmount) {
|
||||
LOGGER.info("Lottery ticket for {} has won! The bank account {} was deposited with {} credits.",
|
||||
details.email(), details.bankAccount(), prizeAmount);
|
||||
LOGGER.info(
|
||||
"Lottery ticket for {} has won! The bank account {} was deposited with {} credits.",
|
||||
details.email(),
|
||||
details.bankAccount(),
|
||||
prizeAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prizeError(PlayerDetails details, int prizeAmount) {
|
||||
LOGGER.error("Lottery ticket for {} has won! Unfortunately the bank credit transfer of"
|
||||
+ " {} failed.", details.email(), prizeAmount);
|
||||
LOGGER.error(
|
||||
"Lottery ticket for {} has won! Unfortunately the bank credit transfer of" + " {} failed.",
|
||||
details.email(),
|
||||
prizeAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ticketSubmitError(PlayerDetails details) {
|
||||
LOGGER.error("Lottery ticket for {} could not be submitted because the credit transfer"
|
||||
+ " of 3 credits failed.", details.email());
|
||||
LOGGER.error(
|
||||
"Lottery ticket for {} could not be submitted because the credit transfer"
|
||||
+ " of 3 credits failed.",
|
||||
details.email());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -32,9 +32,7 @@ import com.iluwatar.hexagonal.database.MongoTicketRepository;
|
||||
import com.iluwatar.hexagonal.eventlog.LotteryEventLog;
|
||||
import com.iluwatar.hexagonal.eventlog.MongoEventLog;
|
||||
|
||||
/**
|
||||
* Guice module for binding production dependencies.
|
||||
*/
|
||||
/** Guice module for binding production dependencies. */
|
||||
public class LotteryModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
||||
+1
-3
@@ -32,9 +32,7 @@ import com.iluwatar.hexagonal.database.LotteryTicketRepository;
|
||||
import com.iluwatar.hexagonal.eventlog.LotteryEventLog;
|
||||
import com.iluwatar.hexagonal.eventlog.StdOutEventLog;
|
||||
|
||||
/**
|
||||
* Guice module for testing dependencies.
|
||||
*/
|
||||
/** Guice module for testing dependencies. */
|
||||
public class LotteryTestingModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
||||
+2
-6
@@ -28,18 +28,14 @@ import java.io.FileInputStream;
|
||||
import java.util.Properties;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Mongo connection properties loader.
|
||||
*/
|
||||
/** Mongo connection properties loader. */
|
||||
@Slf4j
|
||||
public class MongoConnectionPropertiesLoader {
|
||||
|
||||
private static final String DEFAULT_HOST = "localhost";
|
||||
private static final int DEFAULT_PORT = 27017;
|
||||
|
||||
/**
|
||||
* Try to load connection properties from file. Fall back to default connection properties.
|
||||
*/
|
||||
/** Try to load connection properties from file. Fall back to default connection properties. */
|
||||
public static void load() {
|
||||
var host = DEFAULT_HOST;
|
||||
var port = DEFAULT_PORT;
|
||||
|
||||
+43
-47
@@ -36,56 +36,54 @@ import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Utilities for creating sample lottery tickets.
|
||||
*/
|
||||
/** Utilities for creating sample lottery tickets. */
|
||||
public class SampleData {
|
||||
|
||||
private static final List<PlayerDetails> PLAYERS;
|
||||
private static final SecureRandom RANDOM = new SecureRandom();
|
||||
|
||||
static {
|
||||
PLAYERS = List.of(
|
||||
new PlayerDetails("john@google.com", "312-342", "+3242434242"),
|
||||
new PlayerDetails("mary@google.com", "234-987", "+23452346"),
|
||||
new PlayerDetails("steve@google.com", "833-836", "+63457543"),
|
||||
new PlayerDetails("wayne@google.com", "319-826", "+24626"),
|
||||
new PlayerDetails("johnie@google.com", "983-322", "+3635635"),
|
||||
new PlayerDetails("andy@google.com", "934-734", "+0898245"),
|
||||
new PlayerDetails("richard@google.com", "536-738", "+09845325"),
|
||||
new PlayerDetails("kevin@google.com", "453-936", "+2423532"),
|
||||
new PlayerDetails("arnold@google.com", "114-988", "+5646346524"),
|
||||
new PlayerDetails("ian@google.com", "663-765", "+928394235"),
|
||||
new PlayerDetails("robin@google.com", "334-763", "+35448"),
|
||||
new PlayerDetails("ted@google.com", "735-964", "+98752345"),
|
||||
new PlayerDetails("larry@google.com", "734-853", "+043842423"),
|
||||
new PlayerDetails("calvin@google.com", "334-746", "+73294135"),
|
||||
new PlayerDetails("jacob@google.com", "444-766", "+358042354"),
|
||||
new PlayerDetails("edwin@google.com", "895-345", "+9752435"),
|
||||
new PlayerDetails("mary@google.com", "760-009", "+34203542"),
|
||||
new PlayerDetails("lolita@google.com", "425-907", "+9872342"),
|
||||
new PlayerDetails("bruno@google.com", "023-638", "+673824122"),
|
||||
new PlayerDetails("peter@google.com", "335-886", "+5432503945"),
|
||||
new PlayerDetails("warren@google.com", "225-946", "+9872341324"),
|
||||
new PlayerDetails("monica@google.com", "265-748", "+134124"),
|
||||
new PlayerDetails("ollie@google.com", "190-045", "+34453452"),
|
||||
new PlayerDetails("yngwie@google.com", "241-465", "+9897641231"),
|
||||
new PlayerDetails("lars@google.com", "746-936", "+42345298345"),
|
||||
new PlayerDetails("bobbie@google.com", "946-384", "+79831742"),
|
||||
new PlayerDetails("tyron@google.com", "310-992", "+0498837412"),
|
||||
new PlayerDetails("tyrell@google.com", "032-045", "+67834134"),
|
||||
new PlayerDetails("nadja@google.com", "000-346", "+498723"),
|
||||
new PlayerDetails("wendy@google.com", "994-989", "+987324454"),
|
||||
new PlayerDetails("luke@google.com", "546-634", "+987642435"),
|
||||
new PlayerDetails("bjorn@google.com", "342-874", "+7834325"),
|
||||
new PlayerDetails("lisa@google.com", "024-653", "+980742154"),
|
||||
new PlayerDetails("anton@google.com", "834-935", "+876423145"),
|
||||
new PlayerDetails("bruce@google.com", "284-936", "+09843212345"),
|
||||
new PlayerDetails("ray@google.com", "843-073", "+678324123"),
|
||||
new PlayerDetails("ron@google.com", "637-738", "+09842354"),
|
||||
new PlayerDetails("xavier@google.com", "143-947", "+375245"),
|
||||
new PlayerDetails("harriet@google.com", "842-404", "+131243252")
|
||||
);
|
||||
PLAYERS =
|
||||
List.of(
|
||||
new PlayerDetails("john@google.com", "312-342", "+3242434242"),
|
||||
new PlayerDetails("mary@google.com", "234-987", "+23452346"),
|
||||
new PlayerDetails("steve@google.com", "833-836", "+63457543"),
|
||||
new PlayerDetails("wayne@google.com", "319-826", "+24626"),
|
||||
new PlayerDetails("johnie@google.com", "983-322", "+3635635"),
|
||||
new PlayerDetails("andy@google.com", "934-734", "+0898245"),
|
||||
new PlayerDetails("richard@google.com", "536-738", "+09845325"),
|
||||
new PlayerDetails("kevin@google.com", "453-936", "+2423532"),
|
||||
new PlayerDetails("arnold@google.com", "114-988", "+5646346524"),
|
||||
new PlayerDetails("ian@google.com", "663-765", "+928394235"),
|
||||
new PlayerDetails("robin@google.com", "334-763", "+35448"),
|
||||
new PlayerDetails("ted@google.com", "735-964", "+98752345"),
|
||||
new PlayerDetails("larry@google.com", "734-853", "+043842423"),
|
||||
new PlayerDetails("calvin@google.com", "334-746", "+73294135"),
|
||||
new PlayerDetails("jacob@google.com", "444-766", "+358042354"),
|
||||
new PlayerDetails("edwin@google.com", "895-345", "+9752435"),
|
||||
new PlayerDetails("mary@google.com", "760-009", "+34203542"),
|
||||
new PlayerDetails("lolita@google.com", "425-907", "+9872342"),
|
||||
new PlayerDetails("bruno@google.com", "023-638", "+673824122"),
|
||||
new PlayerDetails("peter@google.com", "335-886", "+5432503945"),
|
||||
new PlayerDetails("warren@google.com", "225-946", "+9872341324"),
|
||||
new PlayerDetails("monica@google.com", "265-748", "+134124"),
|
||||
new PlayerDetails("ollie@google.com", "190-045", "+34453452"),
|
||||
new PlayerDetails("yngwie@google.com", "241-465", "+9897641231"),
|
||||
new PlayerDetails("lars@google.com", "746-936", "+42345298345"),
|
||||
new PlayerDetails("bobbie@google.com", "946-384", "+79831742"),
|
||||
new PlayerDetails("tyron@google.com", "310-992", "+0498837412"),
|
||||
new PlayerDetails("tyrell@google.com", "032-045", "+67834134"),
|
||||
new PlayerDetails("nadja@google.com", "000-346", "+498723"),
|
||||
new PlayerDetails("wendy@google.com", "994-989", "+987324454"),
|
||||
new PlayerDetails("luke@google.com", "546-634", "+987642435"),
|
||||
new PlayerDetails("bjorn@google.com", "342-874", "+7834325"),
|
||||
new PlayerDetails("lisa@google.com", "024-653", "+980742154"),
|
||||
new PlayerDetails("anton@google.com", "834-935", "+876423145"),
|
||||
new PlayerDetails("bruce@google.com", "284-936", "+09843212345"),
|
||||
new PlayerDetails("ray@google.com", "843-073", "+678324123"),
|
||||
new PlayerDetails("ron@google.com", "637-738", "+09842354"),
|
||||
new PlayerDetails("xavier@google.com", "143-947", "+375245"),
|
||||
new PlayerDetails("harriet@google.com", "842-404", "+131243252"));
|
||||
var wireTransfers = new InMemoryBank();
|
||||
PLAYERS.stream()
|
||||
.map(PlayerDetails::bankAccount)
|
||||
@@ -94,9 +92,7 @@ public class SampleData {
|
||||
.forEach(wireTransfers::setFunds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts lottery tickets into the database based on the sample data.
|
||||
*/
|
||||
/** Inserts lottery tickets into the database based on the sample data. */
|
||||
public static void submitTickets(LotteryService lotteryService, int numTickets) {
|
||||
for (var i = 0; i < numTickets; i++) {
|
||||
var randomPlayerDetails = getRandomPlayerDetails();
|
||||
|
||||
+2
-6
@@ -32,15 +32,11 @@ import com.iluwatar.hexagonal.mongo.MongoConnectionPropertiesLoader;
|
||||
import java.util.Scanner;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Console interface for lottery players.
|
||||
*/
|
||||
/** Console interface for lottery players. */
|
||||
@Slf4j
|
||||
public class ConsoleLottery {
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*/
|
||||
/** Program entry point. */
|
||||
public static void main(String[] args) {
|
||||
MongoConnectionPropertiesLoader.load();
|
||||
var injector = Guice.createInjector(new LotteryModule());
|
||||
|
||||
+4
-15
@@ -28,28 +28,17 @@ import com.iluwatar.hexagonal.banking.WireTransfers;
|
||||
import com.iluwatar.hexagonal.domain.LotteryService;
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
/**
|
||||
* Console interface for lottery service.
|
||||
*/
|
||||
/** Console interface for lottery service. */
|
||||
public interface LotteryConsoleService {
|
||||
|
||||
void checkTicket(LotteryService service, Scanner scanner);
|
||||
|
||||
/**
|
||||
* Submit lottery ticket to participate in the lottery.
|
||||
*/
|
||||
/** Submit lottery ticket to participate in the lottery. */
|
||||
void submitTicket(LotteryService service, Scanner scanner);
|
||||
|
||||
/**
|
||||
* Add funds to lottery account.
|
||||
*/
|
||||
/** Add funds to lottery account. */
|
||||
void addFundsToLotteryAccount(WireTransfers bank, Scanner scanner);
|
||||
|
||||
|
||||
/**
|
||||
* Recovery funds from lottery account.
|
||||
*/
|
||||
/** Recovery funds from lottery account. */
|
||||
void queryLotteryAccountFunds(WireTransfers bank, Scanner scanner);
|
||||
|
||||
}
|
||||
|
||||
+14
-17
@@ -36,16 +36,12 @@ import java.util.Scanner;
|
||||
import java.util.stream.Collectors;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* Console implementation for lottery console service.
|
||||
*/
|
||||
/** Console implementation for lottery console service. */
|
||||
public class LotteryConsoleServiceImpl implements LotteryConsoleService {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
/** Constructor. */
|
||||
public LotteryConsoleServiceImpl(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
@@ -57,10 +53,11 @@ public class LotteryConsoleServiceImpl implements LotteryConsoleService {
|
||||
logger.info("Give the 4 comma separated winning numbers?");
|
||||
var numbers = readString(scanner);
|
||||
try {
|
||||
var winningNumbers = Arrays.stream(numbers.split(","))
|
||||
.map(Integer::parseInt)
|
||||
.limit(4)
|
||||
.collect(Collectors.toSet());
|
||||
var winningNumbers =
|
||||
Arrays.stream(numbers.split(","))
|
||||
.map(Integer::parseInt)
|
||||
.limit(4)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
final var lotteryTicketId = new LotteryTicketId(Integer.parseInt(id));
|
||||
final var lotteryNumbers = LotteryNumbers.create(winningNumbers);
|
||||
@@ -90,15 +87,15 @@ public class LotteryConsoleServiceImpl implements LotteryConsoleService {
|
||||
logger.info("Give 4 comma separated lottery numbers?");
|
||||
var numbers = readString(scanner);
|
||||
try {
|
||||
var chosen = Arrays.stream(numbers.split(","))
|
||||
.map(Integer::parseInt)
|
||||
.collect(Collectors.toSet());
|
||||
var chosen =
|
||||
Arrays.stream(numbers.split(",")).map(Integer::parseInt).collect(Collectors.toSet());
|
||||
var lotteryNumbers = LotteryNumbers.create(chosen);
|
||||
var lotteryTicket = new LotteryTicket(new LotteryTicketId(), details, lotteryNumbers);
|
||||
service.submitTicket(lotteryTicket).ifPresentOrElse(
|
||||
(id) -> logger.info("Submitted lottery ticket with id: {}", id),
|
||||
() -> logger.info("Failed submitting lottery ticket - please try again.")
|
||||
);
|
||||
service
|
||||
.submitTicket(lotteryTicket)
|
||||
.ifPresentOrElse(
|
||||
(id) -> logger.info("Submitted lottery ticket with id: {}", id),
|
||||
() -> logger.info("Failed submitting lottery ticket - please try again."));
|
||||
} catch (Exception e) {
|
||||
logger.info("Failed submitting lottery ticket - please try again.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user