Search in sources :

Example 6 with LocalizableMessage

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

the class AlwaysTrueConstraintEvaluator method createBuiltInMessage.

@NotNull
private <AH extends AssignmentHolderType> LocalizableMessage createBuiltInMessage(String keyPrefix, JAXBElement<AlwaysTruePolicyConstraintType> constraintElement, PolicyRuleEvaluationContext<AH> ctx, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    AlwaysTruePolicyConstraintType constraint = constraintElement.getValue();
    List<Object> args = new ArrayList<>();
    args.add(evaluatorHelper.createBeforeAfterMessage(ctx));
    String keySuffix;
    if (constraint.getName() != null) {
        args.add(constraint.getName());
        keySuffix = KEY_NAMED;
    } else {
        keySuffix = KEY_UNNAMED;
    }
    LocalizableMessage builtInMessage = new LocalizableMessageBuilder().key(keyPrefix + keySuffix).args(args).build();
    return evaluatorHelper.createLocalizableMessage(constraintElement, ctx, builtInMessage, result);
}
Also used : ArrayList(java.util.ArrayList) AlwaysTruePolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.AlwaysTruePolicyConstraintType) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with LocalizableMessage

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

the class OrphanedConstraintEvaluator method createBuiltInMessage.

@NotNull
private <AH extends AssignmentHolderType> LocalizableMessage createBuiltInMessage(String keyPrefix, JAXBElement<OrphanedPolicyConstraintType> constraintElement, PolicyRuleEvaluationContext<AH> ctx, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    OrphanedPolicyConstraintType constraint = constraintElement.getValue();
    List<Object> args = new ArrayList<>();
    args.add(evaluatorHelper.createBeforeAfterMessage(ctx));
    String keySuffix;
    if (constraint.getName() != null) {
        args.add(constraint.getName());
        keySuffix = KEY_NAMED;
    } else {
        keySuffix = KEY_UNNAMED;
    }
    LocalizableMessage builtInMessage = new LocalizableMessageBuilder().key(keyPrefix + keySuffix).args(args).build();
    return evaluatorHelper.createLocalizableMessage(constraintElement, ctx, builtInMessage, result);
}
Also used : ArrayList(java.util.ArrayList) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) PrismObject(com.evolveum.midpoint.prism.PrismObject) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) OrphanedPolicyConstraintType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrphanedPolicyConstraintType) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with LocalizableMessage

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

the class AssignmentModificationConstraintEvaluator method createMessage.

private <AH extends AssignmentHolderType> LocalizableMessage createMessage(JAXBElement<AssignmentModificationPolicyConstraintType> constraint, AssignmentPolicyRuleEvaluationContext<AH> ctx, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    String keyPostfix = createStateKey(ctx) + createOperationKey(ctx);
    QName relation = ctx.evaluatedAssignment.getNormalizedRelation();
    LocalizableMessage builtInMessage = new LocalizableMessageBuilder().key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_KEY_PREFIX + CONSTRAINT_KEY_PREFIX + keyPostfix).arg(ObjectTypeUtil.createDisplayInformation(ctx.evaluatedAssignment.getTarget(), false)).arg(relation != null ? relation.getLocalPart() : null).build();
    return evaluatorHelper.createLocalizableMessage(constraint, ctx, builtInMessage, result);
}
Also used : QName(javax.xml.namespace.QName) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder)

Example 9 with LocalizableMessage

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

the class AssignmentModificationConstraintEvaluator method createShortMessage.

private <AH extends AssignmentHolderType> LocalizableMessage createShortMessage(JAXBElement<AssignmentModificationPolicyConstraintType> constraint, AssignmentPolicyRuleEvaluationContext<AH> ctx, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    String keyPostfix = createStateKey(ctx) + createOperationKey(ctx);
    QName relation = ctx.evaluatedAssignment.getNormalizedRelation();
    LocalizableMessage builtInMessage;
    if (relation == null || relation == prismContext.getDefaultRelation()) {
        builtInMessage = new LocalizableMessageBuilder().key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_SHORT_MESSAGE_KEY_PREFIX + CONSTRAINT_KEY_PREFIX + keyPostfix).arg(ObjectTypeUtil.createDisplayInformation(ctx.evaluatedAssignment.getTarget(), false)).arg(ObjectTypeUtil.createDisplayInformation(ctx.getObject(), false)).build();
    } else {
        // non-default relation = print relation to short message
        builtInMessage = new LocalizableMessageBuilder().key(SchemaConstants.DEFAULT_POLICY_CONSTRAINT_SHORT_REL_MESSAGE_KEY_PREFIX + CONSTRAINT_KEY_PREFIX + keyPostfix).arg(ObjectTypeUtil.createDisplayInformation(ctx.evaluatedAssignment.getTarget(), false)).arg(ObjectTypeUtil.createDisplayInformation(ctx.getObject(), false)).arg(relation.getLocalPart()).build();
    }
    return evaluatorHelper.createLocalizableShortMessage(constraint, ctx, builtInMessage, result);
}
Also used : QName(javax.xml.namespace.QName) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder)

Example 10 with LocalizableMessage

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

the class LocalizationTest method assertTranslation.

private void assertTranslation(LocalizationService service, String key, String defaultValue, String expectedValue) {
    Locale locale = new Locale("sk");
    String real = service.translate(key, null, locale, defaultValue);
    AssertJUnit.assertEquals("Expected translation for key '" + key + "' was '" + expectedValue + "', real '" + real + "'", expectedValue, real);
    LocalizableMessage msg = new LocalizableMessageBuilder().key(key).fallbackMessage(defaultValue).build();
    real = service.translate(msg, locale);
    AssertJUnit.assertEquals("Expected translation for localization message key '" + key + "' was '" + expectedValue + "', real '" + real + "'", expectedValue, real);
}
Also used : Locale(java.util.Locale) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) 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