Skip to content

Commit

Permalink
Adapted TestAssignmentEvaluator to check MID-2192.
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Mar 27, 2017
1 parent 9b8e881 commit d4785ff
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 65 deletions.
Expand Up @@ -331,18 +331,8 @@ private ResourceType resolveTarget(String sourceDescription, Task task, Operatio
if (assignmentPathVariables == null) {
assignmentPathVariables = LensUtil.computeAssignmentPathVariables(assignmentPath);
}

if (assignmentPathVariables != null) {
variables.addVariableDefinition(ExpressionConstants.VAR_IMMEDIATE_ROLE,
assignmentPathVariables.getImmediateRole());
variables.addVariableDefinition(ExpressionConstants.VAR_IMMEDIATE_ASSIGNMENT,
assignmentPathVariables.getImmediateAssignment());
variables.addVariableDefinition(ExpressionConstants.VAR_THIS_ASSIGNMENT,
assignmentPathVariables.getThisAssignment());
variables.addVariableDefinition(ExpressionConstants.VAR_FOCUS_ASSIGNMENT,
assignmentPathVariables.getFocusAssignment());
}
LOGGER.info("Expression valriables for filter evaluation: {}", variables);
Utils.addAssignmentPathVariables(assignmentPathVariables, variables);
LOGGER.info("Expression variables for filter evaluation: {}", variables);

ObjectFilter origFilter = QueryConvertor.parseFilter(constructionType.getResourceRef().getFilter(),
ResourceType.class, prismContext);
Expand All @@ -358,27 +348,21 @@ private ResourceType resolveTarget(String sourceDescription, Task task, Operatio
}

final Collection<PrismObject<ResourceType>> results = new ArrayList<>();
ResultHandler<ResourceType> handler = new ResultHandler<ResourceType>() {

@Override
public boolean handle(PrismObject<ResourceType> object, OperationResult parentResult) {
LOGGER.info("Found object {}", object);
return results.add(object);
}
ResultHandler<ResourceType> handler = (object, parentResult) -> {
LOGGER.info("Found object {}", object);
return results.add(object);
};
objectResolver.searchIterative(ResourceType.class, ObjectQuery.createObjectQuery(evaluatedFilter),
null, handler, task, result);

if (org.apache.commons.collections.CollectionUtils.isEmpty(results)) {
throw new IllegalArgumentException("Got null target from repository, filter:" + evaluatedFilter
+ ", class:" + ResourceType.class + " (should not happen, probably a bug) in "
+ sourceDescription);
throw new IllegalArgumentException("Got no target from repository, filter:" + evaluatedFilter
+ ", class:" + ResourceType.class + " in " + sourceDescription);
}

if (results.size() > 1) {
throw new IllegalArgumentException("Got more than one target from repository, filter:"
+ evaluatedFilter + ", class:" + ResourceType.class
+ " (should not happen, probably a bug) in " + sourceDescription);
+ evaluatedFilter + ", class:" + ResourceType.class + " in " + sourceDescription);
}

PrismObject<ResourceType> target = results.iterator().next();
Expand Down
Expand Up @@ -31,6 +31,7 @@
import com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule;
import com.evolveum.midpoint.model.api.context.EvaluatedPolicyRuleTrigger;
import com.evolveum.midpoint.model.common.expression.*;
import com.evolveum.midpoint.model.impl.util.Utils;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.polystring.PrismDefaultPolyStringNormalizer;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
Expand Down Expand Up @@ -975,19 +976,9 @@ private static void mergeExtension(PrismContainer<Containerable> magicExtension,
}

public static <V extends PrismValue,D extends ItemDefinition> Mapping.Builder<V,D> addAssignmentPathVariables(Mapping.Builder<V,D> builder, AssignmentPathVariables assignmentPathVariables) {
if (assignmentPathVariables != null ) {
return builder
.addVariableDefinition(ExpressionConstants.VAR_ASSIGNMENT_PATH, assignmentPathVariables.getAssignmentPath())
.addVariableDefinition(ExpressionConstants.VAR_ASSIGNMENT, assignmentPathVariables.getMagicAssignment())
.addVariableDefinition(ExpressionConstants.VAR_IMMEDIATE_ASSIGNMENT, assignmentPathVariables.getImmediateAssignment())
.addVariableDefinition(ExpressionConstants.VAR_THIS_ASSIGNMENT, assignmentPathVariables.getThisAssignment())
.addVariableDefinition(ExpressionConstants.VAR_FOCUS_ASSIGNMENT, assignmentPathVariables.getFocusAssignment())
.addVariableDefinition(ExpressionConstants.VAR_IMMEDIATE_ROLE, assignmentPathVariables.getImmediateRole());
} else {
// to avoid "no such variable" exceptions in boundary cases
// for null/empty paths we might consider creating empty AssignmentPathVariables objects to keep null/empty path distinction
return builder.addVariableDefinition(ExpressionConstants.VAR_ASSIGNMENT_PATH, (Object) null);
}
ExpressionVariables expressionVariables = new ExpressionVariables();
Utils.addAssignmentPathVariables(assignmentPathVariables, expressionVariables);
return builder.addVariableDefinitions(expressionVariables.getMap());
}

public static <F extends ObjectType> void checkContextSanity(LensContext<F> context, String activityDescription,
Expand Down
Expand Up @@ -570,11 +570,18 @@ public static <O extends ObjectType> void addDefaultExpressionVariables(Expressi
}

public static void addAssignmentPathVariables(AssignmentPathVariables assignmentPathVariables, ExpressionVariables expressionVariables) {
expressionVariables.addVariableDefinition(ExpressionConstants.VAR_ASSIGNMENT, assignmentPathVariables.getMagicAssignment());
expressionVariables.addVariableDefinition(ExpressionConstants.VAR_IMMEDIATE_ASSIGNMENT, assignmentPathVariables.getImmediateAssignment());
expressionVariables.addVariableDefinition(ExpressionConstants.VAR_THIS_ASSIGNMENT, assignmentPathVariables.getThisAssignment());
expressionVariables.addVariableDefinition(ExpressionConstants.VAR_FOCUS_ASSIGNMENT, assignmentPathVariables.getFocusAssignment());
expressionVariables.addVariableDefinition(ExpressionConstants.VAR_IMMEDIATE_ROLE, assignmentPathVariables.getImmediateRole());
if (assignmentPathVariables != null) {
expressionVariables.addVariableDefinition(ExpressionConstants.VAR_ASSIGNMENT, assignmentPathVariables.getMagicAssignment());
expressionVariables.addVariableDefinition(ExpressionConstants.VAR_ASSIGNMENT_PATH, assignmentPathVariables.getAssignmentPath());
expressionVariables.addVariableDefinition(ExpressionConstants.VAR_IMMEDIATE_ASSIGNMENT, assignmentPathVariables.getImmediateAssignment());
expressionVariables.addVariableDefinition(ExpressionConstants.VAR_THIS_ASSIGNMENT, assignmentPathVariables.getThisAssignment());
expressionVariables.addVariableDefinition(ExpressionConstants.VAR_FOCUS_ASSIGNMENT, assignmentPathVariables.getFocusAssignment());
expressionVariables.addVariableDefinition(ExpressionConstants.VAR_IMMEDIATE_ROLE, assignmentPathVariables.getImmediateRole());
} else {
// to avoid "no such variable" exceptions in boundary cases
// for null/empty paths we might consider creating empty AssignmentPathVariables objects to keep null/empty path distinction
expressionVariables.addVariableDefinition(ExpressionConstants.VAR_ASSIGNMENT_PATH, null);
}
}

public static String getPolicyDesc(ObjectSynchronizationType synchronizationPolicy) {
Expand Down
Expand Up @@ -25,9 +25,6 @@ xmlns:ext="http://midpoint.evolveum.com/xml/ns/samples/piracy"
</extension>
<assignment id="1">
<targetRef oid="12345678-d34d-b33f-f00d-55555555a010" type="RoleType"/> <!-- job metarole -->
</assignment>
<assignment id="2">
<targetRef oid="12345678-d34d-b33f-f00d-55555555a020" type="RoleType"/> <!-- generic metarole (see comment in that role) -->
</assignment>
<assignment id="4">
<policyRule>
Expand Down
Expand Up @@ -25,9 +25,6 @@
</extension>
<assignment id="1">
<targetRef oid="12345678-d34d-b33f-f00d-55555555a010" type="RoleType"/> <!-- job metarole -->
</assignment>
<assignment id="2">
<targetRef oid="12345678-d34d-b33f-f00d-55555555a020" type="RoleType"/> <!-- generic metarole (see comment in that role) -->
</assignment>
<assignment id="4">
<policyRule>
Expand Down
Expand Up @@ -26,9 +26,6 @@ xmlns:ext="http://midpoint.evolveum.com/xml/ns/samples/piracy"
<assignment id="1">
<targetRef oid="12345678-d34d-b33f-f00d-55555555a010" type="RoleType"/> <!-- job metarole -->
</assignment>
<assignment id="2">
<targetRef oid="12345678-d34d-b33f-f00d-55555555a020" type="RoleType"/> <!-- generic metarole (see comment in that role) -->
</assignment>
<inducement id="3">
<targetRef oid="12345678-d34d-b33f-f00d-55555555a001" type="RoleType"/> <!-- employee role -->
</inducement>
Expand Down
Expand Up @@ -51,7 +51,10 @@ metaroles:
<q:equal>
<q:path>name</q:path>
<expression>
<path>$immediateRole/extension/ext:resourceName</path> <!-- should be Dummy Resource -->
<path>$assignment/extension/ext:resourceName</path> <!-- should be Dummy Resource -->
<!-- originally here was "immediateRole"; however, this does not work on the path of
(e.g.) Engineer->JobMetarole->GenericMetarole ... so perhaps the easier solution
is to use magic assignment that contains all the extensions on the path -->
</expression>
</q:equal>
</filter>
Expand Down
Expand Up @@ -35,6 +35,14 @@ metaroles:
- Generic Metarole: assigned to Visitor and Customer
- Job Metarole (induces Generic Metarole): assigned to Contractor, Employee, Engineer, Manager
Job Metarole ========[I]===========> Generic Metarole
^^ ^ ^ ^
|| | | |
+=========|| | | |
| | +=======|==+===[I]====+ | |
| | | | | | | |
| | | | | V | |
Contractor Engineer Manager Employee Visitor Customer
-->

<role oid="12345678-d34d-b33f-f00d-55555555a020"
Expand Down
Expand Up @@ -20,13 +20,11 @@
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3">
<name>Job Metarole Dynamic</name>
<description>Metarole for all job roles</description>
<!--<inducement id="1">-->
<!--<targetRef oid="12345678-d34d-b33f-f00d-55555555a020" type="RoleType"/>-->
<!-- generic metarole -->
<inducement id="1">
<targetRef oid="12345678-d34d-b33f-f00d-55555555a020" type="RoleType"/> <!-- generic metarole -->
<!-- Generic metarole should be induced to any bearer of this role (job metarole) -->
<!-- So roles of Contractor, Employee, Engineer and Manager should be assigned the Generic Metarole as well as they are assigned Job Metarole -->
<!-- THIS DOES NOT WORK (MID-2192) SO IT IS COMMENTED OUT HERE, AND REPLACED BY DIRECT ASSIGNMENTS IN CORRESPONDING ROLES -->
<!--</inducement>-->
</inducement>
<inducement id="2">
<construction>
<resourceRef type="ResourceType"> <!-- should be evaluated to oid="10000000-0000-0000-0000-000000000004" -->
Expand Down
Expand Up @@ -19,13 +19,11 @@
xmlns:ri="http://midpoint.evolveum.com/xml/ns/public/resource/instance-3">
<name>Job Metarole</name>
<description>Metarole for all job roles</description>
<!--<inducement id="1">-->
<!--<targetRef oid="12345678-d34d-b33f-f00d-55555555a020" type="RoleType"/>-->
<!-- generic metarole -->
<inducement id="1">
<targetRef oid="12345678-d34d-b33f-f00d-55555555a020" type="RoleType"/> <!-- generic metarole -->
<!-- Generic metarole should be induced to any bearer of this role (job metarole) -->
<!-- So roles of Contractor, Employee, Engineer and Manager should be assigned the Generic Metarole as well as they are assigned Job Metarole -->
<!-- THIS DOES NOT WORK (MID-2192) SO IT IS COMMENTED OUT HERE, AND REPLACED BY DIRECT ASSIGNMENTS IN CORRESPONDING ROLES -->
<!--</inducement>-->
</inducement>
<inducement id="2">
<construction>
<resourceRef oid="10000000-0000-0000-0000-000000000004" type="ResourceType"/>
Expand Down
Expand Up @@ -26,9 +26,6 @@
<assignment id="1">
<targetRef oid="12345678-d34d-b33f-f00d-55555555a010" type="RoleType"/> <!-- job metarole -->
</assignment>
<assignment id="2">
<targetRef oid="12345678-d34d-b33f-f00d-55555555a020" type="RoleType"/> <!-- generic metarole (see comment in that role) -->
</assignment>
<inducement id="3">
<targetRef oid="12345678-d34d-b33f-f00d-55555555a001" type="RoleType"/> <!-- employee role -->
</inducement>
Expand Down

0 comments on commit d4785ff

Please sign in to comment.