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
 
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
 
24
public class AramaxTrackingService {
517 rajveer 25
	//public static String ARAMAX_URL = "http://www.aramex.com/track_xml.asp?ShipmentNumber=";
26
 
27
	private static String ARAMAX_URL = "file:///home/rajveer/shop2020/logistics/AWB_Track.xml";
459 rajveer 28
 
517 rajveer 29
	static{
30
		try {
31
			ARAMAX_URL = ConfigClient.getClient().get(ARAMAX_URL);
32
 
33
		} catch (ConfigException e) {
34
			ARAMAX_URL = "http://www.aramex.com/track_xml.asp?ShipmentNumber=";
35
			e.printStackTrace();
36
		}
37
		ARAMAX_URL = "file:///home/rajveer/shop2020/logistics/AWB_Track.xml";
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; 
71
			String uri = ARAMAX_URL;
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
			}
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
	}
106
 
107
 
108
	public static List<Map<String, String>> getUpdates(String awbNumber){
109
		//String uri = ARAMAX_URL + awbNumber;
110
		String uri = ARAMAX_URL;
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");
196
 
197
	}
198
}