Skip to content

Commit

Permalink
Remove ModelCommonBeans from AbstractMappingImpl
Browse files Browse the repository at this point in the history
The field was not serializable, and is no longer needed.

This should resolve MID-8061.

(cherry picked from commit 9cf3c69)
  • Loading branch information
mederly committed Sep 22, 2022
1 parent 23bd6ed commit be26ba9
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
* Commonly-used beans for model-common module.
*
Expand All @@ -32,6 +34,17 @@
@Component
public class ModelCommonBeans {

private static ModelCommonBeans instance;

@PostConstruct
public void init() {
instance = this;
}

public static ModelCommonBeans get() {
return instance;
}

@Autowired public PrismContext prismContext;
@Autowired @Qualifier("cacheRepositoryService") public RepositoryService cacheRepositoryService;
@Autowired public MatchingRuleRegistry matchingRuleRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private void recordEvaluationStart() throws SchemaException {
for (SourceTriple<?, ?> sourceTriple : sourceTripleList) {
trace.getSource().get(i)
.setDeltaSetTriple(
DeltaSetTripleType.fromDeltaSetTriple(sourceTriple, prismContext));
DeltaSetTripleType.fromDeltaSetTriple(sourceTriple));
i++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void recordEvaluationStart(ValueTransformationEvaluationModeType mode) throws Sc
for (Source<?, ?> source : context.getSources()) {
trace.beginSource()
.name(source.getName())
.itemDeltaItem(source.toItemDeltaItemType(prismContext));
.itemDeltaItem(source.toItemDeltaItemType());
}
trace.skipEvaluationPlus(context.isSkipEvaluationPlus())
.skipEvaluationMinus(context.isSkipEvaluationMinus())
Expand All @@ -76,7 +76,7 @@ void recordEvaluationStart(ValueTransformationEvaluationModeType mode) throws Sc

void recordEvaluationEnd(PrismValueDeltaSetTriple<V> outputTriple) {
if (trace != null && outputTriple != null) {
trace.setOutput(DeltaSetTripleType.fromDeltaSetTriple(outputTriple, prismContext));
trace.setOutput(DeltaSetTripleType.fromDeltaSetTriple(outputTriple));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,6 @@ public abstract class AbstractMappingImpl<V extends PrismValue, D extends ItemDe
@NotNull final PrismContainerDefinition<ValueMetadataType> valueMetadataDefinition;
//endregion

/**
* Useful Spring beans.
*/
final ModelCommonBeans beans;

//region Working and output properties

/**
Expand Down Expand Up @@ -374,7 +369,6 @@ public abstract class AbstractMappingImpl<V extends PrismValue, D extends ItemDe

//region Constructors and (relatively) simple getters
protected AbstractMappingImpl(AbstractMappingBuilder<V, D, MBT, ?> builder) {
beans = builder.getBeans();
variables = builder.getVariables();
mappingBean = Objects.requireNonNull(builder.getMappingBean(), "Mapping definition cannot be null");
mappingKind = builder.getMappingKind();
Expand Down Expand Up @@ -402,15 +396,15 @@ protected AbstractMappingImpl(AbstractMappingBuilder<V, D, MBT, ?> builder) {
now = builder.getNow();
sources.addAll(builder.getAdditionalSources());
parser = new MappingParser<>(this);
valueMetadataDefinition = beans.prismContext.getSchemaRegistry()
valueMetadataDefinition = PrismContext.get().getSchemaRegistry()
.findContainerDefinitionByCompileTimeClass(ValueMetadataType.class);
}

private MappingSpecificationType createDefaultSpecification() {
MappingSpecificationType specification = new MappingSpecificationType(beans.prismContext);
MappingSpecificationType specification = new MappingSpecificationType();
specification.setMappingName(mappingBean.getName());
if (originObject != null) {
specification.setDefinitionObjectRef(ObjectTypeUtil.createObjectRef(originObject, beans.prismContext));
specification.setDefinitionObjectRef(ObjectTypeUtil.createObjectRef(originObject));
}
return specification;
}
Expand All @@ -424,8 +418,6 @@ protected AbstractMappingImpl(AbstractMappingImpl<V, D, MBT> prototype) {
this.sources.addAll(prototype.sources);
this.variables = prototype.variables;

this.beans = prototype.beans;

this.sourceContext = prototype.sourceContext;
// typedSourceContext as well?
this.defaultSource = prototype.defaultSource;
Expand Down Expand Up @@ -463,7 +455,7 @@ protected AbstractMappingImpl(AbstractMappingImpl<V, D, MBT> prototype) {
}

public ObjectResolver getObjectResolver() {
return beans.objectResolver;
return ModelCommonBeans.get().objectResolver;
}

public QName getItemName() {
Expand Down Expand Up @@ -661,12 +653,12 @@ private OperationResult createOpResultAndRecordStart(String opName, Task task, O
.build();
tracingLevel = result.getTracingLevel(MappingEvaluationTraceType.class);
if (isAtLeastMinimal(tracingLevel)) {
trace = new MappingEvaluationTraceType(beans.prismContext)
trace = new MappingEvaluationTraceType()
.mapping(mappingBean.clone())
.mappingKind(mappingKind)
.implicitSourcePath(implicitSourcePath != null ? new ItemPathType(implicitSourcePath) : null)
.implicitTargetPath(implicitTargetPath != null ? new ItemPathType(implicitTargetPath) : null)
.containingObjectRef(ObjectTypeUtil.createObjectRef(originObject, beans.prismContext));
.containingObjectRef(ObjectTypeUtil.createObjectRef(originObject));
result.addTrace(trace);
} else {
trace = null;
Expand Down Expand Up @@ -799,7 +791,7 @@ private void recordSources() throws SchemaException {
for (Source<?, ?> source : sources) {
trace.beginSource()
.name(source.getName())
.itemDeltaItem(source.toItemDeltaItemType(beans.prismContext));
.itemDeltaItem(source.toItemDeltaItemType());
}
}
}
Expand All @@ -812,15 +804,15 @@ private void recordOutput() {
trace.setPushChanges(pushChanges);
if (isAtLeastNormal(tracingLevel)) {
if (outputTriple != null) {
trace.setOutput(DeltaSetTripleType.fromDeltaSetTriple(outputTriple, beans.prismContext));
trace.setOutput(DeltaSetTripleType.fromDeltaSetTriple(outputTriple));
}
trace.setStateProperties(createStatePropertiesTrace());
}
}
}

private @NotNull MappingStatePropertiesType createStatePropertiesTrace() {
MappingStatePropertiesType properties = new MappingStatePropertiesType(PrismContext.get());
MappingStatePropertiesType properties = new MappingStatePropertiesType();
if (stateProperties != null) {
stateProperties.forEach((name, value) ->
properties.beginProperty()
Expand Down Expand Up @@ -896,7 +888,7 @@ private void checkExistingTargetValues(OperationResult result)
ValueSetDefinition<V, D> rangeSetDef = new ValueSetDefinition<>(rangeSetDefBean, getOutputDefinition(), valueMetadataDefinition,
expressionProfile, name, mappingSpecification, "range",
"range of " + name + " in " + getMappingContextDescription(), task, result);
rangeSetDef.init(beans.expressionFactory);
rangeSetDef.init(ModelCommonBeans.get().expressionFactory);
rangeSetDef.setAdditionalVariables(variables);
for (V originalValue : originalTargetValues) {
if (rangeSetDef.contains(originalValue)) {
Expand Down Expand Up @@ -1023,7 +1015,7 @@ private void addToMinusIfNecessary(V originalValue, ValueSetDefinition<V, D> ran
}
// remove it!
if (outputTriple == null) {
outputTriple = beans.prismContext.deltaFactory().createPrismValueDeltaSetTriple();
outputTriple = PrismContext.get().deltaFactory().createPrismValueDeltaSetTriple();
}

V valueToDelete = (V) originalValue.clone();
Expand Down Expand Up @@ -1235,7 +1227,7 @@ private void recomputeValues() {
}
Visitor visitor = visitable -> {
if (visitable instanceof PrismValue) {
((PrismValue) visitable).recompute(beans.prismContext);
((PrismValue) visitable).recompute(PrismContext.get());
}
};
outputTriple.accept(visitor);
Expand Down Expand Up @@ -1274,16 +1266,20 @@ private void computeConditionTriple(OperationResult result)
ExpressionType conditionExpressionType = mappingBean.getCondition();
if (conditionExpressionType == null) {
// True -> True
conditionOutputTriple = beans.prismContext.deltaFactory().createPrismValueDeltaSetTriple();
conditionOutputTriple.addToZeroSet(beans.prismContext.itemFactory().createPropertyValue(Boolean.TRUE));
conditionOutputTriple = PrismContext.get().deltaFactory().createPrismValueDeltaSetTriple();
conditionOutputTriple.addToZeroSet(PrismContext.get().itemFactory().createPropertyValue(Boolean.TRUE));
} else {
Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression =
ExpressionUtil.createCondition(conditionExpressionType, expressionProfile, beans.expressionFactory,
"condition in " + getMappingContextDescription(), task, result);
ExpressionUtil.createCondition(
conditionExpressionType,
expressionProfile,
ModelCommonBeans.get().expressionFactory,
"condition in " + getMappingContextDescription(),
task, result);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(sources, variables,
"condition in " + getMappingContextDescription(), task);
context.setValuePolicySupplier(valuePolicySupplier);
context.setExpressionFactory(beans.expressionFactory);
context.setExpressionFactory(ModelCommonBeans.get().expressionFactory);
context.setDefaultSource(defaultSource);
context.setMappingQName(mappingQName);
context.setVariableProducer(variableProducer);
Expand All @@ -1295,15 +1291,16 @@ private void computeConditionTriple(OperationResult result)
private void evaluateExpression(OperationResult result)
throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException,
CommunicationException, ConfigurationException, SecurityViolationException {
expression = beans.expressionFactory.makeExpression(mappingBean.getExpression(), getOutputDefinition(), expressionProfile,
expression = ModelCommonBeans.get().expressionFactory.makeExpression(
mappingBean.getExpression(), getOutputDefinition(), expressionProfile,
"expression in " + getMappingContextDescription(), task, result);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(sources, variables,
"expression in " + getMappingContextDescription(), task);
context.setDefaultSource(defaultSource);
context.setSkipEvaluationMinus(!conditionResultOld);
context.setSkipEvaluationPlus(!conditionResultNew);
context.setValuePolicySupplier(valuePolicySupplier);
context.setExpressionFactory(beans.expressionFactory);
context.setExpressionFactory(ModelCommonBeans.get().expressionFactory);
context.setMappingQName(mappingQName);
context.setVariableProducer(variableProducer);
context.setValueMetadataComputer(valueMetadataComputer);
Expand All @@ -1326,7 +1323,7 @@ private void evaluateExpression(OperationResult result)
// so the mapping is applicable.
// Returning null would mean that the mapping is not applicable
// at all.
outputTriple = beans.prismContext.deltaFactory().createPrismValueDeltaSetTriple();
outputTriple = PrismContext.get().deltaFactory().createPrismValueDeltaSetTriple();
}

} else {
Expand Down Expand Up @@ -1539,9 +1536,8 @@ void recordTimeTo(XMLGregorianCalendar timeTo) {
}
}

@NotNull
public ModelCommonBeans getBeans() {
return beans;
public @NotNull ModelCommonBeans getBeans() {
return ModelCommonBeans.get();
}

public @NotNull MappingSpecificationType getMappingSpecification() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.evolveum.midpoint.model.api.ModelExecuteOptions;
import com.evolveum.midpoint.model.api.context.ModelContext;
import com.evolveum.midpoint.model.common.ModelCommonBeans;
import com.evolveum.midpoint.model.common.expression.ModelExpressionThreadLocalHolder;
import com.evolveum.midpoint.model.common.mapping.metadata.TransformationalMetadataComputation;
import com.evolveum.midpoint.model.common.mapping.metadata.ItemValueMetadataProcessingSpec;
Expand Down Expand Up @@ -79,7 +80,7 @@ private ItemValueMetadataProcessingSpec createProcessingSpec(OperationResult res
ItemValueMetadataProcessingSpec processingSpec = ItemValueMetadataProcessingSpec.forScope(TRANSFORMATION);
processingSpec.addPathsToIgnore(mappingBean.getIgnoreMetadataProcessing());
// TODO What about persona mappings? outbound mappings? We should not use object template for that.
processingSpec.populateFromCurrentFocusTemplate(parser.getOutputPath(), beans.objectResolver,
processingSpec.populateFromCurrentFocusTemplate(parser.getOutputPath(), ModelCommonBeans.get().objectResolver,
getMappingContextDescription(), task, result);
processingSpec.addMetadataMappings(mappingBean.getMetadataMapping());
return processingSpec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

package com.evolveum.midpoint.model.common.mapping;

import com.evolveum.midpoint.model.common.ModelCommonBeans;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
Expand Down Expand Up @@ -135,7 +137,7 @@ private <IV extends PrismValue, ID extends ItemDefinition<?>> Source<IV, ID> par
String variableName = sourceQName.getLocalPart();

TypedValue<?> typedSourceObject = ExpressionUtil.resolvePathGetTypedValue(path, m.variables, true,
m.getTypedSourceContext(), m.beans.objectResolver, m.beans.prismContext,
m.getTypedSourceContext(), ModelCommonBeans.get().objectResolver, PrismContext.get(),
"source definition in " + m.getMappingContextDescription(), m.getTask(), result);

Object sourceObject = typedSourceObject != null ? typedSourceObject.getValue() : null;
Expand Down Expand Up @@ -179,7 +181,7 @@ private <IV extends PrismValue, ID extends ItemDefinition<?>> Source<IV, ID> par
m.expressionProfile, variableName, null,
"domain of " + variableName, "domain of " + variableName + " in " + m.getMappingContextDescription(),
m.getTask(), result);
setDef.init(m.beans.expressionFactory);
setDef.init(ModelCommonBeans.get().expressionFactory);
setDef.setAdditionalVariables(m.variables);
try {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.evolveum.midpoint.model.common.mapping;

import com.evolveum.midpoint.model.common.ModelCommonBeans;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.util.ItemDeltaItem;
Expand Down Expand Up @@ -133,7 +134,8 @@ private XMLGregorianCalendar parseTime(MappingTimeDeclarationType timeBean, Oper
time = (XMLGregorianCalendar) referenceTime.clone();
}
} else {
MutablePrismPropertyDefinition<XMLGregorianCalendar> timeDefinition = m.beans.prismContext.definitionFactory().createPropertyDefinition(
MutablePrismPropertyDefinition<XMLGregorianCalendar> timeDefinition =
PrismContext.get().definitionFactory().createPropertyDefinition(
ExpressionConstants.OUTPUT_ELEMENT_NAME, PrimitiveType.XSD_DATETIME);
timeDefinition.setMaxOccurs(1);

Expand All @@ -142,7 +144,7 @@ private XMLGregorianCalendar parseTime(MappingTimeDeclarationType timeBean, Oper
timeVariables.addVariableDefinition(ExpressionConstants.VAR_REFERENCE_TIME, referenceTime, timeDefinition);

PrismPropertyValue<XMLGregorianCalendar> timePropVal = ExpressionUtil.evaluateExpression(m.sources, timeVariables, timeDefinition,
expressionBean, m.expressionProfile, m.beans.expressionFactory, "time expression in " + m.getMappingContextDescription(), m.getTask(), result);
expressionBean, m.expressionProfile, ModelCommonBeans.get().expressionFactory, "time expression in " + m.getMappingContextDescription(), m.getTask(), result);

if (timePropVal == null) {
return null;
Expand All @@ -165,7 +167,7 @@ private XMLGregorianCalendar parseTimeSource(VariableBindingDefinitionType sourc
ItemPath path = m.parser.getSourcePath(source);

Object sourceObject = ExpressionUtil.resolvePathGetValue(path, m.variables, false,
m.getTypedSourceContext(), m.beans.objectResolver, m.beans.prismContext,
m.getTypedSourceContext(), ModelCommonBeans.get().objectResolver, PrismContext.get(),
"reference time definition in " + m.getMappingContextDescription(), m.getTask(), result);
LOGGER.trace("parseTimeSource: path = {}, source object = {}", path, sourceObject);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ private void logEnd() {
if (ivwoTriple != null) {
PrismValueDeltaSetTriple<PrismValue> prismValueDeltaSetTriple = prismContext.deltaFactory().createPrismValueDeltaSetTriple();
ivwoTriple.transform(prismValueDeltaSetTriple, ItemValueWithOrigin::getItemValue);
trace.setDeltaSetTriple(DeltaSetTripleType.fromDeltaSetTriple(prismValueDeltaSetTriple, prismContext));
trace.setDeltaSetTriple(DeltaSetTripleType.fromDeltaSetTriple(prismValueDeltaSetTriple));
}
if (existingItem != null) {
trace.setExistingItem(ItemType.fromItem(existingItem, prismContext));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ public String debugDump(int indent) {
}

@NotNull
public ItemDeltaItemType toItemDeltaItemType(PrismContext prismContext) throws SchemaException {
public ItemDeltaItemType toItemDeltaItemType() throws SchemaException {
ItemDeltaItemType rv = new ItemDeltaItemType();
rv.setOldItem(ItemType.fromItem(getItemOld(), prismContext));
rv.setOldItem(ItemType.fromItem(getItemOld(), PrismContext.get()));
ItemDelta<V, D> delta = getDelta();
if (delta != null) {
rv.getDelta().addAll(DeltaConvertor.toItemDeltaTypes(delta));
}
rv.setNewItem(ItemType.fromItem(getItemNew(), prismContext));
rv.setNewItem(ItemType.fromItem(getItemNew(), PrismContext.get()));
return rv;
}
}

0 comments on commit be26ba9

Please sign in to comment.