Search in sources :

Example 11 with LocalizableMessage

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

the class MidpointAbstractProvider method writeTo.

@Override
public void writeTo(T object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    // TODO implement in the standard serializer; also change root name
    QName fakeQName = new QName(PrismConstants.NS_TYPES, "object");
    String serializedForm;
    PrismSerializer<String> serializer = getSerializer().options(SerializationOptions.createSerializeReferenceNames());
    try {
        if (object instanceof ObjectType) {
            ObjectType ot = (ObjectType) object;
            serializedForm = serializer.serialize(ot.asPrismObject());
        } else if (object instanceof PrismObject) {
            serializedForm = serializer.serialize((PrismObject<?>) object);
        } else if (object instanceof OperationResult) {
            Function<LocalizableMessage, String> resolveKeys = msg -> localizationService.translate(msg, Locale.US);
            OperationResultType operationResultType = ((OperationResult) object).createOperationResultType(resolveKeys);
            serializedForm = serializer.serializeAnyData(operationResultType, fakeQName);
        } else {
            serializedForm = serializer.serializeAnyData(object, fakeQName);
        }
        entityStream.write(serializedForm.getBytes(StandardCharsets.UTF_8));
    } catch (SchemaException | RuntimeException e) {
        LoggingUtils.logException(LOGGER, "Couldn't marshal element to string: {}", e, object);
    }
}
Also used : Arrays(java.util.Arrays) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) Trace(com.evolveum.midpoint.util.logging.Trace) LocalizationService(com.evolveum.midpoint.common.LocalizationService) Function(java.util.function.Function) AbstractConfigurableProvider(org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) MediaType(javax.ws.rs.core.MediaType) Locale(java.util.Locale) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) OutputStream(java.io.OutputStream) IOException(java.io.IOException) StandardCharsets(java.nio.charset.StandardCharsets) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) List(java.util.List) Type(java.lang.reflect.Type) SystemException(com.evolveum.midpoint.util.exception.SystemException) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) QName(javax.xml.namespace.QName) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) InputStream(java.io.InputStream) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)

Example 12 with LocalizableMessage

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

the class PolicyRuleBasedAspect method createProcessName.

// evaluatedAssignment present only if relevant
LocalizableMessage createProcessName(ApprovalSchemaBuilder.Result schemaBuilderResult, @Nullable EvaluatedAssignment<?> evaluatedAssignment, ModelInvocationContext<?> ctx, OperationResult result) {
    LocalizableMessage name = processNameFromApprovalActions(schemaBuilderResult, evaluatedAssignment, ctx, result);
    LOGGER.trace("Approval display name from approval actions: {}", name);
    if (name != null) {
        return name;
    }
    name = processNameFromTriggers(schemaBuilderResult);
    LOGGER.trace("Approval display name from triggers: {}", name);
    return name;
}
Also used : SingleLocalizableMessage(com.evolveum.midpoint.util.SingleLocalizableMessage) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage)

Example 13 with LocalizableMessage

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

the class AbstractHigherUnitTest method assertExceptionUserFriendly.

protected void assertExceptionUserFriendly(CommonException e, String expectedMessage) {
    LocalizableMessage userFriendlyMessage = e.getUserFriendlyMessage();
    assertNotNull("No user friendly exception message", userFriendlyMessage);
    assertEquals("Unexpected user friendly exception fallback message", expectedMessage, userFriendlyMessage.getFallbackMessage());
}
Also used : LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage)

Example 14 with LocalizableMessage

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

the class ObjectValidator method msg.

private <V extends PrismValue, D extends ItemDefinition> void msg(ValidationResult result, OperationResultStatus status, Item<V, D> item, String message) {
    ValidationItem resultItem = new ValidationItem();
    resultItem.setStatus(status);
    if (item != null) {
        resultItem.setItemPath(item.getPath());
    }
    LocalizableMessage lMessage = new SingleLocalizableMessage(null, null, message);
    resultItem.setMessage(lMessage);
    result.addItem(resultItem);
}
Also used : SingleLocalizableMessage(com.evolveum.midpoint.util.SingleLocalizableMessage) SingleLocalizableMessage(com.evolveum.midpoint.util.SingleLocalizableMessage) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage)

Example 15 with LocalizableMessage

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

the class ValuePolicyProcessor method testProhibitedValues.

private StringLimitationResult testProhibitedValues(String newPassword, ProhibitedValuesType prohibitedValuesType, ObjectBasedValuePolicyOriginResolver<?> originResolver, String shortDesc, Task task, OperationResult result, List<LocalizableMessage> messages) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    if (prohibitedValuesType == null || originResolver == null) {
        return null;
    }
    StringLimitationResult limitation = new StringLimitationResult();
    PolyStringType name = new PolyStringType("prohibited value");
    PolyStringTranslationType translation = new PolyStringTranslationType();
    translation.setKey("ValuePolicy.prohibitedValueName");
    name.setTranslation(translation);
    limitation.setName(name);
    PolyStringType help = new PolyStringType("");
    PolyStringTranslationType helpTranslation = new PolyStringTranslationType();
    helpTranslation.setKey("ValuePolicy.prohibitedValue");
    help.setTranslation(helpTranslation);
    limitation.setHelp(help);
    limitation.setSuccess(true);
    Consumer<ProhibitedValueItemType> failAction = (prohibitedItemType) -> {
        LocalizableMessage msg = new LocalizableMessageBuilder().key("ValuePolicy.prohibitedValue").build();
        result.addSubresult(new OperationResult("Prohibited value", OperationResultStatus.FATAL_ERROR, msg));
        messages.add(msg);
        limitation.setSuccess(false);
    };
    checkProhibitedValues(newPassword, prohibitedValuesType, originResolver, failAction, shortDesc, task, result);
    return limitation;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) StringUtils(org.apache.commons.lang.StringUtils) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionConstants(com.evolveum.midpoint.schema.constants.ExpressionConstants) StringLimitType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringLimitType) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) LimitationsType(com.evolveum.midpoint.xml.ns._public.common.common_3.LimitationsType) MiscSchemaUtil(com.evolveum.midpoint.schema.util.MiscSchemaUtil) LocalizableMessageList(com.evolveum.midpoint.util.LocalizableMessageList) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) LocalizationUtil(com.evolveum.midpoint.schema.util.LocalizationUtil) StringPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.StringPolicyType) Task(com.evolveum.midpoint.task.api.Task) MutablePrismPropertyDefinition(com.evolveum.midpoint.prism.MutablePrismPropertyDefinition) CheckExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CheckExpressionType) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType) PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ExpressionUtil(com.evolveum.midpoint.repo.common.expression.ExpressionUtil) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) BooleanUtils.isTrue(org.apache.commons.lang3.BooleanUtils.isTrue) NotNull(org.jetbrains.annotations.NotNull) Validate(org.apache.commons.lang.Validate) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) StrBuilder(org.apache.commons.lang.text.StrBuilder) java.util(java.util) CharacterClassType(com.evolveum.midpoint.xml.ns._public.common.common_3.CharacterClassType) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) CollectionUtils(org.apache.commons.collections4.CollectionUtils) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ProhibitedValueItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProhibitedValueItemType) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) PrismContext(com.evolveum.midpoint.prism.PrismContext) PrimitiveType(com.evolveum.midpoint.prism.PrimitiveType) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) RandomStringUtils(org.apache.commons.lang.RandomStringUtils) PrismObject(com.evolveum.midpoint.prism.PrismObject) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Consumer(java.util.function.Consumer) LocalizableMessageListBuilder(com.evolveum.midpoint.util.LocalizableMessageListBuilder) Component(org.springframework.stereotype.Component) ItemName(com.evolveum.midpoint.prism.path.ItemName) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) Protector(com.evolveum.midpoint.prism.crypto.Protector) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) ProhibitedValuesType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProhibitedValuesType) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) StringLimitationResult(com.evolveum.midpoint.model.api.validator.StringLimitationResult) LocalizableMessage(com.evolveum.midpoint.util.LocalizableMessage) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProhibitedValueItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProhibitedValueItemType) LocalizableMessageBuilder(com.evolveum.midpoint.util.LocalizableMessageBuilder) PolyStringTranslationType(com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType)

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