mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-20 07:26:49 +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:
+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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user