Search in sources :

Example 21 with LocalizableMessage

use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.

the class ValuePolicyProcessor method testMinimalUniqueCharacters.

private StringLimitationResult testMinimalUniqueCharacters(String password, LimitationsType limitations, OperationResult result, List<LocalizableMessage> message) {
    if (limitations.getMinUniqueChars() == null) {
        return null;
    }
    HashSet<String> distinctCharacters = new HashSet<>(StringPolicyUtils.stringTokenizer(password));
    StringLimitationResult limitation = new StringLimitationResult();
    limitation.setMinOccurs(limitations.getMinUniqueChars());
    PolyStringType name = new PolyStringType("unique characters");
    PolyStringTranslationType translation = new PolyStringTranslationType();
    translation.setKey("ValuePolicy.uniqueCharacters");
    name.setTranslation(translation);
    limitation.setName(name);
    limitation.setSuccess(true);
    if (limitations.getMinUniqueChars() > distinctCharacters.size()) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.minimalUniqueCharactersNotMet").arg(limitations.getMinUniqueChars()).arg(distinctCharacters.size()).build();
        result.addSubresult(new OperationResult("Check minimal count of unique chars", OperationResultStatus.FATAL_ERROR, msg));
        message.add(msg);
        limitation.setSuccess(false);
    }
    return limitation;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)

Example 22 with LocalizableMessage

use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.

the class ValuePolicyProcessor method testMinimalOccurrence.

private StringLimitationResult testMinimalOccurrence(StringLimitType stringLimitation, int count, OperationResult result, List<LocalizableMessage> messages, StringLimitationResult limitation) {
    if (stringLimitation.getMinOccurs() == null) {
        return limitation;
    }
    if (limitation == null) {
        limitation = new StringLimitationResult();
        limitation.setMinOccurs(stringLimitation.getMinOccurs());
        limitation.setSuccess(true);
    } else {
        limitation.setMinOccurs(stringLimitation.getMinOccurs());
    }
    if (count < stringLimitation.getMinOccurs()) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.minimalOccurrenceNotMet").arg(stringLimitation.getMinOccurs()).arg(stringLimitation.getDescription()).arg(count).build();
        result.addSubresult(new OperationResult("Check minimal occurrence of characters", OperationResultStatus.FATAL_ERROR, msg));
        messages.add(msg);
        limitation.setSuccess(false);
    }
    return limitation;
}
Also used : StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder)

Example 23 with LocalizableMessage

use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.

the class ValuePolicyProcessor method testCheckExpression.

private List<StringLimitationResult> testCheckExpression(String newPassword, LimitationsType lims, ExpressionProfile expressionProfile, ObjectBasedValuePolicyOriginResolver<?> originResolver, String shortDesc, Task task, OperationResult result, List<LocalizableMessage> messages) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    List<StringLimitationResult> limitations = new ArrayList<>();
    for (CheckExpressionType checkExpression : lims.getCheckExpression()) {
        ExpressionType expressionType = checkExpression.getExpression();
        if (expressionType == null) {
            continue;
        }
        StringLimitationResult limitation = new StringLimitationResult();
        PolyStringType name = null;
        if (checkExpression.getDisplay() != null) {
            name = checkExpression.getDisplay().getLabel();
            limitation.setHelp(checkExpression.getDisplay().getHelp());
        }
        if (name == null) {
            name = new PolyStringType("Check expression");
            PolyStringTranslationType translation = new PolyStringTranslationType();
            translation.setKey("ValuePolicy.checkExpression");
            name.setTranslation(translation);
        }
        limitation.setName(name);
        limitation.setSuccess(true);
        if (!checkExpression(newPassword, expressionType, expressionProfile, originResolver, shortDesc, task, result)) {
            LocalizableMessage msg;
            if (checkExpression.getLocalizableFailureMessage() != null) {
                msg = LocalizationUtil.toLocalizableMessage(checkExpression.getLocalizableFailureMessage());
            } else if (checkExpression.getFailureMessage() != null) {
                msg = LocalizableMessageBuilder.buildFallbackMessage(checkExpression.getFailureMessage());
            } else {
                msg = LocalizableMessageBuilder.buildKey("ValuePolicy.checkExpressionFailed");
            }
            result.addSubresult(new OperationResult("Check expression", OperationResultStatus.FATAL_ERROR, msg));
            messages.add(msg);
            limitation.setSuccess(false);
        }
        limitations.add(limitation);
    }
    return limitations;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) CheckExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CheckExpressionType) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CheckExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CheckExpressionType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)

Example 24 with LocalizableMessage

use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.

the class Projector method computeResultStatus.

private void computeResultStatus(XMLGregorianCalendar projectorStartTimestampCal, OperationResult result) {
    boolean hasProjectionError = false;
    OperationResultStatus finalStatus = OperationResultStatus.SUCCESS;
    String message = null;
    LocalizableMessage userFriendlyMessage = null;
    for (OperationResult subresult : result.getSubresults()) {
        if (subresult.isNotApplicable() || subresult.isSuccess()) {
            continue;
        }
        if (subresult.isHandledError()) {
            if (finalStatus == OperationResultStatus.SUCCESS) {
                finalStatus = OperationResultStatus.HANDLED_ERROR;
            }
            continue;
        }
        if (subresult.isError()) {
            message = subresult.getMessage();
            userFriendlyMessage = subresult.getUserFriendlyMessage();
            if (OPERATION_PROJECT_PROJECTION.equals(subresult.getOperation())) {
                hasProjectionError = true;
            } else {
                if (finalStatus != OperationResultStatus.FATAL_ERROR) {
                    finalStatus = subresult.getStatus();
                }
            }
        }
    }
    if (finalStatus != OperationResultStatus.FATAL_ERROR && hasProjectionError) {
        finalStatus = OperationResultStatus.PARTIAL_ERROR;
    }
    result.setStatus(finalStatus);
    result.setMessage(message);
    result.setUserFriendlyMessage(userFriendlyMessage);
    result.cleanupResult();
    if (LOGGER.isDebugEnabled()) {
        long projectorStartTimestamp = XmlTypeConverter.toMillis(projectorStartTimestampCal);
        long projectorEndTimestamp = clock.currentTimeMillis();
        LOGGER.trace("Projector finished ({}). Etime: {} ms", result.getStatus(), (projectorEndTimestamp - projectorStartTimestamp));
    }
}
Also used : OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 25 with LocalizableMessage

use of com.evolveum.midpoint.util.LocalizableMessage in project midpoint by Evolveum.

the class ModelHelper method createInstructionForRoot.

/**
 * Creates a root job creation instruction.
 *
 * @param changeProcessor reference to the change processor responsible for the whole operation
 * @param contextForRootCase model context that should be put into the root task (might be different from the modelContext)
 * @return the job creation instruction
 */
public StartInstruction createInstructionForRoot(ChangeProcessor changeProcessor, @NotNull ModelInvocationContext<?> ctx, ModelContext<?> contextForRootCase, OperationResult result) throws SchemaException {
    StartInstruction instruction = StartInstruction.create(changeProcessor, SystemObjectsType.ARCHETYPE_OPERATION_REQUEST.value());
    instruction.setModelContext(contextForRootCase);
    LocalizableMessage rootCaseName = determineRootCaseName(ctx);
    String rootCaseNameInDefaultLocale = localizationService.translate(rootCaseName, Locale.getDefault());
    instruction.setName(rootCaseNameInDefaultLocale, rootCaseName);
    instruction.setObjectRef(ctx);
    instruction.setRequesterRef(ctx.getRequestor(result));
    return instruction;
}
Also used : LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage)

Aggregations

LocalizableMessage (com.evolveum.midpoint.util.LocalizableMessage)33 LocalizableMessageBuilder (com.evolveum.midpoint.util.LocalizableMessageBuilder)18 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)17 StringLimitationResult (com.evolveum.midpoint.model.api.validator.StringLimitationResult)8 NotNull (org.jetbrains.annotations.NotNull)8 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)6 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)5 PolyStringTranslationType (com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)5 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 QName (javax.xml.namespace.QName)4 EvaluatedPolicyRule (com.evolveum.midpoint.model.api.context.EvaluatedPolicyRule)3 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl)3 AssignmentPolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.AssignmentPolicyRuleEvaluationContext)3 PolicyRuleEvaluationContext (com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleEvaluationContext)3 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)3 SystemException (com.evolveum.midpoint.util.exception.SystemException)3 Trace (com.evolveum.midpoint.util.logging.Trace)3 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)3