Skip to content

Commit

Permalink
MID-9508: AssociationTargetSearch uses correct shadow definition for MQL
Browse files Browse the repository at this point in the history
Query Language requires correct definition for parsing shadow attributes:
Added support to AssociationTargetSearchEvaluator to parse queries using
correct definition.
  • Loading branch information
tonydamage committed Mar 15, 2024
1 parent e300202 commit 7916b2f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected abstract class Evaluation {
final QName targetTypeQName;

/** Class corresponding to {@link #targetTypeQName}. */
private final Class<O> targetTypeClass;
protected final Class<O> targetTypeClass;

/** Do we have explicitly specified target object OID? */
private final String explicitTargetOid;
Expand Down Expand Up @@ -285,16 +285,20 @@ protected QName getDefaultTargetType() {
}
}

private @NotNull ObjectQuery createQuery()
throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException,
ConfigurationException, SecurityViolationException {

protected ObjectQuery createRawQuery(ExpressionEvaluationContext params) throws ConfigurationException, SchemaException, ExpressionEvaluationException {
SearchFilterType filterBean =
MiscUtil.configNonNull(
expressionEvaluatorBean.getFilter(),
() -> "No filter in " + shortDebugDump());
return prismContext.getQueryConverter().createObjectQuery(targetTypeClass, filterBean);
};


private @NotNull ObjectQuery createQuery()
throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException,
ConfigurationException, SecurityViolationException {

ObjectQuery rawQuery = prismContext.getQueryConverter().createObjectQuery(targetTypeClass, filterBean);
ObjectQuery rawQuery = createRawQuery(context);
LOGGER.trace("XML query converted to: {}", rawQuery.debugDumpLazily());

ObjectQuery evaluatedQuery = ExpressionUtil.evaluateQueryExpressions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ protected PrismContainerValue<ShadowAssociationType> createResultValue(
return associationCVal;
}

@Override
protected ObjectQuery extendQuery(ObjectQuery query, ExpressionEvaluationContext params)
throws ExpressionEvaluationException {
@SuppressWarnings("unchecked")
private ResourceObjectTypeDefinition associationTargetDef(ExpressionEvaluationContext params) throws ExpressionEvaluationException {
var rAssocTargetDefTypedValue = (TypedValue<ResourceObjectTypeDefinition>)
params.getVariables().get(ExpressionConstants.VAR_ASSOCIATION_TARGET_OBJECT_CLASS_DEFINITION);
if (rAssocTargetDefTypedValue == null || rAssocTargetDefTypedValue.getValue() == null) {
Expand All @@ -123,7 +120,14 @@ protected ObjectQuery extendQuery(ObjectQuery query, ExpressionEvaluationContext
+ " a wrong place. It is only supposed to create an association.",
params.getContextDescription()));
}
ResourceObjectTypeDefinition rAssocTargetDef = (ResourceObjectTypeDefinition) rAssocTargetDefTypedValue.getValue();
return (ResourceObjectTypeDefinition) rAssocTargetDefTypedValue.getValue();
}

@Override
protected ObjectQuery extendQuery(ObjectQuery query, ExpressionEvaluationContext params)
throws ExpressionEvaluationException {
@SuppressWarnings("unchecked")
var rAssocTargetDef = associationTargetDef(params);
ObjectFilter coordinatesFilter = prismContext.queryFor(ShadowType.class)
.item(ShadowType.F_RESOURCE_REF).ref(rAssocTargetDef.getResourceOid())
.and().item(ShadowType.F_KIND).eq(rAssocTargetDef.getKind())
Expand Down Expand Up @@ -170,6 +174,17 @@ protected CacheInfo getCacheInfo() {
ShadowType.class);
}

protected ObjectQuery createRawQuery(ExpressionEvaluationContext params) throws ConfigurationException, SchemaException, ExpressionEvaluationException {
SearchFilterType filterBean =
MiscUtil.configNonNull(expressionEvaluatorBean.getFilter(), () -> "No filter in " + shortDebugDump());

var associationTargetDef = associationTargetDef(params);
var concreteShadowDef = associationTargetDef.getPrismObjectDefinition();
var filter = prismContext.getQueryConverter().createObjectFilter(concreteShadowDef, filterBean);
return prismContext.queryFactory().createQuery(filter);
};


};
}

Expand Down

0 comments on commit 7916b2f

Please sign in to comment.