Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
459 rajveer 1
package in.shop2020.serving.services;
2
 
3
 
4
import in.shop2020.logistics.ShipmentUpdate;
5
import in.shop2020.thrift.clients.LogisticsServiceClient;
6
 
7
import javax.xml.xpath.XPath;
8
import javax.xml.xpath.XPathConstants;
9
import javax.xml.xpath.XPathExpressionException;
10
import javax.xml.xpath.XPathFactory;
11
 
12
import org.apache.thrift.TException;
13
import org.w3c.dom.Node;
14
import org.w3c.dom.NodeList;
15
import org.xml.sax.InputSource;
16
 
17
public class AramaxTrackingService {
18
	private String awbNumber;
19
	private InputSource inputSource;
20
	private XPath xpath;
21
	public static String ARAMAX_URL = "http://www.aramex.com/track_xml.asp?ShipmentNumber=";
22
 
23
	public AramaxTrackingService(String awbNumber){
24
		this.awbNumber = awbNumber;
25
		String uri = ARAMAX_URL + this.awbNumber; 
26
		this.inputSource = new InputSource(uri);
27
		this.xpath= XPathFactory.newInstance().newXPath();
28
	}
29
 
30
	public String getAwbNumber() {
31
		return awbNumber;
32
	}
33
 
34
	public void setAwbNumber(String awbNumber) {
35
		this.awbNumber = awbNumber;
36
	}
37
 
38
	public InputSource getInputSource() {
39
		return inputSource;
40
	}
41
 
42
	public void setInputSource(InputSource inputSource) {
43
		this.inputSource = inputSource;
44
	}
45
 
46
	public String getUpdates(){
47
		String expression = "/HAWBs/HAWBDetails/HAWBHistory/HAWBUpdate";
48
		NodeList nodes = null;
49
		try {
50
			nodes = (NodeList) xpath.evaluate(expression, this.inputSource,	XPathConstants.NODESET);
51
		} 
52
		catch(XPathExpressionException xpee) {
53
			return null;
54
		}
55
 
56
 
57
		for(int i=nodes.getLength()-1; i>=0; i--) {
58
			Node node = nodes.item(i);
59
			NodeList childNodes = node.getChildNodes();
60
			System.out.println("Action date is :		" + childNodes.item(0).getTextContent());
61
			System.out.println("PIN number  is :		" + childNodes.item(1).getTextContent());
62
			System.out.println("Entry Date  is :		" + childNodes.item(3).getTextContent());
63
			System.out.println("Update City is :		" + childNodes.item(6).getTextContent());
64
			System.out.println("Tracking Code Desc is  :" + childNodes.item(7).getTextContent());
65
			System.out.println("UpdateLocation		is :" + childNodes.item(8).getTextContent());
66
			System.out.println("UpdateCountry		is :" + childNodes.item(11).getTextContent());
67
			System.out.println("Tracking Condition	is :" + childNodes.item(12).getTextContent());
68
			System.out.println("Customer Desc		is :" + childNodes.item(14).getTextContent());
69
			System.out.println("\n\n\n\n ");
70
 
71
			ShipmentUpdate update = new ShipmentUpdate();
72
			update.setDescription(childNodes.item(14).getTextContent());
73
			update.setPin(childNodes.item(1).getTextContent());
74
			update.setTimestamp(10);
75
 
76
			try {
77
				LogisticsServiceClient lsc = new LogisticsServiceClient();
78
				lsc.getClient().updateShipmentStatus(this.awbNumber, update);
79
 
80
			} catch (TException e) {
81
				// TODO Auto-generated catch block
82
				e.printStackTrace();
83
			}
84
			//childNodes.item(0).getTextContent()
85
			/*
86
			for(int j=0; j<childNodes.getLength(); j++) {
87
				System.out.println("value is :" +j + " " +  childNodes.item(j).getTextContent());
88
			}
89
			*/ catch (Exception e) {
90
				// TODO Auto-generated catch block
91
				e.printStackTrace();
92
			}
93
		}
94
 
95
 
96
		System.out.println("nodes length " +  nodes.getLength() );
97
 
98
 
99
		return nodes.toString(); 
100
 
101
	}
102
 
103
	public String getOriginCity(){
104
 
105
		String expression = "/HAWBs/HAWBDetails/HAWBOriginEntity";
106
 
107
		NodeList nodes = null;
108
		try {
109
			nodes = (NodeList) xpath.evaluate(expression, this.inputSource,	XPathConstants.NODESET);
110
		} 
111
		catch(XPathExpressionException xpee) {
112
			return null;
113
		}
114
 
115
		System.out.println("nodes length " +  nodes.getLength() + nodes.item(0).getTextContent());
116
 
117
 
118
		return nodes.toString(); 
119
	}
120
	public static void main(String[] args){
121
		System.out.println("Aramax number is " + "6149183666");
122
		AramaxTrackingService trackingService = new AramaxTrackingService("6149183666");
123
		System.out.println("Document is " + trackingService.getInputSource());
124
		System.out.println("origin city is : " + trackingService.getOriginCity());
125
		trackingService.getUpdates();
126
 
127
	}
128
}