Search in sources :

Example 1 with QUserMapping

use of com.evolveum.midpoint.repo.sqale.qmodel.focus.QUserMapping in project midpoint by Evolveum.

the class SqaleRepoModifyObjectTest method test951ReindexAfterManualChangeOfFullObject.

@Test
public void test951ReindexAfterManualChangeOfFullObject() throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException {
    OperationResult result = createOperationResult();
    UserType user = new UserType(prismContext).name("corrupted").beginAssignment().policySituation("kept").<UserType>end().beginAssignment().policySituation("removed").end();
    String oid = repositoryService.addObject(user.asPrismObject(), null, result);
    when("full object is modified in the database (indices are desynced from full object)");
    user = repositoryService.getObject(UserType.class, oid, null, result).asObjectable();
    // remove removed
    user.getAssignment().remove(1);
    user.beginAssignment().policySituation("added");
    QUserMapping mapping = QUserMapping.getUserMapping();
    byte[] fullObject = mapping.createFullObject(user);
    try (JdbcSession session = mapping.repositoryContext().newJdbcSession().startTransaction()) {
        session.newUpdate(mapping.defaultAlias()).set(mapping.defaultAlias().fullObject, fullObject).where(mapping.defaultAlias().oid.eq(SqaleUtils.oidToUUid(oid))).execute();
        session.commit();
    }
    assertPolicySituationFound("kept", 1, result);
    assertPolicySituationFound("removed", 1, result);
    assertPolicySituationFound("added", 0, result);
    given("object is reindexed");
    RepoModifyOptions options = RepoModifyOptions.createForceReindex();
    repositoryService.modifyObject(UserType.class, oid, Collections.emptyList(), options, result);
    then("indices are updated according new full object");
    assertPolicySituationFound("kept", 1, result);
    assertPolicySituationFound("removed", 0, result);
    assertPolicySituationFound("added", 1, result);
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) RepoModifyOptions(com.evolveum.midpoint.repo.api.RepoModifyOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) QUserMapping(com.evolveum.midpoint.repo.sqale.qmodel.focus.QUserMapping) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Aggregations

PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 RepoModifyOptions (com.evolveum.midpoint.repo.api.RepoModifyOptions)1 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)1 QUserMapping (com.evolveum.midpoint.repo.sqale.qmodel.focus.QUserMapping)1 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Test (org.testng.annotations.Test)1