/
ProductCustomersToCsv.java
61 lines (53 loc) · 1.93 KB
/
ProductCustomersToCsv.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*******************************************************************************
* Copyright (c) 2019, 2020 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.loc.report.internal.core;
import java.nio.file.Path;
import java.util.Set;
import org.eclipse.passage.loc.yars.internal.api.DefaultDosHandler;
import org.eclipse.passage.loc.yars.internal.api.DosHandleMedia;
import org.eclipse.passage.loc.yars.internal.api.Progress;
import org.eclipse.passage.loc.yars.internal.api.ReportException;
import org.eclipse.passage.loc.yars.internal.api.SingleSwoopExport;
/**
* OSGi-free final implementation of the <i>customers for these products</i>
* export command
*
* @since 0.1
*/
@SuppressWarnings("restriction")
public final class ProductCustomersToCsv {
private final CustomerStorage source;
public ProductCustomersToCsv(CustomerStorage storage) {
this.source = storage;
}
/**
* The <i>exporting</i> command to be called by the pachake's clients directly
* or by means of OSGi {@code services}.
*
* @since 0.1
*/
public void export(Set<String> products, Path target, Progress<ProductCustomer> progress) throws ReportException {
new SingleSwoopExport<CustomerStorage, ProductCustomer>(//
new CustomersForProductsQuery()//
.fetch(source, //
new ProductNames(products)))//
.write(//
new DosHandleMedia<ProductCustomer>( //
new Csv( //
new ExistingFileStream(target), //
"email", //$NON-NLS-1$
"name"), //$NON-NLS-1$
new DefaultDosHandler()), //
progress);
}
}