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 12, 2024
1 parent 2af9bec commit 71ffe54
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 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 @@ -10,12 +10,17 @@
import java.util.List;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.schema.SchemaService;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.processor.ShadowAssociationDefinition;

import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationValueType;

import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.common.LocalizationService;
Expand Down Expand Up @@ -115,19 +120,23 @@ protected PrismContainerValue<ShadowAssociationValueType> createResultValue(
return newAssociationValue.clone(); // It needs to be parent-less when included in the output triple
}

@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) {
throw new ExpressionEvaluationException(
String.format("No association target object definition variable in %s; the expression may be used in"
+ " a wrong place. It is only supposed to create an association.",
+ " 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 @@ -174,6 +183,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 71ffe54

Please sign in to comment.