Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3090 mandeep.dh 1
/**
2
 * 
3
 */
4
package in.shop2020.serving.controllers;
5
 
6
import in.shop2020.crm.Activity;
3106 mandeep.dh 7
import in.shop2020.crm.ActivityType;
3090 mandeep.dh 8
import in.shop2020.crm.Agent;
9
import in.shop2020.crm.Ticket;
10
import in.shop2020.crm.TicketPriority;
11
import in.shop2020.crm.TicketStatus;
12
import in.shop2020.model.v1.user.User;
13
import in.shop2020.model.v1.user.UserContextException;
14
 
15
import java.util.LinkedHashMap;
16
import java.util.List;
17
import java.util.Map;
18
 
19
import org.apache.thrift.TException;
20
 
21
/**
22
 * Action class for activity pages in CRM.
3106 mandeep.dh 23
 * 
3090 mandeep.dh 24
 * @author mandeep
25
 */
26
public class UserActivityController extends BaseController {
27
    /**
28
     * 
29
     */
30
    private static final long   serialVersionUID = 1L;
31
 
32
    private Map<Long, Activity> activities       = new LinkedHashMap<Long, Activity>();
33
    private long                userId;
34
    private String              description;
35
    private User                user;
3106 mandeep.dh 36
    private String              type;
3090 mandeep.dh 37
 
38
    public String index() throws TException, UserContextException {
39
        createServiceClients();
40
        List<Activity> activityList = crmServiceClient.getActivities(userId);
41
        if (activityList != null) {
42
            for (Activity activity : activityList) {
43
                activities.put(activity.getId(), activity);
44
            }
45
        }
46
 
47
        user = userContextServiceClient.getUserById(userId);
48
 
49
        return INDEX;
50
    }
51
 
3106 mandeep.dh 52
    public String editNew() {
3090 mandeep.dh 53
        return EDIT_NEW;
54
    }
55
 
56
    public Map<Long, Activity> getActivities() {
57
        return activities;
58
    }
59
 
60
    public TicketStatus[] getTicketStatuses() {
61
        return TicketStatus.values();
62
    }
63
 
64
    public TicketPriority[] getTicketPriorities() {
65
        return TicketPriority.values();
66
    }
67
 
3106 mandeep.dh 68
    public ActivityType[] getActivityTypes() {
69
        return ActivityType.values();
3090 mandeep.dh 70
    }
71
 
72
    public User getUser() {
73
        return user;
74
    }
75
 
76
    public Ticket getTicket(long activityId) throws TException {
77
        Ticket ticket = null;
78
        Activity activity = crmServiceClient.getActivity(activityId);
79
        if (activity != null && activity.getTicketId() != 0) {
80
            ticket = crmServiceClient.getTicket(activity.getTicketId());
3106 mandeep.dh 81
        } else {
3090 mandeep.dh 82
            ticket = new Ticket();
83
        }
84
 
85
        return ticket;
86
    }
87
 
88
    public String create() throws Exception {
89
        createServiceClients();
90
        Activity activity = new Activity();
91
        activity.setCustomerId(userId);
3106 mandeep.dh 92
        activity.setDescription(description);
93
        activity.setType(ActivityType.valueOf(type));
94
        activity.setCreatorId(crmServiceClient.getAgentByEmailId(
3090 mandeep.dh 95
                currentAgentEmailId).getId());
96
 
97
        crmServiceClient.insertActivity(activity);
98
 
99
        return index();
100
    }
101
 
3106 mandeep.dh 102
    public String getLoggerRole() throws TException {
3090 mandeep.dh 103
        createServiceClients();
3106 mandeep.dh 104
        return crmServiceClient.getRoleNamesForAgent(currentAgentEmailId)
105
                .get(0);
106
    }
107
 
108
    public List<Agent> getAllAgents() throws TException {
109
        createServiceClients();
3090 mandeep.dh 110
        return crmServiceClient.getAllAgents();
111
    }
112
 
113
    public Agent getAgent(long agentId) throws TException {
114
        return crmServiceClient.getAgent(agentId);
115
    }
116
 
117
    public void setUserId(String userId) {
118
        this.userId = Long.parseLong(userId);
119
    }
120
 
121
    public void setDescription(String description) {
122
        this.description = description;
123
    }
124
 
3106 mandeep.dh 125
    public long getUserId() {
126
        return userId;
3090 mandeep.dh 127
    }
128
 
3106 mandeep.dh 129
    public String getType() {
130
        return type;
3090 mandeep.dh 131
    }
132
 
3106 mandeep.dh 133
    public void setType(String type) {
134
        this.type = type;
3090 mandeep.dh 135
    }
136
 
3106 mandeep.dh 137
    public String getDescription() {
138
        return description;
3090 mandeep.dh 139
    }
140
 
3106 mandeep.dh 141
    public void setActivities(Map<Long, Activity> activities) {
142
        this.activities = activities;
3090 mandeep.dh 143
    }
144
 
3106 mandeep.dh 145
    public void setUserId(long userId) {
146
        this.userId = userId;
3090 mandeep.dh 147
    }
148
}