Search in sources :

Example 6 with ActionGroup

use of org.ovirt.engine.core.common.businessentities.ActionGroup in project ovirt-engine by oVirt.

the class GetRoleActionGroupsByRoleIdQueryTest method testExecuteQueryCommand.

@Test
public void testExecuteQueryCommand() {
    // Mock parameters
    Guid roleId = Guid.newGuid();
    when(getQueryParameters().getId()).thenReturn(roleId);
    // Mock the expected result
    ActionGroup group = RandomUtils.instance().nextEnum(ActionGroup.class);
    List<ActionGroup> expected = Collections.singletonList(group);
    // Mock the Dao
    when(actionGroupDaoMock.getAllForRole(roleId)).thenReturn(expected);
    // Execute the query and assert the result
    getQuery().executeQueryCommand();
    assertEquals("Wrong query result", expected, getQuery().getQueryReturnValue().getReturnValue());
}
Also used : ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 7 with ActionGroup

use of org.ovirt.engine.core.common.businessentities.ActionGroup in project ovirt-engine by oVirt.

the class ExistingPoolModelBehavior method postInitStorageDomains.

@Override
protected void postInitStorageDomains() {
    ArrayList<DiskModel> disks = (ArrayList<DiskModel>) getModel().getDisks();
    if (disks == null) {
        return;
    }
    ActionGroup actionGroup = getModel().isCreateInstanceOnly() ? ActionGroup.CREATE_INSTANCE : ActionGroup.CREATE_VM;
    StoragePool dataCenter = getModel().getSelectedDataCenter();
    AsyncDataProvider.getInstance().getPermittedStorageDomainsByStoragePoolId(asyncQuery(storageDomains -> {
        ArrayList<DiskModel> disks1 = (ArrayList<DiskModel>) getModel().getDisks();
        ArrayList<StorageDomain> activeStorageDomains = filterStorageDomains(storageDomains);
        DisksAllocationModel disksAllocationModel = getModel().getDisksAllocationModel();
        disksAllocationModel.setActiveStorageDomains(activeStorageDomains);
        getModel().getStorageDomain().setItems(activeStorageDomains);
        for (DiskModel diskModel : disks1) {
            // Setting Quota
            diskModel.getQuota().setItems(getModel().getQuota().getItems());
            diskModel.getQuota().setIsChangeable(false);
            List<Guid> storageIds = ((DiskImage) diskModel.getDisk()).getStorageIds();
            for (DiskImage disk : pool.getDiskList()) {
                if (diskModel.getDisk() instanceof DiskImage && ((DiskImage) diskModel.getDisk()).getImageId().equals(disk.getImageTemplateId())) {
                    storageIds = new ArrayList<>(disk.getStorageIds());
                    break;
                }
            }
            if (storageIds == null || storageIds.size() == 0) {
                continue;
            }
            Guid storageId = storageIds.get(0);
            StorageDomain storageDomain = activeStorageDomains.stream().filter(new Linq.IdPredicate<>(storageId)).findFirst().orElse(null);
            List<StorageDomain> diskStorageDomains = new ArrayList<>();
            diskStorageDomains.add(storageDomain);
            diskModel.getStorageDomain().setItems(diskStorageDomains);
            diskModel.getStorageDomain().setIsChangeable(false);
        }
    }), dataCenter.getId(), actionGroup);
    getModel().getDisksAllocationModel().initializeAutoSelectTarget(false, actualPool.isAutoStorageSelect());
}
Also used : VmPool(org.ovirt.engine.core.common.businessentities.VmPool) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Linq(org.ovirt.engine.ui.uicommonweb.Linq) Guid(org.ovirt.engine.core.compat.Guid) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StringHelper(org.ovirt.engine.core.compat.StringHelper) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ArrayList(java.util.ArrayList) List(java.util.List) VM(org.ovirt.engine.core.common.businessentities.VM) ExistingPoolInstanceTypeManager(org.ovirt.engine.ui.uicommonweb.models.vms.instancetypes.ExistingPoolInstanceTypeManager) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) ExistingPoolNameLengthValidation(org.ovirt.engine.ui.uicommonweb.validation.ExistingPoolNameLengthValidation) LatestVmTemplate(org.ovirt.engine.ui.uicommonweb.models.templates.LatestVmTemplate) InstanceTypeManager(org.ovirt.engine.ui.uicommonweb.models.vms.instancetypes.InstanceTypeManager) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) DisksAllocationModel(org.ovirt.engine.ui.uicommonweb.models.storage.DisksAllocationModel) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) DisksAllocationModel(org.ovirt.engine.ui.uicommonweb.models.storage.DisksAllocationModel) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) ArrayList(java.util.ArrayList) List(java.util.List) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 8 with ActionGroup

use of org.ovirt.engine.core.common.businessentities.ActionGroup in project ovirt-engine by oVirt.

the class AddRoleWithActionGroupsCommand method prepareRoleForCommand.

/**
 */
protected void prepareRoleForCommand() {
    // Note that the role is take from the parameters
    Role role = getRole();
    role.setId(Guid.newGuid());
    role.setAllowsViewingChildren(false);
    // Set the application mode as 255 - AllModes by default
    getRole().setAppMode(ApplicationMode.AllModes);
    for (ActionGroup group : getParameters().getActionGroups()) {
        if (group.allowsViewingChildren()) {
            role.setAllowsViewingChildren(true);
            break;
        }
    }
}
Also used : Role(org.ovirt.engine.core.common.businessentities.Role) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup)

Example 9 with ActionGroup

use of org.ovirt.engine.core.common.businessentities.ActionGroup in project ovirt-engine by oVirt.

the class AttachActionGroupsToRoleCommand method executeCommand.

@Override
protected void executeCommand() {
    boolean addedGroupThatAllowsViewingChildren = false;
    List<ActionGroup> groups = getParameters().getActionGroups();
    for (ActionGroup group : groups) {
        addedGroupThatAllowsViewingChildren |= group.allowsViewingChildren();
        roleGroupMapDao.save(new RoleGroupMap(group, getParameters().getRoleId()));
        appendCustomCommaSeparatedValue("ActionGroup", group.toString());
    }
    // Only adding groups that allow viewing children could make a role allow viewing its children
    if (addedGroupThatAllowsViewingChildren) {
        Role role = getRole();
        // The role should be updated only if it didn't allow viewing children in the first place
        if (!role.allowsViewingChildren()) {
            role.setAllowsViewingChildren(true);
            roleDao.update(role);
        }
    }
    setSucceeded(true);
}
Also used : Role(org.ovirt.engine.core.common.businessentities.Role) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) RoleGroupMap(org.ovirt.engine.core.common.businessentities.RoleGroupMap)

Example 10 with ActionGroup

use of org.ovirt.engine.core.common.businessentities.ActionGroup in project ovirt-engine by oVirt.

the class AttachActionGroupsToRoleCommand method checkIfGroupsCanBeAttached.

protected boolean checkIfGroupsCanBeAttached(List<String> validationMessages) {
    List<ActionGroup> attachGroups = getParameters().getActionGroups();
    Guid roleId = getParameters().getRoleId();
    Role role = getRole();
    // Get all groups by ID and check if they already exist
    List<ActionGroup> allGroups = getActionGroupsByRoleId(roleId);
    for (ActionGroup group : attachGroups) {
        if (allGroups.contains(group)) {
            // group already exist
            validationMessages.add(EngineMessage.ERROR_CANNOT_ATTACH_ACTION_GROUP_TO_ROLE_ATTACHED.toString());
            return true;
        } else if (role.getType() != RoleType.ADMIN && group.getRoleType() == RoleType.ADMIN) {
            validationMessages.add(EngineMessage.CANNOT_ADD_ACTION_GROUPS_TO_ROLE_TYPE.toString());
            return true;
        }
    }
    return false;
}
Also used : Role(org.ovirt.engine.core.common.businessentities.Role) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)24 ArrayList (java.util.ArrayList)9 Guid (org.ovirt.engine.core.compat.Guid)8 ActionGroupsToRoleParameter (org.ovirt.engine.core.common.action.ActionGroupsToRoleParameter)6 Role (org.ovirt.engine.core.common.businessentities.Role)6 HashMap (java.util.HashMap)3 List (java.util.List)3 RoleGroupMap (org.ovirt.engine.core.common.businessentities.RoleGroupMap)3 SelectionTreeNodeModel (org.ovirt.engine.ui.uicommonweb.models.common.SelectionTreeNodeModel)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Test (org.junit.Test)2 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)2 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)2 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)2 VM (org.ovirt.engine.core.common.businessentities.VM)2 VmBase (org.ovirt.engine.core.common.businessentities.VmBase)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 NameableComparator (org.ovirt.engine.core.common.businessentities.comparators.NameableComparator)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2