Rev 20091 | Rev 20172 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/****/package in.shop2020.serving.controllers;import in.shop2020.crm.Activity;import in.shop2020.crm.ActivityType;import in.shop2020.crm.Agent;import in.shop2020.crm.SearchFilter;import in.shop2020.crm.Ticket;import in.shop2020.crm.TicketCategory;import in.shop2020.crm.TicketPriority;import in.shop2020.crm.TicketStatus;import in.shop2020.model.v1.order.Attribute;import in.shop2020.model.v1.order.LineItem;import in.shop2020.model.v1.order.Order;import in.shop2020.model.v1.order.OrderStatus;import in.shop2020.model.v1.order.Transaction;import in.shop2020.model.v1.order.TransactionServiceException;import in.shop2020.model.v1.order.TransactionStatus;import in.shop2020.model.v1.user.User;import in.shop2020.model.v1.user.UserContextException;import in.shop2020.payments.Payment;import in.shop2020.payments.PaymentException;import in.shop2020.payments.PaymentStatus;import in.shop2020.serving.auth.CRMAuthorizingRealm;import in.shop2020.thrift.clients.CRMClient;import in.shop2020.thrift.clients.HelperClient;import in.shop2020.thrift.clients.PaymentClient;import in.shop2020.thrift.clients.TransactionClient;import in.shop2020.thrift.clients.UserClient;import in.shop2020.util.CRMConstants;import in.shop2020.util.CRMConstants.Actionable;import in.shop2020.util.CRMConstants.EscalationMatrix;import in.shop2020.util.CRMConstants.PMEscalationMatrix;import in.shop2020.util.SendGrid;import in.shop2020.util.SendGridException;import in.shop2020.utils.GmailUtils;import in.shop2020.utils.HelperService.Client;import in.shop2020.utils.HelperServiceException;import in.shop2020.utils.ModelUtils;import java.io.File;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.Arrays;import java.util.Calendar;import java.util.Collections;import java.util.Date;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.mail.MessagingException;import net.htmlparser.jericho.Source;import org.apache.shiro.SecurityUtils;import org.apache.thrift.TException;import org.apache.thrift.transport.TTransportException;/*** @author mandeep**/public class TicketsController extends BaseController {/****/private static final long serialVersionUID = 1L;List<Ticket> tickets = new ArrayList<Ticket>();private String customerEmailId;private String description;private String assigneeEmailId;private String priority;private String category;private String orderId;private String[] agentIds;private String startTimestamp;private String endTimestamp;private String userId;private String id;private String activityDescription;private String status;private String activityType;private Ticket ticket;private List<Activity> activities;private String subject;private String body;private String customerName;private String customerMobileNumber;private User user;private String orderStatus;private List<Order> orders;private Map<Long, Order> transactions;private Map<Long, Long> transactionShipping;private Map<Long, Long> transactionTotal;private List<Payment> payments;private String escalate;private String cancelReason;private String transactionId;private String pickupExtension;private Map<String, Long> ticketCategorycountMap;private String premises = "";private String closureType = "";private String paymentId;private String quantity;private String disposition;private List<String> actionable;private HashMap<String, String> allAttachmentsForTicket;public String index() {try {if (id != null && !id.isEmpty()) {SearchFilter searchFilter = new SearchFilter();crmServiceClient = new CRMClient().getClient();searchFilter.setTicketId(Long.parseLong(id));tickets = crmServiceClient.getTickets(searchFilter);}} catch (TException e) {log.error("Error while getting tickets", e);return EXCEPTION;}return INDEX;}public String edit() {try {long ticketId = Long.parseLong(id);SearchFilter searchFilter = new SearchFilter();searchFilter.setTicketId(ticketId);crmServiceClient = new CRMClient().getClient();ticket = crmServiceClient.getTickets(searchFilter).get(0);activities = crmServiceClient.getActivities(searchFilter);populateAttachments();subject = createSubjectString(ticket);if (ticket.isSetCustomerId()) {userId = String.valueOf(ticket.getCustomerId());userContextServiceClient = new UserClient().getClient();try {user = userContextServiceClient.getUserById(ticket.getCustomerId());} catch (UserContextException e) {log.error("Could not fetch user details", e);}}customerEmailId = ticket.getCustomerEmailId();setSuitableActionable(ticket.getCategory());//log.info("actionable list "+ getActionable());if (TicketCategory.ORDER_CANCELLATION.equals(ticket.getCategory())) {log.info("Fetching orders for " + ticket.getCustomerId());orders = new ArrayList<Order>();transactionServiceClient = new TransactionClient().getClient();for (Order order : transactionServiceClient.getOrdersForCustomer(ticket.getCustomerId(), 0, 0,Collections.singletonList(OrderStatus.CANCEL_REQUEST_RECEIVED))) {log.info("Processing Order: " + order.getId());orders.add(order);}}if (TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())) {log.info("Fetching orders for " + ticket.getCustomerId());orders = new ArrayList<Order>();transactions = new HashMap<Long, Order>();transactionShipping = new HashMap<Long, Long>();transactionTotal = new HashMap<Long, Long>();transactionServiceClient = new TransactionClient().getClient();for (Order order : transactionServiceClient.getOrdersForCustomer(ticket.getCustomerId(), 0, 0,Collections.singletonList(OrderStatus.COD_VERIFICATION_PENDING))) {log.info("Processing Order: " + order);if (order.isCod()) {transactions.put(order.getTransactionId(), order);if (!transactionShipping.containsKey(order.getTransactionId())){transactionShipping.put(order.getTransactionId(), (long)order.getShippingCost());} else {transactionShipping.put(order.getTransactionId(), transactionShipping.get(order.getTransactionId()).longValue() + (long)order.getShippingCost());}if (!transactionTotal.containsKey(order.getTransactionId())){transactionTotal.put(order.getTransactionId(), (long)order.getTotal_amount()-(long)order.getGvAmount());} else {transactionTotal.put(order.getTransactionId(), transactionTotal.get(order.getTransactionId()).longValue() + (long)order.getTotal_amount()-(long)order.getGvAmount());}orders.add(order);}}}if (TicketCategory.DOA_RECEIVED.equals(ticket.getCategory())) {log.info("Fetching orders for " + ticket.getCustomerId());orders = new ArrayList<Order>();transactionServiceClient = new TransactionClient().getClient();for (Order order : transactionServiceClient.getOrdersForCustomer(ticket.getCustomerId(), 0, 0,Collections.singletonList(OrderStatus.DOA_REQUEST_RECEIVED))) {log.info("Processing Order: " + order);if (order != null) {orders.add(order);}}}if (TicketCategory.RETURN_FORM.equals(ticket.getCategory())) {log.info("Fetching orders for " + ticket.getCustomerId());orders = new ArrayList<Order>();transactionServiceClient = new TransactionClient().getClient();for (Order order : transactionServiceClient.getOrdersForCustomer(ticket.getCustomerId(), 0, 0,Collections.singletonList(OrderStatus.RET_REQUEST_RECEIVED))) {log.info("Processing Order: " + order);if (order != null) {orders.add(order);}}}if (TicketCategory.PAYMENT_FLAGGED.equals(ticket.getCategory())) {log.info("Fetching orders for " + ticket.getCustomerId());payments = new ArrayList<Payment>();in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();transactionServiceClient = new TransactionClient().getClient();for (Transaction transaction : transactionServiceClient.getTransactionsForCustomer(ticket.getCustomerId(), 0, 0, TransactionStatus.FLAGGED)) {log.info("Processing Transaction: " + transaction);for ( Payment payment : paymentClient.getPaymentForTxnId(transaction.getId())) {if( payment.getStatus().equals(PaymentStatus.AUTHORIZED)) {payments.add(payment);}}}}if (TicketCategory.FAILED_PAYMENTS.equals(ticket.getCategory())) {log.info("Fetching orders for " + ticket.getCustomerId());orders = new ArrayList<Order>();in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();long failedTransactionId = -1;long lastfailedTransactionTimestamp = -1;for (Payment payment : paymentClient.getPaymentsForUser(ticket.getCustomerId(), 0, getTomorrow().getTime(), PaymentStatus.FAILED, 0)) {if (payment.getErrorTimestamp() > lastfailedTransactionTimestamp) {failedTransactionId = payment.getMerchantTxnId();}}transactionServiceClient = new TransactionClient().getClient();orders.addAll(transactionServiceClient.getOrdersForTransaction(failedTransactionId, ticket.getCustomerId()));}if (TicketCategory.DELAYED_DELIVERY.equals(ticket.getCategory())) {log.info("Fetching orders for " + ticket.getCustomerId());orders = new ArrayList<Order>();transactionServiceClient = new TransactionClient().getClient();for (Order order : transactionServiceClient.getOrdersForCustomer(ticket.getCustomerId(), 0, 0, null)) {if (order.getExpected_delivery_time() > order.getPromised_delivery_time() && order.getExpected_delivery_time() > new Date().getTime()) {orders.add(order);}}}if (TicketCategory.STORE_PICKUP.equals(ticket.getCategory())) {log.info("Fetching orders for " + ticket.getCustomerId());orders = new ArrayList<Order>();transactionServiceClient = new TransactionClient().getClient();for (Order order : transactionServiceClient.getOrdersForCustomer(ticket.getCustomerId(), 0, 0,Collections.singletonList(OrderStatus.RECEIVED_AT_STORE))) {log.info("Processing Order: " + order.getId());orders.add(order);}}} catch (TException e) {log.error("Error loading edit page", e);} catch (NumberFormatException e) {log.error("Error parsing orderId", e);} catch (TransactionServiceException e) {log.error("Error fetching orders for " + ticket.getCustomerId(), e);} catch (PaymentException e) {log.error("Error fetching payments for " + ticket.getCustomerId(), e);}return EDIT;}private void populateAttachments() {allAttachmentsForTicket = new HashMap<String, String>();for (Activity activity : activities) {log.info("" + activity.getId());String attachment = activity.getAttachments();if (attachment != null && !attachment.isEmpty()) {log.info("" + attachment);String [] attachmentList = attachment.split(";");for (String attachmentName : attachmentList) {if (attachmentName != null && !attachmentName.isEmpty()) {log.info("" + attachmentName);allAttachmentsForTicket.put(activity.getId() + "-" + attachmentName, attachmentName);}}}}}public static void main(String[] args) throws TException {SearchFilter s = new SearchFilter();// s.setTicketId(200l);// s.setTicketAssigneeIds(null);// s.setTicketAssigneeIds(new ArrayList<Long>());// s.setActivityCreatorIds(Collections.singletonList(2l));// s.setEndTimestamp(new Date());//s.setTicketCategory(TicketCategory.STORE_PICKUP);s.setTicketId((long) 51345);in.shop2020.crm.CRMService.Client crmServiceClient = new CRMClient().getClient();Ticket ticket = crmServiceClient.getTickets(s).get(0);System.out.println(ticket.getCategory().name());}private String createSubjectString(Ticket ticket) {if(!profitMandiTicketCategoryList.contains(ticket.getCategory())){return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId()+ " " + ticket.getCategory().name();}else{return CRMConstants.PROFIT_MANDI_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId()+ " " + ticket.getCategory().name();}}private Date getTomorrow() {Calendar calendar = Calendar.getInstance();calendar.setTime(new Date());calendar.add(Calendar.DAY_OF_MONTH, 1);return calendar.getTime();}public String create() {try {long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();Ticket ticket = new Ticket();ticket.setDescription(description);ticket.setCreatorId(creatorId);ticket.setStatus(TicketStatus.OPEN);ticket.setPriority(TicketPriority.valueOf(priority));ticket.setCategory(TicketCategory.valueOf(category));Activity activity = new Activity();activity.setDescription("Creating Ticket");activity.setType(ActivityType.OTHER);activity.setTicketPriority(TicketPriority.valueOf(priority));activity.setTicketStatus(TicketStatus.OPEN);activity.setCreatorId(creatorId);activity.setTicketCategory(TicketCategory.valueOf(category));activity.setTicketDescription(description);if (orderId != null && !orderId.isEmpty()) {ticket.setOrderId(Long.parseLong(orderId));}if (TicketCategory.valueOf(category) == TicketCategory.DOA_RECEIVED) {transactionServiceClient = new TransactionClient().getClient();if (!transactionServiceClient.markOrderDoaRequestReceived(Long.parseLong(orderId))) {throw new Exception("Order cannot be marked as DOA Received");}log.info("" + userId);try{Order order = transactionServiceClient.getOrder(Long.parseLong(orderId));log.info("In order table id is : " + order.getCustomer_id());if (userId == null || userId.isEmpty() || order.getCustomer_id() != Long.parseLong(userId)) {throw new Exception("This order is not associated with this user Id");}}catch(Exception e){throw new Exception("No Order Found for given order id");}}if (TicketCategory.valueOf(category) == TicketCategory.RETURN_FORM) {transactionServiceClient = new TransactionClient().getClient();if (!transactionServiceClient.markOrderReturnRequestReceived(Long.parseLong(orderId))) {throw new Exception("Order cannot be marked as Return Requested");}log.info("" + userId);try{Order order = transactionServiceClient.getOrder(Long.parseLong(orderId));log.info("In order table id is : " + order.getCustomer_id());if (userId == null || userId.isEmpty() || order.getCustomer_id() != Long.parseLong(userId)) {throw new Exception("This order is not associated with this user Id");}}catch(Exception e){throw new Exception("No Order Found for given order id");}}if(body!=null && !body.isEmpty()){String plainTextbody = new Source(body).getTextExtractor().toString();ticket.setDescription(description + " : " + plainTextbody);}if (userId != null && !userId.isEmpty()) {ticket.setCustomerId(Long.parseLong(userId));activity.setCustomerId(Long.parseLong(userId));} else {User user = null;userContextServiceClient = new UserClient().getClient();try {if (customerName != null && !customerName.isEmpty()) {ticket.setCustomerName(customerName);activity.setCustomerName(customerName);}if (customerEmailId != null && !customerEmailId.isEmpty()) {ticket.setCustomerEmailId(customerEmailId);activity.setCustomerEmailId(customerEmailId);user = userContextServiceClient.getUserByEmail(customerEmailId);}if ((user == null || user.getUserId() == -1)&& customerMobileNumber != null&& !customerMobileNumber.isEmpty()) {ticket.setCustomerMobileNumber(customerMobileNumber);activity.setCustomerMobileNumber(customerMobileNumber);user = userContextServiceClient.getUserByMobileNumber(Long.parseLong(customerMobileNumber));}} catch (UserContextException e) {log.error("Could not fetch user for: " + customerEmailId+ " " + customerMobileNumber + " " + customerName,e);}if (user != null && user.getUserId() != -1) {ticket.setCustomerId(user.getUserId());activity.setCustomerId(user.getUserId());}}// handling null values appropriatelyif (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {long assigneeId = CRMAuthorizingRealm.getAgent(assigneeEmailId).getId();ticket.setAssigneeId(assigneeId);activity.setTicketAssigneeId(assigneeId);}crmServiceClient = new CRMClient().getClient();id = String.valueOf(crmServiceClient.insertTicket(ticket, activity));} catch (TException e) {log.error("Error while creating ticket", e);return EXCEPTION;} catch (NumberFormatException e) {log.error("Error while parsing Order Id", e);return EXCEPTION;} catch (TransactionServiceException e) {log.error("Error while updating order status", e);return EXCEPTION;} catch (Exception e) {log.error(e.getMessage());return EXCEPTION;}return index();}public boolean isAssigneeEditable() {return (SecurityUtils.getSubject().hasRole("TeamLead") || SecurityUtils.getSubject().hasRole("Outbound"));}public String searchTickets() throws ParseException {try {SearchFilter searchFilter = new SearchFilter();if (userId != null && !userId.isEmpty()) {searchFilter.setCustomerId(Long.parseLong(userId));}if (agentIds != null && agentIds.length != 0) {searchFilter.setTicketAssigneeIds(new ArrayList<Long>());for (String agentId : agentIds) {searchFilter.getTicketAssigneeIds().add(CRMAuthorizingRealm.getAgent(agentId).getId());}}//Start:- Added By Manish Sharma for Searching Tickets/Activities using Mobile No. on 21-Jun-2013if(customerMobileNumber!=null && !customerMobileNumber.isEmpty()){searchFilter.setCustomerMobileNumber(customerMobileNumber);}//End:- Added By Manish Sharma for Searching Tickets/Activities using Mobile No. on 21-Jun-2013if (startTimestamp != null && !startTimestamp.isEmpty()) {searchFilter.setStartTimestamp(SDF.parse(startTimestamp).getTime());}if (endTimestamp != null && !endTimestamp.isEmpty()) {searchFilter.setEndTimestamp(SDF.parse(endTimestamp).getTime());}if (id != null && !id.isEmpty()) {searchFilter.setTicketId(Long.parseLong(id));}if (status != null && !status.isEmpty()) {searchFilter.setTicketStatuses(new ArrayList<TicketStatus>());searchFilter.getTicketStatuses().add(TicketStatus.valueOf(status));if (TicketStatus.OPEN.name().equals(status)) {searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);}}if (category != null && !category.isEmpty()) {searchFilter.setTicketCategory(TicketCategory.valueOf(category));}crmServiceClient = new CRMClient().getClient();tickets = crmServiceClient.getTickets(searchFilter);} catch (TException e) {String errorString = "Error getting tickets for "+ currentAgentEmailId;log.error(errorString, e);addActionError(errorString);}return index();}public String getUnassignedTickets() {try {tickets = new ArrayList<Ticket>();crmServiceClient = new CRMClient().getClient();List<Ticket> unassignedTickets = crmServiceClient.getUnassignedTickets();for(Ticket unassignedTicket: unassignedTickets){if(isSaholicAndProfitMandiAllowed()){tickets.add(unassignedTicket);}else if(isProfitMandiAgent()){if(profitMandiTicketCategoryList.contains(unassignedTicket.getCategory())){tickets.add(unassignedTicket);}}else{if(!profitMandiTicketCategoryList.contains(unassignedTicket.getCategory())){tickets.add(unassignedTicket);}}}} catch (TException e) {String errorString = "Error getting tickets for "+ currentAgentEmailId;log.error(errorString, e);addActionError(errorString);}return index();}public String update() {String commonDescription ="";String addTo[]= new String[]{"amit.sirohi@shop2020.in","rajneesh.arora@saholic.com"};try {long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();SearchFilter searchFilter = new SearchFilter();searchFilter.setTicketId(Long.parseLong(id));crmServiceClient = new CRMClient().getClient();Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);ticket.setDescription(description);ticket.setPriority(TicketPriority.valueOf(priority));// Update when a ticket is closed!if (TicketStatus.CLOSED.name().equals(status) || TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())) {if (TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())&& pendingCODOrders(ticket.getCustomerId())) {addActionMessage("Cod orders pending for verification. Ticket can not be closed and its category cannot be changed.");} else {ticket.setCategory(TicketCategory.valueOf(category));ticket.setStatus(TicketStatus.valueOf(status));ticket.setCloseDate(new Date().getTime());}}else {ticket.setCategory(TicketCategory.valueOf(category));ticket.setStatus(TicketStatus.valueOf(status));}if (activityDescription == null || activityDescription.isEmpty()) {activityDescription = "Ticket fields updated";}Activity activity = new Activity();activity.setDescription(activityDescription);if(getDisposition()!=null&&!Actionable.NO_ACTION.toString().equals(getDisposition())){activity.setDescription(getDisposition()+" -> "+activityDescription);}activity.setType(ActivityType.valueOf(activityType));activity.setTicketPriority(ticket.getPriority());activity.setTicketStatus(ticket.getStatus());activity.setCreatorId(creatorId);activity.setTicketCategory(ticket.getCategory());activity.setTicketDescription(ticket.getDescription());if (userId != null && !userId.isEmpty()) {activity.setCustomerId(Long.parseLong(userId));}// Handling null values appropriatelyif (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {long assigneeId = CRMAuthorizingRealm.getAgent(assigneeEmailId).getId();ticket.setAssigneeId(assigneeId);activity.setTicketAssigneeId(assigneeId);}if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {log.info("Sending mail");Client helperClient = new HelperClient().getClient();if(!profitMandiTicketCategoryList.contains(ticket.getCategory())){activity.setUserEmailId(helperClient.saveUserEmailForSending(Arrays.asList(customerEmailId), CRMConstants.CRM_EMAIL_SENDOR,subject, body, null, CRMConstants.CRM_EMAIL_TYPE, null, null, 1));}else{try{sendMailToUser();} catch(Exception e){log.info("Error while sending mail to user:- "+customerEmailId+" ticket Id:- "+ticket.getId());log.error("Error while sending mail to user:- "+customerEmailId+" ticket Id:- "+ticket.getId(), e);}/*activity.setUserEmailId(helperClient.saveUserEmailForSending(Arrays.asList(customerEmailId), CRMConstants.PROFIT_MANDI_EMAIL_SENDER,subject, body, null, CRMConstants.PROFIT_MANDI_EMAIL_TYPE, null, null, 1));*/}String plainTextbody = new Source(body).getTextExtractor().toString();// We change activityType to OTHER when pop up box for email// closesactivity.setDescription("Subject: " + subject + "\n\n"+ "Body: " + plainTextbody);String activityDesc = activity.getDescription();if (activityDesc.length() > CRMConstants.DESCRIPTION_MAX_WIDTH) {activityDesc = activityDesc.substring(0, CRMConstants.DESCRIPTION_MAX_WIDTH);activityDesc += "\n\nTHIS TEXT IS TRUNCATED. PLEASE VISIT INBOX TO SEE COMPLETE DETAILS.";}activity.setDescription(activityDesc);}if (ActivityType.ESCALATE_TICKET.equals(activity.getType())) {log.info("Sending escalation mail");if(escalate.startsWith("PM")){PMEscalationMatrix escalation = CRMConstants.PMEscalationMatrix.valueOf(escalate);List<Integer> escalationReceipients = escalation.getAgentIds();List<String> toMailIds = new ArrayList<String>();for (Integer agentId : escalationReceipients) {toMailIds.add(CRMAuthorizingRealm.getAgent(agentId).getEmailId());// Setting last agent as assigneeticket.setAssigneeId(agentId);activity.setTicketAssigneeId(agentId);}Client helperClient = new HelperClient().getClient();String escalationMailSubject = createPMEscalationMailSubject(ticket, escalation);String escalationMailBody = createEscalationMailBody(ticket);if(profitMandiTicketCategoryList.contains(ticket.getCategory())){activity.setUserEmailId(helperClient.saveUserEmailForSending(toMailIds, CRMConstants.PROFIT_MANDI_EMAIL_SENDER,escalationMailSubject, escalationMailBody,null, CRMConstants.PROFIT_MANDI_EMAIL_TYPE, null, null, 1));}else{activity.setUserEmailId(helperClient.saveUserEmailForSending(Arrays.asList(customerEmailId), CRMConstants.CRM_EMAIL_SENDOR,subject, body, null, CRMConstants.CRM_EMAIL_TYPE, null, null, 1));}// We change activityType to OTHER when pop up box for email// closesactivity.setDescription("To: " + toMailIds + "\n\nSubject: " + escalationMailSubject + "\n\n"+ "Body: " + escalationMailBody);}else{EscalationMatrix escalation = CRMConstants.EscalationMatrix.valueOf(escalate);List<Integer> escalationReceipients = escalation.getAgentIds();List<String> toMailIds = new ArrayList<String>();for (Integer agentId : escalationReceipients) {toMailIds.add(CRMAuthorizingRealm.getAgent(agentId).getEmailId());// Setting last agent as assigneeticket.setAssigneeId(agentId);activity.setTicketAssigneeId(agentId);}Client helperClient = new HelperClient().getClient();String escalationMailSubject = createEscalationMailSubject(ticket, escalation);String escalationMailBody = createEscalationMailBody(ticket);activity.setUserEmailId(helperClient.saveUserEmailForSending(toMailIds, CRMConstants.CRM_EMAIL_SENDOR,escalationMailSubject, escalationMailBody,null, CRMConstants.CRM_EMAIL_TYPE, null, null, 1));// We change activityType to OTHER when pop up box for email// closesactivity.setDescription("To: " + toMailIds + "\n\nSubject: " + escalationMailSubject + "\n\n"+ "Body: " + escalationMailBody);}}if(isProfitMandiAgent()){try{if (ActivityType.RECEIVED_CALL_FROM_CUSTOMER.equals(activity.getType())) {commonDescription = "Received Call From Customer || Email Id- ";if (customerEmailId != null && !customerEmailId.isEmpty()) {commonDescription = commonDescription+customerEmailId;}if(customerMobileNumber != null&& !customerMobileNumber.isEmpty()) {commonDescription = commonDescription+" & Mobile No:- "+customerMobileNumber;}commonDescription = "PM Ticket: "+ commonDescription;sendMailtoManagersUsingGmailUtils(commonDescription, addTo, description);}}catch(Exception e){e.printStackTrace();try{sendMailToManagers(commonDescription, addTo, description);}catch(Exception e1){e1.printStackTrace();}}}User user = null;userContextServiceClient = new UserClient().getClient();try {if (customerName != null && !customerName.isEmpty()) {ticket.setCustomerName(customerName);activity.setCustomerName(customerName);}if (customerEmailId != null && !customerEmailId.isEmpty()) {ticket.setCustomerEmailId(customerEmailId);activity.setCustomerEmailId(customerEmailId);user = userContextServiceClient.getUserByEmail(customerEmailId);}if ((user == null || user.getUserId() == -1)&& customerMobileNumber != null&& !customerMobileNumber.isEmpty()) {ticket.setCustomerMobileNumber(customerMobileNumber);activity.setCustomerMobileNumber(customerMobileNumber);user = userContextServiceClient.getUserByMobileNumber(Long.parseLong(customerMobileNumber));}} catch (UserContextException e) {log.error("Could not fetch user for: " + customerEmailId + " "+ customerMobileNumber + " " + customerName, e);}if (user != null && user.getUserId() != -1) {ticket.setCustomerId(user.getUserId());activity.setCustomerId(user.getUserId());}crmServiceClient = new CRMClient().getClient();crmServiceClient.updateTicket(ticket, activity);if(getDisposition()!=null&&!Actionable.NO_ACTION.toString().equals(getDisposition())){if(Actionable.EMAIL_PROVIDER_REATTEMPT_DELIVERY.toString().equals(getDisposition())){TransactionClient transactionServiceClient = new TransactionClient();Order order = transactionServiceClient.getClient().getOrder(ticket.getOrderId());CRMConstants.LogisticProvider lgp = CRMConstants.LogisticProvider.findByValue(order.getLogistics_provider_id());List<String> emailDetails = CRMConstants.LOGISTIC_PROVIDER_MAP.get(lgp);if(emailDetails!=null){String to[] = emailDetails.get(0).split(",");String cc[] = emailDetails.get(1).split(",");String awb = order.getAirwaybill_no();String subject = "Arrange the delivery on priority - "+awb;String masterOrderId = order.getLogisticsTransactionId();String emailBody = "Hi,\n\nPlease find the below shipment details as customer is ready "+ "to take delivery. So please arrange the delivery on priority.\n\nOrder "+ "details: Master Order Id:- "+masterOrderId+"\n\nAirway Bill No : "+awb+"\nLogitics Provider : "+lgp.toString()+"\n\nRegards,\nShailesh Kumar\nHotspot Sales "+ "& Solution Pvt Ltd.\nContact-: +91-8826003137, 0120-3859501";//send maillog.info("Sending delivery attempt mail to logistic provider :- "+to[0]);GmailUtils mailer = new GmailUtils();mailer.sendSSLMessage(to,cc, subject, emailBody, CRMConstants.ADWORDS_EMAIL,CRMConstants.ADWORDS_PASSWORD, new ArrayList<File>());log.info("Mail sent to logistic provider:- "+to[0]+" "+cc[0]);}}}} catch (TException e) {log.error("Error while updating ticket", e);return EXCEPTION;} catch (HelperServiceException hse) {log.error("Error while sending mail", hse);return EXCEPTION;} catch (TransactionServiceException e) {log.error("Error while fetching order details", e);return EXCEPTION;} catch (MessagingException e) {// TODO Auto-generated catch blocke.printStackTrace();}return INDEX;}private String createEscalationMailBody(Ticket ticket){return body + "<br />Please visit following URL to check ticket details.<br />" +"http://cs.shop2020.in:8080/crm?ticketId=" + ticket.getId();}private String createEscalationMailSubject(Ticket ticket,EscalationMatrix escalation){return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId() + " - ESCALATION FROM CRM - Type: " + escalation.name();}private String createPMEscalationMailSubject(Ticket ticket,PMEscalationMatrix escalation){return CRMConstants.PROFIT_MANDI_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId() + " - ESCALATION FROM CRM - Type: " + escalation.name();}private boolean pendingCODOrders(long customerId) {try {log.info("Trying to fetch orders for " + customerId);transactionServiceClient = new TransactionClient().getClient();for (Order order : transactionServiceClient.getOrdersForCustomer(customerId, 0, 0,Collections.singletonList(OrderStatus.COD_VERIFICATION_PENDING))) {log.info("Processing order: " + order.getId() + " with COD: " + order.isCod());if (order.isCod()) {log.info("Returning true from pendingCODOrders() for " + customerId);return true;}}} catch (TTransportException e) {log.error("Error while creating thrift client", e);} catch (TransactionServiceException e) {log.error("Error fetching orders", e);} catch (TException e) {log.error("Error fetching orders", e);}log.info("Returning false from pendingCODOrders() for " + customerId);return false;}public String extendExpiry() {try {log.info("order Id = " + orderId);log.info("pickup : " + pickupExtension);Attribute newAttribute = new Attribute();List<Attribute> attributes = new ArrayList<Attribute>();String extendedBy = "0";transactionServiceClient = new TransactionClient().getClient();attributes = transactionServiceClient.getAllAttributesForOrderId(Long.parseLong(orderId));for (Attribute attribute : attributes) {if (attribute.getName().equals("pickupExtension")) {extendedBy = attribute.getValue();break;}}log.info("ATTR = " + attributes);log.info("1");if (extendedBy.equals("0")) {newAttribute.setName("pickupExtension");newAttribute.setValue(pickupExtension);attributes.add(newAttribute);log.info("2");} else {Long totalExtension = Long.parseLong(extendedBy) + Long.parseLong(pickupExtension);for (Attribute attribute : attributes) {if (attribute.getName().equals("pickupExtension")) {attribute.setValue(totalExtension.toString());log.info("3");}}}transactionServiceClient = new TransactionClient().getClient();transactionServiceClient.setOrderAttributes(Long.parseLong(orderId), attributes);SearchFilter searchFilter = new SearchFilter();searchFilter.setTicketId(Long.parseLong(id));crmServiceClient = new CRMClient().getClient();Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);// Inserting activityActivity activity = new Activity();activity.setDescription("Pickup extended by " + pickupExtension+ " Days.");activity.setType(ActivityType.OTHER);activity.setTicketPriority(ticket.getPriority());activity.setTicketStatus(ticket.getStatus());activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());activity.setTicketCategory(ticket.getCategory());activity.setTicketDescription(ticket.getDescription());activity.setCustomerId(ticket.getCustomerId());activity.setTicketAssigneeId(ticket.getAssigneeId());crmServiceClient = new CRMClient().getClient();crmServiceClient.updateTicket(ticket, activity);//transactionServiceClient = new TransactionClient().getClient();//transactionServiceClient.enqueueExpiryExtensionEmail(orderId);} catch (NumberFormatException e) {e.printStackTrace();} catch (TException e) {e.printStackTrace();}return edit();}public String getPickupExpiryDate(long id, long deliveryTimestamp) {try {log.info("orderID" + id);log.info("Delivery Time : " + deliveryTimestamp);Date deliveryDate = new Date(deliveryTimestamp);Calendar cal = Calendar.getInstance();cal.setTime(deliveryDate);log.info("Orig Del Date :" + cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR));cal.add(Calendar.DATE, 5);log.info("After adding 5 days" + cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR));transactionServiceClient = new TransactionClient().getClient();List<Attribute> attributes = new ArrayList<Attribute>();String extendedBy = "0";attributes = transactionServiceClient.getAllAttributesForOrderId(id);for (Attribute attribute : attributes) {if (attribute.getName().equals("pickupExtension")) {extendedBy = attribute.getValue();}}cal.add(Calendar.DATE, Integer.parseInt(extendedBy));log.info("Extended by" + extendedBy);log.info("Final : " + cal.get(Calendar.DAY_OF_MONTH) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.YEAR));SimpleDateFormat SDF = new SimpleDateFormat("dd MMM, yyyy");return SDF.format(cal.getTime());} catch (NumberFormatException e) {e.printStackTrace();} catch (TException e) {e.printStackTrace();}return "N/A";}public String updateOrderStatus() {long creatorId;OrderStatus orderStatusEnum = null;try {creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();if(orderStatus.equals("DENY_CANCEL_REQUEST")) {transactionServiceClient = new TransactionClient().getClient();transactionServiceClient.markOrderCancellationRequestDenied(Long.parseLong(orderId));}else {orderStatusEnum = OrderStatus.valueOf(orderStatus);transactionServiceClient = new TransactionClient().getClient();if (OrderStatus.SUBMITTED_FOR_PROCESSING.equals(orderStatusEnum)) {transactionServiceClient.verifyOrder(Long.parseLong(orderId));transactionServiceClient.updateCODAgent(currentAgentEmailId, Long.parseLong(orderId));}else if (OrderStatus.COD_VERIFICATION_FAILED.equals(orderStatusEnum)) {transactionServiceClient.refundOrder(Long.parseLong(orderId), currentAgentEmailId, cancelReason);transactionServiceClient.updateCODAgent(currentAgentEmailId, Long.parseLong(orderId));}else if (OrderStatus.CANCEL_REQUEST_CONFIRMED.equals(orderStatusEnum)) {transactionServiceClient.markOrderCancellationRequestConfirmed(Long.parseLong(orderId));}else {throw new UnsupportedOperationException("Cannot update status of orderId: " + orderId + " to: " + orderStatus);}}SearchFilter searchFilter = new SearchFilter();searchFilter.setTicketId(Long.parseLong(id));crmServiceClient = new CRMClient().getClient();Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);// Inserting activityActivity activity = new Activity();activity.setDescription("Status updated for Order Id: " + orderId+ " to " + orderStatus + ", Reason: " + cancelReason + body);activity.setType(ActivityType.OTHER);activity.setTicketPriority(ticket.getPriority());activity.setTicketStatus(ticket.getStatus());activity.setCreatorId(creatorId);activity.setTicketCategory(ticket.getCategory());activity.setTicketDescription(ticket.getDescription());activity.setCustomerId(ticket.getCustomerId());activity.setTicketAssigneeId(ticket.getAssigneeId());crmServiceClient = new CRMClient().getClient();crmServiceClient.updateTicket(ticket, activity);} catch (TException e) {log.info("Thrift exception", e);} catch (NumberFormatException e) {log.info("Could not convert to long", e);} catch (TransactionServiceException e) {log.info("Transaction client exception", e);}return edit();}public String updateTxnStatus() {long creatorId;OrderStatus orderStatusEnum = null;try {creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId();orderStatusEnum = OrderStatus.valueOf(orderStatus);transactionServiceClient = new TransactionClient().getClient();if (OrderStatus.SUBMITTED_FOR_PROCESSING.equals(orderStatusEnum)) {transactionServiceClient.verifyOrderForTransaction(Long.parseLong(transactionId));transactionServiceClient.updateCODAgent(currentAgentEmailId, Long.parseLong(orderId));}else if (OrderStatus.COD_VERIFICATION_FAILED.equals(orderStatusEnum)) {transactionServiceClient.refundTransaction(Long.parseLong(transactionId), currentAgentEmailId, cancelReason);transactionServiceClient.updateCODAgent(currentAgentEmailId, Long.parseLong(orderId));}else {throw new UnsupportedOperationException("Cannot update status of transactionId: " + transactionId + " to: " + orderStatus);}SearchFilter searchFilter = new SearchFilter();searchFilter.setTicketId(Long.parseLong(id));crmServiceClient = new CRMClient().getClient();Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);// Inserting activityActivity activity = new Activity();activity.setDescription("Status updated for Transaction Id: " + transactionId+ " to " + orderStatus + ", Reason: " + cancelReason + body);activity.setType(ActivityType.OTHER);activity.setTicketPriority(ticket.getPriority());activity.setTicketStatus(ticket.getStatus());activity.setCreatorId(creatorId);activity.setTicketCategory(ticket.getCategory());activity.setTicketDescription(ticket.getDescription());activity.setCustomerId(ticket.getCustomerId());activity.setTicketAssigneeId(ticket.getAssigneeId());crmServiceClient = new CRMClient().getClient();crmServiceClient.updateTicket(ticket, activity);} catch (TException e) {log.info("Thrift exception", e);} catch (NumberFormatException e) {log.info("Could not convert to long", e);} catch (TransactionServiceException e) {log.info("Transaction client exception", e);}return edit();}public User getUser(Long userId) {User user = null;try {userContextServiceClient = new UserClient().getClient();user = userContextServiceClient.getUserById(userId);} catch (UserContextException e) {String errorString = "Could not fetch user for " + userId;log.error(errorString, e);addActionError(errorString);} catch (TException e) {String errorString = "Could not create client";log.error(errorString, e);addActionError(errorString);}return user;}public String allowPayment() {try {log.info("Allowing payment for paymentId = " + paymentId);transactionServiceClient = new TransactionClient().getClient();transactionServiceClient.markTransactionAsPaymentFlagRemoved(Long.parseLong(transactionId));if (id != null && !id.isEmpty()) {SearchFilter searchFilter = new SearchFilter();crmServiceClient = new CRMClient().getClient();searchFilter.setTicketId(Long.parseLong(id));Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);// Inserting activityif(ticket != null) {Activity activity = new Activity();activity.setDescription("Flagged Payment allowed");activity.setType(ActivityType.OTHER);activity.setTicketPriority(ticket.getPriority());activity.setTicketStatus(ticket.getStatus());activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());activity.setTicketCategory(ticket.getCategory());activity.setTicketDescription(ticket.getDescription());activity.setCustomerId(ticket.getCustomerId());activity.setTicketAssigneeId(ticket.getAssigneeId());crmServiceClient = new CRMClient().getClient();crmServiceClient.updateTicket(ticket, activity);}}} catch (TException e) {log.error("Error while getting tickets", e);return EXCEPTION;} catch (NumberFormatException e) {log.error("Invalid ticket Id", e);return EXCEPTION;} catch (TransactionServiceException e) {log.error("Error while marking transactions as Flag removed", e);return EXCEPTION;}return edit();}public String blockPayment() {try {log.info("Blocking payment for paymentId = " + paymentId);transactionServiceClient = new TransactionClient().getClient();transactionServiceClient.refundTransaction(Long.parseLong(transactionId), currentAgentEmailId, "FLAGGED_PAYMENT_CANCELLED");if (id != null && !id.isEmpty()) {SearchFilter searchFilter = new SearchFilter();crmServiceClient = new CRMClient().getClient();searchFilter.setTicketId(Long.parseLong(id));Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);// Inserting activityif(ticket != null) {Activity activity = new Activity();activity.setDescription("Flagged Payment allowed");activity.setType(ActivityType.OTHER);activity.setTicketPriority(ticket.getPriority());activity.setTicketStatus(ticket.getStatus());activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());activity.setTicketCategory(ticket.getCategory());activity.setTicketDescription(ticket.getDescription());activity.setCustomerId(ticket.getCustomerId());activity.setTicketAssigneeId(ticket.getAssigneeId());crmServiceClient = new CRMClient().getClient();crmServiceClient.updateTicket(ticket, activity);}}} catch (TException e) {log.error("Error while getting tickets", e);return EXCEPTION;} catch (NumberFormatException e) {log.error("Invalid ticket Id", e);return EXCEPTION;} catch (TransactionServiceException e) {log.error("Error while allowing flagged payment", e);return EXCEPTION;}return edit();}public String authorizeReturn() {try {log.info("Authorizing OrderId =" + orderId);boolean isReship = false;boolean fromStore = false;transactionServiceClient = new TransactionClient().getClient();if(premises.equals("store")) {fromStore = true;}if(closureType.equals("reship")) {isReship = true;}transactionServiceClient.markOrderReturnRequestAuthorized(Long.parseLong(orderId), true, fromStore, isReship);if (id != null && !id.isEmpty()) {SearchFilter searchFilter = new SearchFilter();crmServiceClient = new CRMClient().getClient();searchFilter.setTicketId(Long.parseLong(id));Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);// Inserting activityif(ticket != null) {Activity activity = new Activity();activity.setDescription("Return Authorized");activity.setType(ActivityType.OTHER);activity.setTicketPriority(ticket.getPriority());activity.setTicketStatus(ticket.getStatus());activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());activity.setTicketCategory(ticket.getCategory());activity.setTicketDescription(ticket.getDescription());activity.setCustomerId(ticket.getCustomerId());activity.setTicketAssigneeId(ticket.getAssigneeId());crmServiceClient = new CRMClient().getClient();crmServiceClient.updateTicket(ticket, activity);}}} catch (TException e) {log.error("Error while getting tickets", e);return EXCEPTION;} catch (NumberFormatException e) {log.error("Invalid ticket Id", e);return EXCEPTION;} catch (TransactionServiceException e) {log.error("Error while authorizing Return", e);return EXCEPTION;}return edit();}public String denyReturn() {try {log.info("Denying OrderId =" + orderId);transactionServiceClient = new TransactionClient().getClient();transactionServiceClient.markOrderReturnRequestAuthorized(Long.parseLong(orderId), false, false, false);if (id != null && !id.isEmpty()) {SearchFilter searchFilter = new SearchFilter();crmServiceClient = new CRMClient().getClient();searchFilter.setTicketId(Long.parseLong(id));Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);// Inserting activityif(ticket != null) {Activity activity = new Activity();activity.setDescription("Return Denied");activity.setType(ActivityType.OTHER);activity.setTicketPriority(ticket.getPriority());activity.setTicketStatus(ticket.getStatus());activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());activity.setTicketCategory(ticket.getCategory());activity.setTicketDescription(ticket.getDescription());activity.setCustomerId(ticket.getCustomerId());activity.setTicketAssigneeId(ticket.getAssigneeId());crmServiceClient = new CRMClient().getClient();crmServiceClient.updateTicket(ticket, activity);}}} catch (TException e) {log.error("Error while getting tickets", e);return EXCEPTION;} catch (NumberFormatException e) {log.error("Invalid ticket Id", e);return EXCEPTION;} catch (TransactionServiceException e) {log.error("Error while denying Return", e);return EXCEPTION;}return edit();}public String authorizeDOA() {try {log.info("Authorizing OrderId =" + orderId);boolean isReship = false;boolean fromStore = false;transactionServiceClient = new TransactionClient().getClient();if(premises.equals("store")) {fromStore = true;}if(closureType.equals("reship")) {isReship = true;}transactionServiceClient.markOrderDoaRequestAuthorized(Long.parseLong(orderId), true, fromStore, isReship);if (id != null && !id.isEmpty()) {SearchFilter searchFilter = new SearchFilter();crmServiceClient = new CRMClient().getClient();searchFilter.setTicketId(Long.parseLong(id));Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);// Inserting activityif(ticket != null) {Activity activity = new Activity();activity.setDescription("DOA Authorized");activity.setType(ActivityType.OTHER);activity.setTicketPriority(ticket.getPriority());activity.setTicketStatus(ticket.getStatus());activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());activity.setTicketCategory(ticket.getCategory());activity.setTicketDescription(ticket.getDescription());activity.setCustomerId(ticket.getCustomerId());activity.setTicketAssigneeId(ticket.getAssigneeId());crmServiceClient = new CRMClient().getClient();crmServiceClient.updateTicket(ticket, activity);}}} catch (TException e) {log.error("Error while getting tickets", e);return EXCEPTION;} catch (NumberFormatException e) {log.error("Invalid ticket Id", e);return EXCEPTION;} catch (TransactionServiceException e) {log.error("Error while authorizing DOA", e);return EXCEPTION;}return edit();}public String denyDOA() {try {log.info("Denying OrderId =" + orderId);transactionServiceClient = new TransactionClient().getClient();transactionServiceClient.markOrderDoaRequestAuthorized(Long.parseLong(orderId), false, false, false);if (id != null && !id.isEmpty()) {SearchFilter searchFilter = new SearchFilter();crmServiceClient = new CRMClient().getClient();searchFilter.setTicketId(Long.parseLong(id));Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);// Inserting activityif(ticket != null) {Activity activity = new Activity();activity.setDescription("DOA Denied");activity.setType(ActivityType.OTHER);activity.setTicketPriority(ticket.getPriority());activity.setTicketStatus(ticket.getStatus());activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());activity.setTicketCategory(ticket.getCategory());activity.setTicketDescription(ticket.getDescription());activity.setCustomerId(ticket.getCustomerId());activity.setTicketAssigneeId(ticket.getAssigneeId());crmServiceClient = new CRMClient().getClient();crmServiceClient.updateTicket(ticket, activity);}}} catch (TException e) {log.error("Error while getting tickets", e);return EXCEPTION;} catch (NumberFormatException e) {log.error("Invalid ticket Id", e);return EXCEPTION;} catch (TransactionServiceException e) {log.error("Error while denying DOA", e);return EXCEPTION;}return edit();}public String loadProfitMandiTickets() throws ParseException {try {SearchFilter searchFilter = new SearchFilter();searchFilter.setTicketStatuses(new ArrayList<TicketStatus>());searchFilter.getTicketStatuses().add(TicketStatus.OPEN);searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);crmServiceClient = new CRMClient().getClient();tickets = new ArrayList<Ticket>();searchFilter.setTicketCategoryList(profitMandiTicketCategoryList);tickets.addAll(crmServiceClient.getTickets(searchFilter));} catch (TException e) {String errorString = "Error getting tickets for "+ currentAgentEmailId;log.error(errorString, e);addActionError(errorString);}return index();}public String getAllOpenTickets() {try {ticketCategorycountMap= new HashMap<String, Long>();crmServiceClient = new CRMClient().getClient();ticketCategorycountMap = crmServiceClient.getOpenTicketsMap();} catch (TException e) {String errorString = "Error getting tickets for "+ currentAgentEmailId;log.error(errorString, e);addActionError(errorString);}return OPEN;}public double getCustomerTrustLevel(long userId) {try {userContextServiceClient = new UserClient().getClient();return userContextServiceClient.getTrustLevel(userId);} catch (TException e) {log.info("Exception while getting trustLevel for " +"userId " + userId);}return 0;}public EscalationMatrix[] getEscalationMatrix () {return CRMConstants.EscalationMatrix.values();}public PMEscalationMatrix[] getPMEscalationMatrix () {return CRMConstants.PMEscalationMatrix.values();}public String getAddress(Order order) {return ModelUtils.extractAddressFromOrder(order);}public String getProductName(LineItem lineItem) {return ModelUtils.extractProductNameFromLineItem(lineItem) + " " + lineItem.getColor();}public ActivityType[] getActivityTypes() {return ActivityType.values();}public TicketStatus[] getTicketStatuses() {return TicketStatus.values();}public Agent getAgent(long agentId) throws TException {return CRMAuthorizingRealm.getAgent(agentId);}public List<Agent> getAllAgents() {List<Agent> allagents = CRMAuthorizingRealm.getAgents();List<Agent> requiredAgents = new ArrayList<Agent>();if(isSaholicAndProfitMandiAllowed()){return allagents;} else if(isProfitMandiAgent()){for(Agent agent: allagents){if(agent.isIs_pmCrmUser()){requiredAgents.add(agent);}}return requiredAgents;} else{for(Agent agent: allagents){if(!agent.isIs_pmCrmUser()||agent.isIs_allAssignable()){requiredAgents.add(agent);}}return requiredAgents;}}public List<TicketCategory> getTicketCategories() {List<TicketCategory> allCategories = Arrays.asList(TicketCategory.values());List<TicketCategory> requiredCategories = new ArrayList<TicketCategory>();if(isSaholicAndProfitMandiAllowed()){return allCategories;}else if(isProfitMandiAgent()){for(TicketCategory tkCategory: allCategories){if(profitMandiTicketCategoryList.contains(tkCategory)){requiredCategories.add(tkCategory);}}return requiredCategories;}else{for(TicketCategory tkCategory: allCategories){if(!profitMandiTicketCategoryList.contains(tkCategory)){requiredCategories.add(tkCategory);}}return requiredCategories;}}private void sendMailToUser() throws SendGridException{log.info("Sending mail to user:- "+customerEmailId);SendGrid sendgrid = new SendGrid("profitmandi", "pma20aug");SendGrid.Email email = new SendGrid.Email();email.setFrom(CRMConstants.PROFIT_MANDI_EMAIL_SENDER);email.setFromName("ProfitMandi");email.addTo(customerEmailId);email.addBcc("backup@saholic.com");email.setSubject(subject);email.setHtml(body);log.info("Mail Body:- "+body);sendgrid.send(email);log.info("Mail sent to user:- "+customerEmailId);}private void sendMailToManagers(String subject, String[] addTo, String body) throws SendGridException{SendGrid sendgrid = new SendGrid("profitmandi", "pma20aug");SendGrid.Email email = new SendGrid.Email();email.setFrom(CRMConstants.PROFIT_MANDI_EMAIL_SENDER);email.setFromName("ProfitMandi");email.addTo(addTo);email.addBcc("backup@saholic.com");email.setSubject(subject);email.setHtml(body);log.info("Mail Body:- "+body);sendgrid.send(email);log.info("Mail sent to user:- "+addTo);}public void sendMailtoManagersUsingGmailUtils(String subject, String[] addTo, String body) throws MessagingException{GmailUtils mailer = new GmailUtils();mailer.sendSSLMessage(addTo, subject, body, "build-staging@shop2020.in", "shop2020", new ArrayList<File>());}public TicketPriority[] getTicketPriorities() {return TicketPriority.values();}public List<Ticket> getTickets() {return tickets;}public void setTickets(List<Ticket> tickets) {this.tickets = tickets;}public String getCustomerEmailId() {return customerEmailId;}public void setCustomerEmailId(String customerEmailId) {this.customerEmailId = customerEmailId;}public String getDescription() {return description;}public void setDescription(String description) {this.description = description;}public String getAssigneeEmailId() {return assigneeEmailId;}public void setAssigneeEmailId(String assigneeEmailId) {this.assigneeEmailId = assigneeEmailId;}public String getPriority() {return priority;}public void setPriority(String priority) {this.priority = priority;}public String getCategory() {return category;}public void setCategory(String category) {this.category = category;}public String getOrderId() {return orderId;}public void setOrderId(String orderId) {this.orderId = orderId;}public String[] getAgentIds() {return agentIds;}public void setAgentIds(String[] agentIds) {this.agentIds = agentIds;}public String getStartTimestamp() {return startTimestamp;}public void setStartTimestamp(String startTimestamp) {this.startTimestamp = startTimestamp;}public String getEndTimestamp() {return endTimestamp;}public void setEndTimestamp(String endTimestamp) {this.endTimestamp = endTimestamp;}public String getUserId() {return userId;}public void setUserId(String userId) {this.userId = userId;}public String getId() {return id;}public void setId(String id) {this.id = id;}public String getActivityDescription() {return activityDescription;}public void setActivityDescription(String activityDescription) {this.activityDescription = activityDescription;}public String getStatus() {return status;}public void setStatus(String status) {this.status = status;}public String getActivityType() {return activityType;}public void setActivityType(String activityType) {this.activityType = activityType;}public Ticket getTicket() {return ticket;}public void setTicket(Ticket ticket) {this.ticket = ticket;}public List<Activity> getActivities() {return activities;}public void setActivities(List<Activity> activities) {this.activities = activities;}public String getSubject() {return subject;}public void setSubject(String subject) {this.subject = subject;}public String getBody() {return body;}public void setBody(String body) {this.body = body;}public String getCustomerName() {return customerName;}public void setCustomerName(String customerName) {this.customerName = customerName;}public String getCustomerMobileNumber() {return customerMobileNumber;}public void setCustomerMobileNumber(String customerMobileNumber) {this.customerMobileNumber = customerMobileNumber;}public User getUser() {return user;}public void setUser(User user) {this.user = user;}public String getOrderStatus() {return orderStatus;}public void setOrderStatus(String orderStatus) {this.orderStatus = orderStatus;}public List<Order> getOrders() {return orders;}public void setOrders(List<Order> orders) {this.orders = orders;}public String getEscalate() {return escalate;}public void setEscalate(String escalate) {this.escalate = escalate;}public String getCancelReason() {return cancelReason;}public void setCancelReason(String cancelReason) {this.cancelReason = cancelReason;}public List<Payment> getPayments() {return payments;}public void setPayments(List<Payment> payments) {this.payments = payments;}public String getTransactionId() {return transactionId;}public void setTransactionId(String transactionId) {this.transactionId = transactionId;}public String getPaymentId() {return paymentId;}public void setPaymentId(String paymentId) {this.paymentId = paymentId;}public HashMap<String, String> getAllAttachmentsForTicket() {return allAttachmentsForTicket;}public void setAllAttachmentsForTicket(HashMap<String, String> allAttachmentsForTicket) {this.allAttachmentsForTicket = allAttachmentsForTicket;}public String getPickupExtension() {return pickupExtension;}public void setPickupExtension(String pickupExtension) {this.pickupExtension = pickupExtension;}public Map<String, Long> getTicketCategorycountMap() {return ticketCategorycountMap;}public void setTicketCategorycountMap(Map<String, Long> ticketCategorycountMap) {this.ticketCategorycountMap = ticketCategorycountMap;}public String getPremises() {return premises;}public void setPremises(String premises) {this.premises = premises;}public String getClosureType() {return closureType;}public void setClosureType(String closureType) {this.closureType = closureType;}public String getQuantity() {return quantity;}public void setQuantity(String quantity) {this.quantity = quantity;}public Map<Long, Order> getTransactions() {return transactions;}public void setTransactions(Map<Long, Order> transactions) {this.transactions = transactions;}public Map<Long, Long> getTransactionShipping() {return transactionShipping;}public void setTransactionShipping(Map<Long, Long> transactionShipping) {this.transactionShipping = transactionShipping;}public Map<Long, Long> getTransactionTotal() {return transactionTotal;}public void setTransactionTotal(Map<Long, Long> transactionTotal) {this.transactionTotal = transactionTotal;}public String getDisposition() {return disposition;}public void setDisposition(String disposition) {this.disposition = disposition;}public List<String> getActionable() {return actionable;}public void setActionable(List<String> actionable) {this.actionable = actionable;}public void setSuitableActionable(TicketCategory ticketCategory){this.actionable = CRMConstants.CATEGORY_ACTION_MAP.get(ticketCategory);}}