Rev 3126 | Rev 4484 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.controllers;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.Date;import java.util.HashMap;import java.util.List;import java.util.Map;import in.shop2020.logistics.Provider;import in.shop2020.model.v1.order.Order;import in.shop2020.model.v1.order.OrderStatus;import in.shop2020.serving.utils.FormattingUtils;import in.shop2020.thrift.clients.LogisticsClient;import in.shop2020.thrift.clients.TransactionClient;import org.apache.log4j.Logger;import org.apache.struts2.convention.annotation.InterceptorRef;import org.apache.struts2.convention.annotation.InterceptorRefs;import org.apache.struts2.convention.annotation.Result;import org.apache.struts2.convention.annotation.Results;/*** @author rajveer**/@SuppressWarnings("serial")@InterceptorRefs({@InterceptorRef("myDefault"),@InterceptorRef("login")})@Results({@Result(name="redirect", type="redirectAction",params = {"actionName" , "login"})})public class MyaccountController extends BaseController {private static Logger logger = Logger.getLogger(Class.class);private static final List<OrderStatus> statuses = Arrays.asList(new OrderStatus[] {OrderStatus.PAYMENT_PENDING,OrderStatus.INIT,OrderStatus.SUBMITTED_FOR_PROCESSING,OrderStatus.INVENTORY_LOW,OrderStatus.ACCEPTED,OrderStatus.BILLED,OrderStatus.PAYMENT_FLAGGED,OrderStatus.SHIPPED_FROM_WH,OrderStatus.SHIPPED_TO_LOGST,OrderStatus.PAYMENT_FLAGGED_DENIED,OrderStatus.CANCEL_REQUEST_RECEIVED,OrderStatus.CANCEL_REQUEST_CONFIRMED,OrderStatus.CANCELLED_ON_CUSTOMER_REQUEST,OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY,OrderStatus.SALES_RETURN_IN_TRANSIT,OrderStatus.SALES_RET_RECEIVED,OrderStatus.DOA_PICKUP_REQUESTED,OrderStatus.DOA_RETURN_AUTHORIZED,OrderStatus.DOA_RETURN_IN_TRANSIT,OrderStatus.DOA_RECEIVED,OrderStatus.DOA_CERT_INVALID,OrderStatus.DOA_CERT_VALID});private FormattingUtils formattingUtils = new FormattingUtils();Map<Long, String> providerNames = new HashMap<Long, String>();List<Order> orders = null;List<String> orderDate = new ArrayList<String>();public MyaccountController() {super();}public String index(){logger.info("this.request=" + this.request);try {TransactionClient transactionServiceClient = new TransactionClient();in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), statuses);//Reverse the list of order. Last come first displayedCollections.reverse(orders);LogisticsClient logisticsServiceClient = new LogisticsClient();in.shop2020.logistics.LogisticsService.Client logisticsClient = logisticsServiceClient.getClient();List<Provider> providers = logisticsClient.getAllProviders();for(Provider provider: providers)providerNames.put(provider.getId(), provider.getName());} catch (Exception e) {logger.error("Error while getting the orders for the user", e);}SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa");if(orders != null && !orders.isEmpty()){for(Order order: orders) {Date orderedOn = new Date(order.getCreated_timestamp());orderDate.add(dateformat.format(orderedOn));}}return "index";}public String formatPrice(double price) {return formattingUtils.formatPrice(price);}public Map<Long, String> getProviderNames() {return providerNames;}public List<Order> getOrders() {return orders;}public List<String> getOrderDate() {return orderDate;}}