Skip to content

Commit

Permalink
Multiaccounts: reworking construction collector. It does NOT compile,…
Browse files Browse the repository at this point in the history
… WIP (MID-6242)
  • Loading branch information
semancik committed Apr 30, 2020
1 parent 023c73d commit 9651460
Show file tree
Hide file tree
Showing 12 changed files with 313 additions and 247 deletions.
Expand Up @@ -10,6 +10,7 @@

import com.evolveum.midpoint.prism.OriginType;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.delta.DeltaSetTriple;
import com.evolveum.midpoint.prism.delta.PlusMinusZero;
import com.evolveum.midpoint.prism.util.ObjectDeltaObject;
import com.evolveum.midpoint.repo.common.ObjectResolver;
Expand All @@ -19,30 +20,29 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractConstructionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionStrengthType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;

/**
* @author Radovan Semancik
*/
public abstract class AbstractConstruction<F extends AssignmentHolderType, T extends AbstractConstructionType> implements DebugDumpable, Serializable {
public abstract class AbstractConstruction<AH extends AssignmentHolderType, ACT extends AbstractConstructionType, EC extends EvaluatedConstructionImpl<AH>> implements DebugDumpable, Serializable {

private static final Trace LOGGER = TraceManager.getTrace(AbstractConstruction.class);

private AssignmentPathImpl assignmentPath;
private T constructionType;
private ACT constructionType;
private ObjectType source;
private OriginType originType;
private String channel;
private LensContext<F> lensContext;
private ObjectDeltaObject<F> focusOdo;
private LensContext<AH> lensContext;
private ObjectDeltaObject<AH> focusOdo;
private ObjectResolver objectResolver;
private PrismContext prismContext;
private boolean isValid = true;
private boolean wasValid = true;
private PlusMinusZero relativityMode;

public AbstractConstruction(T constructionType, ObjectType source) {
public AbstractConstruction(ACT constructionType, ObjectType source) {
this.constructionType = constructionType;
this.source = source;
this.assignmentPath = null;
Expand Down Expand Up @@ -72,23 +72,23 @@ public void setChannel(String channel) {
this.channel = channel;
}

public LensContext<F> getLensContext() {
public LensContext<AH> getLensContext() {
return lensContext;
}

public void setLensContext(LensContext<F> lensContext) {
public void setLensContext(LensContext<AH> lensContext) {
this.lensContext = lensContext;
}

public T getConstructionType() {
public ACT getConstructionType() {
return constructionType;
}

public ObjectDeltaObject<F> getFocusOdo() {
public ObjectDeltaObject<AH> getFocusOdo() {
return focusOdo;
}

public void setFocusOdo(ObjectDeltaObject<F> focusOdo) {
public void setFocusOdo(ObjectDeltaObject<AH> focusOdo) {
if (focusOdo.getDefinition() == null) {
throw new IllegalArgumentException("No definition in focus ODO "+focusOdo);
}
Expand Down Expand Up @@ -151,6 +151,8 @@ public void setAssignmentPath(AssignmentPathImpl assignmentPath) {
this.assignmentPath = assignmentPath;
}

public abstract DeltaSetTriple<EC> getEvaluatedConstructionTriple();

@Override
public int hashCode() {
final int prime = 31;
Expand Down
Expand Up @@ -64,7 +64,7 @@
* implements Serializable interface only to be storable in the
* PrismPropertyValue.
*/
public class Construction<AH extends AssignmentHolderType> extends AbstractConstruction<AH, ConstructionType> {
public class Construction<AH extends AssignmentHolderType, EC extends EvaluatedConstructionImpl<AH>> extends AbstractConstruction<AH, ConstructionType, EC> {

private static final Trace LOGGER = TraceManager.getTrace(Construction.class);

Expand All @@ -83,7 +83,7 @@ public class Construction<AH extends AssignmentHolderType> extends AbstractConst
private PrismContainerDefinition<ShadowAssociationType> associationContainerDefinition;
private PrismObject<SystemConfigurationType> systemConfiguration; // only to provide $configuration variable (MID-2372)

private DeltaSetTriple<EvaluatedConstructionImpl<AH>> evaluatedConstructionTriple;
private DeltaSetTriple<EC> evaluatedConstructionTriple;

public Construction(ConstructionType constructionType, ObjectType source) {
super(constructionType, source);
Expand Down Expand Up @@ -185,7 +185,7 @@ public String getIntent() {
return refinedObjectClassDefinition.getIntent();
}

public DeltaSetTriple<EvaluatedConstructionImpl<AH>> getEvaluatedConstructionTriple() {
public DeltaSetTriple<EC> getEvaluatedConstructionTriple() {
return evaluatedConstructionTriple;
}

Expand Down Expand Up @@ -403,7 +403,7 @@ protected void createEvaluatedConstructions(Task task, OperationResult result) t

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

} else {
Expand Down Expand Up @@ -446,13 +446,13 @@ private PrismValueDeltaSetTriple<PrismPropertyValue<String>> evaluateTagTripe(Ta
return evaluatedMapping.getOutputTriple();
}

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

protected EvaluatedConstructionImpl<AH> createEvaluatedConstruction(ResourceShadowDiscriminator rsd) {
return new EvaluatedConstructionImpl<>(this, rsd);
protected EC createEvaluatedConstruction(ResourceShadowDiscriminator rsd) {
return (EC) new EvaluatedConstructionImpl<AH>(this, rsd);
}

protected NextRecompute evaluateConstructions(Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
Expand Down Expand Up @@ -596,7 +596,7 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass()) {
return false;
}
Construction<?> other = (Construction<?>) obj;
Construction<?,?> other = (Construction<?,?>) obj;
if (assignmentPathVariables == null) {
if (other.assignmentPathVariables != null) {
return false;
Expand Down

This file was deleted.

Expand Up @@ -37,12 +37,13 @@

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

private static final Trace LOGGER = TraceManager.getTrace(EvaluatedConstructionImpl.class);

@NotNull final private Construction<AH> construction;
@NotNull final private Construction<AH,?> construction;
@NotNull final private ResourceShadowDiscriminator rsd;
@NotNull final private Collection<MappingImpl<? extends PrismPropertyValue<?>, ? extends PrismPropertyDefinition<?>>> attributeMappings = new ArrayList<>();;
@NotNull final private Collection<MappingImpl<PrismContainerValue<ShadowAssociationType>, PrismContainerDefinition<ShadowAssociationType>>> associationMappings = new ArrayList<>();
Expand All @@ -51,12 +52,12 @@ public class EvaluatedConstructionImpl<AH extends AssignmentHolderType> implemen
/**
* @pre construction is already evaluated and not ignored (has resource)
*/
EvaluatedConstructionImpl(@NotNull final Construction<AH> construction, @NotNull final ResourceShadowDiscriminator rsd) {
EvaluatedConstructionImpl(@NotNull final Construction<AH,?> construction, @NotNull final ResourceShadowDiscriminator rsd) {
this.construction = construction;
this.rsd = rsd;
}

public Construction<AH> getConstruction() {
public Construction<AH,?> getConstruction() {
return construction;
}

Expand Down
@@ -0,0 +1,77 @@
/*
* 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.
*/
package com.evolveum.midpoint.model.impl.lens;

import java.util.ArrayList;
import java.util.Collection;

import com.evolveum.midpoint.model.api.context.EvaluatedConstruction;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.schema.util.SchemaDebugUtil;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentHolderType;

/**
* @author semancik
*
*/
public class EvaluatedConstructionPack<EC extends EvaluatedConstructionImpl> implements DebugDumpable {

private final Collection<EC> evaluatedConstructions = new ArrayList<>();
private boolean forceRecon;
private boolean hasValidAssignment = false;

public boolean isForceRecon() {
return forceRecon;
}

public void setForceRecon(boolean forceRecon) {
this.forceRecon = forceRecon;
}

public Collection<EC> getEvaluatedConstructions() {
return evaluatedConstructions;
}

public void add(EC evaluatedConstruction) {
evaluatedConstructions.add(evaluatedConstruction);
}

public boolean hasValidAssignment() {
return hasValidAssignment;
}

public void setHasValidAssignment(boolean hasValidAssignment) {
this.hasValidAssignment = hasValidAssignment;
}

public boolean hasNonWeakConstruction() {
for (EC evaluatedConstruction: evaluatedConstructions) {
if (!evaluatedConstruction.getConstruction().isWeak()) {
return true;
}
}
return false;
}

@Override
public String toString() {
return "EvaluatedConstructionPack(" + SchemaDebugUtil.prettyPrint(evaluatedConstructions) + (forceRecon ? ", forceRecon" : "") + ")";
}

@Override
public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
DebugUtil.debugDumpLabelLn(sb, "EvaluatedConstructionPack", indent);
DebugUtil.debugDumpWithLabelLn(sb, "forceRecon", forceRecon, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "hasValidAssignment", hasValidAssignment, indent + 1);
DebugUtil.debugDumpWithLabel(sb, "evaluatedConstructions", evaluatedConstructions, indent + 1);
return sb.toString();
}

}
Expand Up @@ -68,6 +68,11 @@ public NextRecompute evaluate(Task task, OperationResult result) throws Communic
}


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

private NextRecompute evaluateAttributes(Task task, OperationResult result)
throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, CommunicationException {

Expand Down
Expand Up @@ -144,13 +144,13 @@ public void onUnassigned(PersonaKey key, String desc) {

@Override
public void after(PersonaKey key, String desc,
DeltaMapTriple<PersonaKey, ConstructionPack<PersonaConstruction<F>>> constructionMapTriple) {
DeltaMapTriple<PersonaKey, EvaluatedConstructionPack<PersonaConstruction<F>>> constructionMapTriple) {
}


};

DeltaMapTriple<PersonaKey, ConstructionPack<PersonaConstruction<F>>> constructionMapTriple =
DeltaMapTriple<PersonaKey, EvaluatedConstructionPack<PersonaConstruction<F>>> constructionMapTriple =
constructionProcessor.processConstructions(context, evaluatedAssignmentTriple,
evaluatedAssignment -> evaluatedAssignment.getPersonaConstructionTriple(),
construction -> new PersonaKey(construction.getConstructionType()),
Expand All @@ -165,11 +165,11 @@ public void after(PersonaKey key, String desc,
FocusType existingPersona = findPersona(existingPersonas, key);
LOGGER.trace("existingPersona: {}", existingPersona);
// TODO: add ability to merge several constructions
ConstructionPack<PersonaConstruction<F>> pack = constructionMapTriple.getPlusMap().get(key);
EvaluatedConstructionPack<PersonaConstruction<F>> pack = constructionMapTriple.getPlusMap().get(key);
if (pack == null) {
pack = constructionMapTriple.getZeroMap().get(key);
}
Collection<PrismPropertyValue<PersonaConstruction<F>>> constructions = pack.getConstructions();
Collection<PrismPropertyValue<PersonaConstruction<F>>> constructions = pack.getEvaluatedConstructions();
if (constructions.isEmpty()) {
continue;
}
Expand Down

0 comments on commit 9651460

Please sign in to comment.