Rev 4837 | 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.model.v1.order.OrderStatusGroups;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 FormattingUtils formattingUtils = new FormattingUtils();Map<Long, String> providerNames = new HashMap<Long, String>();List<Order> orders = null;List<String> orderDate = new ArrayList<String>();private static final OrderStatusGroups statusGroup = new OrderStatusGroups();private static final List<OrderStatus> openOrderStatuses = statusGroup.getOpenOrders();private static final List<OrderStatus> shippedOrderStatuses = statusGroup.getShippedOrders();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(), openOrderStatuses);//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;}public boolean showAwbforOrder(OrderStatus status) {if(shippedOrderStatuses.contains(status)){return true;}return false;}}