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());
}
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());
}
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;
}
}
}
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);
}
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;
}
Aggregations