Skip to content

Commit

Permalink
Multiaccounts: fixing collateral damage (MID-6242)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Apr 29, 2020
1 parent 8553e9a commit 38fe046
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 52 deletions.
Expand Up @@ -71,7 +71,6 @@ public class Construction<AH extends AssignmentHolderType> extends AbstractConst
protected 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 Down Expand Up @@ -351,13 +350,11 @@ public NextRecompute evaluate(Task task, OperationResult parentResult)

private void evaluateKindIntentObjectClass(ResourceType resource, Task task, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, SecurityViolationException, ExpressionEvaluationException {
if (getConstructionType().getResourceRef() != null) {
resourceOid = getConstructionType().getResourceRef().getOid();
String resourceOid = getConstructionType().getResourceRef().getOid();
if (resourceOid != null && !resource.getOid().equals(resourceOid)) {
throw new IllegalStateException(
"The specified resource and the resource in construction does not match");
}
} else {
resourceOid = null;
}

RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource,
Expand Down Expand Up @@ -450,52 +447,37 @@ private PrismValueDeltaSetTriple<PrismPropertyValue<String>> evaluateTagTripe(Ta
}

private EvaluatedConstructionImpl<AH> createEvaluatedConstruction(String tag) {
ResourceShadowDiscriminator rsd = new ResourceShadowDiscriminator(resourceOid, refinedObjectClassDefinition.getKind(), refinedObjectClassDefinition.getIntent(), tag, false);
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 void evaluateConstructions(Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
try {
evaluatedConstructionTriple.foreach( evaluatedConstruction -> {
try {
evaluateConstruction(evaluatedConstruction, task, result);
} catch (Exception e) {
throw new TunnelException(e);
}
});
} catch (TunnelException te) {
Exception e = (Exception) te.getCause();
if (e instanceof RuntimeException) {
throw (RuntimeException)e;
}
if (e instanceof CommunicationException) {
throw (CommunicationException)e;
}
if (e instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException)e;
}
if (e instanceof SchemaException) {
throw (SchemaException)e;
}
if (e instanceof SecurityViolationException) {
throw (SecurityViolationException)e;
}
if (e instanceof ConfigurationException) {
throw (ConfigurationException)e;
}
if (e instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException)e;
}
throw new SystemException(e);
protected NextRecompute evaluateConstructions(Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
NextRecompute nextRecompute = null;

// This code may seem primitive and old-fashioned.
// But equivalent functional code (using foreach()) is just insane due to nextRecompute and exception handling.
for (EvaluatedConstructionImpl<AH> evaluatedConstruction : evaluatedConstructionTriple.getZeroSet()) {
NextRecompute construcionNextRecompute = evaluateConstruction(evaluatedConstruction, task, result);
nextRecompute = NextRecompute.update(construcionNextRecompute, nextRecompute);
}
for (EvaluatedConstructionImpl<AH> evaluatedConstruction : evaluatedConstructionTriple.getPlusSet()) {
NextRecompute construcionNextRecompute = evaluateConstruction(evaluatedConstruction, task, result);
nextRecompute = NextRecompute.update(construcionNextRecompute, nextRecompute);
}
for (EvaluatedConstructionImpl<AH> evaluatedConstruction : evaluatedConstructionTriple.getMinusSet()) {
NextRecompute construcionNextRecompute = evaluateConstruction(evaluatedConstruction, task, result);
nextRecompute = NextRecompute.update(construcionNextRecompute, nextRecompute);
}

return nextRecompute;
}

protected void evaluateConstruction(EvaluatedConstructionImpl<AH> evaluatedConstruction, Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
evaluatedConstruction.evaluate(task, result);
protected NextRecompute evaluateConstruction(EvaluatedConstructionImpl<AH> evaluatedConstruction, Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
return evaluatedConstruction.evaluate(task, result);
}


Expand Down Expand Up @@ -764,6 +746,16 @@ public String debugDump(int indent) {
sb.append("\n");
sb.append(getAssignmentPath().debugDump(indent + 1));
}
sb.append("\n");
DebugUtil.debugDumpLabel(sb, "evaluated constructions", indent + 1);
if (evaluatedConstructionTriple == null) {
sb.append(" (null)");
} else if (evaluatedConstructionTriple.isEmpty()) {
sb.append(" (empty)");
} else {
sb.append("\n");
sb.append(evaluatedConstructionTriple.debugDump(indent + 2));
}
return sb.toString();
}

Expand Down
Expand Up @@ -133,6 +133,7 @@ protected void addAssociationMapping(
public NextRecompute evaluate(Task task, OperationResult result) throws CommunicationException, ObjectNotFoundException, SchemaException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
initializeProjectionContext();
evaluateAttributes(task, result);
evaluateAssociations(task, result);
return null;
}

Expand Down Expand Up @@ -326,7 +327,8 @@ public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
DebugUtil.debugDumpLabelLn(sb, this.getClass().getSimpleName(), indent);
DebugUtil.debugDumpWithLabelShortDumpLn(sb, "discriminator", rsd, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "construction", construction, indent + 1);
// We do not want to dump construction here. This can lead to cycles.
// We usually dump EvaluatedConstruction is a Construction dump anyway, therefore the context should be quite clear.
DebugUtil.debugDumpWithLabelToString(sb, "projectionContext", projectionContext, indent + 1);
if (attributeMappings != null && !attributeMappings.isEmpty()) {
sb.append("\n");
Expand Down
Expand Up @@ -78,9 +78,9 @@ public NextRecompute evaluate(Task task, OperationResult parentResult)
try {
initializeDefinitions();
createEvaluatedConstructions(task, result);
evaluateConstructions(task, result);
NextRecompute nextRecompute = evaluateConstructions(task, result);
result.recordSuccess();
return null;
return nextRecompute;
} catch (Throwable e) {
result.recordFatalError(e);
throw e;
Expand Down
Expand Up @@ -80,4 +80,12 @@ public static <V extends PrismValue, D extends ItemDefinition> NextRecompute upd
return existing;
}
}

public static <V extends PrismValue, D extends ItemDefinition> NextRecompute update(NextRecompute mappingNextRecompute, NextRecompute existing) {
if (mappingNextRecompute != null && (existing == null || existing.nextRecomputeTime.compare(mappingNextRecompute.nextRecomputeTime) == DatatypeConstants.GREATER)) {
return mappingNextRecompute;
} else {
return existing;
}
}
}
Expand Up @@ -223,10 +223,10 @@ public void test200AssignRoleSwashbucklerToJack() throws Exception {
then();
assertSuccess(result);

PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
display("User after", userAfter);
assertAssignedRole(userAfter, ROLE_SWASHBUCKLER_OID);
assertAssignments(userAfter, 1);
assertUserAfter(USER_JACK_OID)
.assignments()
.assertAssignments(1)
.assertRole(ROLE_SWASHBUCKLER_OID);

assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
DummyGroup dummyGroup = getDummyResource().getGroupByName(GROUP_DUMMY_SWASHBUCKLERS_NAME);
Expand Down
11 changes: 6 additions & 5 deletions model/model-intest/src/test/resources/logback-test.xml
Expand Up @@ -52,18 +52,19 @@
<!-- "TRACE" is just too much info, "DEBUG" should be enough for the following talkative components ...
if any of the following is set to "TRACE" then it was changed by mistake and should be changed back -->
<logger name="com.evolveum.midpoint.model.impl.lens.projector" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.Projector" level="TRACE" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.ContextLoader" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.PasswordPolicyProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.ConstructionProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.ProjectionValuesProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.OutboundProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.ConsolidationProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.ConstructionProcessor" level="TRACE" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.ProjectionValuesProcessor" level="TRACE" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.OutboundProcessor" level="TRACE" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.ConsolidationProcessor" level="TRACE" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.ReconciliationProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.ActivationProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.DependencyProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.mappings.MappingEvaluator" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.FocusActivationProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.AssignmentHolderProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.AssignmentHolderProcessor" level="TRACE" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.InboundProcessor" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.FocusConstraintsChecker" level="DEBUG" />
<logger name="com.evolveum.midpoint.model.impl.lens.projector.focus.FocusPolicyProcessor" level="DEBUG" />
Expand Down

0 comments on commit 38fe046

Please sign in to comment.