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