Search in sources :

Example 16 with LocalizableMessage

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

the class ValuePolicyProcessor method testMustBeFirst.

private StringLimitationResult testMustBeFirst(StringLimitType stringLimitation, OperationResult result, List<LocalizableMessage> messages, String value, Set<String> validFirstChars, StringLimitationResult limitation) {
    if (stringLimitation.isMustBeFirst() == null) {
        return limitation;
    }
    if (limitation == null) {
        limitation = new StringLimitationResult();
        limitation.setMustBeFirst(stringLimitation.isMustBeFirst());
        limitation.setSuccess(StringUtils.isNotEmpty(value));
    } else {
        limitation.setMustBeFirst(stringLimitation.isMustBeFirst());
    }
    if (StringUtils.isNotEmpty(value) && isTrue(stringLimitation.isMustBeFirst()) && !validFirstChars.contains(value.substring(0, 1))) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.firstCharacterNotAllowed").arg(validFirstChars.toString()).build();
        result.addSubresult(new OperationResult("Check valid first char", 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 17 with LocalizableMessage

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

the class ValuePolicyProcessor method testInvalidCharacters.

private StringLimitationResult testInvalidCharacters(List<String> valueCharacters, HashSet<String> validChars, OperationResult result, List<LocalizableMessage> message) {
    StringBuilder invalidCharacters = new StringBuilder();
    for (String character : valueCharacters) {
        if (!validChars.contains(character)) {
            invalidCharacters.append(character);
        }
    }
    StringLimitationResult limitation = new StringLimitationResult();
    PolyStringType name = new PolyStringType("invalid characters");
    PolyStringTranslationType translation = new PolyStringTranslationType();
    translation.setKey("ValuePolicy.invalidCharacters");
    name.setTranslation(translation);
    limitation.setName(name);
    PolyStringType help = new PolyStringType(getCharsetAsString(validChars));
    limitation.setHelp(help);
    limitation.setSuccess(true);
    if (invalidCharacters.length() > 0) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.charactersNotAllowed").arg(invalidCharacters).build();
        result.addSubresult(new OperationResult("Check if value does not contain invalid characters", 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 18 with LocalizableMessage

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

the class OpResult method getOpResult.

public static OpResult getOpResult(PageBase page, OperationResult result) {
    OpResult opResult = new OpResult();
    Validate.notNull(result, "Operation result must not be null.");
    Validate.notNull(result.getStatus(), "Operation result status must not be null.");
    if (result.getCause() != null && result.getCause() instanceof CommonException) {
        LocalizableMessage localizableMessage = ((CommonException) result.getCause()).getUserFriendlyMessage();
        if (localizableMessage != null) {
            opResult.message = WebComponentUtil.resolveLocalizableMessage(localizableMessage, page);
        // Exclamation code:
        // String key = localizableMessage.getKey() != null ? localizableMessage.getKey() : localizableMessage.getFallbackMessage();
        // StringResourceModel stringResourceModel = new StringResourceModel(key, page).setModel(new Model<String>()).setDefaultValue(localizableMessage.getFallbackMessage())
        // .setParameters(localizableMessage.getArgs());
        // opResult.message = stringResourceModel.getString();
        }
    }
    if (opResult.message == null) {
        opResult.message = result.getMessage();
    }
    opResult.operation = result.getOperation();
    opResult.status = result.getStatus();
    opResult.count = result.getCount();
    opResult.userFriendlyMessage = result.getUserFriendlyMessage();
    if (result.getCause() != null) {
        Throwable cause = result.getCause();
        opResult.exceptionMessage = cause.getMessage();
        Writer writer = new StringWriter();
        cause.printStackTrace(new PrintWriter(writer));
        opResult.exceptionsStackTrace = writer.toString();
    }
    for (Map.Entry<String, Collection<String>> entry : result.getParams().entrySet()) {
        String paramValue = null;
        Collection<String> values = entry.getValue();
        if (values != null) {
            paramValue = values.toString();
        }
        opResult.getParams().add(new Param(entry.getKey(), paramValue));
    }
    for (Map.Entry<String, Collection<String>> entry : result.getContext().entrySet()) {
        String contextValue = null;
        Collection<String> values = entry.getValue();
        if (values != null) {
            contextValue = values.toString();
        }
        opResult.getContexts().add(new Context(entry.getKey(), contextValue));
    }
    for (OperationResult subresult : result.getSubresults()) {
        OpResult subOpResult = OpResult.getOpResult(page, subresult);
        opResult.getSubresults().add(subOpResult);
        subOpResult.parent = opResult;
    }
    String asynchronousOperationReference = result.findAsynchronousOperationReference();
    opResult.backgroundTaskOid = OperationResult.referenceToTaskOid(asynchronousOperationReference);
    opResult.caseOid = OperationResult.referenceToCaseOid(asynchronousOperationReference);
    if (opResult.parent == null) {
        opResult.xml = createXmlModel(result, page);
    }
    return opResult;
}
Also used : LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) StringWriter(java.io.StringWriter) Collection(java.util.Collection) Map(java.util.Map) PrintWriter(java.io.PrintWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) PrintWriter(java.io.PrintWriter)

Example 19 with LocalizableMessage

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

the class ValuePolicyProcessor method testLength.

private StringLimitationResult testLength(String value, LimitationsType limitations, OperationResult result, List<LocalizableMessage> messages) {
    if (limitations.getMinLength() == null && limitations.getMaxLength() == null) {
        return null;
    }
    StringLimitationResult limitation = new StringLimitationResult();
    limitation.setMinOccurs(limitations.getMinLength());
    limitation.setMaxOccurs(limitations.getMaxLength());
    PolyStringType name = new PolyStringType("characters");
    PolyStringTranslationType translation = new PolyStringTranslationType();
    translation.setKey("ValuePolicy.characters");
    name.setTranslation(translation);
    limitation.setName(name);
    limitation.setSuccess(true);
    if (limitations.getMinLength() != null && value.length() < limitations.getMinLength()) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.minimalSizeNotMet").arg(limitations.getMinLength()).arg(value.length()).build();
        result.addSubresult(new OperationResult("Check global minimal length", OperationResultStatus.FATAL_ERROR, msg));
        messages.add(msg);
        limitation.setSuccess(false);
    }
    if (limitations.getMaxLength() != null && value.length() > limitations.getMaxLength()) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.maximalSizeExceeded").arg(limitations.getMaxLength()).arg(value.length()).build();
        result.addSubresult(new OperationResult("Check global maximal length", OperationResultStatus.FATAL_ERROR, msg));
        messages.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 20 with LocalizableMessage

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

the class ValuePolicyProcessor method testMaximalOccurrence.

private StringLimitationResult testMaximalOccurrence(StringLimitType stringLimitation, int count, OperationResult result, List<LocalizableMessage> messages, StringLimitationResult limitation) {
    if (stringLimitation.getMaxOccurs() == null) {
        return limitation;
    }
    if (limitation == null) {
        limitation = new StringLimitationResult();
        limitation.setMaxOccurs(stringLimitation.getMaxOccurs());
        limitation.setSuccess(true);
    } else {
        limitation.setMaxOccurs(stringLimitation.getMaxOccurs());
    }
    if (count > stringLimitation.getMaxOccurs()) {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.maximalOccurrenceExceeded").arg(stringLimitation.getMaxOccurs()).arg(stringLimitation.getDescription()).arg(count).build();
        result.addSubresult(new OperationResult("Check maximal 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)

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