Skip to content

Commit

Permalink
Add condition to reaction definition
Browse files Browse the repository at this point in the history
Now we are able to specify a condition for synchronization reaction
application. This allows e.g. skip synchronization for some kinds
of asynchronous updates (MID-5853) while doing it for others (MID-5932).

Also, operation result was removed from SynchronizationContext. Storing
operation result in such structures is quite dangerous and can lead
to wrong tracing of performance and functionality issues.

Various minor code improvements are there as well.
  • Loading branch information
mederly committed Nov 29, 2019
1 parent f71458c commit bcbc5a6
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 232 deletions.
Expand Up @@ -211,9 +211,8 @@ public static boolean isPolicyApplicable(QName objectClass, ShadowKindType kind,
return true;
}

public static boolean isPolicyApplicable(QName objectClass, ShadowKindType kind, String intent, ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException{
public static boolean isPolicyApplicable(QName objectClass, ShadowKindType kind, String intent,
ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource) throws SchemaException {
return isPolicyApplicable(objectClass, kind, intent, synchronizationPolicy, resource, false);

}

}
Expand Up @@ -157,11 +157,8 @@ public class ExpressionConstants {

public static final String VAR_AUDIT_RECORD = "auditRecord";

// Do we need those?
// This one is used in approvals.
public static final String VAR_OBJECT_DELTA = "objectDelta";

// Too vague. modelContext or prismConext should be used instead.
@Deprecated
public static final String VAR_CONTEXT = "context";

public static final String VAR_RESOURCE_OBJECT_DELTA = "resourceObjectDelta";
}
Expand Up @@ -11170,6 +11170,18 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="condition" type="c:ExpressionType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Expression that is evaluated to check whether this reaction is applicable in a particular
context. It is assumed to return a boolean value. If it returns 'true' then this reaction
will be applied. If it returns 'false' it will be ignored.
</xsd:documentation>
<xsd:appinfo>
<a:since>4.1</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="action" type="tns:SynchronizationActionType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
Expand Down
Expand Up @@ -1724,7 +1724,7 @@ public <F extends FocusType> List<F> getFocusesByCorrelationRule(Class<F> type,
resource = getObject(ResourceType.class, resourceOid, GetOperationOptions.createNoFetchCollection());
} catch (ObjectNotFoundException | SchemaException | CommunicationException | ConfigurationException
| SecurityViolationException | ExpressionEvaluationException e) {
LOGGER.error("Cannot get resource, reason: {}", e);
LOGGER.error("Cannot get resource, reason: {}", e.getMessage(), e);
return null;
}
SynchronizationType synchronization = resource.getSynchronization();
Expand All @@ -1737,18 +1737,20 @@ public <F extends FocusType> List<F> getFocusesByCorrelationRule(Class<F> type,
discriminator.setIntent(intent);

SynchronizationContext<F> syncCtx = new SynchronizationContext<>(shadow.asPrismObject(), shadow.asPrismObject(),
resource.asPrismObject(), getCurrentTask().getChannel(), getPrismContext(), getCurrentTask(), getCurrentResult());
null, resource.asPrismObject(), getCurrentTask().getChannel(), getPrismContext(), expressionFactory, getCurrentTask());

ObjectSynchronizationType applicablePolicy = null;

OperationResult result = getCurrentResult();

try {

SystemConfigurationType systemConfiguration = modelInteractionService.getSystemConfiguration(getCurrentResult());
SystemConfigurationType systemConfiguration = modelInteractionService.getSystemConfiguration(result);
syncCtx.setSystemConfiguration(systemConfiguration.asPrismObject());

for (ObjectSynchronizationType objectSync : synchronization.getObjectSynchronization()) {

if (SynchronizationServiceUtils.isPolicyApplicable(objectSync, discriminator, expressionFactory, syncCtx)) {
if (SynchronizationServiceUtils.isPolicyApplicable(objectSync, discriminator, expressionFactory, syncCtx, result)) {
applicablePolicy = objectSync;
break;
}
Expand All @@ -1758,7 +1760,7 @@ public <F extends FocusType> List<F> getFocusesByCorrelationRule(Class<F> type,
return null;
}

List<PrismObject<F>> correlatedFocuses = correlationConfirmationEvaluator.findFocusesByCorrelationRule(type, shadow, applicablePolicy.getCorrelation(), resource, systemConfiguration, syncCtx.getTask(), syncCtx.getResult());
List<PrismObject<F>> correlatedFocuses = correlationConfirmationEvaluator.findFocusesByCorrelationRule(type, shadow, applicablePolicy.getCorrelation(), resource, systemConfiguration, syncCtx.getTask(), result);
return MiscSchemaUtil.toObjectableList(correlatedFocuses);

} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException
Expand Down
Expand Up @@ -508,9 +508,9 @@ private void doFixIntent(ShadowCheckResult checkResult, PrismObject<ShadowType>
return;
}

SynchronizationContext<? extends FocusType> syncCtx = null;
SynchronizationContext<? extends FocusType> syncCtx;
try {
syncCtx = synchronizationService.loadSynchronizationContext(fullShadow, fullShadow, resource, task.getChannel(), systemObjectCache.getSystemConfiguration(result), task, result);
syncCtx = synchronizationService.loadSynchronizationContext(fullShadow, fullShadow, null, resource, task.getChannel(), systemObjectCache.getSystemConfiguration(result), task, result);
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | RuntimeException | CommunicationException | ConfigurationException | SecurityViolationException e) {
checkResult.recordError(ShadowStatistics.CANNOT_APPLY_FIX, new SystemException("Couldn't prepare fix for missing intent, because the synchronization policy couldn't be determined", e));
return;
Expand Down
Expand Up @@ -332,7 +332,7 @@ private <F extends FocusType> void processProjections(LensContext<F> context,
boolean match = synchronizationService.matchUserCorrelationRule(fullConflictingShadow,
context.getFocusContext().getObjectNew(), resourceType, context.getSystemConfiguration(), task, result);

if (match){
if (match) {
//check if it is add account (primary delta contains add shadow deltu)..
//if it is add account, create new context for conflicting account..
//it ensures, that conflicting account is linked to the user
Expand Down

0 comments on commit bcbc5a6

Please sign in to comment.