Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/tmp/correlation-cleanup' into fe…
Browse files Browse the repository at this point in the history
…ature/forgot-username

# Conflicts:
#	model/model-api/src/main/java/com/evolveum/midpoint/model/api/correlation/CorrelationService.java
#	model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/correlation/CorrelationServiceImpl.java
  • Loading branch information
KaterynaHonchar committed Jul 19, 2023
2 parents c3ba375 + 885f8b1 commit 10f77f4
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,13 @@
*
* Not to be confused with {@link CorrelatorContext} which describes the context of the whole {@link Correlator} lifespan.
*/
public class CorrelationContext implements DebugDumpable, Cloneable {

/**
* Shadowed resource object to be correlated.
*/
@NotNull private final ShadowType resourceObject;
public abstract class CorrelationContext implements DebugDumpable, Cloneable {

/**
* Focus that was created using pre-mappings.
* May be empty (but not null) e.g. if there are no such mappings.
*/
@NotNull private final FocusType preFocus;

/**
* Resource on which the correlated shadow resides.
*/
@NotNull private final ResourceType resource;

/**
* Usually resource object type definition (~ schemaHandling section).
*/
@NotNull private final ResourceObjectDefinition resourceObjectDefinition;
@NotNull final FocusType preFocus;

/**
* System configuration to use during the correlation.
Expand All @@ -70,25 +55,14 @@ public class CorrelationContext implements DebugDumpable, Cloneable {
private AbstractCorrelatorStateType correlatorState;

public CorrelationContext(
@NotNull ShadowType resourceObject,
@NotNull FocusType preFocus,
@NotNull ResourceType resource,
@NotNull ResourceObjectDefinition objectDefinition,
@Nullable ObjectTemplateType currentObjectTemplate, // TODO remove?
@Nullable SystemConfigurationType systemConfiguration,
@NotNull Task task) {
this.resourceObject = resourceObject;
this.preFocus = preFocus;
this.resource = resource;
this.resourceObjectDefinition = objectDefinition;
this.systemConfiguration = systemConfiguration;
this.task = task;
}

public @NotNull ShadowType getResourceObject() {
return resourceObject;
}

public @NotNull FocusType getPreFocus() {
return preFocus;
}
Expand All @@ -97,20 +71,8 @@ public CorrelationContext(
return preFocus.getClass();
}

public @Nullable String getArchetypeOid() {
// Note that the archetype OID can be specified only on the object type. It is not supported
// for legacy synchronization definition. Therefore we may safely access it in the following way:
ResourceObjectTypeDefinition typeDefinition = resourceObjectDefinition.getTypeDefinition();
return typeDefinition != null ? typeDefinition.getArchetypeOid() : null;
}

public @NotNull ResourceType getResource() {
return resource;
}

public @NotNull ResourceObjectDefinition getResourceObjectDefinition() {
return resourceObjectDefinition;
}
/** Returns the archetype for focus objects that the candidate(s) must possess. Null means "no restrictions". */
public abstract @Nullable String getArchetypeOid();

public @Nullable SystemConfigurationType getSystemConfiguration() {
return systemConfiguration;
Expand All @@ -128,27 +90,23 @@ public void setCorrelatorState(AbstractCorrelatorStateType correlatorState) {
return task;
}

@Override
public String toString() {
return "CorrelationContext("
+ getFocusType().getSimpleName() + ", "
+ resourceObjectDefinition.getHumanReadableName() + "@" + resource
+ ')';
}

@Override
public String debugDump(int indent) {
StringBuilder sb = DebugUtil.createTitleStringBuilderLn(getClass(), indent);
DebugUtil.debugDumpWithLabelLn(sb, "resourceObject", resourceObject, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "preFocus", preFocus, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "focusType", getFocusType(), indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "resource", String.valueOf(resource), indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "resourceObjectDefinition", String.valueOf(resourceObjectDefinition), indent + 1);
debugDumpSpecific(sb, indent);
DebugUtil.debugDumpWithLabelLn(sb, "systemConfiguration", String.valueOf(systemConfiguration), indent + 1);
DebugUtil.debugDumpWithLabel(sb, "correlatorState", correlatorState, indent + 1);
return sb.toString();
}

void debugDumpSpecific(StringBuilder sb, int indent) {
// Nothing to do here. To be overridden by subclasses.
}

public @NotNull abstract Shadow asShadowCtx();

/**
* A simple shallow clone. Use with care.
*/
Expand All @@ -160,4 +118,119 @@ public CorrelationContext clone() {
throw new SystemException(e);
}
}

/** Returns the object (e.g. shadow or focus) that is being correlated. Currently for logging purposes. */
@NotNull public abstract ObjectType getPrimaryCorrelatedObject();

/** Context for correlating a shadow to a set of matching focuses. */
public static class Shadow extends CorrelationContext {

/**
* Shadowed resource object to be correlated.
*/
@NotNull private final ShadowType resourceObject;

/**
* Resource on which the correlated shadow resides.
*/
@NotNull private final ResourceType resource;

/**
* Usually resource object type definition (~ schemaHandling section).
*/
@NotNull private final ResourceObjectDefinition resourceObjectDefinition;

public Shadow(
@NotNull ShadowType resourceObject,
@NotNull ResourceType resource,
@NotNull ResourceObjectDefinition resourceObjectDefinition,
@NotNull FocusType preFocus,
@Nullable SystemConfigurationType systemConfiguration,
@NotNull Task task) {
super(preFocus, systemConfiguration, task);
this.resourceObject = resourceObject;
this.resource = resource;
this.resourceObjectDefinition = resourceObjectDefinition;
}

public @NotNull ShadowType getResourceObject() {
return resourceObject;
}

public @NotNull ResourceType getResource() {
return resource;
}

public @NotNull ResourceObjectDefinition getResourceObjectDefinition() {
return resourceObjectDefinition;
}

public @Nullable String getArchetypeOid() {
// Note that the archetype OID can be specified only on the object type. It is not supported
// for legacy synchronization definition. Therefore we may safely access it in the following way:
ResourceObjectTypeDefinition typeDefinition = resourceObjectDefinition.getTypeDefinition();
return typeDefinition != null ? typeDefinition.getArchetypeOid() : null;
}

@Override
public @NotNull Shadow asShadowCtx() {
return this;
}

@Override
public @NotNull ObjectType getPrimaryCorrelatedObject() {
return resourceObject;
}

@Override
public String toString() {
return "CorrelationContext.Shadow("
+ getFocusType().getSimpleName() + ", "
+ resourceObjectDefinition.getHumanReadableName() + "@" + resource
+ ')';
}

@Override
void debugDumpSpecific(StringBuilder sb, int indent) {
DebugUtil.debugDumpWithLabelLn(sb, "resourceObject", resourceObject, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "resource", String.valueOf(resource), indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "resourceObjectDefinition", String.valueOf(resourceObjectDefinition), indent + 1);
}
}

/**
* Context for correlating a focus to a set of matching focuses.
*
* TODO finish this class
*/
public static class Focus extends CorrelationContext {

public Focus(
@NotNull FocusType preFocus, @Nullable SystemConfigurationType systemConfiguration, @NotNull Task task) {
super(preFocus, systemConfiguration, task);
}

@Override
public @NotNull Shadow asShadowCtx() {
throw new IllegalStateException("Focus context cannot be used as shadow context");
}

@Override
public @Nullable String getArchetypeOid() {
throw new UnsupportedOperationException(); // TODO implement
}

@Override
public @NotNull ObjectType getPrimaryCorrelatedObject() {
return preFocus;
}

@Override
public String toString() {
return "CorrelationContext.Focus("
+ getFocusType().getSimpleName() + ", "
+ preFocus
+ ')';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import java.io.Serializable;

import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;

import com.evolveum.midpoint.model.api.correlator.CorrelatorConfiguration;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateCorrelationType;

Expand All @@ -29,6 +31,18 @@
*/
public interface CorrelationService {

/**
* Correlates the provided (partial) focus object to a set of candidate matches.
*
* TODO finish the method signature
*/
@NotNull CompleteCorrelationResult correlate(
@NotNull FocusType preFocus,
@NotNull Task task,
@NotNull OperationResult result)
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException;

/**
* Describes the provided correlation case by providing {@link CorrelationCaseDescription} object.
*
Expand Down

This file was deleted.

0 comments on commit 10f77f4

Please sign in to comment.