Subversion Repositories SmartDukaan

Rev

Rev 7905 | Rev 7992 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7905 Rev 7923
Line 1... Line 1...
1
package com;
1
package com;
2
import in.shop2020.config.ConfigException;
-
 
3
import in.shop2020.model.v1.order.Order;
2
import in.shop2020.model.v1.order.Order;
4
import in.shop2020.thrift.clients.config.ConfigClient;
-
 
5
 
3
 
6
 
4
 
7
import java.util.*;
5
import java.util.*;
8
import java.io.*;
6
import java.io.*;
9
import java.math.*;
7
import java.math.*;
Line 25... Line 23...
25
 
23
 
26
 
24
 
27
public class ShipWebServiceClient 
25
public class ShipWebServiceClient 
28
{
26
{
29
 
27
 
30
	public static ProcessShipmentReply getShipmentCreationReply(Order t_order){
28
	public static ProcessShipmentReply getShipmentCreationReply(Order t_order ,ClientDetail clientDetail, WebAuthenticationDetail wac, String endpointAddress){
31
		ProcessShipmentRequest request = new ProcessShipmentRequest(); // Build a request object
29
		ProcessShipmentRequest request = new ProcessShipmentRequest(); // Build a request object
32
        request.setClientDetail(createClientDetail());
30
        request.setClientDetail(clientDetail);
33
        request.setWebAuthenticationDetail(createWebAuthenticationDetail());
31
        request.setWebAuthenticationDetail(wac);
34
        
32
        
35
        TransactionDetail transactionDetail = new TransactionDetail();
33
        TransactionDetail transactionDetail = new TransactionDetail();
36
	    transactionDetail.setCustomerTransactionId("Domestic Express Ship Request"); // The client will get the same value back in the response
34
	    transactionDetail.setCustomerTransactionId("Domestic Express Ship Request"); // The client will get the same value back in the response
37
	    request.setTransactionDetail(transactionDetail);
35
	    request.setTransactionDetail(transactionDetail);
38
	    
36
	    
Line 44... Line 42...
44
	    requestedShipment.setDropoffType(DropoffType.REGULAR_PICKUP); 
42
	    requestedShipment.setDropoffType(DropoffType.REGULAR_PICKUP); 
45
	    requestedShipment.setServiceType(ServiceType.FEDEX_EXPRESS_SAVER); 
43
	    requestedShipment.setServiceType(ServiceType.FEDEX_EXPRESS_SAVER); 
46
	    requestedShipment.setPackagingType(PackagingType.YOUR_PACKAGING); 
44
	    requestedShipment.setPackagingType(PackagingType.YOUR_PACKAGING); 
47
	    requestedShipment.setShipper(addShipper());
45
	    requestedShipment.setShipper(addShipper());
48
	    requestedShipment.setRecipient(addRecipient(t_order));
46
	    requestedShipment.setRecipient(addRecipient(t_order));
49
	    requestedShipment.setShippingChargesPayment(addShippingChargesPayment());
47
	    requestedShipment.setShippingChargesPayment(addShippingChargesPayment(clientDetail.getAccountNumber()));
50
	    if(t_order.isCod()){
48
	    if(t_order.isCod()){
51
	    	requestedShipment.setSpecialServicesRequested(addShipmentSpecialServicesRequested(t_order)); 
49
	    	requestedShipment.setSpecialServicesRequested(addShipmentSpecialServicesRequested(t_order)); 
52
	    }
50
	    }
53
	    else{
51
	    else{
54
	    	requestedShipment.setSpecialServicesRequested(null); 
52
	    	requestedShipment.setSpecialServicesRequested(null); 
Line 67... Line 65...
67
			// Initialize the service
65
			// Initialize the service
68
			ShipServiceLocator service;
66
			ShipServiceLocator service;
69
			ShipPortType port;
67
			ShipPortType port;
70
			
68
			
71
			service = new ShipServiceLocator();
69
			service = new ShipServiceLocator();
72
			updateEndPoint(service);
70
			updateEndPoint(service, endpointAddress);
73
			port = service.getShipServicePort();
71
			port = service.getShipServicePort();
74
 
72
 
75
			reply = port.processShipment(request); // This is the call to the ship web service passing in a request object and returning a reply object
73
			reply = port.processShipment(request); // This is the call to the ship web service passing in a request object and returning a reply object
76
			
74
			
77
			printNotifications(reply.getNotifications());
75
			printNotifications(reply.getNotifications());
Line 165... Line 163...
165
				//System.out.println();
163
				//System.out.println();
166
			}
164
			}
167
		}
165
		}
168
	}
166
	}
169
			
167
			
170
    
-
 
171
	private static String getPayorAccountNumber() {
-
 
172
		//String payorAccountNumber = System.getProperty("Payor.AccountNumber");
-
 
173
		String payorAccountNumber ="";
-
 
174
		try {
-
 
175
			payorAccountNumber = ConfigClient.getClient().get("fedex_account_number");
-
 
176
		} catch (ConfigException e) {
-
 
177
			// TODO Auto-generated catch block
-
 
178
			e.printStackTrace();
-
 
179
		}
-
 
180
		/*if (payorAccountNumber == null) {
-
 
181
			payorAccountNumber = "510087089"; // Replace "XXX" with the payor account number
-
 
182
		}*/
-
 
183
		return payorAccountNumber;
-
 
184
	}
-
 
185
		
168
		
186
	private static Party addShipper(){
169
	private static Party addShipper(){
187
	    Party shipperParty = new Party(); // Sender information
170
	    Party shipperParty = new Party(); // Sender information
188
	    Contact shipperContact = new Contact();
171
	    Contact shipperContact = new Contact();
189
	    shipperContact.setPersonName("Spice Online");
172
	    shipperContact.setPersonName("Spice Online");
Line 234... Line 217...
234
	    recipientParty.setContact(recipientContact);
217
	    recipientParty.setContact(recipientContact);
235
	    recipientParty.setAddress(recipientAddress);
218
	    recipientParty.setAddress(recipientAddress);
236
	    return recipientParty;
219
	    return recipientParty;
237
	}
220
	}
238
	
221
	
239
	private static Payment addShippingChargesPayment(){
222
	private static Payment addShippingChargesPayment(String payorAccountNumber){
240
	    Payment payment = new Payment(); 
223
	    Payment payment = new Payment(); 
241
	    payment.setPaymentType(PaymentType.SENDER);
224
	    payment.setPaymentType(PaymentType.SENDER);
242
	    Payor payor = new Payor();
225
	    Payor payor = new Payor();
243
	    Party responsibleParty = new Party();
226
	    Party responsibleParty = new Party();
244
	    responsibleParty.setAccountNumber(getPayorAccountNumber());
227
	    responsibleParty.setAccountNumber(payorAccountNumber);
245
	    Address responsiblePartyAddress = new Address();
228
	    Address responsiblePartyAddress = new Address();
246
	    String address[] = new String[2];
229
	    String address[] = new String[2];
247
	    address[0] = new String("Plot No. 19A-19B");
230
	    address[0] = new String("Plot No. 19A-19B");
248
	    address[1] = new String("Sector - 125");
231
	    address[1] = new String("Sector - 125");
249
	    responsiblePartyAddress.setCountryCode("IN");
232
	    responsiblePartyAddress.setCountryCode("IN");
Line 400... Line 383...
400
			fos.close();
383
			fos.close();
401
			System.out.println("\nAssociated shipment label file name " + associatedShipmentLabelFile.getAbsolutePath());
384
			System.out.println("\nAssociated shipment label file name " + associatedShipmentLabelFile.getAbsolutePath());
402
		}
385
		}
403
	}
386
	}
404
	
387
	
405
	private static ClientDetail createClientDetail() {
-
 
406
        ClientDetail clientDetail = new ClientDetail();
-
 
407
        String accountNumber ="";
-
 
408
		try {
-
 
409
			accountNumber = ConfigClient.getClient().get("fedex_account_number");
-
 
410
		} catch (ConfigException e) {
-
 
411
			// TODO Auto-generated catch block
-
 
412
			e.printStackTrace();
-
 
413
		}
-
 
414
		
-
 
415
        String meterNumber ="";
-
 
416
		try {
-
 
417
			meterNumber = ConfigClient.getClient().get("fedex_meter_number");
-
 
418
		} catch (ConfigException e) {
-
 
419
			// TODO Auto-generated catch block
-
 
420
			e.printStackTrace();
-
 
421
		}
-
 
422
		
-
 
423
        /*if (accountNumber == null) {
-
 
424
        	accountNumber = "510087089"; // Replace "XXX" with clients account number
-
 
425
        }
-
 
426
        if (meterNumber == null) {
-
 
427
        	meterNumber = "118585428"; // Replace "XXX" with clients meter number
-
 
428
        }*/
-
 
429
        clientDetail.setAccountNumber(accountNumber);
-
 
430
        clientDetail.setMeterNumber(meterNumber);
-
 
431
        return clientDetail;
-
 
432
	}
-
 
433
	
-
 
434
	private static WebAuthenticationDetail createWebAuthenticationDetail() {
-
 
435
        WebAuthenticationCredential wac = new WebAuthenticationCredential();
-
 
436
        String key="";
-
 
437
		try {
-
 
438
			key = ConfigClient.getClient().get("fedex_authenication_key");
-
 
439
		} catch (ConfigException e) {
-
 
440
			// TODO Auto-generated catch block
-
 
441
			e.printStackTrace();
-
 
442
		}
-
 
443
		
-
 
444
        String password="";
-
 
445
		try {
-
 
446
			password = ConfigClient.getClient().get("fedex_authenication_password");
-
 
447
		} catch (ConfigException e) {
-
 
448
			// TODO Auto-generated catch block
-
 
449
			e.printStackTrace();
-
 
450
		}
-
 
451
        
-
 
452
        /*if (key == null) {
-
 
453
        	key = "4XqfCFRFM4uXe6Wm"; // Replace "XXX" with clients key
-
 
454
        }
-
 
455
        if (password == null) {
-
 
456
        	password = "LtIgtKmluqOPikdNmTjXWPkTo"; // Replace "XXX" with clients password
-
 
457
        }*/
-
 
458
        wac.setKey(key);
-
 
459
        wac.setPassword(password);
-
 
460
		return new WebAuthenticationDetail(wac);
-
 
461
	}
-
 
462
	
-
 
463
	private static void updateEndPoint(ShipServiceLocator serviceLocator) {
388
	private static void updateEndPoint(ShipServiceLocator serviceLocator, String endPoint) {
464
		String endPoint = System.getProperty("endPoint");
-
 
465
		if (endPoint != null) {
389
		if (endPoint != null) {
466
			serviceLocator.setShipServicePortEndpointAddress(endPoint);
390
			serviceLocator.setShipServicePortEndpointAddress(endPoint);
467
		}
391
		}
468
	}	
392
	}	
469
	
393