private void handleGroups(AjaxRequest vars, HttpServletRequest request, HttpServletResponse response) {
        EntityManager em = getEntityManager();
        GroupDefinitionDao dbDefinition = new GroupDefinitionDao(em);
        CustomerDao dbCustomer = new CustomerDao(em);

        if (vars.getAction().equals("groupsList")) {
            writeResponse(response, dbDefinition.getGroupsList());
        } else if (vars.getAction().equals("customerGroups")) {
            Customer customer = dbCustomer.getById(vars.getId());
            writeResponse(response, customer.getGroups());
        } else if (vars.getAction().equals("toggleGroup")) {
            try {
                em.getTransaction().begin();

                Customer customer = dbCustomer.getById(vars.getId());
//                GroupDefinition definition = dbDefinition.getById((Long) vars.getValues().get("g"));

//                if (customer.inGroup(definition)) {
//                    Group group = customer.getGroup(definition);
//                    if (group != null) {
//                        em.remove(group);
//                    }
//                } else {
//                    createGroup(customer, definition);
//                }
                em.getTransaction().commit();
                emptyResponse(request, response);
            } catch (Exception e) {
                handleException(e, em, request, response);
            }
        } else if (vars.getAction().equals("addGroup")) {
            try {
                em.getTransaction().begin();

                // TODO: Validator
                Customer customer = dbCustomer.getById(vars.getId());
                GroupDefinition definition = new GroupDefinition();
                definition.setName((String) vars.getValues().get("n"));
                em.persist(definition);

                createGroup(customer, definition);

                em.getTransaction().commit();
                emptyResponse(request, response);
            } catch (Exception e) {
                handleException(e, em, request, response);
            }
        }

        em.close();
    }