Skip to content

Commit

Permalink
report-indirect-assignments: added parameters userName and roleRef
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Feb 28, 2023
1 parent afc3b08 commit 11e5c97
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
Expand All @@ -34,6 +35,9 @@ public class TestCsvReportAllAssignments extends TestCsvReport {
private static final TestTask TASK_EXPORT_CLASSIC_ROLE_CACHING = new TestTask(TEST_DIR_REPORTS,
"task-export-role-caching.xml", "0ff414b6-76c6-4d38-95e8-d2d34c7a11cb");

private String appArchetypeOid;
private String appRoleOid;

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
// Only for Native repo, as Generic repo does not support reference search.
Expand All @@ -42,10 +46,10 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
}
super.initSystem(initTask, initResult);

repoAdd(TASK_EXPORT_CLASSIC_ROLE_CACHING, initResult);
repoAdd(REPORT_INDIRECT_ASSIGNMENTS, initResult);
REPORT_INDIRECT_ASSIGNMENTS.init(this, initTask, initResult); // new style (2023-02 and later)
repoAdd(TASK_EXPORT_CLASSIC_ROLE_CACHING, initResult); // old style

String appArchetypeOid = addObject(new ArchetypeType().name("Application")
appArchetypeOid = addObject(new ArchetypeType().name("Application")
.asPrismObject(), initTask, initResult);
String orgOid = addObject(new OrgType().name("Org1")
.asPrismObject(), initTask, initResult);
Expand All @@ -54,7 +58,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
String appServiceOid = addObject(new ServiceType().name("appService")
.assignment(new AssignmentType().targetRef(appArchetypeOid, ArchetypeType.COMPLEX_TYPE))
.asPrismObject(), initTask, initResult);
String appRoleOid = addObject(new RoleType().name("appRole")
appRoleOid = addObject(new RoleType().name("appRole")
.inducement(new AssignmentType().targetRef(appServiceOid, ServiceType.COMPLEX_TYPE))
.asPrismObject(), initTask, initResult);
String businessRoleOid = addObject(new RoleType().name("businessRole")
Expand Down Expand Up @@ -100,8 +104,62 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
public void test100RunReport() throws Exception {
skipIfNotNativeRepository();

// 50 * 3 (normal) + 50 // 3 * 2 (direct assignments + orgs) + 3 (without metadata) + deleted + jack + header
// (subscription footer is considered automatically later, do not count it here)
testExport(TASK_EXPORT_CLASSIC_ROLE_CACHING, REPORT_INDIRECT_ASSIGNMENTS, 188, REPORT_COLUMN_COUNT, null, null);
when("report is run without any parameters");
List<String> rows = REPORT_INDIRECT_ASSIGNMENTS.export()
.execute(getTestOperationResult());

then("only rows for that user are exported");
assertCsv(rows, "after")
.assertColumns(REPORT_COLUMN_COUNT)
// 50 * 3 (normal) + 50 // 3 * 2 (direct assignments + orgs) + 3 (without metadata) + deleted + jack
.assertRecords(187);
}

@Test
public void test200RunReportWithUserParameter() throws Exception {
skipIfNotNativeRepository();

when("report is run with userName parameter set");
List<String> rows = REPORT_INDIRECT_ASSIGNMENTS.export()
.withParameter("userName", "user-00001")
.execute(getTestOperationResult());

then("only rows for that user are exported");
assertCsv(rows, "after")
.assertColumns(REPORT_COLUMN_COUNT)
.assertRecords(3); // rows for user-00001
}

@Test
public void test210RunReportWithRoleParameter() throws Exception {
skipIfNotNativeRepository();

when("report is run with role parameter set");
List<String> rows = REPORT_INDIRECT_ASSIGNMENTS.export()
.withParameter("roleRef", new ObjectReferenceType().oid(appRoleOid).type(RoleType.COMPLEX_TYPE))
.execute(getTestOperationResult());

then("only rows with that role are exported");
assertCsv(rows, "after")
.assertColumns(REPORT_COLUMN_COUNT)
// 50 normal + 1 without metadata, but still properly matched by ref search
.assertRecords(51);
}

@Test(enabled = false) // TODO when roleArchetypeRef parameter is supported
public void test220RunReportWithRoleParameter() throws Exception {
skipIfNotNativeRepository();

when("report is run with role archetype parameter set");
List<String> rows = REPORT_INDIRECT_ASSIGNMENTS.export()
.withParameter("roleArchetypeRef",
new ObjectReferenceType().oid(appArchetypeOid).type(ArchetypeType.COMPLEX_TYPE))
.execute(getTestOperationResult());

then("only rows with that role are exported");
assertCsv(rows, "after")
.assertColumns(REPORT_COLUMN_COUNT)
// 50 normal + 16 direct + 1 without metadata, but still properly matched by ref search
.assertRecords(67);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,78 @@
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<!--
NOTE: This is the test version of 200-report-indirect-assignments.xml.
If enhanced, add the features into 200-report-indirect-assignments.xml as well.
-->
<report xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="7f1695f2-d826-4d78-a046-b8249b79d2b5">
<name>Indirect assignment report</name>
<description>Shows information stored in roleMembershipRef value metadata.</description>
<!--
Serious report would have this archetype, but it's not available for test.
<assignment>
<targetRef oid="00000000-0000-0000-0000-000000000171" type="ArchetypeType"/>
</assignment>
-->
<objectCollection>
<collection>
<!-- Type is declared in the view element. -->
<filter>
<q:text>
. ownedBy (@type = UserType and @path = roleMembershipRef)
</q:text>
<q:and>
<q:ownedBy>
<q:type>UserType</q:type>
<q:path>roleMembershipRef</q:path>
<q:filter>
<q:equal>
<q:path>name</q:path>
<expression>
<queryInterpretationOfNoValue>filterAll</queryInterpretationOfNoValue>
<path>$userName</path>
</expression>
</q:equal>
</q:filter>
</q:ownedBy>
<q:ref>
<q:path>.</q:path>
<expression>
<queryInterpretationOfNoValue>filterAll</queryInterpretationOfNoValue>
<path>$roleRef</path>
</expression>
</q:ref>
<!--
TODO: this does not work yet, expression is not allowed for collection (multi-value)
<q:ref>
<q:path>.</q:path>
<q:filter>
<q:ref>
<q:path>archetypeRef</q:path>
<expression>
<queryInterpretationOfNoValue>filterAll</queryInterpretationOfNoValue>
<path>$roleArchetypeRef</path>
</expression>
</q:ref>
</q:filter>
</q:ref>
-->
</q:and>
</filter>
</collection>
<parameter>
<name>userName</name>
<type>PolyStringType</type>
</parameter>
<parameter>
<name>roleRef</name>
<type>c:ObjectReferenceType</type>
<targetType>c:AbstractRoleType</targetType>
</parameter>
<!--
TODO: not supported yet
<parameter>
<name>roleArchetypeRef</name>
<type>c:ObjectReferenceType</type>
<targetType>c:ArchetypeRef</targetType>
</parameter>
-->

<subreport>
<!--
This subreport generates additional lines per each metadata value,
Expand Down Expand Up @@ -106,9 +157,7 @@
<expression>
<script>
<objectVariableMode>prismReference</objectVariableMode>
<code>
return object?.relation
</code>
<code>object?.relation</code>
</script>
</expression>
</export>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,6 @@ public SearchResultMetadata searchReferencesIterative(
@Nullable Collection<SelectorOptions<GetOperationOptions>> options,
@NotNull OperationResult parentResult)
throws SchemaException {
// TODO + use in model calls as appropriate
Objects.requireNonNull(query, "Query must be provided for reference search");
Objects.requireNonNull(parentResult, "Operation result must not be null.");
Objects.requireNonNull(handler, "Result handler must not be null.");
Expand Down

0 comments on commit 11e5c97

Please sign in to comment.