| 459 |
rajveer |
1 |
package in.shop2020.serving.services;
|
|
|
2 |
|
|
|
3 |
|
| 517 |
rajveer |
4 |
import in.shop2020.config.ConfigException;
|
| 459 |
rajveer |
5 |
import in.shop2020.thrift.clients.LogisticsServiceClient;
|
| 517 |
rajveer |
6 |
import in.shop2020.thrift.clients.config.ConfigClient;
|
| 459 |
rajveer |
7 |
|
| 517 |
rajveer |
8 |
import java.util.ArrayList;
|
|
|
9 |
import java.util.HashMap;
|
|
|
10 |
import java.util.List;
|
|
|
11 |
import java.util.Map;
|
|
|
12 |
|
| 459 |
rajveer |
13 |
import javax.xml.xpath.XPath;
|
|
|
14 |
import javax.xml.xpath.XPathConstants;
|
|
|
15 |
import javax.xml.xpath.XPathExpressionException;
|
|
|
16 |
import javax.xml.xpath.XPathFactory;
|
|
|
17 |
|
|
|
18 |
import org.apache.thrift.TException;
|
|
|
19 |
import org.w3c.dom.Node;
|
|
|
20 |
import org.w3c.dom.NodeList;
|
|
|
21 |
import org.xml.sax.InputSource;
|
|
|
22 |
|
| 545 |
rajveer |
23 |
public class AramexTrackingService {
|
| 517 |
rajveer |
24 |
//public static String ARAMAX_URL = "http://www.aramex.com/track_xml.asp?ShipmentNumber=";
|
|
|
25 |
|
| 545 |
rajveer |
26 |
private static String ARAMEX_URL;
|
| 459 |
rajveer |
27 |
|
| 517 |
rajveer |
28 |
static{
|
|
|
29 |
try {
|
| 545 |
rajveer |
30 |
ARAMEX_URL = ConfigClient.getClient().get("aramex_update_url");
|
| 517 |
rajveer |
31 |
|
|
|
32 |
} catch (ConfigException e) {
|
| 545 |
rajveer |
33 |
ARAMEX_URL = "file:///root/docs/logistics/AWB_Track.xml";
|
| 517 |
rajveer |
34 |
e.printStackTrace();
|
|
|
35 |
}
|
| 536 |
rajveer |
36 |
|
| 459 |
rajveer |
37 |
}
|
| 517 |
rajveer |
38 |
/*
|
|
|
39 |
private static AramaxTrackingService trackingService;
|
|
|
40 |
|
|
|
41 |
static{
|
|
|
42 |
synchronized(AramaxTrackingService.class){
|
|
|
43 |
trackingService = new AramaxTrackingService();
|
|
|
44 |
}
|
|
|
45 |
}
|
|
|
46 |
*/
|
| 459 |
rajveer |
47 |
|
| 517 |
rajveer |
48 |
/*
|
| 459 |
rajveer |
49 |
public String getAwbNumber() {
|
|
|
50 |
return awbNumber;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
public void setAwbNumber(String awbNumber) {
|
|
|
54 |
this.awbNumber = awbNumber;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
public InputSource getInputSource() {
|
|
|
58 |
return inputSource;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public void setInputSource(InputSource inputSource) {
|
|
|
62 |
this.inputSource = inputSource;
|
|
|
63 |
}
|
| 517 |
rajveer |
64 |
*/
|
|
|
65 |
|
| 681 |
rajveer |
66 |
/*
|
| 517 |
rajveer |
67 |
public static void getShipmentUpdates(String awbNumber){
|
|
|
68 |
String expression = "/HAWBs/HAWBDetails/HAWBHistory/HAWBUpdate";
|
|
|
69 |
//String uri = ARAMAX_URL + awbNumber;
|
| 545 |
rajveer |
70 |
String uri = ARAMEX_URL;
|
| 517 |
rajveer |
71 |
InputSource inputSource = new InputSource(uri);
|
|
|
72 |
XPath xpath= XPathFactory.newInstance().newXPath();
|
|
|
73 |
|
|
|
74 |
NodeList nodes = null;
|
|
|
75 |
try {
|
|
|
76 |
nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
|
|
|
77 |
}
|
|
|
78 |
catch(XPathExpressionException xpee) {
|
|
|
79 |
return ;
|
|
|
80 |
}
|
| 536 |
rajveer |
81 |
|
| 517 |
rajveer |
82 |
|
|
|
83 |
for(int i=nodes.getLength()-1; i>=0; i--) {
|
|
|
84 |
Node node = nodes.item(i);
|
|
|
85 |
NodeList childNodes = node.getChildNodes();
|
|
|
86 |
ShipmentUpdate update = new ShipmentUpdate();
|
|
|
87 |
update.setDescription(childNodes.item(14).getTextContent());
|
|
|
88 |
update.setPin(childNodes.item(1).getTextContent());
|
|
|
89 |
update.setTimestamp(10);
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
try {
|
|
|
93 |
LogisticsServiceClient lsc = new LogisticsServiceClient();
|
|
|
94 |
lsc.getClient().updateShipmentStatus(awbNumber, update);
|
|
|
95 |
|
|
|
96 |
} catch (TException e) {
|
|
|
97 |
// TODO Auto-generated catch block
|
|
|
98 |
e.printStackTrace();
|
|
|
99 |
}catch (Exception e) {
|
|
|
100 |
// TODO Auto-generated catch block
|
|
|
101 |
e.printStackTrace();
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
}
|
| 681 |
rajveer |
106 |
*/
|
| 517 |
rajveer |
107 |
|
|
|
108 |
public static List<Map<String, String>> getUpdates(String awbNumber){
|
|
|
109 |
//String uri = ARAMAX_URL + awbNumber;
|
| 545 |
rajveer |
110 |
String uri = ARAMEX_URL;
|
| 517 |
rajveer |
111 |
InputSource inputSource = new InputSource(uri);
|
|
|
112 |
XPath xpath = XPathFactory.newInstance().newXPath();
|
|
|
113 |
|
| 459 |
rajveer |
114 |
String expression = "/HAWBs/HAWBDetails/HAWBHistory/HAWBUpdate";
|
|
|
115 |
NodeList nodes = null;
|
|
|
116 |
try {
|
| 517 |
rajveer |
117 |
nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
|
| 459 |
rajveer |
118 |
}
|
|
|
119 |
catch(XPathExpressionException xpee) {
|
|
|
120 |
return null;
|
|
|
121 |
}
|
|
|
122 |
|
| 517 |
rajveer |
123 |
List<Map<String, String>> updates = new ArrayList<Map<String,String>>();
|
| 459 |
rajveer |
124 |
|
| 517 |
rajveer |
125 |
System.out.println("Action date "+ "Update City " + "Tracki Code Desc" );
|
| 459 |
rajveer |
126 |
for(int i=nodes.getLength()-1; i>=0; i--) {
|
|
|
127 |
Node node = nodes.item(i);
|
|
|
128 |
NodeList childNodes = node.getChildNodes();
|
| 517 |
rajveer |
129 |
/*
|
| 459 |
rajveer |
130 |
System.out.println("Action date is : " + childNodes.item(0).getTextContent());
|
|
|
131 |
System.out.println("PIN number is : " + childNodes.item(1).getTextContent());
|
|
|
132 |
System.out.println("Entry Date is : " + childNodes.item(3).getTextContent());
|
|
|
133 |
System.out.println("Update City is : " + childNodes.item(6).getTextContent());
|
|
|
134 |
System.out.println("Tracking Code Desc is :" + childNodes.item(7).getTextContent());
|
|
|
135 |
System.out.println("UpdateLocation is :" + childNodes.item(8).getTextContent());
|
|
|
136 |
System.out.println("UpdateCountry is :" + childNodes.item(11).getTextContent());
|
|
|
137 |
System.out.println("Tracking Condition is :" + childNodes.item(12).getTextContent());
|
|
|
138 |
System.out.println("Customer Desc is :" + childNodes.item(14).getTextContent());
|
|
|
139 |
System.out.println("\n\n\n\n ");
|
| 517 |
rajveer |
140 |
*/
|
| 459 |
rajveer |
141 |
|
| 517 |
rajveer |
142 |
System.out.println(childNodes.item(0).getTextContent() +"\t\t"+childNodes.item(6).getTextContent()+"\t\t"
|
|
|
143 |
+childNodes.item(7).getTextContent());
|
| 459 |
rajveer |
144 |
|
| 517 |
rajveer |
145 |
Map<String,String> update = new HashMap<String,String>();
|
|
|
146 |
|
|
|
147 |
String dateString = childNodes.item(0).getTextContent();
|
|
|
148 |
String[] tokens = dateString.split("\\s");
|
|
|
149 |
String date = tokens[0];
|
|
|
150 |
String time = tokens[1] + " " + tokens[2];
|
|
|
151 |
String city = childNodes.item(6).getTextContent();
|
|
|
152 |
String status = childNodes.item(7).getTextContent();
|
|
|
153 |
|
|
|
154 |
System.out.println("date:"+date+":time:" + time +":city:"+city+":status:"+status);
|
|
|
155 |
|
|
|
156 |
update.put("date", date);
|
|
|
157 |
update.put("time", time);
|
|
|
158 |
update.put("city", city);
|
|
|
159 |
update.put("status", status);
|
|
|
160 |
|
|
|
161 |
updates.add(update);
|
|
|
162 |
|
| 459 |
rajveer |
163 |
}
|
|
|
164 |
|
|
|
165 |
|
|
|
166 |
System.out.println("nodes length " + nodes.getLength() );
|
|
|
167 |
|
| 517 |
rajveer |
168 |
return updates;
|
|
|
169 |
//return nodes.toString();
|
| 459 |
rajveer |
170 |
|
|
|
171 |
}
|
|
|
172 |
|
| 517 |
rajveer |
173 |
/*
|
| 459 |
rajveer |
174 |
public String getOriginCity(){
|
|
|
175 |
|
|
|
176 |
String expression = "/HAWBs/HAWBDetails/HAWBOriginEntity";
|
|
|
177 |
|
|
|
178 |
NodeList nodes = null;
|
|
|
179 |
try {
|
|
|
180 |
nodes = (NodeList) xpath.evaluate(expression, this.inputSource, XPathConstants.NODESET);
|
|
|
181 |
}
|
|
|
182 |
catch(XPathExpressionException xpee) {
|
|
|
183 |
return null;
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
System.out.println("nodes length " + nodes.getLength() + nodes.item(0).getTextContent());
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
return nodes.toString();
|
|
|
190 |
}
|
| 517 |
rajveer |
191 |
*/
|
|
|
192 |
|
|
|
193 |
|
| 459 |
rajveer |
194 |
public static void main(String[] args){
|
|
|
195 |
System.out.println("Aramax number is " + "6149183666");
|
| 637 |
rajveer |
196 |
AramexTrackingService.getUpdates(ARAMEX_URL);
|
| 459 |
rajveer |
197 |
}
|
|
|
198 |
}
|