Skip to content

Commit

Permalink
TestCsvReportAllAssignments: added orgs + archetype name column
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Feb 27, 2023
1 parent 527b961 commit f15eec6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;

import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.TestReport;
Expand Down Expand Up @@ -43,8 +44,15 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
repoAdd(TASK_EXPORT_CLASSIC_ROLE_CACHING, initResult);
repoAdd(REPORT_INDIRECT_ASSIGNMENTS, initResult);

String appArchetypeOid = addObject(new ArchetypeType().name("Application")
.asPrismObject(), initTask, initResult);
String orgOid = addObject(new OrgType().name("Org1")
.asPrismObject(), initTask, initResult);

// adding role chain: businessRole -> appRole -> appService
String appServiceOid = addObject(new ServiceType().name("appService").asPrismObject(), initTask, initResult);
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")
.inducement(new AssignmentType().targetRef(appServiceOid, ServiceType.COMPLEX_TYPE))
.asPrismObject(), initTask, initResult);
Expand All @@ -67,6 +75,8 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
// To mix it up, every third user has also direct assignment to the service.
user.assignment(new AssignmentType()
.targetRef(appServiceOid, ServiceType.COMPLEX_TYPE)
.targetRef(orgOid, OrgType.COMPLEX_TYPE,
i == 3 ? SchemaConstants.ORG_MANAGER : SchemaConstants.ORG_DEFAULT)
.activation(new ActivationType()
// for some output variation
.validFrom(MiscUtil.asXMLGregorianCalendar(Instant.now().minus(10, ChronoUnit.DAYS)))
Expand All @@ -82,6 +92,6 @@ public void test100RunReport() throws Exception {

// 50 * 3 (normal) + 50 // 3 (direct assignments) + 3 (without metadata) + jack + header
// (subscription footer is considered automatically later, do not count it here)
testExport(TASK_EXPORT_CLASSIC_ROLE_CACHING, REPORT_INDIRECT_ASSIGNMENTS, 171, 8, null, null);
testExport(TASK_EXPORT_CLASSIC_ROLE_CACHING, REPORT_INDIRECT_ASSIGNMENTS, 171, 9, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.evolveum.midpoint.schema.SelectorOptions
import com.evolveum.midpoint.schema.result.OperationResult
import com.evolveum.midpoint.util.exception.ObjectNotFoundException
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType

Expand Down Expand Up @@ -75,19 +76,22 @@
def segmentTargets = assignmentPath.segment
// .collect(s -> midpoint.resolveReferenceIfExists(s?.targetRef)) // slow
.collect(s -> resolveWithRepo(s?.targetRef))
AbstractRoleType role = prismRefValue?.object?.asObjectable() // this one should be available (resolved)

// we'll return object/hashmap for each assignment path metadata value
return [
assignmentPath: m.provenance.assignmentPath,
segmentTargets: segmentTargets,
createTimestamp: m.storage?.createTimestamp,
owner: owner,
targetName: prismRefValue?.object?.name?.orig,
role: role,
roleArchetype: midpoint.getStructuralArchetype(role),
assignment: directAssignment
]
}

private ObjectType resolveWithRepo(ObjectReferenceType ref) {
if (ref == null) return null
try {
var typeDef = prismContext.schemaRegistry.findObjectDefinitionByType(ref.type)
// We're creating ignored operation result as we don't want to contaminate the master
Expand Down Expand Up @@ -129,15 +133,32 @@
<column>
<name>nameColumn</name>
<display>
<label>Access</label>
<label>Role</label>
</display>
<previousColumn>user</previousColumn>
<export>
<expression>
<script>
<objectVariableMode>prismReference</objectVariableMode>
<code>
return data?.targetName
return data?.role?.name?.orig
</code>
</script>
</expression>
</export>
</column>
<column>
<name>archetypeName</name>
<display>
<label>Type</label>
</display>
<previousColumn>nameColumn</previousColumn>
<export>
<expression>
<script>
<objectVariableMode>prismReference</objectVariableMode>
<code>
return data?.roleArchetype?.name?.orig
</code>
</script>
</expression>
Expand All @@ -148,7 +169,7 @@
<display>
<label>Path</label>
</display>
<previousColumn>nameColumn</previousColumn>
<previousColumn>archetypeName</previousColumn>
<export>
<expression>
<script>
Expand Down

0 comments on commit f15eec6

Please sign in to comment.