Skip to content

Commit

Permalink
Typed variables: fixing model-intest
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Mar 19, 2019
1 parent fa6d9a3 commit a0363c0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 20 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2018 Evolveum
* Copyright (c) 2014-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,6 +40,7 @@
import com.evolveum.midpoint.schema.ResultHandler;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.expression.TypedValue;
import com.evolveum.midpoint.schema.processor.ObjectFactory;
import com.evolveum.midpoint.schema.processor.ResourceAttribute;
import com.evolveum.midpoint.schema.processor.ResourceAttributeContainer;
Expand Down Expand Up @@ -97,10 +98,12 @@ public PrismValueDeltaSetTriple<PrismContainerValue<ShadowAssociationType>> eval
Integer assignmentPathIndex = evaluatorType.getAssignmentPathIndex();
if (assignmentPathIndex == null) {
// Legacy ... or default in simple cases
Object orderOneObject = context.getVariables().get(ExpressionConstants.VAR_ORDER_ONE_OBJECT);
if (orderOneObject == null) {
@SuppressWarnings("unchecked")
TypedValue<AbstractRoleType> orderOneObjectTypedValue = context.getVariables().get(ExpressionConstants.VAR_ORDER_ONE_OBJECT);
if (orderOneObjectTypedValue == null || orderOneObjectTypedValue.getValue() == null) {
throw new ExpressionEvaluationException("No order one object variable in "+desc+"; the expression may be used in a wrong place. It is only supposed to work in a role.");
}
Object orderOneObject = orderOneObjectTypedValue.getValue();
if (!(orderOneObject instanceof AbstractRoleType)) {
throw new ExpressionEvaluationException("Order one object variable in "+desc+" is not a role, it is "+orderOneObject.getClass().getName()
+"; the expression may be used in a wrong place. It is only supposed to work in a role.");
Expand All @@ -110,11 +113,13 @@ public PrismValueDeltaSetTriple<PrismContainerValue<ShadowAssociationType>> eval

} else {

AssignmentPath assignmentPath = (AssignmentPath) context.getVariables().get(ExpressionConstants.VAR_ASSIGNMENT_PATH);
if (assignmentPath == null) {
@SuppressWarnings("unchecked")
TypedValue<AssignmentPath> assignmentPathTypedValue = context.getVariables().get(ExpressionConstants.VAR_ASSIGNMENT_PATH);
if (assignmentPathTypedValue == null || assignmentPathTypedValue.getValue() == null) {
throw new ExpressionEvaluationException("No assignment path variable in "+desc+"; the expression may be used in a wrong place. It is only supposed to work in a role.");
}

AssignmentPath assignmentPath = (AssignmentPath) assignmentPathTypedValue.getValue();
if (assignmentPath.isEmpty()) {
throw new ExpressionEvaluationException("Empty assignment path variable in "+desc+"; the expression may be used in a wrong place. It is only supposed to work in a role.");
}
Expand All @@ -135,10 +140,11 @@ public PrismValueDeltaSetTriple<PrismContainerValue<ShadowAssociationType>> eval

LOGGER.trace("Evaluating association from link on: {}", thisRole);

RefinedObjectClassDefinition rAssocTargetDef = (RefinedObjectClassDefinition) context.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION);
if (rAssocTargetDef == null) {
TypedValue<RefinedObjectClassDefinition> rAssocTargetDefTypedValue = context.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION);
if (rAssocTargetDefTypedValue == null || rAssocTargetDefTypedValue.getValue() == null) {
throw new ExpressionEvaluationException("No association target object class definition variable in "+desc+"; the expression may be used in a wrong place. It is only supposed to create an association.");
}
RefinedObjectClassDefinition rAssocTargetDef = (RefinedObjectClassDefinition) rAssocTargetDefTypedValue.getValue();

ShadowDiscriminatorType projectionDiscriminator = evaluatorType.getProjectionDiscriminator();
if (projectionDiscriminator == null) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,6 +38,7 @@
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.ExpressionConstants;
import com.evolveum.midpoint.schema.expression.TypedValue;
import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.security.api.SecurityContextManager;
Expand Down Expand Up @@ -75,11 +76,13 @@ protected AbstractSearchExpressionEvaluatorCache getCache() {

@Override
protected ObjectQuery extendQuery(ObjectQuery query, ExpressionEvaluationContext params) throws SchemaException, ExpressionEvaluationException {
RefinedObjectClassDefinition rAssocTargetDef = (RefinedObjectClassDefinition) params.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION);
if (rAssocTargetDef == null) {
@SuppressWarnings("unchecked")
TypedValue<RefinedObjectClassDefinition> rAssocTargetDefTypedValue = params.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION);
if (rAssocTargetDefTypedValue == null || rAssocTargetDefTypedValue.getValue() == null) {
throw new ExpressionEvaluationException("No association target object class definition variable in "+
params.getContextDescription()+"; the expression may be used in a wrong place. It is only supposed to create an association.");
}
RefinedObjectClassDefinition rAssocTargetDef = (RefinedObjectClassDefinition) rAssocTargetDefTypedValue.getValue();
ObjectFilter resourceFilter = ObjectQueryUtil.createResourceFilter(rAssocTargetDef.getResourceOid(), getPrismContext());
ObjectFilter objectClassFilter = ObjectQueryUtil.createObjectClassFilter(rAssocTargetDef.getObjectClassDefinition().getTypeName(),
getPrismContext());
Expand Down
Expand Up @@ -731,13 +731,19 @@ private <F extends FocusType, V extends PrismValue, D extends ItemDefinition> vo
return;
}

PrismObject<ShadowType> accountNew = projectionCtx.getObjectNew();
PrismObject<ShadowType> shadowNew = projectionCtx.getObjectNew();
PrismObjectDefinition<ShadowType> shadowNewDef;
if (shadowNew == null) {
shadowNewDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class);
} else {
shadowNewDef = shadowNew.getDefinition();
}
ExpressionVariables variables = new ExpressionVariables();
variables.put(ExpressionConstants.VAR_USER, focusNew, focusNew.getDefinition());
variables.put(ExpressionConstants.VAR_FOCUS, focusNew, focusNew.getDefinition());
variables.put(ExpressionConstants.VAR_ACCOUNT, accountNew, accountNew.getDefinition());
variables.put(ExpressionConstants.VAR_SHADOW, accountNew, accountNew.getDefinition());
variables.put(ExpressionConstants.VAR_PROJECTION, accountNew, accountNew.getDefinition());
variables.put(ExpressionConstants.VAR_ACCOUNT, shadowNew, shadowNewDef);
variables.put(ExpressionConstants.VAR_SHADOW, shadowNew, shadowNewDef);
variables.put(ExpressionConstants.VAR_PROJECTION, shadowNew, shadowNewDef);
variables.put(ExpressionConstants.VAR_RESOURCE, resource, resource.asPrismObject().getDefinition());
variables.put(ExpressionConstants.VAR_CONFIGURATION, context.getSystemConfiguration(), context.getSystemConfiguration().getDefinition());
variables.put(ExpressionConstants.VAR_OPERATION, context.getFocusContext().getOperation().getValue(), String.class);
Expand Down
Expand Up @@ -142,7 +142,8 @@ public PipelineData execute(ActionExpressionType expression, PipelineData input,
}
Throwable exception = null;
try {
TypedValue<PrismValue> typedValue = new TypedValue<>(value, value.getParent().getDefinition());
// Hack. TODO: we need to add definitions to Pipeline items.
TypedValue typedValue = new TypedValue(value, value == null ? Object.class : value.getClass());
Object outObject = executeScript(scriptExpression, typedValue, item.getVariables(), context, result);
if (outObject != null) {
addToData(outObject, item.getResult(), output);
Expand Down
Expand Up @@ -891,21 +891,21 @@ public void test120AddAccount() throws Exception {
*/
@Test
public void test121ModifyUserAddAccountRef() throws Exception {
TestUtil.displayTestTitle(this, "test121ModifyUserAddAccountRef");
final String TEST_NAME = "test121ModifyUserAddAccountRef";
displayTestTitle(TEST_NAME);

// GIVEN
Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + ".test121ModifyUserAddAccountRef");
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);

ObjectDelta<UserType> userDelta = prismContext.deltaFactory().object()
.createEmptyModifyDelta(UserType.class, USER_JACK_OID);
ReferenceDelta accountDelta = prismContext.deltaFactory().reference().createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountJackOid);
userDelta.addModification(accountDelta);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);

// WHEN
modelService.executeChanges(deltas, null, task, result);
executeChanges(userDelta, null, task, result);

// THEN
assertSuccess(result);
Expand Down
Expand Up @@ -252,7 +252,7 @@ protected TypedValue<ObjectType> resolveTypedObject(SimpleObjectRef ref, boolean
PrismObjectDefinition<ObjectType> def = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ObjectType.class);
return new TypedValue<>(null, def);
} else {
ObjectType resolveObjectType = requester.resolveObjectType(result, allowNotFound);
ObjectType resolveObjectType = ref.resolveObjectType(result, allowNotFound);
return new TypedValue<>(resolveObjectType, resolveObjectType.asPrismObject().getDefinition());
}
}
Expand Down

0 comments on commit a0363c0

Please sign in to comment.