-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestR.java
92 lines (77 loc) · 3.01 KB
/
TestR.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package com.homedepot.myproject;
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.lang.Object;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.cloud.dataflow.sdk.Pipeline;
import com.google.cloud.dataflow.sdk.io.TextIO;
import com.google.cloud.dataflow.sdk.io.XmlSource;
import com.google.cloud.dataflow.sdk.options.PipelineOptionsFactory;
import com.google.cloud.dataflow.sdk.transforms.Create;
import com.google.cloud.dataflow.sdk.transforms.DoFn;
import com.google.cloud.dataflow.sdk.transforms.DoFnWithContext.ProcessContext;
import com.google.cloud.dataflow.sdk.transforms.ParDo;
import com.google.cloud.dataflow.sdk.values.PCollection;
public class TestR {
public static void main(String[] args) throws IOException {
Pipeline p = Pipeline.create(PipelineOptionsFactory.fromArgs(args).
withValidation().create());
File file2 = new File("Resources/messages-04.xml");
Serializer serializer = new Persister();
File output = new File("Resources/output.xml");
try {
BufferedReader reader = new BufferedReader(new FileReader(file2));
FileWriter writer = new FileWriter(output);
String currentLine;
int lineCount = 0;
while((currentLine = reader.readLine()) != null) {
if(!currentLine.contains("<?xml") || lineCount == 0) {
writer.write(currentLine);
writer.write(System.getProperty( "line.separator" ));
if(lineCount == 0) {
writer.write("<root>");
writer.write(System.getProperty( "line.separator" ));
}
}
lineCount++;
}
writer.write("</root>");
writer.close();
reader.close();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
TransactionContainer container = null;
try {
container = serializer.read(TransactionContainer.class, output);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ArrayList<String> cloudOutput = new ArrayList<String>();
for(Transaction transaction : container.getTransactions()) {
String cloudWrite = "StoreNumber: " + transaction.getStoreNumber() + " salesDate " + transaction.getSalesDate()
+ " registerNumber: " + transaction.getRegisterNumber() + " postTransId " + transaction.getPosTransId();
cloudOutput.add(cloudWrite);
/*System.out.println("StoreNumber: " + transaction.getStoreNumber() + " salesDate " + transaction.getSalesDate()
+ " registerNumber: " + transaction.getRegisterNumber() + " postTransId " + transaction.getPosTransId());*/
}
//System.out.println(cloudOutput.size());
p.apply(Create.of(cloudOutput)).apply(TextIO.Write.named("WriteMyFile")
.to("gs://ronaksandboxthd/Transaction Data 4"));
p.run();
return;
}
}