<commit_before>/**
 * Copyright (C) 2011  JTalks.org Team
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package org.jtalks.poulpe.web.controller.users;

import org.jtalks.common.model.entity.Group;
import org.jtalks.common.model.entity.User;
import org.jtalks.common.service.exceptions.NotFoundException;
import org.jtalks.poulpe.model.entity.PoulpeUser;
import org.jtalks.poulpe.service.GroupService;
import org.jtalks.poulpe.service.UserService;
import org.jtalks.poulpe.web.controller.section.dialogs.AbstractDialogVm;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.NotifyChange;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * View-model for 'Edit user group list' dialog Is used to order to work with page that allows admin to manage groups
 * list of selected user.
 *
 * @author <NAME>
 */
public class EditGroupsVm extends AbstractDialogVm {
    private boolean chosen = true;
    private boolean notChosen = true;
    protected static final String GROUPS = "groupsToShow";
    private static final String EDIT_GROUPS = "editGroups";
    private static final String FILTER_GROUPS = "filterGroups";
    private static final String SAVE_CHANGES = "saveUserGroupsChanges";
    private static final String USER_TO_EDIT = "userToEdit";

    private List<GroupBooleanPair> groupsToShow;
    private List<GroupBooleanPair> groups;

    /**
     * User to be edited
     */
    private PoulpeUser userToEdit;
    private final UserService userService;
    private final GroupService groupService;
    private final UsersVm usersVm;

    /**
     * @param usersVm     view model of parent window
     * @param userService service instance to save changes
     * @param groupService service instance to save changes
     */
    public EditGroupsVm(@Nonnull UsersVm usersVm,
                        @Nonnull UserService userService,
                        @Nonnull GroupService groupService) {
        this.userService = userService;
        this.groupService = groupService;
        this.usersVm = usersVm;
    }

    /**
     * Dialog opening command.
     * @throws NotFoundException on user not found
     */
    @GlobalCommand(EDIT_GROUPS)
    @NotifyChange({SHOW_DIALOG, GROUPS, USER_TO_EDIT})
    public void editGroups() throws NotFoundException {
        userToEdit = usersVm.getSelectedUser();
        init();
        showDialog();
    }

    /**
     * Activates group filtering.
     */
    @GlobalCommand(FILTER_GROUPS)
    @NotifyChange(GROUPS)
    public void filterGroups() {
        doFilter();
    }

    /**
     * Save changes command.
     */
    @GlobalCommand(SAVE_CHANGES)<commit_msg>#POULPE-456 Edit user groups. Bugfix&testfix, docs.<commit_after>/**
 * Copyright (C) 2011  JTalks.org Team
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package org.jtalks.poulpe.web.controller.users;

import org.jtalks.common.model.entity.Group;
import org.jtalks.common.model.entity.User;
import org.jtalks.common.service.exceptions.NotFoundException;
import org.jtalks.poulpe.model.entity.PoulpeUser;
import org.jtalks.poulpe.service.GroupService;
import org.jtalks.poulpe.service.UserService;
import org.jtalks.poulpe.web.controller.section.dialogs.AbstractDialogVm;
import org.zkoss.bind.annotation.GlobalCommand;
import org.zkoss.bind.annotation.NotifyChange;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * View-model for 'Edit user group list' dialog Is used to order to work with page that allows admin to manage groups
 * list of selected user.
 *
 * @author <NAME>
 */
public class EditGroupsVm extends AbstractDialogVm {
    private boolean chosen = true;
    private boolean notChosen = true;
    protected static final String GROUPS = "groupsToShow";
    public static final String CHOSEN = "chosen";
    public static final String NOT_CHOSEN = "notChosen";
    private static final String EDIT_GROUPS = "editGroups";
    private static final String FILTER_GROUPS = "filterGroups";
    private static final String SAVE_CHANGES = "saveUserGroupsChanges";
    private static final String USER_TO_EDIT = "userToEdit";

    private List<GroupBooleanPair> groupsToShow;
    private List<GroupBooleanPair> groups;

    /**
     * User to be edited
     */
    private PoulpeUser userToEdit;
    private final UserService userService;
    private final GroupService groupService;
    private final UsersVm usersVm;

    /**
     * @param usersVm     view model of parent window
     * @param userService service instance to save changes
     * @param groupService service instance to save changes
     */
    public EditGroupsVm(@Nonnull UsersVm usersVm,
                        @Nonnull UserService userService,
                        @Nonnull GroupService groupService) {
        this.userService = userService;
        this.groupService = groupService;
        this.usersVm = usersVm;
    }

    /**
     * Dialog opening command.
     * @throws NotFoundException on user not found
     */
    @GlobalCommand(EDIT_GROUPS)
    @NotifyChange({SHOW_DIALOG, GROUPS, USER_TO_EDIT, CHOSEN, NOT_CHOSEN})
    public void editGroups() throws NotFoundException {
        userToEdit = usersVm.getSelectedUser();
        init();
        showDialog();
    }

    /**
     * Activates group filtering.
     */
    @GlobalCommand(FILTER_GROUPS)
    @NotifyChange(GROUPS)
    public void filterGroups() {
        doFilter();
    }

    /**
     * Save changes command.
     */
    @GlobalCommand(SAVE_CHANGES)
{'fraction_non_alphanumeric': 0.07792579859618966, 'fraction_numerical': 0.0053001002721673116, 'mean_word_length': 3.393958464443046, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2410779', 'n_tokens_mistral': 1977, 'n_tokens_neox': 1931, 'n_words': 652}