Skip to content

Commit

Permalink
human readable message for already existing focus (MID-9365). It affe…
Browse files Browse the repository at this point in the history
…cts not only self-service part, such as registration, but also administration part.
  • Loading branch information
katkav authored and tonydamage committed Jan 18, 2024
1 parent 9bdd5a9 commit 347c29d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,11 @@ public static void save(Collection<ObjectDelta<? extends ObjectType>> deltas, Mo

page.getModelService().executeChanges(deltas, options, task, result);
} catch (Exception ex) {
subResult.recordFatalError(ex.getMessage());
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save object", ex);
if (ex instanceof CommonException) {
subResult.setUserFriendlyMessage(((CommonException) ex).getUserFriendlyMessage());
}
subResult.recordFatalError(ex.getMessage());
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save object", ex);
} finally {
subResult.computeStatus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

import com.evolveum.midpoint.schema.config.AssignmentConfigItem;

import com.evolveum.midpoint.util.LocalizableMessage;

import com.evolveum.midpoint.util.SingleLocalizableMessage;

import org.apache.commons.lang3.BooleanUtils;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -749,7 +753,7 @@ public static <T extends ObjectType> LensObjectDeltaOperation<T> createObjectDel
return objectDeltaOp;
}

public static void checkMaxIterations(int iteration, int maxIterations, String conflictMessage, String humanReadableName)
public static void checkMaxIterations(int iteration, int maxIterations, String conflictMessage, SingleLocalizableMessage humanReadableReason, String humanReadableName)
throws ObjectAlreadyExistsException {
if (iteration > maxIterations) {
StringBuilder sb = new StringBuilder();
Expand All @@ -767,7 +771,8 @@ public static void checkMaxIterations(int iteration, int maxIterations, String c
if (conflictMessage != null) {
sb.append(conflictMessage);
}
throw new ObjectAlreadyExistsException(sb.toString());
SingleLocalizableMessage message = new SingleLocalizableMessage(humanReadableReason.getKey(), humanReadableReason.getArgs(), conflictMessage);
throw new ObjectAlreadyExistsException(message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.evolveum.midpoint.model.impl.correlation.CorrelationServiceImpl;
import com.evolveum.midpoint.model.impl.lens.projector.loader.ContextLoader;

import com.evolveum.midpoint.util.SingleLocalizableMessage;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -320,7 +322,8 @@ private <F extends FocusType> void processProjectionValues(LensContext<F> contex

iteration++;
iterationToken = null;
LensUtil.checkMaxIterations(iteration, maxIterations, conflictMessage, projContext.getHumanReadableName());
//TODO use conflict message and human readable conflict message
LensUtil.checkMaxIterations(iteration, maxIterations, conflictMessage, new SingleLocalizableMessage(conflictMessage), projContext.getHumanReadableName());

cleanupContext(projContext, null, rememberedProjectionState);
context.checkConsistenceIfNeeded();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import com.evolveum.midpoint.model.impl.lens.LensContext;
import com.evolveum.midpoint.prism.PrismContext;
Expand All @@ -25,7 +26,9 @@
import com.evolveum.midpoint.schema.cache.CacheConfigurationManager;
import com.evolveum.midpoint.schema.cache.CacheType;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.LocalizableMessage;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.SingleLocalizableMessage;
import com.evolveum.midpoint.util.caching.AbstractThreadLocalCache;
import com.evolveum.midpoint.util.caching.CacheConfiguration;
import com.evolveum.midpoint.util.caching.CachePerformanceCollector;
Expand Down Expand Up @@ -61,6 +64,8 @@ public class FocusConstraintsChecker<AH extends AssignmentHolderType> {
private StringBuilder messageBuilder = new StringBuilder();
private PrismObject<AH> conflictingObject;

private SingleLocalizableMessage localizableMessage;

public PrismContext getPrismContext() {
return prismContext;
}
Expand Down Expand Up @@ -97,6 +102,10 @@ public String getMessages() {
return messageBuilder.toString();
}

public SingleLocalizableMessage getLocalizableMessage() {
return localizableMessage;
}

public PrismObject<AH> getConflictingObject() {
return conflictingObject;
}
Expand Down Expand Up @@ -178,6 +187,17 @@ private <T> boolean checkPropertyUniqueness(PrismObject<AH> objectNew, ItemPath
message("Found conflicting existing object with property "+propPath+" = " + property + ": "
+ foundObjects.get(0));

// move to message()
localizableMessage = new SingleLocalizableMessage("FocusConstraintsChecker.object.already.exists",
new Object[]{
new SingleLocalizableMessage("ObjectType." + objectNew.getCompileTimeClass().getSimpleName()),
propPath,
property.getRealValues()
.stream()
.map(Object::toString)
.collect(Collectors.joining(", "))
});

conflictingObject = foundObjects.get(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.evolveum.midpoint.schema.expression.VariablesMap;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.LocalizableMessage;
import com.evolveum.midpoint.util.SingleLocalizableMessage;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand Down Expand Up @@ -90,6 +92,11 @@ class IterationHelper<AH extends AssignmentHolderType> {
*/
private String reIterationReason;

/**
* message shown to the end users using GUI.
*/
private SingleLocalizableMessage humanReadableReason;

/**
* Initial element state (before iteration).
*/
Expand Down Expand Up @@ -240,6 +247,7 @@ boolean isIterationOk(PrismObject<AH> objectNew, Task task, OperationResult resu
LOGGER.trace("Current focus does not satisfy constraints. Conflicting object: {}; iteration={}, maxIterations={}",
checker.getConflictingObject(), iteration, maxIterations);
reIterationReason = checker.getMessages();
humanReadableReason = checker.getLocalizableMessage();
return false;
}
}
Expand Down Expand Up @@ -279,7 +287,7 @@ private boolean shouldCheckConstraints() {
void incrementIterationCounter() throws ObjectAlreadyExistsException {
iteration++;
iterationToken = null;
LensUtil.checkMaxIterations(iteration, maxIterations, reIterationReason, focusContext.getHumanReadableName());
LensUtil.checkMaxIterations(iteration, maxIterations, reIterationReason, humanReadableReason, focusContext.getHumanReadableName());
}

boolean didResetOnRenameOccur() {
Expand Down

0 comments on commit 347c29d

Please sign in to comment.