Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0a13721
#496 Add pipeline module to parent pom :sparkles:
jjjimenez100 Oct 6, 2019
7ec12ab
#496: Add main application class and test for pipeline
jjjimenez100 Oct 6, 2019
5040db1
#496: Checkstyle format and add log messages on pipeline stages :art:
jjjimenez100 Oct 6, 2019
0465113
#496: Fill readme sections of pipeline :sparkles:
jjjimenez100 Oct 6, 2019
a038a4f
#496: Javadocs and checkstyle formatting :art:
jjjimenez100 Oct 6, 2019
ba3ce83
#496: Follow PMD checks and add more explanation as block comment on …
jjjimenez100 Oct 7, 2019
e795983
#496: Apply requested PR changes by iluwatar :art:
jjjimenez100 Oct 8, 2019
216d51c
Merge branch 'master' of https://github.com/iluwatar/java-design-patt…
jjjimenez100 Oct 12, 2019
84c77ce
Merge branch 'master' of https://github.com/iluwatar/java-design-patt…
jjjimenez100 Oct 13, 2019
f27eb1f
#970: Replace log4j usage on commander pattern to Slf4j API :art:
jjjimenez100 Oct 12, 2019
e7efa2d
#970: Replace log4j usage on dao pattern to Slf4j API :art:
jjjimenez100 Oct 12, 2019
5f2c347
#970: Replace log4j usage on data mapper pattern to Slf4j API :art:
jjjimenez100 Oct 12, 2019
ddc2cce
#970: Remove log4j dependency on data transfer object pom :fire:
jjjimenez100 Oct 12, 2019
5a948fb
#970: Replace log4j usage on module pattern to Slf4j API :art:
jjjimenez100 Oct 12, 2019
5766dfe
#970: Replace log4j usage on serverless pattern to Slf4j API :art:
jjjimenez100 Oct 12, 2019
a2cd605
jjjimenez100 Oct 13, 2019
73878dd
#970: Remove unnecessary gitignore line for log4j.xml :fire:
jjjimenez100 Oct 12, 2019
1f34630
jjjimenez100 Oct 13, 2019
a367a32
#970: Remove remaining remnants of log4j :fire:
jjjimenez100 Oct 13, 2019
f736c7e
#970: Replace System.out logging with appropriate logging methods :art:
jjjimenez100 Oct 13, 2019
3069e17
#970: Replace System.out method references to Logger::info :art:
jjjimenez100 Oct 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ datanucleus.log
/bin/
/bin/
*.log
data-mapper/src/main/resources/log4j.xml
event-sourcing/Journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
import java.util.Map;

import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Tests that Collection Pipeline methods work as expected.
*/
public class AppTest {

private static final Logger LOGGER = LoggerFactory.getLogger(AppTest.class);

private List<Car> cars = CarFactory.createCars();

@Test
Expand All @@ -61,7 +64,7 @@ public void testGetGroupingOfCarsByCategory() {
new Car("Jeep", "Comanche", 1990, Category.JEEP)));
Map<Category, List<Car>> modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars);
Map<Category, List<Car>> modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars);
System.out.println("Category " + modelsFunctional);
LOGGER.info("Category " + modelsFunctional);
assertEquals(modelsExpected, modelsFunctional);
assertEquals(modelsExpected, modelsImperative);
}
Expand Down
5 changes: 0 additions & 5 deletions commander/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,5 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</project>
41 changes: 0 additions & 41 deletions commander/properties/log4j.properties

This file was deleted.

19 changes: 10 additions & 9 deletions commander/src/main/java/com/iluwatar/commander/Commander.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,6 +36,8 @@
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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -125,27 +126,27 @@ private void sendShippingRequest(Order order) throws Exception {
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;
}
Expand Down Expand Up @@ -183,7 +184,7 @@ public void run() {
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);
Expand All @@ -193,7 +194,7 @@ public void run() {
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;
}
Expand All @@ -204,7 +205,7 @@ public void run() {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

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
Expand All @@ -32,6 +34,7 @@
*/

public class MessagingService extends Service {
private static final Logger LOGGER = LoggerFactory.getLogger(MessagingService.class);

enum MessageToSend {
PaymentFail, PaymentTrying, PaymentSuccessful
Expand Down Expand Up @@ -74,7 +77,7 @@ protected String updateDb(Object...parameters) throws DatabaseUnavailableExcepti
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;
Expand Down
14 changes: 9 additions & 5 deletions converter/src/main/java/com/iluwatar/converter/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@


import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -35,6 +37,8 @@
* objects between types.
*/
public class App {

private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point
*
Expand All @@ -45,16 +49,16 @@ public static void main(String[] args) {

UserDto dtoUser = new UserDto("John", "Doe", true, "whatever[at]wherever.com");
User user = userConverter.convertFromDto(dtoUser);
System.out.println("Entity converted from DTO:" + user);
LOGGER.info("Entity converted from DTO:" + user);

ArrayList<User> users = Lists.newArrayList(new User("Camile", "Tough", false, "124sad"),
new User("Marti", "Luther", true, "42309fd"), new User("Kate", "Smith", true, "if0243"));
System.out.println("Domain entities:");
users.forEach(System.out::println);
LOGGER.info("Domain entities:");
users.stream().map(User::toString).forEach(LOGGER::info);

System.out.println("DTO entities converted from domain:");
LOGGER.info("DTO entities converted from domain:");
List<UserDto> dtoEntities = userConverter.createFromEntities(users);
dtoEntities.forEach(System.out::println);
dtoEntities.stream().map(UserDto::toString).forEach(LOGGER::info);

}
}
49 changes: 0 additions & 49 deletions dao/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand All @@ -53,49 +49,4 @@
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>

<build>

<!--
log4j.xml file will be copied both in ${project.build.outputDirectory}
and ${project.build.directory}. Thanks to Sean Patrick Floyd
(http://stackoverflow.com/questions/5637532/maven-how-to-place-resource-file-together-with-jar)
-->

<resources>
<resource> <!-- regular processing for every resource file -->
<directory>src/main/resources</directory>
</resource>
<resource> <!-- processing with a different output directory for log4j.xml -->
<directory>src/main/resources</directory>
<includes>
<include>log4j.xml</include>
</includes>
<targetPath>..</targetPath> <!-- relative to target/classes i.e. ${project.build.directory} -->
</resource>
</resources>

<plugins>

<!--
This will exclude log4j.xml file from generated JAR
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<excludes>
<exclude>log4j.xml</exclude>
</excludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>

</plugins>
</build>
</project>
9 changes: 5 additions & 4 deletions dao/src/main/java/com/iluwatar/dao/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@

import javax.sql.DataSource;

import org.apache.log4j.Logger;
import org.h2.jdbcx.JdbcDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Data Access Object (DAO) is an object that provides an abstract interface to some type of
Expand All @@ -50,7 +51,7 @@
*/
public class App {
private static final String DB_URL = "jdbc:h2:~/dao";
private static Logger log = Logger.getLogger(App.class);
private static Logger log = LoggerFactory.getLogger(App.class);
private static final String ALL_CUSTOMERS = "customerDao.getAllCustomers(): ";

/**
Expand Down Expand Up @@ -94,7 +95,7 @@ private static void performOperationsUsing(final CustomerDao customerDao) throws
addCustomers(customerDao);
log.info(ALL_CUSTOMERS);
try (Stream<Customer> customerStream = customerDao.getAll()) {
customerStream.forEach((customer) -> log.info(customer));
customerStream.forEach((customer) -> log.info(customer.toString()));
}
log.info("customerDao.getCustomerById(2): " + customerDao.getById(2));
final Customer customer = new Customer(4, "Dan", "Danson");
Expand All @@ -105,7 +106,7 @@ private static void performOperationsUsing(final CustomerDao customerDao) throws
customerDao.update(customer);
log.info(ALL_CUSTOMERS);
try (Stream<Customer> customerStream = customerDao.getAll()) {
customerStream.forEach((cust) -> log.info(cust));
customerStream.forEach((cust) -> log.info(cust.toString()));
}
customerDao.delete(customer);
log.info(ALL_CUSTOMERS + customerDao.getAll());
Expand Down
7 changes: 4 additions & 3 deletions dao/src/main/java/com/iluwatar/dao/DbCustomerDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*/
package com.iluwatar.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand All @@ -35,15 +38,13 @@

import javax.sql.DataSource;

import org.apache.log4j.Logger;

/**
* An implementation of {@link CustomerDao} that persists customers in RDBMS.
*
*/
public class DbCustomerDao implements CustomerDao {

private static final Logger LOGGER = Logger.getLogger(DbCustomerDao.class);
private static final Logger LOGGER = LoggerFactory.getLogger(DbCustomerDao.class);

private final DataSource dataSource;

Expand Down
Loading