Subversion Repositories SmartDukaan

Rev

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

Rev 5286 Rev 5851
Line 1... Line 1...
1
/**
1
/**
2
 * 
2
 * 
3
 */
3
 */
4
package in.shop2020.crm.service.handler;
4
package in.shop2020.crm.service.handler;
5
 
5
 
-
 
6
import in.shop2020.alert.AlertService;
-
 
7
import in.shop2020.alert.EntityType;
-
 
8
import in.shop2020.alert.MonitoredEntity;
6
import in.shop2020.crm.Activity;
9
import in.shop2020.crm.Activity;
7
import in.shop2020.crm.ActivityType;
10
import in.shop2020.crm.ActivityType;
8
import in.shop2020.crm.Agent;
11
import in.shop2020.crm.Agent;
9
import in.shop2020.crm.CRMService.Iface;
12
import in.shop2020.crm.CRMService.Iface;
10
import in.shop2020.crm.SearchFilter;
13
import in.shop2020.crm.SearchFilter;
11
import in.shop2020.crm.Ticket;
14
import in.shop2020.crm.Ticket;
12
import in.shop2020.crm.handler.ActivityHandler;
15
import in.shop2020.crm.handler.ActivityHandler;
13
import in.shop2020.crm.handler.AgentHandler;
16
import in.shop2020.crm.handler.AgentHandler;
14
import in.shop2020.crm.handler.TicketHandler;
17
import in.shop2020.crm.handler.TicketHandler;
-
 
18
import in.shop2020.thrift.clients.AlertClient;
15
 
19
 
16
import java.text.ParseException;
20
import java.text.ParseException;
17
import java.util.ArrayList;
21
import java.util.ArrayList;
-
 
22
import java.util.Calendar;
18
import java.util.Date;
23
import java.util.Date;
19
import java.util.List;
24
import java.util.List;
20
 
25
 
21
import org.apache.commons.logging.Log;
26
import org.apache.commons.logging.Log;
22
import org.apache.commons.logging.LogFactory;
27
import org.apache.commons.logging.LogFactory;
Line 76... Line 81...
76
            ticketHandler.updateTicket(in.shop2020.crm.domain.Ticket
81
            ticketHandler.updateTicket(in.shop2020.crm.domain.Ticket
77
                    .create(ticket));
82
                    .create(ticket));
78
            activity.setTicketId(ticket.getId());
83
            activity.setTicketId(ticket.getId());
79
            activityHandler.insertActivity(in.shop2020.crm.domain.Activity
84
            activityHandler.insertActivity(in.shop2020.crm.domain.Activity
80
                    .create(activity));
85
                    .create(activity));
-
 
86
            try{
-
 
87
	            /*For now monitoring is only done for New tickets and hence once any 
-
 
88
	        	 * activity is done on a ticket after its creation, we stop monitoring that ticket*/
-
 
89
	        	AlertService.Client alertClient = new AlertClient().getClient();
-
 
90
	            alertClient.endMonitoringEntity(EntityType.TICKET, "ticketId = " + ticket.getId());
-
 
91
            } catch(Exception ex) {
-
 
92
            	log.error("Exception while ending monitoring for ticketId " + ticket.getId());
-
 
93
            	log.error(ex);
-
 
94
            }
81
        } catch (ParseException e) {
95
        } catch (ParseException e) {
82
            throw new TException("Could not update " + ticket, e);
96
            throw new TException("Could not update " + ticket, e);
83
        }
97
        }
84
    }
98
    }
85
 
99
 
Line 90... Line 104...
90
            long ticketId = ticketHandler
104
            long ticketId = ticketHandler
91
                    .insertTicket(in.shop2020.crm.domain.Ticket.create(ticket));
105
                    .insertTicket(in.shop2020.crm.domain.Ticket.create(ticket));
92
            activity.setTicketId(ticketId);
106
            activity.setTicketId(ticketId);
93
            activityHandler.insertActivity(in.shop2020.crm.domain.Activity
107
            activityHandler.insertActivity(in.shop2020.crm.domain.Activity
94
                    .create(activity));
108
                    .create(activity));
-
 
109
            try {
-
 
110
	            MonitoredEntity entity = new MonitoredEntity();
-
 
111
	            entity.setEntityType(EntityType.TICKET);
-
 
112
	            entity.setEventType(0);
-
 
113
	            entity.setEntityIdentifier("ticketId = " + new Long(ticketId).toString());
-
 
114
	            entity.setDescription(ticket.getDescription());
-
 
115
	            Calendar thresholdTime = Calendar.getInstance();
-
 
116
	            thresholdTime.add(Calendar.HOUR, 4);
-
 
117
	            entity.setWarnExpiryTime(thresholdTime.getTimeInMillis());
-
 
118
	            thresholdTime.add(Calendar.HOUR, 2);
-
 
119
	            entity.setCriticalExpiryTime(thresholdTime.getTimeInMillis());
-
 
120
	            AlertService.Client alertClient = new AlertClient().getClient();
-
 
121
	            alertClient.scheduleAlert(entity);
-
 
122
            } catch (Exception ex) {
-
 
123
            	log.error("Exception while scheduling alert for Ticket Id "+ticketId);
-
 
124
            	log.error(ex);
-
 
125
            }
95
            return ticketId;
126
            return ticketId;
96
        } catch (ParseException e) {
127
        } catch (ParseException e) {
97
            throw new TException("Could not insert " + ticket, e);
128
            throw new TException("Could not insert " + ticket, e);
98
        }
129
        }
99
    }
130
    }