Skip to content

Commit

Permalink
Outbound multiaccounts WIP (MID-6242)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Apr 24, 2020
1 parent 0689215 commit c63687f
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 45 deletions.
Expand Up @@ -12,10 +12,7 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.HumanReadableDescribable;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowDiscriminatorType;
Expand All @@ -35,7 +32,7 @@
*
* @author Radovan Semancik
*/
public class ResourceShadowDiscriminator implements Serializable, DebugDumpable, HumanReadableDescribable {
public class ResourceShadowDiscriminator implements Serializable, DebugDumpable, ShortDumpable, HumanReadableDescribable {
private static final long serialVersionUID = 346600684011645741L;

private String resourceOid;
Expand Down Expand Up @@ -286,12 +283,11 @@ public String toString() {
}

@Override
public String toHumanReadableDescription() {
return toHumanReadableDescription(true);
public void shortDump(StringBuilder sb) {
shortDump(sb, true);
}

public String toHumanReadableDescription(boolean writeOid) {
StringBuilder sb = new StringBuilder("RSD(");
private void shortDump(StringBuilder sb, boolean writeOid) {
sb.append(kind==null?"null":kind.value());
sb.append(" (").append(intent);
if (tag != null) {
Expand All @@ -312,6 +308,16 @@ public String toHumanReadableDescription(boolean writeOid) {
if (tombstone) {
sb.append(" TOMBSTONE");
}
}

@Override
public String toHumanReadableDescription() {
return toHumanReadableDescription(true);
}

public String toHumanReadableDescription(boolean writeOid) {
StringBuilder sb = new StringBuilder("RSD(");
shortDump(sb, writeOid);
sb.append(")");
return sb.toString();
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2015 Evolveum and contributors
* Copyright (c) 2010-2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -11,18 +11,32 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @author mederly
* Facade interface that provides insight about construction that was evaluted by projector code.
* It is used for several purposes, e.g. to display all evaluated assignments, both direct and indirect.
*
* WARNING: Implementation of this interface are NOT required to be Serializable.
* They contain "live" data used by projector computation.
* Do NOT store this object in web session.
*
* @author mederly
* @author Radovan Semancik
*/
public interface EvaluatedConstruction extends DebugDumpable {

PrismObject<ResourceType> getResource();

@NotNull
ShadowKindType getKind();

String getIntent();

@Nullable
String getTag();

boolean isDirectlyAssigned();

AssignmentPath getAssignmentPath();
Expand Down
Expand Up @@ -12,6 +12,8 @@
import java.util.Objects;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.delta.DeltaSetTriple;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -64,6 +66,7 @@ public class Construction<AH extends AssignmentHolderType> extends AbstractConst
private static final String OP_EVALUATE = Construction.class.getName() + ".evaluate";

private ObjectType orderOneObject;
private String resourceOid;
private ResolvedResource resolvedResource;
private ExpressionProfile expressionProfile;
private MappingFactory mappingFactory;
Expand All @@ -75,7 +78,11 @@ public class Construction<AH extends AssignmentHolderType> extends AbstractConst
private AssignmentPathVariables assignmentPathVariables = null;
private PrismContainerDefinition<ShadowAssociationType> associationContainerDefinition;
private PrismObject<SystemConfigurationType> systemConfiguration; // only to provide $configuration variable (MID-2372)
private LensProjectionContext projectionContext;

private DeltaSetTriple<EvaluatedConstructionImpl<AH>> evaluatedConstructionTriple;

// TODO: remove


public Construction(ConstructionType constructionType, ObjectType source) {
super(constructionType, source);
Expand Down Expand Up @@ -320,6 +327,7 @@ public void evaluate(Task task, OperationResult parentResult)
ResourceType resource = resolveResource(task, result);
if (resource != null) {
evaluateKindIntentObjectClass(resource, task, result);
createEvaluatedConstructions(task, result);
evaluateAttributes(task, result);
evaluateAssociations(task, result);
result.recordSuccess();
Expand All @@ -338,7 +346,6 @@ public void evaluate(Task task, OperationResult parentResult)
}

private void evaluateKindIntentObjectClass(ResourceType resource, Task task, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
String resourceOid;
if (getConstructionType().getResourceRef() != null) {
resourceOid = getConstructionType().getResourceRef().getOid();
if (resourceOid != null && !resource.getOid().equals(resourceOid)) {
Expand Down Expand Up @@ -385,14 +392,28 @@ private void evaluateKindIntentObjectClass(ResourceType resource, Task task, Ope
auxiliaryObjectClassDefinitions.add(auxOcDef);
}

}

private void createEvaluatedConstructions(Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
PrismValueDeltaSetTriple<PrismPropertyValue<String>> tagTriple = evaluateTagTripe(task, result);
LOGGER.info("XXXX: tagTriple\n{}", DebugUtil.debugDump(tagTriple));

ResourceShadowDiscriminator rsd = new ResourceShadowDiscriminator(resourceOid, kind, getConstructionType().getIntent(), null, false);
projectionContext = getLensContext().findProjectionContext(rsd);
// projection context may not exist yet (existence might not be yet decided)
evaluatedConstructionTriple = getPrismContext().deltaFactory().createDeltaSetTriple();

if (tagTriple == null) {
// Singleaccount case (not multiaccount). We just create a simple EvaluatedConstruction
EvaluatedConstructionImpl<AH> evaluatedConstruction = createEvaluatedConstruction(null);
evaluatedConstructionTriple.addToZeroSet(evaluatedConstruction);

} else {

tagTriple.transform(evaluatedConstructionTriple, tag -> createEvaluatedConstruction(tag.getRealValue()));
}

LOGGER.info("XXXX: evaluatedConstructionTriple\n{}", DebugUtil.debugDump(evaluatedConstructionTriple));
}


private PrismValueDeltaSetTriple<PrismPropertyValue<String>> evaluateTagTripe(Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
ResourceObjectMultiplicityType multiplicity = refinedObjectClassDefinition.getMultiplicity();
if (!RefinedDefinitionUtil.isMultiaccount(multiplicity)) {
Expand Down Expand Up @@ -424,6 +445,13 @@ private PrismValueDeltaSetTriple<PrismPropertyValue<String>> evaluateTagTripe(Ta
return evaluatedMapping.getOutputTriple();
}

private EvaluatedConstructionImpl<AH> createEvaluatedConstruction(String tag) {
ResourceShadowDiscriminator rsd = new ResourceShadowDiscriminator(resourceOid, refinedObjectClassDefinition.getKind(), refinedObjectClassDefinition.getIntent(), tag, false);
EvaluatedConstructionImpl<AH> evaluatedConstruction = new EvaluatedConstructionImpl<>(this, rsd);
evaluatedConstruction.initialize();
return evaluatedConstruction;
}

private void evaluateAttributes(Task task, OperationResult result)
throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, CommunicationException {
attributeMappings = new ArrayList<>();
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum and contributors
* Copyright (c) 2010-2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
Expand All @@ -10,83 +10,88 @@
import com.evolveum.midpoint.model.api.context.AssignmentPath;
import com.evolveum.midpoint.model.api.context.EvaluatedConstruction;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;

import org.jetbrains.annotations.NotNull;

/**
* @author mederly
*/
public class EvaluatedConstructionImpl implements EvaluatedConstruction {
public class EvaluatedConstructionImpl<AH extends AssignmentHolderType> implements EvaluatedConstruction {

@NotNull final private Construction<AH> construction;
@NotNull final private ResourceShadowDiscriminator rsd;

final private PrismObject<ResourceType> resource;
final private ShadowKindType kind;
final private String intent;
final private boolean directlyAssigned;
final private AssignmentPath assignmentPath;
final private boolean weak;
private LensProjectionContext projectionContext;

/**
* @pre construction is already evaluated and not ignored (has resource)
*/
<AH extends AssignmentHolderType> EvaluatedConstructionImpl(Construction<AH> construction) {
resource = construction.getResource().asPrismObject();
kind = construction.getKind();
intent = construction.getIntent();
assignmentPath = construction.getAssignmentPath();
directlyAssigned = assignmentPath == null || assignmentPath.size() == 1;
weak = construction.isWeak();
EvaluatedConstructionImpl(@NotNull final Construction<AH> construction, @NotNull final ResourceShadowDiscriminator rsd) {
this.construction = construction;
this.rsd = rsd;
}

public void initialize() {
projectionContext = construction.getLensContext().findProjectionContext(rsd);
// projection context may not exist yet (existence might not be yet decided)
}

@Override
public PrismObject<ResourceType> getResource() {
return resource;
return construction.getResource().asPrismObject();
}

@Override
public ShadowKindType getKind() {
return kind;
return rsd.getKind();
}

@Override
public String getIntent() {
return intent;
return rsd.getIntent();
}

@Override
public String getTag() {
return rsd.getTag();
}

@Override
public boolean isDirectlyAssigned() {
return directlyAssigned;
return construction.getAssignmentPath() == null || construction.getAssignmentPath().size() == 1;
}

@Override
public AssignmentPath getAssignmentPath() {
return assignmentPath;
return construction.getAssignmentPath();
}

@Override
public boolean isWeak() {
return weak;
return construction.isWeak();
}

@Override
public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
DebugUtil.debugDumpLabelLn(sb, "EvaluatedConstruction", indent);
DebugUtil.debugDumpWithLabelLn(sb, "resource", resource, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "kind", kind.value(), indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "intent", intent, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "directlyAssigned", directlyAssigned, indent + 1);
DebugUtil.debugDumpWithLabel(sb, "weak", weak, indent + 1);
DebugUtil.debugDumpWithLabelShortDumpLn(sb, "discriminator", rsd, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "construction", construction, indent + 1);
DebugUtil.debugDumpWithLabelToString(sb, "projectionContext", projectionContext, indent + 1);
return sb.toString();
}

@Override
public String toString() {
return "EvaluatedConstruction(" +
"resource=" + resource +
", kind=" + kind +
", intent='" + intent +
"discriminator=" + rsd +
", construction=" + construction +
", projectionContext='" + projectionContext +
')';
}
}

0 comments on commit c63687f

Please sign in to comment.