Search in sources :

Example 1 with RolesOperationsParameters

use of org.ovirt.engine.core.common.action.RolesOperationsParameters in project ovirt-engine by oVirt.

the class RoleListModel method onSave.

public void onSave() {
    RoleModel model = (RoleModel) getWindow();
    if (model.getProgress() != null) {
        return;
    }
    role = commandType != CommandType.Edit ? new Role() : getSelectedItem();
    role.setType(model.getIsAdminRole().getEntity() ? RoleType.ADMIN : RoleType.USER);
    if (!model.validate()) {
        return;
    }
    role.setName(model.getName().getEntity());
    role.setDescription(model.getDescription().getEntity());
    ArrayList<ActionGroup> actions = new ArrayList<>();
    HashMap<ActionGroup, ActionGroup> actionDistinctSet = new HashMap<>();
    for (SelectionTreeNodeModel sm : model.getPermissionGroupModels()) {
        for (SelectionTreeNodeModel smChild : sm.getChildren()) {
            if (smChild.getIsSelectedNullable() == null || smChild.getIsSelectedNullable()) {
                for (SelectionTreeNodeModel smGrandChild : smChild.getChildren()) {
                    if (smGrandChild.getIsSelectedNullable()) {
                        ActionGroup actionGroup = ActionGroup.valueOf(smGrandChild.getTitle());
                        if (actionDistinctSet.containsKey(actionGroup)) {
                            continue;
                        }
                        actionDistinctSet.put(actionGroup, actionGroup);
                        actions.add(actionGroup);
                    }
                }
            }
        }
    }
    ActionReturnValue returnValue;
    model.startProgress();
    if (commandType != CommandType.Edit) {
        // Add a new role.
        RoleWithActionGroupsParameters tempVar = new RoleWithActionGroupsParameters();
        tempVar.setRole(role);
        tempVar.setActionGroups(actions);
        Frontend.getInstance().runAction(ActionType.AddRoleWithActionGroups, tempVar, result -> {
            RoleListModel localModel = (RoleListModel) result.getState();
            localModel.postOnSaveNew(result.getReturnValue());
        }, this);
    } else {
        detachActionGroup = new ArrayList<>(publicAttachedActions);
        detachActionGroup.removeAll(actions);
        attachActionGroup = actions;
        attachActionGroup.removeAll(publicAttachedActions);
        Frontend.getInstance().runAction(ActionType.UpdateRole, new RolesOperationsParameters(role), result -> {
            RoleListModel roleListModel = (RoleListModel) result.getState();
            ActionReturnValue retVal = result.getReturnValue();
            if (retVal != null && retVal.getSucceeded()) {
                if (roleListModel.detachActionGroup.size() > 0) {
                    ActionGroupsToRoleParameter tempVar2 = new ActionGroupsToRoleParameter();
                    tempVar2.setActionGroups(roleListModel.detachActionGroup);
                    tempVar2.setRoleId(roleListModel.role.getId());
                    Frontend.getInstance().runAction(ActionType.DetachActionGroupsFromRole, tempVar2);
                }
                if (roleListModel.attachActionGroup.size() > 0) {
                    ActionGroupsToRoleParameter tempVar3 = new ActionGroupsToRoleParameter();
                    tempVar3.setActionGroups(roleListModel.attachActionGroup);
                    tempVar3.setRoleId(roleListModel.role.getId());
                    Frontend.getInstance().runAction(ActionType.AttachActionGroupsToRole, tempVar3);
                }
                roleListModel.getWindow().stopProgress();
                roleListModel.cancel();
            } else {
                roleListModel.getWindow().stopProgress();
            }
        }, this);
    }
}
Also used : SelectionTreeNodeModel(org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel) ActionGroupsToRoleParameter(org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Role(org.ovirt.engine.core.common.businessentities.Role) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) RoleWithActionGroupsParameters(org.ovirt.engine.core.common.action.RoleWithActionGroupsParameters) RolesOperationsParameters(org.ovirt.engine.core.common.action.RolesOperationsParameters)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ActionGroupsToRoleParameter (org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 RoleWithActionGroupsParameters (org.ovirt.engine.core.common.action.RoleWithActionGroupsParameters)1 RolesOperationsParameters (org.ovirt.engine.core.common.action.RolesOperationsParameters)1 ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)1 Role (org.ovirt.engine.core.common.businessentities.Role)1 SelectionTreeNodeModel (org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel)1