Search in sources :

Example 1 with LocalizedMessageType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageType in project midpoint by Evolveum.

the class OperationResult method createOperationResult.

public static OperationResult createOperationResult(OperationResultType result) {
    if (result == null) {
        return null;
    }
    Map<String, Serializable> params = ParamsTypeUtil.fromParamsType(result.getParams());
    Map<String, Serializable> context = ParamsTypeUtil.fromParamsType(result.getContext());
    Map<String, Serializable> returns = ParamsTypeUtil.fromParamsType(result.getReturns());
    List<OperationResult> subresults = null;
    if (!result.getPartialResults().isEmpty()) {
        subresults = new ArrayList<>();
        for (OperationResultType subResult : result.getPartialResults()) {
            subresults.add(createOperationResult(subResult));
        }
    }
    LocalizedMessageType message = result.getLocalizedMessage();
    String localizedMessage = message == null ? null : message.getKey();
    // FIXME: brutal hack
    List<Serializable> localizedArguments = message == null ? null : (List<Serializable>) (List) message.getArgument();
    OperationResult opResult = new OperationResult(result.getOperation(), params, context, returns, OperationResultStatus.parseStatusType(result.getStatus()), result.getToken(), result.getMessageCode(), result.getMessage(), localizedMessage, localizedArguments, null, subresults);
    if (result.getCount() != null) {
        opResult.setCount(result.getCount());
    }
    if (result.getHiddenRecordsCount() != null) {
        opResult.setHiddenRecordsCount(result.getHiddenRecordsCount());
    }
    return opResult;
}
Also used : Serializable(java.io.Serializable) LocalizedMessageType(com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)

Example 2 with LocalizedMessageType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageType in project midpoint by Evolveum.

the class OperationResult method createOperationResultType.

private OperationResultType createOperationResultType(OperationResult opResult) {
    OperationResultType result = new OperationResultType();
    result.setToken(opResult.getToken());
    result.setStatus(OperationResultStatus.createStatusType(opResult.getStatus()));
    if (opResult.getCount() != 1) {
        result.setCount(opResult.getCount());
    }
    if (opResult.getHiddenRecordsCount() != 0) {
        result.setHiddenRecordsCount(opResult.getHiddenRecordsCount());
    }
    result.setOperation(opResult.getOperation());
    result.setMessage(opResult.getMessage());
    result.setMessageCode(opResult.getMessageCode());
    if (opResult.getCause() != null || !opResult.details.isEmpty()) {
        StringBuilder detailsb = new StringBuilder();
        // Record text messages in details (if present)
        if (!opResult.details.isEmpty()) {
            for (String line : opResult.details) {
                detailsb.append(line);
                detailsb.append("\n");
            }
        }
        // Record stack trace in details if a cause is present
        if (opResult.getCause() != null) {
            Throwable ex = opResult.getCause();
            detailsb.append(ex.getClass().getName());
            detailsb.append(": ");
            detailsb.append(ex.getMessage());
            detailsb.append("\n");
            StackTraceElement[] stackTrace = ex.getStackTrace();
            for (StackTraceElement aStackTrace : stackTrace) {
                detailsb.append(aStackTrace.toString());
                detailsb.append("\n");
            }
        }
        result.setDetails(detailsb.toString());
    }
    if (StringUtils.isNotEmpty(opResult.getLocalizationMessage())) {
        LocalizedMessageType message = new LocalizedMessageType();
        message.setKey(opResult.getLocalizationMessage());
        if (opResult.getLocalizationArguments() != null) {
            message.getArgument().addAll(opResult.getLocalizationArguments());
        }
        result.setLocalizedMessage(message);
    }
    result.setParams(ParamsTypeUtil.toParamsType(opResult.getParams()));
    result.setContext(ParamsTypeUtil.toParamsType(opResult.getContext()));
    result.setReturns(ParamsTypeUtil.toParamsType(opResult.getReturns()));
    for (OperationResult subResult : opResult.getSubresults()) {
        result.getPartialResults().add(opResult.createOperationResultType(subResult));
    }
    return result;
}
Also used : LocalizedMessageType(com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)

Example 3 with LocalizedMessageType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageType in project midpoint by Evolveum.

the class OperationResultFactory method createOperationResult.

public static OperationResultType createOperationResult(String operation, OperationResultStatusType status, Map<String, Element> params, String message, String messageCode, String localizedMessage, Object[] localizedArguments) {
    OperationResultType result = createOperationResult(operation, status, params, message, messageCode);
    if (StringUtils.isEmpty(localizedMessage)) {
        return result;
    }
    ObjectFactory factory = new ObjectFactory();
    LocalizedMessageType localizedMessageType = factory.createLocalizedMessageType();
    result.setLocalizedMessage(localizedMessageType);
    localizedMessageType.setKey(localizedMessage);
    if (localizedArguments == null || localizedArguments.length == 0) {
        return result;
    }
    for (Object object : localizedArguments) {
        localizedMessageType.getArgument().add(object);
    }
    return result;
}
Also used : ObjectFactory(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory) LocalizedMessageType(com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)

Aggregations

LocalizedMessageType (com.evolveum.midpoint.xml.ns._public.common.common_3.LocalizedMessageType)3 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)3 ObjectFactory (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory)1 Serializable (java.io.Serializable)1