Skip to content

Commit

Permalink
new repo: fix of missing containerType conditions for assignments/indc.
Browse files Browse the repository at this point in the history
This affects only AbstractRole subtypes, but the problem was that filter
on F_ASSIGNMENT and F_INDUCEMENT were not distinguished properly.
This is fixed now in the mapping, in addition to the owner OID condition
on the ON clause, proper containerType condition is added as well.

(cherry picked from commit 5971d8f)
  • Loading branch information
virgo47 committed Jan 11, 2022
1 parent 9c28807 commit ed42641
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.evolveum.midpoint.repo.sqale.SqaleRepoContext;
import com.evolveum.midpoint.repo.sqale.qmodel.assignment.QAssignmentMapping;
import com.evolveum.midpoint.repo.sqale.qmodel.common.MContainerType;
import com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReferenceMapping;
import com.evolveum.midpoint.repo.sqlbase.JdbcSession;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand Down Expand Up @@ -59,7 +60,8 @@ protected QAssignmentHolderMapping(

addContainerTableMapping(AssignmentHolderType.F_ASSIGNMENT,
QAssignmentMapping.initAssignmentMapping(repositoryContext),
joinOn((o, a) -> o.oid.eq(a.ownerOid)));
joinOn((o, a) -> o.oid.eq(a.ownerOid)
.and(a.containerType.eq(MContainerType.ASSIGNMENT))));

addRefMapping(F_ARCHETYPE_REF, QObjectReferenceMapping.initForArchetype(repositoryContext));
addRefMapping(F_DELEGATED_REF, QObjectReferenceMapping.initForDelegated(repositoryContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.evolveum.midpoint.repo.sqale.SqaleRepoContext;
import com.evolveum.midpoint.repo.sqale.qmodel.assignment.QAssignmentMapping;
import com.evolveum.midpoint.repo.sqale.qmodel.common.MContainerType;
import com.evolveum.midpoint.repo.sqale.qmodel.focus.QFocusMapping;
import com.evolveum.midpoint.repo.sqlbase.JdbcSession;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand Down Expand Up @@ -67,7 +68,8 @@ protected QAbstractRoleMapping(

addContainerTableMapping(F_INDUCEMENT,
QAssignmentMapping.initInducementMapping(repositoryContext),
joinOn((o, a) -> o.oid.eq(a.ownerOid)));
joinOn((o, a) -> o.oid.eq(a.ownerOid)
.and(a.containerType.eq(MContainerType.INDUCEMENT))));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class SqaleRepoSearchTest extends SqaleRepoBaseTest {
private String accCertCampaign1Oid;
private String connector1Oid;
private String connector2Oid;
private String roleOid; // role for assignment-vs-inducement tests

// other info used in queries
private final QName relation1 = QName.valueOf("{https://random.org/ns}rel-1");
Expand Down Expand Up @@ -401,6 +402,15 @@ public void initObjects() throws Exception {
.framework(SchemaConstants.UCF_FRAMEWORK_URI_BUILTIN)
.asPrismObject(), null, result);

roleOid = repositoryService.addObject(
new RoleType(prismContext)
.name("role-ass-vs-ind")
.assignment(new AssignmentType(prismContext)
.lifecycleState("role-ass-lc"))
.inducement(new AssignmentType(prismContext)
.lifecycleState("role-ind-lc"))
.asPrismObject(), null, result);

// objects for OID range tests
List.of("00000000-1000-0000-0000-000000000000",
"00000000-1000-0000-0000-000000000001",
Expand Down Expand Up @@ -631,15 +641,37 @@ public void test151SearchUserByOrganizationUnits() throws Exception {
}

@Test
public void test160SearchShadowByObjectClass() throws SchemaException {
public void test160SearchRoleByAssignment() throws SchemaException {
searchObjectTest("having assignment with specified lifecycle", RoleType.class,
f -> f.item(RoleType.F_ASSIGNMENT, AssignmentType.F_LIFECYCLE_STATE).eq("role-ass-lc"),
roleOid);
}

@Test
public void test161SearchRoleByInducementWithWrongName() throws SchemaException {
// this shows the bug when the containerType condition is missing in the query
searchObjectTest("having inducement with specified (wrong) lifecycle", RoleType.class,
f -> f.item(RoleType.F_INDUCEMENT, AssignmentType.F_LIFECYCLE_STATE).eq("role-ass-lc"));
// nothing must be found
}

@Test
public void test162SearchRoleByInducementWithRightName() throws SchemaException {
searchObjectTest("having inducement with specified lifecycle", RoleType.class,
f -> f.item(RoleType.F_INDUCEMENT, AssignmentType.F_LIFECYCLE_STATE).eq("role-ind-lc"),
roleOid);
}

@Test
public void test170SearchShadowByObjectClass() throws SchemaException {
// this uses URI mapping with QName instead of String
searchObjectTest("having specified object class", ShadowType.class,
f -> f.item(ShadowType.F_OBJECT_CLASS).eq(SchemaConstants.RI_ACCOUNT_OBJECT_CLASS),
shadow1Oid);
}

@Test
public void test170SearchShadowOwner() {
public void test171SearchShadowOwner() {
when("searching for shadow owner by shadow OID");
OperationResult operationResult = createOperationResult();
PrismObject<UserType> result =
Expand All @@ -654,7 +686,7 @@ public void test170SearchShadowOwner() {
}

@Test
public void test171SearchShadowOwnerByNonexistentOid() {
public void test172SearchShadowOwnerByNonexistentOid() {
when("searching for shadow owner by shadow OID");
OperationResult operationResult = createOperationResult();
PrismObject<UserType> result =
Expand Down

0 comments on commit ed42641

Please sign in to comment.