Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
68 ashish 1
package in.shop2020.thrift.clients;
2
 
3
import java.util.Date;
4
import java.util.List;
5
 
6
import javax.annotation.PostConstruct;
7
import javax.annotation.PreDestroy;
8
 
9
import org.apache.thrift.transport.TTransportException;
10
 
11
import in.shop2020.model.v1.order.Billing;
12
import in.shop2020.model.v1.order.BillingInfo;
13
import in.shop2020.model.v1.order.OrderInfo;
14
import in.shop2020.model.v1.order.ShipmentInfo;
15
import in.shop2020.model.v1.order.ShipmentStatus;
16
import in.shop2020.model.v1.order.Transaction;
17
import in.shop2020.model.v1.order.TransactionStatus;
18
import in.shop2020.model.v1.order.TransactionService.Client;
19
import in.shop2020.utils.ConfigClientKeys;
20
import in.shop2020.utils.Logger;
21
 
22
public class TransactionServiceClient extends GenericServiceClient{
23
 
24
	private Client client = null;
25
 
26
	public TransactionServiceClient(String clientIdentifier,
27
			String hostConfigKey, String portConfigKey) throws Exception {
28
		super(clientIdentifier, hostConfigKey, portConfigKey);
29
		client = new Client(protocol);
30
 
31
	}
32
 
33
	public TransactionServiceClient()throws Exception{
34
		this(TransactionServiceClient.class.getSimpleName(), ConfigClientKeys.transaction_service_hostname.toString(), ConfigClientKeys.transaction_service_port.toString());
35
	}
36
 
37
	@PostConstruct
38
	private void openTransport(){
39
		if(transport.isOpen()){
40
			Logger.log("Transport was already open", this);
41
		}
42
		try {
43
			transport.open();
44
		} catch (TTransportException e) {
45
			Logger.log("Encountered exception while open transport "+ e, this);
46
		}
47
	}
48
 
49
	//Api methods
50
	//TODO: Add logging to this class.
51
 
52
	public void createTransaction(Transaction t) throws Exception{
53
		client.createTransaction(t);
54
	}
55
 
56
	public Transaction getTransactionById(long id) throws Exception{
57
		return client.getTransaction(id);
58
	}
59
 
60
	public List<Transaction> getAllTransactions(TransactionStatus status, Date from, Date to) throws Exception{
61
		return client.getAllTransactions(status, from.getTime(), to.getTime());
62
	}
63
 
64
	public List<Transaction> getAllTransactions(ShipmentStatus status, Date from, Date to) throws Exception{
65
		return client.getTransactionsForShipmentStatus(status, from.getTime(), to.getTime());
66
	}
67
 
68
	public List<Transaction> getAllTransactions(long userId, Date from, Date to, TransactionStatus status) throws Exception{
69
		return client.getTransactionsForCustomer(userId, from.getTime(), to.getTime(), status);
70
	}
71
 
72
	public List<Transaction> getAllTransactions(long userId, Date from, Date to, ShipmentStatus status) throws Exception{
73
		return client.getTransactionsForCustomerAndShipmentStatus(userId, from.getTime(), to.getTime(), status);
74
	}
75
 
76
	public TransactionStatus getTransactionStatus(long id) throws Exception{
77
		return client.getTransactionStatus(id);
78
	}
79
 
80
	public boolean changeTransactionStatus(long id, TransactionStatus newStatus, String description) throws Exception {
81
		return client.changeTransactionStatus(id, newStatus, description);
82
	}
83
 
84
	public OrderInfo getOrderInfo(long transactionId) throws Exception{
85
		return client.getOrderInfo(transactionId);
86
	}
87
 
88
	public ShipmentInfo getShipmentInfo(long transactionId) throws Exception{
89
		return client.getShippingInfo(transactionId);
90
	}
91
 
92
	public BillingInfo getBillingInfo(long transactionId) throws Exception{
93
		return client.getBillingInfo(transactionId);
94
	}
95
 
96
	public boolean addBilling(long transactionId, Billing billing) throws Exception{
97
		return client.addBilling(transactionId, billing);
98
	}
99
 
100
	public boolean setShipmentTracker(long transactionId, long shippingId, String trackingId, String airwayBillNo, String provider)throws Exception{
101
		return client.setShippingTracker(transactionId, shippingId, trackingId, airwayBillNo, provider);
102
	}
103
 
104
	public boolean setShipmentDate(long transactionId, long shippingId, Date date) throws Exception{
105
		return client.setShippingDate(transactionId, shippingId, date.getTime());
106
	}
107
 
108
	public boolean setDeliveryDate(long transactionId, long shippingId, Date date) throws Exception{
109
		return client.setDeliveryDate(transactionId, shippingId, date.getTime());
110
	}
111
 
112
	public boolean changeShippingStatus(long transactionId, long shippingId, ShipmentStatus status, String description) throws Exception{
113
		return client.changeShippingStatus(transactionId, shippingId, status, description);
114
	}
115
 
116
	public boolean addTrail(long transactionId, String message)throws Exception{
117
		return client.addTrail(transactionId, message);
118
	}
119
 
120
	@PreDestroy
121
	private void closeTransport(){
122
		if(transport != null && transport.isOpen()){
123
			Logger.log("Closing transport :", this);
124
			transport.close();
125
		}
126
	}
127
 
128
}