Skip to content

Commit f58256d

Browse files
iluwatar#352- Unit Of Work : Updated applicability of pattern in README.
2 parents 7185830 + 390c33e commit f58256d

File tree

14 files changed

+255
-8
lines changed

14 files changed

+255
-8
lines changed

converter/src/main/java/com/iluwatar/converter/App.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ public class App {
4141
* @param args command line args
4242
*/
4343
public static void main(String[] args) {
44-
Converter<UserDto, User> userConverter = new Converter<>(
45-
userDto -> new User(userDto.getFirstName(), userDto.getLastName(), userDto.isActive(),
46-
userDto.getEmail()),
47-
user -> new UserDto(user.getFirstName(), user.getLastName(), user.isActive(), user.getUserId()));
44+
Converter<UserDto, User> userConverter = new UserConverter();
4845

4946
UserDto dtoUser = new UserDto("John", "Doe", true, "whatever[at]wherever.com");
5047
User user = userConverter.convertFromDto(dtoUser);

converter/src/main/java/com/iluwatar/converter/Converter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public final T convertFromEntity(final U user) {
6868
/**
6969
* @param dtoUsers collection of DTO entities
7070
* @return List of domain representation of provided entities retrieved by
71-
* mapping each of them with the convertion function
71+
* mapping each of them with the conversion function
7272
*/
7373
public final List<U> createFromDtos(final Collection<T> dtoUsers) {
7474
return dtoUsers.stream().map(this::convertFromDto).collect(Collectors.toList());
@@ -77,7 +77,7 @@ public final List<U> createFromDtos(final Collection<T> dtoUsers) {
7777
/**
7878
* @param users collection of domain entities
7979
* @return List of domain representation of provided entities retrieved by
80-
* mapping each of them with the convertion function
80+
* mapping each of them with the conversion function
8181
*/
8282
public final List<T> createFromEntities(final Collection<U> users) {
8383
return users.stream().map(this::convertFromEntity).collect(Collectors.toList());

decorator/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Wikipedia says
3535
3636
**Programmatic Example**
3737

38-
Lets take the troll example. First of all we have a simple troll implementing the troll interface
38+
Let's take the troll example. First of all we have a simple troll implementing the troll interface
3939

4040
```
4141
public interface Troll {

eip-splitter/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
layout: pattern
3+
title: EIP Splitter
4+
folder: eip-splitter
5+
permalink: /patterns/eip-splitter/
6+
categories: Enterprise integration
7+
tags:
8+
- Java
9+
- Difficulty-Intermittent
10+
- Enterprise integration
11+
---
12+
13+
## Intent
14+
It is very common in integration systems that incoming messages consists of many items bundled together. For example
15+
an invoice document contains multiple invoice lines describing transaction (quantity, name of provided
16+
service/sold goods, price etc.). Such bundled messages may not be accepted by other systems. This is where splitter
17+
pattern comes in handy. It will take the whole document, split it based on given criteria and send individual
18+
items to the endpoint.
19+
20+
![alt text](./etc/sequencer.gif "Splitter")
21+
22+
## Applicability
23+
Use the Splitter pattern when
24+
25+
* You need to split received data into smaller pieces to process them individually
26+
* You need to control the size of data batches you are able to process
27+
28+
## Credits
29+
30+
* [Gregor Hohpe, Bobby Woolf - Enterprise Integration Patterns](http://www.enterpriseintegrationpatterns.com/patterns/messaging/Sequencer.html)
31+
* [Apache Camel - Documentation](http://camel.apache.org/splitter.html)
32+

eip-splitter/etc/sequencer.gif

2.24 KB
Loading

eip-splitter/pom.xml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
The MIT License
4+
Copyright (c) 2014-2016 Ilkka Seppälä
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
20+
-->
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
<artifactId>eip-splitter</artifactId>
26+
<parent>
27+
<groupId>com.iluwatar</groupId>
28+
<artifactId>java-design-patterns</artifactId>
29+
<version>1.18.0-SNAPSHOT</version>
30+
</parent>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.apache.camel</groupId>
40+
<artifactId>camel-core</artifactId>
41+
<version>${camel.version}</version>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>org.apache.camel</groupId>
46+
<artifactId>camel-spring-boot</artifactId>
47+
<version>${camel.version}</version>
48+
</dependency>
49+
50+
<!-- Testing -->
51+
<dependency>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-starter-test</artifactId>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>org.apache.camel</groupId>
58+
<artifactId>camel-test-spring</artifactId>
59+
<version>${camel.version}</version>
60+
</dependency>
61+
62+
</dependencies>
63+
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.iluwatar.eip.splitter;
2+
3+
import org.apache.camel.CamelContext;
4+
import org.apache.camel.builder.RouteBuilder;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.context.ConfigurableApplicationContext;
8+
9+
/**
10+
* It is very common in integration systems that incoming messages consists of many items bundled together. For example
11+
* an invoice document contains multiple invoice lines describing transaction (quantity, name of provided
12+
* service/sold goods, price etc.). Such bundled messages may not be accepted by other systems. This is where splitter
13+
* pattern comes in handy. It will take the whole document, split it based on given criteria and send individual
14+
* items to the endpoint.
15+
*
16+
* <p>
17+
* Splitter allows you to split messages based on defined criteria. It takes original message, process it and send
18+
* multiple parts to the output channel. It is not defined if it should keep the order of items though.
19+
* </p>
20+
*
21+
*/
22+
@SpringBootApplication
23+
public class App {
24+
25+
/**
26+
* Program entry point. It starts Spring Boot application and using Apache Camel it auto-configures routes.
27+
*
28+
* @param args command line args
29+
*/
30+
public static void main(String[] args) throws Exception {
31+
// Run Spring Boot application and obtain ApplicationContext
32+
ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
33+
34+
// Get CamelContext from ApplicationContext
35+
CamelContext camelContext = (CamelContext) context.getBean("camelContext");
36+
37+
// Add a new routes that will handle endpoints form SplitterRoute class.
38+
camelContext.addRoutes(new RouteBuilder() {
39+
40+
@Override
41+
public void configure() throws Exception {
42+
from("{{endpoint}}").log("ENDPOINT: ${body}");
43+
}
44+
45+
});
46+
47+
// Add producer that will send test message to an entry point in WireTapRoute
48+
String[] stringArray = {"Test item #1", "Test item #2", "Test item #3"};
49+
camelContext.createProducerTemplate().sendBody("{{entry}}", stringArray);
50+
51+
SpringApplication.exit(context);
52+
}
53+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.iluwatar.eip.splitter.routes;
2+
3+
import org.apache.camel.builder.RouteBuilder;
4+
import org.springframework.stereotype.Component;
5+
6+
/**
7+
* Sample splitter route definition.
8+
*
9+
* <p>
10+
* It consumes messages out of the <i>direct:entry</i> entry point and forwards them to <i>direct:endpoint</i>.
11+
* Route accepts messages having body of array or collection of objects. Splitter component split message body and
12+
* forwards single objects to the endpoint.
13+
* </p>
14+
*
15+
* In this example input/output endpoints names are stored in <i>application.properties</i> file.
16+
*/
17+
@Component
18+
public class SplitterRoute extends RouteBuilder {
19+
20+
/**
21+
* Configures the route
22+
* @throws Exception in case of exception during configuration
23+
*/
24+
@Override
25+
public void configure() throws Exception {
26+
// Main route
27+
from("{{entry}}").split().body().to("{{endpoint}}");
28+
}
29+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
entry=direct:entry
2+
endpoint=direct:endpoint
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.iluwatar.eip.splitter;
2+
3+
import org.junit.Test;
4+
5+
/**
6+
* Test for App class
7+
*/
8+
public class AppTest {
9+
10+
@Test
11+
public void testMain() throws Exception {
12+
String[] args = {};
13+
App.main(args);
14+
}
15+
}

0 commit comments

Comments
 (0)