Rev 193 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.thrift.clients;import java.util.Date;import java.util.List;import javax.annotation.PostConstruct;import javax.annotation.PreDestroy;import org.apache.thrift.transport.TTransportException;import in.shop2020.model.v1.order.Billing;import in.shop2020.model.v1.order.BillingInfo;import in.shop2020.model.v1.order.OrderInfo;import in.shop2020.model.v1.order.ShipmentInfo;import in.shop2020.model.v1.order.ShipmentStatus;import in.shop2020.model.v1.order.Transaction;import in.shop2020.model.v1.order.TransactionStatus;import in.shop2020.model.v1.order.TransactionService.Client;import in.shop2020.utils.ConfigClientKeys;import in.shop2020.utils.Logger;public class TransactionServiceClient extends GenericServiceClient{private Client client = null;public TransactionServiceClient(String clientIdentifier,String hostConfigKey, String portConfigKey) throws Exception {super(clientIdentifier, hostConfigKey, portConfigKey);client = new Client(protocol);}public TransactionServiceClient()throws Exception{this(TransactionServiceClient.class.getSimpleName(), ConfigClientKeys.transaction_service_hostname.toString(), ConfigClientKeys.transaction_service_port.toString());}@PostConstructprivate void openTransport(){if(transport.isOpen()){Logger.log("Transport was already open", this);}try {transport.open();} catch (TTransportException e) {Logger.log("Encountered exception while open transport "+ e, this);}}//Api methods//TODO: Add logging to this class.public void createTransaction(Transaction t) throws Exception{client.createTransaction(t);}public Transaction getTransactionById(long id) throws Exception{return client.getTransaction(id);}public List<Transaction> getAllTransactions(TransactionStatus status, Date from, Date to) throws Exception{return client.getAllTransactions(status, from.getTime(), to.getTime());}public List<Transaction> getAllTransactions(ShipmentStatus status, Date from, Date to) throws Exception{return client.getTransactionsForShipmentStatus(status, from.getTime(), to.getTime());}public List<Transaction> getAllTransactions(long userId, Date from, Date to, TransactionStatus status) throws Exception{return client.getTransactionsForCustomer(userId, from.getTime(), to.getTime(), status);}public List<Transaction> getAllTransactions(long userId, Date from, Date to, ShipmentStatus status) throws Exception{return client.getTransactionsForCustomerAndShipmentStatus(userId, from.getTime(), to.getTime(), status);}public TransactionStatus getTransactionStatus(long id) throws Exception{return client.getTransactionStatus(id);}public boolean changeTransactionStatus(long id, TransactionStatus newStatus, String description) throws Exception {return client.changeTransactionStatus(id, newStatus, description);}public OrderInfo getOrderInfo(long transactionId) throws Exception{return client.getOrderInfo(transactionId);}public ShipmentInfo getShipmentInfo(long transactionId) throws Exception{return client.getShippingInfo(transactionId);}public BillingInfo getBillingInfo(long transactionId) throws Exception{return client.getBillingInfo(transactionId);}public boolean addBilling(long transactionId, Billing billing) throws Exception{return client.addBilling(transactionId, billing);}public boolean setShipmentTracker(long transactionId, long shippingId, String trackingId, String airwayBillNo, String provider)throws Exception{return client.setShippingTracker(transactionId, shippingId, trackingId, airwayBillNo, provider);}public boolean setShipmentDate(long transactionId, long shippingId, Date date) throws Exception{return client.setShippingDate(transactionId, shippingId, date.getTime());}public boolean setDeliveryDate(long transactionId, long shippingId, Date date) throws Exception{return client.setDeliveryDate(transactionId, shippingId, date.getTime());}public boolean changeShippingStatus(long transactionId, long shippingId, ShipmentStatus status, String description) throws Exception{return client.changeShippingStatus(transactionId, shippingId, status, description);}public boolean addTrail(long transactionId, String message)throws Exception{return client.addTrail(transactionId, message);}@PreDestroyprivate void closeTransport(){if(transport != null && transport.isOpen()){Logger.log("Closing transport :", this);transport.close();}}}