Search in sources :

Example 1 with Permits

use of org.ovirt.engine.api.model.Permits in project ovirt-engine by oVirt.

the class BackendRolesResourceTest method testAddRole.

@Test
public void testAddRole() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpCreationExpectations(ActionType.AddRoleWithActionGroups, RoleWithActionGroupsParameters.class, new String[] { "Role.Id", "Role.Name" }, new Object[] { GUIDS[0], NAMES[0] }, true, true, GUIDS[0], QueryType.GetRoleById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    Role model = new Role();
    model.setName(NAMES[0]);
    model.setPermits(new Permits());
    model.getPermits().getPermits().add(new Permit());
    model.getPermits().getPermits().get(0).setId("" + ActionGroup.CREATE_VM.getId());
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Role);
    verifyModel((Role) response.getEntity(), 0);
}
Also used : Role(org.ovirt.engine.api.model.Role) Response(javax.ws.rs.core.Response) Permit(org.ovirt.engine.api.model.Permit) Permits(org.ovirt.engine.api.model.Permits) Test(org.junit.Test)

Example 2 with Permits

use of org.ovirt.engine.api.model.Permits in project ovirt-engine by oVirt.

the class V3PermitsInAdapter method adapt.

@Override
public Permits adapt(V3Permits from) {
    Permits to = new Permits();
    if (from.isSetActions()) {
        to.setActions(adaptIn(from.getActions()));
    }
    if (from.isSetActive()) {
        to.setActive(from.getActive());
    }
    if (from.isSetSize()) {
        to.setSize(from.getSize());
    }
    if (from.isSetTotal()) {
        to.setTotal(from.getTotal());
    }
    to.getPermits().addAll(adaptIn(from.getPermits()));
    return to;
}
Also used : Permits(org.ovirt.engine.api.model.Permits) V3Permits(org.ovirt.engine.api.v3.types.V3Permits)

Example 3 with Permits

use of org.ovirt.engine.api.model.Permits in project ovirt-engine by oVirt.

the class V3RoleInAdapter method adapt.

@Override
public Role adapt(V3Role from) {
    Role to = new Role();
    if (from.isSetLinks()) {
        to.getLinks().addAll(adaptIn(from.getLinks()));
    }
    if (from.isSetActions()) {
        to.setActions(adaptIn(from.getActions()));
    }
    if (from.isSetAdministrative()) {
        to.setAdministrative(from.isAdministrative());
    }
    if (from.isSetComment()) {
        to.setComment(from.getComment());
    }
    if (from.isSetDescription()) {
        to.setDescription(from.getDescription());
    }
    if (from.isSetId()) {
        to.setId(from.getId());
    }
    if (from.isSetHref()) {
        to.setHref(from.getHref());
    }
    if (from.isSetMutable()) {
        to.setMutable(from.isMutable());
    }
    if (from.isSetName()) {
        to.setName(from.getName());
    }
    if (from.isSetPermits()) {
        to.setPermits(new Permits());
        to.getPermits().getPermits().addAll(adaptIn(from.getPermits().getPermits()));
    }
    if (from.isSetUser()) {
        to.setUser(adaptIn(from.getUser()));
    }
    return to;
}
Also used : Role(org.ovirt.engine.api.model.Role) V3Role(org.ovirt.engine.api.v3.types.V3Role) Permits(org.ovirt.engine.api.model.Permits)

Example 4 with Permits

use of org.ovirt.engine.api.model.Permits in project ovirt-engine by oVirt.

the class BackendClusterLevelsResource method makeClusterLevel.

public ClusterLevel makeClusterLevel(String version) {
    ClusterLevel level = new ClusterLevel();
    level.setId(version);
    // Not exposing CPU list filtered queries:
    if (!isFiltered()) {
        CpuTypes cpuTypes = new CpuTypes();
        for (ServerCpu serverCpu : getServerCpuList(version)) {
            CpuType cpuType = new CpuType();
            cpuType.setName(serverCpu.getCpuName());
            cpuType.setLevel(serverCpu.getLevel());
            cpuType.setArchitecture(CPUMapper.map(serverCpu.getArchitecture(), null));
            cpuTypes.getCpuTypes().add(cpuType);
        }
        level.setCpuTypes(cpuTypes);
    }
    // Add permits:
    Permits permits = new Permits();
    for (ActionGroup actionGroup : getActionGroups()) {
        Permit permit = PermitMapper.map(actionGroup, null);
        permits.getPermits().add(permit);
    }
    level.setPermits(permits);
    return LinkHelper.addLinks(level);
}
Also used : Permit(org.ovirt.engine.api.model.Permit) ActionGroup(org.ovirt.engine.core.common.businessentities.ActionGroup) ClusterLevel(org.ovirt.engine.api.model.ClusterLevel) ServerCpu(org.ovirt.engine.core.common.businessentities.ServerCpu) CpuTypes(org.ovirt.engine.api.model.CpuTypes) CpuType(org.ovirt.engine.api.model.CpuType) Permits(org.ovirt.engine.api.model.Permits)

Example 5 with Permits

use of org.ovirt.engine.api.model.Permits in project ovirt-engine by oVirt.

the class BackendRolesResourceTest method testAddIncompleteParametersNoName.

@Test
public void testAddIncompleteParametersNoName() throws Exception {
    Role model = new Role();
    model.setPermits(new Permits());
    model.getPermits().getPermits().add(new Permit());
    model.getPermits().getPermits().get(0).setId("1");
    setUriInfo(setUpBasicUriExpectations());
    try {
        collection.add(model);
        fail("expected WebApplicationException on incomplete parameters");
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Role", "add", "name");
    }
}
Also used : Role(org.ovirt.engine.api.model.Role) Permit(org.ovirt.engine.api.model.Permit) WebApplicationException(javax.ws.rs.WebApplicationException) Permits(org.ovirt.engine.api.model.Permits) Test(org.junit.Test)

Aggregations

Permits (org.ovirt.engine.api.model.Permits)6 Permit (org.ovirt.engine.api.model.Permit)4 Role (org.ovirt.engine.api.model.Role)4 Test (org.junit.Test)3 WebApplicationException (javax.ws.rs.WebApplicationException)2 Response (javax.ws.rs.core.Response)2 ClusterLevel (org.ovirt.engine.api.model.ClusterLevel)1 CpuType (org.ovirt.engine.api.model.CpuType)1 CpuTypes (org.ovirt.engine.api.model.CpuTypes)1 V3Permits (org.ovirt.engine.api.v3.types.V3Permits)1 V3Role (org.ovirt.engine.api.v3.types.V3Role)1 ActionGroup (org.ovirt.engine.core.common.businessentities.ActionGroup)1 ServerCpu (org.ovirt.engine.core.common.businessentities.ServerCpu)1