forked from Charmy1006/aftership-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadFiles.java
More file actions
110 lines (95 loc) · 4.5 KB
/
Copy pathLoadFiles.java
File metadata and controls
110 lines (95 loc) · 4.5 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import Classes.ConnectionAPI;
import Classes.Tracking;
import Enums.ISO3Country;
import org.json.JSONException;
import org.junit.Test;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by User on 17/6/14.
*/
public class LoadFiles {
public static void main( String args[])throws Exception{
LoadFiles loadFiles = new LoadFiles();
// loadFiles.loadFile();
}
public void loadFile()throws IOException, JSONException{
BufferedReader br =
new BufferedReader( new InputStreamReader(new FileInputStream("../TrackingsToAdd.txt"), "UTF8"));
ConnectionAPI connection = new ConnectionAPI("a61d6204-6477-4f6d-93ec-86c4f872fb6b");
try {
String line;
String [] elements;
int added =0;
Tracking newTracking;
while ((line = br.readLine()) != null)
{
// slug, smses11, emails10, title5, customerName6, orderID7, orderIDPath8,
// destinationCountryISO3 27
elements=line.split("\t");
// System.out.println("**long "+elements.length + " number "+elements[2]);
newTracking = new Tracking(elements[2]);
newTracking.setSlug(elements[4]);
if(5<elements.length && !elements[5].equals("")) newTracking.setTitle(elements[5]);
if(6<elements.length && !elements[6].equals("")) newTracking.setCustomerName(elements[6]);
if(7<elements.length &&!elements[7].equals("")) newTracking.setOrderID(elements[7]);
if(8<elements.length &&!elements[8].equals("")) newTracking.setOrderIDPath(elements[8]);
if(27<elements.length &&!elements[27].equals("")) newTracking.setDestinationCountryISO3(ISO3Country.valueOf(elements[27]));
if(11<elements.length &&!elements[11].equals("")){
String smses[] = elements[11].split(",");
for(int i=0;i<smses.length;i++)
newTracking.addSmses(smses[i]);
}
if(10<elements.length &&!elements[10].equals("")){
String emails[] = elements[10].split(",");
for(int i=0;i<emails.length;i++)
newTracking.addEmails(emails[i]);
}
System.out.println(newTracking.generateJSON());
try {
connection.postTracking(newTracking);
added++;
System.out.println("added " + added);
}catch(Exception e){
System.out.println(e.getMessage()+" number"+ elements[2]);
}
}
} finally {
br.close();
}
}
}
//order elements in file
// System.out.println("created_at" +elements[0]+
// "\tupdated_at" +elements[1]+
// "\ttracking_number" +elements[2]+
// "\ttags" +elements[3]+
// "\tcourier" +elements[4]+
// "\ttitle" +elements[5]+
// "\tcustomer_name" +elements[6]+
// "\torder_id" +elements[7]+
// "\torder_id_path" +elements[8]+
// "\tsource" +elements[9]+
// "\temails" +elements[10]+
// "\tsmses" +elements[11]+
// "\tshipment_type" +elements[12]+
// "\tshipment_weight" +elements[13]+
// "\tshipment_package_count" +elements[14]+
// "\tshipment_pickup_date" +elements[15]+
// "\tshipment_scheduled_delivery_date" +elements[16]+
// "\tshipment_delivery_date" +elements[17]+
// "\tsigned_by" +elements[18]+
// "\torigin_address" +elements[19]+
// "\torigin_country_name" +elements[20]+
// "\torigin_country_iso3" +elements[21]+
// "\torigin_state" +elements[22]+
// "\torigin_city" +elements[23]+
// "\torigin_zip" +elements[24]+
// "\tdestination_address" +elements[25]+
// "\tdestination_country_name" +elements[26]+
// "\tdestination_country_iso3" +elements[27]+
// "\tdestination_state" +elements[28]+
// "\tdestination_city" +elements[29]+
// "\tdestination_zip");