Search in sources :

Example 6 with Role

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

the class BackendEntityAssignedPermissionsResourceTest method testAddIncompletePermission.

@Test
public void testAddIncompletePermission() throws Exception {
    Permission model = new Permission();
    model.setDataCenter(new DataCenter());
    model.getDataCenter().setId(GUIDS[2].toString());
    model.setRole(new Role());
    model.getRole().setId(GUIDS[3].toString());
    setUriInfo(setUpBasicUriExpectations());
    try {
        collection.add(model);
    } catch (WebApplicationException wae) {
        verifyIncompleteException(wae, "Permission", "add", "user|group.id");
    }
}
Also used : Role(org.ovirt.engine.api.model.Role) DataCenter(org.ovirt.engine.api.model.DataCenter) WebApplicationException(javax.ws.rs.WebApplicationException) Permission(org.ovirt.engine.api.model.Permission) Test(org.junit.Test)

Example 7 with Role

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

the class BackendEntityAssignedPermissionsResourceTest method testAddGroupPermission.

@Test
public void testAddGroupPermission() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpCreationExpectations(ActionType.AddPermission, PermissionsOperationsParameters.class, new String[] { "Group.Id", "Permission.AdElementId", "Permission.ObjectId", "Permission.RoleId" }, new Object[] { GUIDS[1], GUIDS[1], targetId, GUIDS[3] }, true, true, GUIDS[0], QueryType.GetPermissionById, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    Permission model = new Permission();
    model.setRole(new Role());
    model.getRole().setId(GUIDS[3].toString());
    model.setGroup(new Group());
    model.getGroup().setId(GUIDS[1].toString());
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Permission);
    verifyModel((Permission) response.getEntity(), 0);
}
Also used : Role(org.ovirt.engine.api.model.Role) Response(javax.ws.rs.core.Response) Group(org.ovirt.engine.api.model.Group) Permission(org.ovirt.engine.api.model.Permission) Test(org.junit.Test)

Example 8 with Role

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

the class PermissionMapper method map.

@Mapping(from = Permission.class, to = org.ovirt.engine.core.common.businessentities.Permission.class)
public static org.ovirt.engine.core.common.businessentities.Permission map(Permission model, org.ovirt.engine.core.common.businessentities.Permission template) {
    org.ovirt.engine.core.common.businessentities.Permission entity = template != null ? template : new org.ovirt.engine.core.common.businessentities.Permission();
    if (model.isSetId()) {
        entity.setId(GuidUtils.asGuid(model.getId()));
    }
    if (model.isSetRole()) {
        Role role = model.getRole();
        if (role.isSetId()) {
            entity.setRoleId(GuidUtils.asGuid(role.getId()));
        }
        if (role.isSetName()) {
            entity.setRoleName(role.getName());
        }
    }
    entity.setObjectId(map(model, template != null ? template.getObjectId() : null));
    entity.setObjectType(map(model, template != null ? template.getObjectType() : null));
    return entity;
}
Also used : Role(org.ovirt.engine.api.model.Role)

Example 9 with Role

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

the class PermissionMapper method map.

@Mapping(from = org.ovirt.engine.core.common.businessentities.Permission.class, to = Role.class)
public static Role map(org.ovirt.engine.core.common.businessentities.Permission entity, Role template) {
    Role model = template != null ? template : new Role();
    model.setName(entity.getRoleName());
    model.setId(entity.getRoleId().toString());
    return model;
}
Also used : Role(org.ovirt.engine.api.model.Role)

Example 10 with Role

use of org.ovirt.engine.api.model.Role 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)

Aggregations

Role (org.ovirt.engine.api.model.Role)22 Test (org.junit.Test)12 WebApplicationException (javax.ws.rs.WebApplicationException)8 Permission (org.ovirt.engine.api.model.Permission)8 User (org.ovirt.engine.api.model.User)7 Permits (org.ovirt.engine.api.model.Permits)4 Roles (org.ovirt.engine.api.model.Roles)4 Response (javax.ws.rs.core.Response)3 DataCenter (org.ovirt.engine.api.model.DataCenter)3 Permit (org.ovirt.engine.api.model.Permit)3 Group (org.ovirt.engine.api.model.Group)2 V3Role (org.ovirt.engine.api.v3.types.V3Role)1