Subversion Repositories SmartDukaan

Rev

Rev 3024 | Rev 3137 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/**
 * 
 */
package in.shop2020.crm.service.handler;

import in.shop2020.crm.Activity;
import in.shop2020.crm.Agent;
import in.shop2020.crm.CRMService.Iface;
import in.shop2020.crm.Ticket;
import in.shop2020.crm.handler.ActivityHandler;
import in.shop2020.crm.handler.AgentHandler;
import in.shop2020.crm.handler.TicketHandler;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import org.apache.thrift.TException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

/**
 * Implementation of the interface/services exposed by thrift to clients!
 * 
 * @author mandeep
 */
@Service
public class CRMServiceHandler implements Iface {
    ApplicationContext context         = new ClassPathXmlApplicationContext("context.xml");
    TicketHandler      ticketHandler   = context.getBean(TicketHandler.class);
    ActivityHandler    activityHandler = context.getBean(ActivityHandler.class);
    AgentHandler       agentHandler    = context.getBean(AgentHandler.class);

    public List<Ticket> getTickets(long customerId) throws TException {
        List<Ticket> ttickets = new ArrayList<Ticket>();

        for (in.shop2020.crm.domain.Ticket ticket : ticketHandler
                .getTickets(customerId)) {
            ttickets.add(ticket.getThriftTicket());
        }

        return ttickets;
    }

    public void updateTicket(Ticket ticket) throws TException {
        try {
            ticketHandler.updateTicket(in.shop2020.crm.domain.Ticket
                    .create(ticket));
        } catch (ParseException e) {
            throw new TException("Could not update " + ticket, e);
        }
    }

    public long insertTicket(Ticket ticket) throws TException {
        try {
            return ticketHandler.insertTicket(in.shop2020.crm.domain.Ticket
                    .create(ticket));
        } catch (ParseException e) {
            throw new TException("Could not insert " + ticket, e);
        }
    }

    public List<Activity> getActivities(long customerId) throws TException {
        List<Activity> tactivities = new ArrayList<Activity>();
        for (in.shop2020.crm.domain.Activity ticket : activityHandler
                .getActivities(customerId)) {
            tactivities.add(ticket.getThriftActivity());
        }
        return tactivities;
    }

    public void insertActivity(Activity activity) throws TException {
        try {
            activityHandler.insertActivity(in.shop2020.crm.domain.Activity
                    .create(activity));
        } catch (ParseException e) {
            throw new TException("Could not insert " + activity, e);
        }
    }

    public Ticket getTicket(long ticketId) throws TException {
        return ticketHandler.getTicket(ticketId).getThriftTicket();
    }

    public Activity getActivity(long activityId) throws TException {
        return activityHandler.getActivity(activityId).getThriftActivity();
    }

    public Activity getLastActivity(long ticketId) throws TException {
        in.shop2020.crm.domain.Activity lastActivity = activityHandler
                .getLastActivity(ticketId);
        Activity lastThriftActivity = null;

        if (lastActivity != null) {
            lastThriftActivity = lastActivity.getThriftActivity();
        }

        return lastThriftActivity;
    }

    public List<Activity> getActivitiesForTicket(long ticketId)
            throws TException {
        List<Activity> tactivities = new ArrayList<Activity>();

        for (in.shop2020.crm.domain.Activity ticket : activityHandler
                .getActivitiesForTicket(ticketId)) {
            tactivities.add(ticket.getThriftActivity());
        }

        return tactivities;
    }

    public Agent getAgent(long agentId) throws TException {
        return agentHandler.getAgent(agentId).getThriftAgent();
    }

    public Agent getAgentByEmailId(String agentEmailId) throws TException {
        return agentHandler.getAgentByEmail(agentEmailId).getThriftAgent();
    }

    public List<String> getRoleNamesForAgent(String agentEmailId)
            throws TException
    {
        return agentHandler.getRoleNamesForAgent(agentEmailId);
    }

    public List<String> getPermissionsForRoleName(String roleName)
            throws TException
    {
        return agentHandler.getPermissionsForRoleName(roleName);
    }

    public List<Ticket> getAssignedTickets(long agentId) throws TException {
        // TODO Auto-generated method stub
        return null;
    }

    public List<Ticket> getOpenTickets() throws TException {
        // TODO Auto-generated method stub
        return null;
    }

    public List<Agent> getAllAgents() throws TException {
        List<Agent> agents = new ArrayList<Agent>();

        for (in.shop2020.crm.domain.Agent agent : agentHandler.getAllAgents()) {
            agents.add(agent.getThriftAgent());
        }

        return agents;
    }

    public void updatePasswordForAgent(String agentEmailId, String password)
            throws TException
    {
        agentHandler.updatePasswordForAgent(agentEmailId, password);
    }
}