1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.batch.sample.domain.order.internal;
18
19 import java.util.Map;
20
21 import org.springframework.batch.item.file.transform.LineAggregator;
22 import org.springframework.batch.sample.domain.order.LineItem;
23 import org.springframework.batch.sample.domain.order.Order;
24
25
26
27
28
29
30
31 public class OrderLineAggregator implements LineAggregator<Order> {
32
33 private static final String LINE_SEPARATOR = System.getProperty("line.separator");
34
35 private Map<String, LineAggregator<Object>> aggregators;
36
37 public String aggregate(Order order) {
38 StringBuilder result = new StringBuilder();
39
40 result.append(aggregators.get("header").aggregate(order) + LINE_SEPARATOR);
41 result.append(aggregators.get("customer").aggregate(order) + LINE_SEPARATOR);
42 result.append(aggregators.get("address").aggregate(order) + LINE_SEPARATOR);
43 result.append(aggregators.get("billing").aggregate(order) + LINE_SEPARATOR);
44
45 for (LineItem lineItem : order.getLineItems()) {
46 result.append(aggregators.get("item").aggregate(lineItem) + LINE_SEPARATOR);
47 }
48
49 result.append(aggregators.get("footer").aggregate(order));
50
51 return result.toString();
52 }
53
54
55
56
57
58
59 public void setAggregators(Map<String, LineAggregator<Object>> aggregators) {
60 this.aggregators = aggregators;
61 }
62
63 }