Skip to content

Commit

Permalink
Fix target override for inbound mappings
Browse files Browse the repository at this point in the history
This should fix failing model-impl tests.
  • Loading branch information
mederly committed Aug 2, 2022
1 parent aab753e commit fa79120
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@

import org.jetbrains.annotations.NotNull;

import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;

import static com.evolveum.midpoint.repo.common.expression.ExpressionUtil.getPath;
import static com.evolveum.midpoint.schema.constants.ExpressionConstants.VAR_FOCUS;
import static com.evolveum.midpoint.schema.constants.ExpressionConstants.VAR_USER;
import static com.evolveum.midpoint.util.MiscUtil.argCheck;

/**
Expand Down Expand Up @@ -159,7 +162,10 @@ void createMappings(@NotNull PathKeyedMap<List<InboundMappingInContext<?, ?>>> m

String contextDescription = "inbound expression for " + itemDescription + " in " + resource;

ItemPath declaredTargetPath = getPath(mappingBean.getTarget());
ItemPath declaredTargetPath =
stripFocusVariable(
getPath(mappingBean.getTarget()),
contextDescription);
if (ItemPath.isEmpty(declaredTargetPath)) {
throw new ConfigurationException("Empty target path in " + contextDescription);
}
Expand All @@ -175,9 +181,9 @@ void createMappings(@NotNull PathKeyedMap<List<InboundMappingInContext<?, ?>>> m
.contextDescription(contextDescription)
.defaultSource(defaultSource)
.targetContext(target.focusDefinition)
.addVariableDefinition(ExpressionConstants.VAR_USER, target.focus, target.focusDefinition)
.addVariableDefinition(VAR_USER, target.focus, target.focusDefinition)
.addVariableDefinition(ExpressionConstants.VAR_FOCUS, target.focus, target.focusDefinition)
.addAliasRegistration(ExpressionConstants.VAR_USER, ExpressionConstants.VAR_FOCUS)
.addAliasRegistration(VAR_USER, ExpressionConstants.VAR_FOCUS)
.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, shadowVariableValue, shadowVariableDef)
.addVariableDefinition(ExpressionConstants.VAR_SHADOW, shadowVariableValue, shadowVariableDef)
.addVariableDefinition(ExpressionConstants.VAR_PROJECTION, shadowVariableValue, shadowVariableDef)
Expand Down Expand Up @@ -226,6 +232,24 @@ void createMappings(@NotNull PathKeyedMap<List<InboundMappingInContext<?, ?>>> m
}
}

private ItemPath stripFocusVariable(ItemPath targetPath, String contextDescription) {
if (targetPath == null) {
return null;
}
QName variable = targetPath.firstToVariableNameOrNull();
if (variable == null) {
return targetPath;
}
if (VAR_USER.equals(variable.getLocalPart())
|| VAR_FOCUS.equals(variable.getLocalPart())) {
return targetPath.rest();
} else {
throw new IllegalStateException(
String.format("Unsupported variable in target path '%s' in %s. Only $focus and $user are allowed here.",
targetPath, contextDescription));
}
}

private PrismObjectDefinition<ShadowType> getShadowDefinition(PrismObject<ShadowType> shadowNew) {
if (shadowNew != null && shadowNew.getDefinition() != null) {
return shadowNew.getDefinition();
Expand Down

0 comments on commit fa79120

Please sign in to comment.