Subversion Repositories SmartDukaan

Rev

Rev 459 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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