Search in sources :

Example 1 with MRole

use of com.evolveum.midpoint.repo.sqale.qmodel.role.MRole in project midpoint by Evolveum.

the class RoleMemberListRepoTest method fillDatabase.

@Test
public void fillDatabase() throws SchemaException, ObjectAlreadyExistsException {
    OperationResult operationResult = createOperationResult();
    for (int roleIndex = ROLE_MIN; roleIndex <= ROLE_MAX; roleIndex++) {
        String name = String.format("role-%05d", roleIndex);
        RoleType role = new RoleType(prismContext).name(PolyStringType.fromOrig(name));
        try {
            repositoryService.addObject(role.asPrismObject(), null, operationResult);
            roleOids.add(role.getOid());
            System.out.println("Created role " + name);
        } catch (ObjectAlreadyExistsException e) {
            // never mind, we'll use the existing one
            QRole r = aliasFor(QRole.class);
            MRole existingRow = selectOne(r, r.nameOrig.eq(name));
            roleOids.add(existingRow.oid.toString());
            System.out.println("Reused existing role " + name);
        }
    }
    for (int userIndex = USER_MIN; userIndex <= USER_MAX; userIndex++) {
        String name = String.format("user-%07d", userIndex);
        UserType user = new UserType(prismContext).name(PolyStringType.fromOrig(name));
        addRoles(user);
        try {
            repositoryService.addObject(user.asPrismObject(), null, operationResult);
            System.out.println("Created user " + name + " with " + user.getRoleMembershipRef().size() + " roles");
        } catch (ObjectAlreadyExistsException e) {
            System.out.println("User " + name + " already exists");
        }
    }
}
Also used : RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) MRole(com.evolveum.midpoint.repo.sqale.qmodel.role.MRole) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) QRole(com.evolveum.midpoint.repo.sqale.qmodel.role.QRole) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Aggregations

SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)1 MRole (com.evolveum.midpoint.repo.sqale.qmodel.role.MRole)1 QRole (com.evolveum.midpoint.repo.sqale.qmodel.role.QRole)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 Test (org.testng.annotations.Test)1