Subversion Repositories SmartDukaan

Rev

Rev 4438 | Rev 4663 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4438 Rev 4490
Line 38... Line 38...
38
import java.text.ParseException;
38
import java.text.ParseException;
39
import java.util.ArrayList;
39
import java.util.ArrayList;
40
import java.util.Calendar;
40
import java.util.Calendar;
41
import java.util.Collections;
41
import java.util.Collections;
42
import java.util.Date;
42
import java.util.Date;
-
 
43
import java.util.HashMap;
43
import java.util.List;
44
import java.util.List;
44
 
45
 
45
import net.htmlparser.jericho.Source;
46
import net.htmlparser.jericho.Source;
46
 
47
 
47
import org.apache.shiro.SecurityUtils;
48
import org.apache.shiro.SecurityUtils;
Line 89... Line 90...
89
    private String            cancelReason;
90
    private String            cancelReason;
90
    private String            transactionId;
91
    private String            transactionId;
91
 
92
 
92
    private String paymentId;
93
    private String paymentId;
93
 
94
 
-
 
95
    private HashMap<String, String> allAttachmentsForTicket;
-
 
96
 
94
    public String index() {
97
    public String index() {
95
        try {
98
        try {
96
            if (id != null && !id.isEmpty()) {
99
            if (id != null && !id.isEmpty()) {
97
                SearchFilter searchFilter = new SearchFilter();
100
                SearchFilter searchFilter = new SearchFilter();
98
                crmServiceClient = new CRMClient().getClient();
101
                crmServiceClient = new CRMClient().getClient();
Line 113... Line 116...
113
            SearchFilter searchFilter = new SearchFilter();
116
            SearchFilter searchFilter = new SearchFilter();
114
            searchFilter.setTicketId(ticketId);
117
            searchFilter.setTicketId(ticketId);
115
            crmServiceClient = new CRMClient().getClient();
118
            crmServiceClient = new CRMClient().getClient();
116
            ticket = crmServiceClient.getTickets(searchFilter).get(0);
119
            ticket = crmServiceClient.getTickets(searchFilter).get(0);
117
            activities = crmServiceClient.getActivities(searchFilter);
120
            activities = crmServiceClient.getActivities(searchFilter);
-
 
121
            populateAttachments();
118
            subject = createSubjectString(ticket);
122
            subject = createSubjectString(ticket);
119
 
123
 
120
            if (ticket.isSetCustomerId()) {
124
            if (ticket.isSetCustomerId()) {
121
                userId = String.valueOf(ticket.getCustomerId());
125
                userId = String.valueOf(ticket.getCustomerId());
122
                userContextServiceClient = new UserClient().getClient();
126
                userContextServiceClient = new UserClient().getClient();
Line 153... Line 157...
153
                    if (order.isCod()) {
157
                    if (order.isCod()) {
154
                        orders.add(order);
158
                        orders.add(order);
155
                    }
159
                    }
156
                }
160
                }
157
            }
161
            }
-
 
162
            
-
 
163
            if (TicketCategory.DOA_RECEIVED.equals(ticket.getCategory())) {
-
 
164
                log.info("Fetching orders for " + ticket.getCustomerId());
-
 
165
                orders = new ArrayList<Order>();
-
 
166
                transactionServiceClient = new TransactionClient().getClient();
-
 
167
                for (Order order : transactionServiceClient
-
 
168
                        .getOrdersForCustomer(ticket.getCustomerId(), 0, 0,
-
 
169
                                Collections.singletonList(OrderStatus.DOA_REQUEST_RECEIVED))) {
-
 
170
                    log.info("Processing Order: " + order);
-
 
171
                    if (order != null) {
-
 
172
                        orders.add(order);
-
 
173
                    }
-
 
174
                }
-
 
175
            }
-
 
176
            
-
 
177
            if (TicketCategory.RETURN_FORM.equals(ticket.getCategory())) {
-
 
178
                log.info("Fetching orders for " + ticket.getCustomerId());
-
 
179
                orders = new ArrayList<Order>();
-
 
180
                transactionServiceClient = new TransactionClient().getClient();
-
 
181
                for (Order order : transactionServiceClient
-
 
182
                        .getOrdersForCustomer(ticket.getCustomerId(), 0, 0,
-
 
183
                                Collections.singletonList(OrderStatus.RET_REQUEST_RECEIVED))) {
-
 
184
                    log.info("Processing Order: " + order);
-
 
185
                    if (order != null) {
-
 
186
                        orders.add(order);
-
 
187
                    }
-
 
188
                }
-
 
189
            }
158
 
190
 
159
            if (TicketCategory.PAYMENT_FLAGGED.equals(ticket.getCategory())) {
191
            if (TicketCategory.PAYMENT_FLAGGED.equals(ticket.getCategory())) {
160
                log.info("Fetching orders for " + ticket.getCustomerId());
192
                log.info("Fetching orders for " + ticket.getCustomerId());
161
                payments = new ArrayList<Payment>();
193
                payments = new ArrayList<Payment>();
162
                in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
194
                in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
Line 211... Line 243...
211
        }
243
        }
212
 
244
 
213
        return EDIT;
245
        return EDIT;
214
    }
246
    }
215
 
247
 
-
 
248
    private void populateAttachments() {
-
 
249
        allAttachmentsForTicket = new HashMap<String, String>();
-
 
250
        for (Activity activity : activities) {
-
 
251
            log.info("" + activity.getId());
-
 
252
            String attachment = activity.getAttachments();
-
 
253
            if (attachment != null && !attachment.isEmpty()) {
-
 
254
                log.info("" + attachment);
-
 
255
                String [] attachmentList = attachment.split(";");
-
 
256
                for (String attachmentName : attachmentList) {
-
 
257
                    if (attachmentName != null && !attachmentName.isEmpty()) {
-
 
258
                        log.info("" + attachmentName);
-
 
259
                        allAttachmentsForTicket.put(activity.getId() + "-" + attachmentName, attachmentName);
-
 
260
                    }
-
 
261
                }
-
 
262
            }
-
 
263
        }
-
 
264
    }
-
 
265
    
-
 
266
    public static void main(String[] args) {
-
 
267
        TicketsController tc = new TicketsController();
-
 
268
        Integer i = new Integer(14215);
-
 
269
        tc.id = i.toString();
-
 
270
        tc.populateAttachments();
-
 
271
    }
-
 
272
 
216
    private String createSubjectString(Ticket ticket) {
273
    private String createSubjectString(Ticket ticket) {
217
        return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId()
274
        return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId()
218
                + " " + ticket.getCategory().name();
275
                + " " + ticket.getCategory().name();
219
    }
276
    }
220
 
277
 
Line 246... Line 303...
246
            activity.setTicketDescription(description);
303
            activity.setTicketDescription(description);
247
 
304
 
248
            if (orderId != null && !orderId.isEmpty()) {
305
            if (orderId != null && !orderId.isEmpty()) {
249
                ticket.setOrderId(Long.parseLong(orderId));
306
                ticket.setOrderId(Long.parseLong(orderId));
250
            }
307
            }
251
 
308
            
-
 
309
            if (TicketCategory.valueOf(category) == TicketCategory.DOA_RECEIVED) {
-
 
310
                transactionServiceClient = new TransactionClient().getClient();
-
 
311
                if (!transactionServiceClient.markOrderDoaRequestReceived(Long.parseLong(orderId))) {
-
 
312
                    throw new Exception("Order cannot be marked as DOA Received");
-
 
313
                }
-
 
314
                log.info("" + userId);
-
 
315
                
-
 
316
                Order order = transactionServiceClient.getOrder(Long.parseLong(orderId));
-
 
317
                log.info("In order table id is : " + order.getCustomer_id());
-
 
318
                if (userId == null || userId.isEmpty() || order.getCustomer_id() != Long.parseLong(userId)) {
-
 
319
                    throw new Exception("This order is not associated with this user Id");
-
 
320
                }
-
 
321
            }
-
 
322
            
-
 
323
            if (TicketCategory.valueOf(category) == TicketCategory.RETURN_FORM) {
-
 
324
                transactionServiceClient = new TransactionClient().getClient();
-
 
325
                if (!transactionServiceClient.markOrderReturnRequestReceived(Long.parseLong(orderId))) {
-
 
326
                    throw new Exception("Order cannot be marked as Return Requested");
-
 
327
                }
-
 
328
                log.info("" + userId);
-
 
329
                
-
 
330
                Order order = transactionServiceClient.getOrder(Long.parseLong(orderId));
-
 
331
                log.info("In order table id is : " + order.getCustomer_id());
-
 
332
                if (userId == null || userId.isEmpty() || order.getCustomer_id() != Long.parseLong(userId)) {
-
 
333
                    throw new Exception("This order is not associated with this user Id");
-
 
334
                }
-
 
335
            }
-
 
336
            
252
            if (userId != null && !userId.isEmpty()) {
337
            if (userId != null && !userId.isEmpty()) {
253
                ticket.setCustomerId(Long.parseLong(userId));
338
                ticket.setCustomerId(Long.parseLong(userId));
254
                activity.setCustomerId(Long.parseLong(userId));
339
                activity.setCustomerId(Long.parseLong(userId));
255
            } else {
340
            } else {
256
                User user = null;
341
                User user = null;
Line 301... Line 386...
301
            id = String
386
            id = String
302
                    .valueOf(crmServiceClient.insertTicket(ticket, activity));
387
                    .valueOf(crmServiceClient.insertTicket(ticket, activity));
303
        } catch (TException e) {
388
        } catch (TException e) {
304
            log.error("Error while creating ticket", e);
389
            log.error("Error while creating ticket", e);
305
            return EXCEPTION;
390
            return EXCEPTION;
-
 
391
        } catch (NumberFormatException e) {
-
 
392
            log.error("Error while parsing Order Id", e);
-
 
393
            return EXCEPTION;
-
 
394
        } catch (TransactionServiceException e) {
-
 
395
            log.error("Error while updating order status", e);
-
 
396
            return EXCEPTION;
-
 
397
        } catch (Exception e) {
-
 
398
            log.error(e.getMessage());
-
 
399
            return EXCEPTION;
306
        }
400
        }
307
 
401
 
308
        return index();
402
        return index();
309
    }
403
    }
310
 
404
 
Line 688... Line 782...
688
            return EXCEPTION;
782
            return EXCEPTION;
689
        }
783
        }
690
        return edit();
784
        return edit();
691
    }
785
    }
692
    
786
    
693
    public String blockPayment() throws NumberFormatException, TransactionServiceException, TException {
787
    public String blockPayment() {
694
        try {
788
        try {
695
            log.info("Blocking payment for paymentId = " + paymentId);
789
            log.info("Blocking payment for paymentId = " + paymentId);
696
            transactionServiceClient = new TransactionClient().getClient();
790
            transactionServiceClient = new TransactionClient().getClient();
697
            transactionServiceClient.refundTransaction(Long.parseLong(transactionId), currentAgentEmailId, "FLAGGED_PAYMENT_CANCELLED");
791
            transactionServiceClient.refundTransaction(Long.parseLong(transactionId), currentAgentEmailId, "FLAGGED_PAYMENT_CANCELLED");
698
            if (id != null && !id.isEmpty()) {
792
            if (id != null && !id.isEmpty()) {
Line 728... Line 822...
728
            log.error("Error while allowing flagged payment", e);
822
            log.error("Error while allowing flagged payment", e);
729
            return EXCEPTION;
823
            return EXCEPTION;
730
        }
824
        }
731
        return edit();
825
        return edit();
732
    }
826
    }
-
 
827
    
-
 
828
    public String authorizeReturn() {
-
 
829
        try {
-
 
830
            log.info("Authorizing OrderId =" + orderId);
-
 
831
            transactionServiceClient = new TransactionClient().getClient();
-
 
832
            transactionServiceClient.markOrderReturnRequestAuthorized(Long.parseLong(orderId), true);
-
 
833
            if (id != null && !id.isEmpty()) {
-
 
834
                SearchFilter searchFilter = new SearchFilter();
-
 
835
                crmServiceClient = new CRMClient().getClient();
-
 
836
                searchFilter.setTicketId(Long.parseLong(id));
-
 
837
                Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
-
 
838
                // Inserting activity
-
 
839
                if(ticket != null) {
-
 
840
                    Activity activity = new Activity();
-
 
841
                    activity.setDescription("Return Authorized");
-
 
842
                    activity.setType(ActivityType.OTHER);
-
 
843
                    activity.setTicketPriority(ticket.getPriority());
-
 
844
                    activity.setTicketStatus(ticket.getStatus());
-
 
845
                    activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
-
 
846
                    activity.setTicketCategory(ticket.getCategory());
-
 
847
                    activity.setTicketDescription(ticket.getDescription());
-
 
848
                    activity.setCustomerId(ticket.getCustomerId());
-
 
849
                    activity.setTicketAssigneeId(ticket.getAssigneeId());
-
 
850
 
-
 
851
                    crmServiceClient = new CRMClient().getClient();
-
 
852
                    crmServiceClient.updateTicket(ticket, activity);
-
 
853
                }
-
 
854
            }
-
 
855
 
-
 
856
        } catch (TException e) {
-
 
857
            log.error("Error while getting tickets", e);
-
 
858
            return EXCEPTION;
-
 
859
        } catch (NumberFormatException e) {
-
 
860
            log.error("Invalid ticket Id", e);
-
 
861
            return EXCEPTION;
-
 
862
        } catch (TransactionServiceException e) {
-
 
863
            log.error("Error while authorizing Return", e);
-
 
864
            return EXCEPTION;
-
 
865
        }
-
 
866
        return edit();
-
 
867
    }
-
 
868
    
-
 
869
    public String denyReturn() {
-
 
870
        try {
-
 
871
            log.info("Denying OrderId =" + orderId);
-
 
872
            transactionServiceClient = new TransactionClient().getClient();
-
 
873
            transactionServiceClient.markOrderReturnRequestAuthorized(Long.parseLong(orderId), false);
-
 
874
            if (id != null && !id.isEmpty()) {
-
 
875
                SearchFilter searchFilter = new SearchFilter();
-
 
876
                crmServiceClient = new CRMClient().getClient();
-
 
877
                searchFilter.setTicketId(Long.parseLong(id));
-
 
878
                Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
-
 
879
                // Inserting activity
-
 
880
                if(ticket != null) {
-
 
881
                    Activity activity = new Activity();
-
 
882
                    activity.setDescription("Return Denied");
-
 
883
                    activity.setType(ActivityType.OTHER);
-
 
884
                    activity.setTicketPriority(ticket.getPriority());
-
 
885
                    activity.setTicketStatus(ticket.getStatus());
-
 
886
                    activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
-
 
887
                    activity.setTicketCategory(ticket.getCategory());
-
 
888
                    activity.setTicketDescription(ticket.getDescription());
-
 
889
                    activity.setCustomerId(ticket.getCustomerId());
-
 
890
                    activity.setTicketAssigneeId(ticket.getAssigneeId());
-
 
891
 
-
 
892
                    crmServiceClient = new CRMClient().getClient();
-
 
893
                    crmServiceClient.updateTicket(ticket, activity);
-
 
894
                }
-
 
895
            }
-
 
896
 
-
 
897
        } catch (TException e) {
-
 
898
            log.error("Error while getting tickets", e);
-
 
899
            return EXCEPTION;
-
 
900
        } catch (NumberFormatException e) {
-
 
901
            log.error("Invalid ticket Id", e);
-
 
902
            return EXCEPTION;
-
 
903
        } catch (TransactionServiceException e) {
-
 
904
            log.error("Error while denying Return", e);
-
 
905
            return EXCEPTION;
-
 
906
        }
-
 
907
        return edit();
-
 
908
    }
-
 
909
    
-
 
910
    public String authorizeDOA() {
-
 
911
        try {
-
 
912
            log.info("Authorizing OrderId =" + orderId);
-
 
913
            transactionServiceClient = new TransactionClient().getClient();
-
 
914
            transactionServiceClient.markOrderDoaRequestAuthorized(Long.parseLong(orderId), true);
-
 
915
            if (id != null && !id.isEmpty()) {
-
 
916
                SearchFilter searchFilter = new SearchFilter();
-
 
917
                crmServiceClient = new CRMClient().getClient();
-
 
918
                searchFilter.setTicketId(Long.parseLong(id));
-
 
919
                Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
-
 
920
                // Inserting activity
-
 
921
                if(ticket != null) {
-
 
922
                    Activity activity = new Activity();
-
 
923
                    activity.setDescription("DOA Authorized");
-
 
924
                    activity.setType(ActivityType.OTHER);
-
 
925
                    activity.setTicketPriority(ticket.getPriority());
-
 
926
                    activity.setTicketStatus(ticket.getStatus());
-
 
927
                    activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
-
 
928
                    activity.setTicketCategory(ticket.getCategory());
-
 
929
                    activity.setTicketDescription(ticket.getDescription());
-
 
930
                    activity.setCustomerId(ticket.getCustomerId());
-
 
931
                    activity.setTicketAssigneeId(ticket.getAssigneeId());
-
 
932
 
-
 
933
                    crmServiceClient = new CRMClient().getClient();
-
 
934
                    crmServiceClient.updateTicket(ticket, activity);
-
 
935
                }
-
 
936
            }
-
 
937
 
-
 
938
        } catch (TException e) {
-
 
939
            log.error("Error while getting tickets", e);
-
 
940
            return EXCEPTION;
-
 
941
        } catch (NumberFormatException e) {
-
 
942
            log.error("Invalid ticket Id", e);
-
 
943
            return EXCEPTION;
-
 
944
        } catch (TransactionServiceException e) {
-
 
945
            log.error("Error while authorizing DOA", e);
-
 
946
            return EXCEPTION;
-
 
947
        }
-
 
948
        return edit();
-
 
949
    }
-
 
950
    
-
 
951
    public String denyDOA() {
-
 
952
        try {
-
 
953
            log.info("Denying OrderId =" + orderId);
-
 
954
            transactionServiceClient = new TransactionClient().getClient();
-
 
955
            transactionServiceClient.markOrderDoaRequestAuthorized(Long.parseLong(orderId), false);
-
 
956
            if (id != null && !id.isEmpty()) {
-
 
957
                SearchFilter searchFilter = new SearchFilter();
-
 
958
                crmServiceClient = new CRMClient().getClient();
-
 
959
                searchFilter.setTicketId(Long.parseLong(id));
-
 
960
                Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
-
 
961
                // Inserting activity
-
 
962
                if(ticket != null) {
-
 
963
                    Activity activity = new Activity();
-
 
964
                    activity.setDescription("DOA Denied");
-
 
965
                    activity.setType(ActivityType.OTHER);
-
 
966
                    activity.setTicketPriority(ticket.getPriority());
-
 
967
                    activity.setTicketStatus(ticket.getStatus());
-
 
968
                    activity.setCreatorId(CRMAuthorizingRealm.getAgent(currentAgentEmailId).getId());
-
 
969
                    activity.setTicketCategory(ticket.getCategory());
-
 
970
                    activity.setTicketDescription(ticket.getDescription());
-
 
971
                    activity.setCustomerId(ticket.getCustomerId());
-
 
972
                    activity.setTicketAssigneeId(ticket.getAssigneeId());
-
 
973
 
-
 
974
                    crmServiceClient = new CRMClient().getClient();
-
 
975
                    crmServiceClient.updateTicket(ticket, activity);
-
 
976
                }
-
 
977
            }
-
 
978
 
-
 
979
        } catch (TException e) {
-
 
980
            log.error("Error while getting tickets", e);
-
 
981
            return EXCEPTION;
-
 
982
        } catch (NumberFormatException e) {
-
 
983
            log.error("Invalid ticket Id", e);
-
 
984
            return EXCEPTION;
-
 
985
        } catch (TransactionServiceException e) {
-
 
986
            log.error("Error while denying DOA", e);
-
 
987
            return EXCEPTION;
-
 
988
        }
-
 
989
        return edit();
-
 
990
    }
733
 
991
 
734
    public EscalationMatrix[] getEscalationMatrix () {
992
    public EscalationMatrix[] getEscalationMatrix () {
735
        return CRMConstants.EscalationMatrix.values();
993
        return CRMConstants.EscalationMatrix.values();
736
    }
994
    }
737
 
995
 
Line 1000... Line 1258...
1000
    }
1258
    }
1001
 
1259
 
1002
    public void setPaymentId(String paymentId) {
1260
    public void setPaymentId(String paymentId) {
1003
        this.paymentId = paymentId;
1261
        this.paymentId = paymentId;
1004
    }
1262
    }
-
 
1263
 
-
 
1264
    public HashMap<String, String> getAllAttachmentsForTicket() {
-
 
1265
        return allAttachmentsForTicket;
-
 
1266
    }
-
 
1267
 
-
 
1268
    public void setAllAttachmentsForTicket(HashMap<String, String> allAttachmentsForTicket) {
-
 
1269
        this.allAttachmentsForTicket = allAttachmentsForTicket;
-
 
1270
    }
1005
}
1271
}