private void addLists(OpenAcdAgent agent, OpenAcdAgentRestInfoFull agentRestInfo) {
    Set<OpenAcdSkill> skills = new LinkedHashSet<OpenAcdSkill>();
    List<OpenAcdSkillRestInfo> skillsRestInfo = agentRestInfo.getSkills();

    for (OpenAcdSkillRestInfo skillRestInfo : skillsRestInfo) {
      skills.add(m_openAcdContext.getSkillById(skillRestInfo.getId()));
    }

    Set<OpenAcdQueue> queues = new LinkedHashSet<OpenAcdQueue>();
    List<OpenAcdQueueRestInfo> queuesRestInfo = agentRestInfo.getQueues();

    for (OpenAcdQueueRestInfo queueRestInfo : queuesRestInfo) {
      queues.add(m_openAcdContext.getQueueById(queueRestInfo.getId()));
    }

    Set<OpenAcdClient> clients = new LinkedHashSet<OpenAcdClient>();
    List<OpenAcdClientRestInfo> clientsRestInfo = agentRestInfo.getClients();

    for (OpenAcdClientRestInfo clientRestInfo : clientsRestInfo) {
      clients.add(m_openAcdContext.getClientById(clientRestInfo.getId()));
    }

    agent.setSkills(skills);
    agent.setQueues(queues);
    agent.setClients(clients);
  }
  private OpenAcdAgentGroup getAgentGroup(OpenAcdAgentRestInfoFull agentRestInfo) {
    OpenAcdAgentGroup agentGroup;
    int groupId = 0;

    groupId = agentRestInfo.getGroupId();
    agentGroup = m_openAcdContext.getAgentGroupById(groupId);

    return agentGroup;
  }
  private void updateAgent(OpenAcdAgent agent, OpenAcdAgentRestInfoFull agentRestInfo)
      throws ResourceException {
    OpenAcdAgentGroup agentGroup;

    agentGroup = getAgentGroup(agentRestInfo);
    agent.setGroup(agentGroup);

    agent.setSecurity(agentRestInfo.getSecurity());

    addLists(agent, agentRestInfo);
  }
  private OpenAcdAgent createOpenAcdAgent(OpenAcdAgentRestInfoFull agentRestInfo)
      throws ResourceException {
    OpenAcdAgent agent = new OpenAcdAgent();
    OpenAcdAgent duplicateAgent = null;
    User user;

    // set associated user
    user = m_coreContext.getUser(agentRestInfo.getUserId());

    // check if user is already assigned as agent
    duplicateAgent = m_openAcdContext.getAgentByUser(user);
    if (duplicateAgent != null) {
      throw new ResourceException(
          Status.CLIENT_ERROR_BAD_REQUEST, "User " + user.getId() + " already assigned as agent.");
    }

    agent.setUser(user);

    updateAgent(agent, agentRestInfo);

    return agent;
  }