use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType in project midpoint by Evolveum.
the class OutboundProcessor method evaluateMapping.
private <F extends FocusType, V extends PrismValue, D extends ItemDefinition> Mapping<V, D> evaluateMapping(final Mapping.Builder<V, D> mappingBuilder, QName mappingQName, D targetDefinition, ObjectDeltaObject<F> focusOdo, ObjectDeltaObject<ShadowType> projectionOdo, String operation, RefinedObjectClassDefinition rOcDef, RefinedObjectClassDefinition assocTargetObjectClassDefinition, LensContext<F> context, LensProjectionContext projCtx, final Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
if (!mappingBuilder.isApplicableToChannel(context.getChannel())) {
LOGGER.trace("Skipping outbound mapping for {} because the channel does not match", mappingQName);
return null;
}
// TODO: check access
// This is just supposed to be an optimization. The consolidation should deal with the weak mapping
// even if it is there. But in that case we do not need to evaluate it at all.
// Edit 2017-02-16 pmed: It's not quite true. If the attribute is non-tolerant, it will get removed if we would
// skip evaluation of this mapping. So we really need to do this.
// if (mappingBuilder.getStrength() == MappingStrengthType.WEAK && projCtx.hasValueForAttribute(mappingQName)) {
// LOGGER.trace("Skipping outbound mapping for {} because it is weak", mappingQName);
// return null;
// }
mappingBuilder.setDefaultTargetDefinition(targetDefinition);
mappingBuilder.setSourceContext(focusOdo);
mappingBuilder.setMappingQName(mappingQName);
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_USER, focusOdo);
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_FOCUS, focusOdo);
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, projectionOdo);
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_SHADOW, projectionOdo);
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_PROJECTION, projectionOdo);
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_CONFIGURATION, context.getSystemConfiguration());
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ITERATION, LensUtil.getIterationVariableValue(projCtx));
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ITERATION_TOKEN, LensUtil.getIterationTokenVariableValue(projCtx));
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_RESOURCE, projCtx.getResource());
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_OPERATION, operation);
if (assocTargetObjectClassDefinition != null) {
mappingBuilder.addVariableDefinition(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION, assocTargetObjectClassDefinition);
}
mappingBuilder.setRootNode(focusOdo);
mappingBuilder.setOriginType(OriginType.OUTBOUND);
mappingBuilder.setRefinedObjectClassDefinition(rOcDef);
StringPolicyResolver stringPolicyResolver = new StringPolicyResolver() {
private ItemPath outputPath;
private ItemDefinition outputDefinition;
@Override
public void setOutputPath(ItemPath outputPath) {
this.outputPath = outputPath;
}
@Override
public void setOutputDefinition(ItemDefinition outputDefinition) {
this.outputDefinition = outputDefinition;
}
@Override
public StringPolicyType resolve() {
if (mappingBuilder.getMappingType().getExpression() != null) {
List<JAXBElement<?>> evaluators = mappingBuilder.getMappingType().getExpression().getExpressionEvaluator();
for (JAXBElement jaxbEvaluator : evaluators) {
Object object = jaxbEvaluator.getValue();
if (object instanceof GenerateExpressionEvaluatorType && ((GenerateExpressionEvaluatorType) object).getValuePolicyRef() != null) {
ObjectReferenceType ref = ((GenerateExpressionEvaluatorType) object).getValuePolicyRef();
try {
ValuePolicyType valuePolicyType = mappingBuilder.getObjectResolver().resolve(ref, ValuePolicyType.class, null, "resolving value policy for generate attribute " + outputDefinition.getName() + "value", task, new OperationResult("Resolving value policy"));
if (valuePolicyType != null) {
return valuePolicyType.getStringPolicy();
}
} catch (CommonException ex) {
throw new SystemException(ex.getMessage(), ex);
}
}
}
}
return null;
}
};
mappingBuilder.setStringPolicyResolver(stringPolicyResolver);
// (e.g. in old values in ADD situations and new values in DELETE situations).
if (focusOdo.getOldObject() == null) {
mappingBuilder.setConditionMaskOld(false);
}
if (focusOdo.getNewObject() == null) {
mappingBuilder.setConditionMaskNew(false);
}
Mapping<V, D> mapping = mappingBuilder.build();
mappingEvaluator.evaluateMapping(mapping, context, projCtx, task, result);
return mapping;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType in project midpoint by Evolveum.
the class ObjectTemplateProcessor method collectItemDefinitionsFromTemplate.
private Map<ItemPath, ObjectTemplateItemDefinitionType> collectItemDefinitionsFromTemplate(ObjectTemplateType objectTemplateType, String contextDesc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
Map<ItemPath, ObjectTemplateItemDefinitionType> definitions = new HashMap<>();
// Process includes (TODO refactor as a generic method)
for (ObjectReferenceType includeRef : objectTemplateType.getIncludeRef()) {
PrismObject<ObjectTemplateType> includeObject = includeRef.asReferenceValue().getObject();
if (includeObject == null) {
ObjectTemplateType includeObjectType = modelObjectResolver.resolve(includeRef, ObjectTemplateType.class, null, "include reference in " + objectTemplateType + " in " + contextDesc, task, result);
includeObject = includeObjectType.asPrismObject();
// Store resolved object for future use (e.g. next waves).
includeRef.asReferenceValue().setObject(includeObject);
}
LOGGER.trace("Including template {}", includeObject);
ObjectTemplateType includeObjectType = includeObject.asObjectable();
Map<ItemPath, ObjectTemplateItemDefinitionType> includedDefinitions = collectItemDefinitionsFromTemplate(includeObjectType, "include " + includeObject + " in " + objectTemplateType + " in " + contextDesc, task, result);
if (includedDefinitions != null) {
ItemPathUtil.putAllToMap(definitions, includedDefinitions);
}
}
// Process own definitions
for (ObjectTemplateItemDefinitionType def : objectTemplateType.getItem()) {
if (def.getRef() == null) {
throw new IllegalStateException("Item definition with null ref in " + contextDesc);
}
// TODO check for incompatible overrides
ItemPathUtil.putToMap(definitions, def.getRef().getItemPath(), def);
}
return definitions;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType in project midpoint by Evolveum.
the class Expression method evaluate.
public PrismValueDeltaSetTriple<V> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
ExpressionVariables processedVariables = null;
try {
processedVariables = processInnerVariables(context.getVariables(), context.getContextDescription(), context.getTask(), context.getResult());
ExpressionEvaluationContext contextWithProcessedVariables = context.shallowClone();
contextWithProcessedVariables.setVariables(processedVariables);
PrismValueDeltaSetTriple<V> outputTriple;
ObjectReferenceType runAsRef = null;
if (expressionType != null) {
runAsRef = expressionType.getRunAsRef();
}
if (runAsRef == null) {
outputTriple = evaluateExpressionEvaluators(contextWithProcessedVariables);
} else {
UserType userType = objectResolver.resolve(runAsRef, UserType.class, null, "runAs in " + context.getContextDescription(), context.getTask(), context.getResult());
LOGGER.trace("Running {} as {} ({})", context.getContextDescription(), userType, runAsRef);
try {
outputTriple = securityEnforcer.runAs(() -> {
try {
return evaluateExpressionEvaluators(contextWithProcessedVariables);
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException e) {
throw new TunnelException(e);
}
}, userType.asPrismObject());
} catch (TunnelException te) {
Throwable e = te.getCause();
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
if (e instanceof Error) {
throw (Error) e;
}
if (e instanceof SchemaException) {
throw (SchemaException) e;
}
if (e instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException) e;
}
if (e instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) e;
}
throw te;
}
}
traceSuccess(context, processedVariables, outputTriple);
return outputTriple;
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | RuntimeException | Error e) {
traceFailure(context, processedVariables, e);
throw e;
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType in project midpoint by Evolveum.
the class ExpressionUtil method resolvePath.
public static Object resolvePath(ItemPath path, ExpressionVariables variables, Object defaultContext, ObjectResolver objectResolver, String shortDesc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
Object root = defaultContext;
ItemPath relativePath = path;
ItemPathSegment first = path.first();
String varDesc = "default context";
if (first.isVariable()) {
QName varName = ((NameItemPathSegment) first).getName();
varDesc = "variable " + PrettyPrinter.prettyPrint(varName);
relativePath = path.rest();
if (variables.containsKey(varName)) {
root = variables.get(varName);
} else {
throw new SchemaException("No variable with name " + varName + " in " + shortDesc);
}
}
if (root == null) {
return null;
}
if (relativePath.isEmpty()) {
return root;
}
if (root instanceof ObjectReferenceType) {
root = resolveReference((ObjectReferenceType) root, objectResolver, varDesc, shortDesc, task, result);
}
if (root instanceof Objectable) {
return (((Objectable) root).asPrismObject()).find(relativePath);
}
if (root instanceof PrismObject<?>) {
return ((PrismObject<?>) root).find(relativePath);
} else if (root instanceof PrismContainer<?>) {
return ((PrismContainer<?>) root).find(relativePath);
} else if (root instanceof PrismContainerValue<?>) {
return ((PrismContainerValue<?>) root).find(relativePath);
} else if (root instanceof Item<?, ?>) {
// Except for container (which is handled above)
throw new SchemaException("Cannot apply path " + relativePath + " to " + root + " in " + shortDesc);
} else if (root instanceof ObjectDeltaObject<?>) {
return ((ObjectDeltaObject<?>) root).findIdi(relativePath);
} else if (root instanceof ItemDeltaItem<?, ?>) {
return ((ItemDeltaItem<?, ?>) root).findIdi(relativePath);
} else {
throw new IllegalArgumentException("Unexpected root " + root + " (relative path:" + relativePath + ") in " + shortDesc);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType in project midpoint by Evolveum.
the class AbstractAdLdapMultidomainTest method test515AddOrgGroupMeleeIslandPirates.
/**
* Create role under the Melee Island org. This creates group in the orgstruct.
*/
@Test
public void test515AddOrgGroupMeleeIslandPirates() throws Exception {
final String TEST_NAME = "test515AddOrgGroupMeleeIslandPirates";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(TEST_NAME);
OperationResult result = task.getResult();
PrismObject<RoleType> role = instantiateObject(RoleType.class);
RoleType roleType = role.asObjectable();
roleType.setName(new PolyStringType(GROUP_MELEE_ISLAND_PIRATES_NAME));
AssignmentType metaroleAssignment = new AssignmentType();
ObjectReferenceType metaroleRef = new ObjectReferenceType();
metaroleRef.setOid(ROLE_META_ORG_GROUP_OID);
metaroleRef.setType(RoleType.COMPLEX_TYPE);
metaroleAssignment.setTargetRef(metaroleRef);
roleType.getAssignment().add(metaroleAssignment);
AssignmentType orgAssignment = new AssignmentType();
ObjectReferenceType orgRef = new ObjectReferenceType();
orgRef.setOid(orgMeleeIslandOid);
orgRef.setType(OrgType.COMPLEX_TYPE);
orgAssignment.setTargetRef(orgRef);
roleType.getAssignment().add(orgAssignment);
// WHEN
TestUtil.displayWhen(TEST_NAME);
addObject(role, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
roleMeleeIslandPiratesOid = role.getOid();
// TODO: assert LDAP object
Entry entryOrgGroup = assertLdapOrgGroup(GROUP_MELEE_ISLAND_PIRATES_NAME, GROUP_MELEE_ISLAND_NAME);
PrismObject<RoleType> roleAfter = getObject(RoleType.class, roleMeleeIslandPiratesOid);
display("Role after", roleAfter);
groupMeleeIslandPiratesOid = getSingleLinkOid(roleAfter);
PrismObject<ShadowType> shadow = getShadowModel(groupMeleeIslandPiratesOid);
display("Shadow (model)", shadow);
// assertLdapConnectorInstances(2);
}
Aggregations