Rev 1297 | Rev 1481 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package in.shop2020.serving.controllers;import java.io.IOException;import java.text.ParseException;import java.util.ArrayList;import java.util.Date;import java.util.List;import java.util.StringTokenizer;import in.shop2020.model.v1.order.LineItem;import in.shop2020.model.v1.order.Order;import in.shop2020.model.v1.user.UserContextException;import in.shop2020.model.v1.user.UserContextService;import in.shop2020.serving.controllers.BaseController;import in.shop2020.thrift.clients.HelperServiceClient;import in.shop2020.thrift.clients.TransactionServiceClient;import in.shop2020.thrift.clients.UserContextServiceClient;import in.shop2020.serving.utils.UserMessage;import org.apache.log4j.Logger;import org.apache.struts2.rest.DefaultHttpHeaders;import org.apache.struts2.rest.HttpHeaders;import org.apache.velocity.VelocityContext;/*** @author Varun Gupta*/public class ContactUsController extends BaseController{private String id;private static final long serialVersionUID = 1L;private static Logger log = Logger.getLogger(Class.class);List<Order> orders = null;List<LineItem> products = null;public ContactUsController(){super();}// GET /Show Formpublic String index() {try {TransactionServiceClient transactionServiceClient = new TransactionServiceClient();in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();orders = orderClient.getOrdersForCustomer(userinfo.getUserId(), 0, (new Date()).getTime(), null);} catch(Exception e) {e.printStackTrace();}return "index";}public String show() throws SecurityException, IOException {try {TransactionServiceClient transactionServiceClient = new TransactionServiceClient();in.shop2020.model.v1.order.TransactionService.Client orderClient = transactionServiceClient.getClient();long orderId = Integer.parseInt(id);products = orderClient.getLineItemsForOrder(orderId);}catch (Exception e) {e.printStackTrace();}return "ajax";}// POST /Save Communicationpublic String create() {long communicationType = -1;long orderId = -1;try {boolean u = userinfo.isLoggedIn();long userId = u ? userinfo.getUserId() : 0;String email = request.getParameter("email");communicationType = Integer.parseInt(request.getParameter("communication_type"));orderId = Integer.parseInt(request.getParameter("order_id"));String awb = request.getParameter("awb");String product = request.getParameter("product");String subject = request.getParameter("subject");String message = request.getParameter("message");UserContextService.Client userClient = (new UserContextServiceClient()).getClient();if(userClient.saveUserCommunication(userId, email, communicationType, orderId, awb, product, subject, message)) {System.out.println("User Communication saved successfully!");}} catch(NumberFormatException e) {e.printStackTrace();} catch (UserContextException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} finally {}/* Mail mail = new Mail();List<String> mailTo = new ArrayList<String>();this.userMailId = request.getParameter("mailFrom");String mailSubject = request.getParameter("mailSubject");String mailBody = request.getParameter("mailBody");mailTo.add(customerCareMailId);mail.setSubject(mailSubject);mail.setSender(userMailId);mail.setTo(mailTo);mail.setData(mailBody);HelperServiceClient helperServiceClient;try {helperServiceClient = new HelperServiceClient();helperServiceClient.getClient().sendMail(mail);} catch (Exception e) {log.error("Helper service not working properly. Error while sending mail to user.");e.printStackTrace();}*/return "success";}/**** @param id*/public void setId(String id) {this.id = id;}public String getSuccessMsg() {return UserMessage.USER_COMMUNICATION_SUCCESS;}public String getOrderIdSelector() {String html = "";if (orders == null || orders.size() == 0) {html += "<option value='-1'>No Orders Found</option>";} else {html += "<option value='-1'>Select Order ID</option>";for(Order order: orders) {html += "<option value='" + order.getId() + "'>" + order.getId() + "</option>";}}return html;}public String getProductsForOrder() {String html = "";if(products == null || products.size() == 0) {html += "<option value='-1'>No Products Found</option>";} else {for (LineItem product: products) {html += "<option value='" + product.getId() + "'>";if(product.getBrand() != null) html += product.getBrand() + " ";if(product.getModel_name() != null) html += product.getModel_name() + " ";if(product.getModel_number() != null) html += product.getModel_number();html += "</option>";}}return html;}}