2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.dom.adapter;
10 import java.util.Collection;
11 import org.eclipse.jdt.annotation.NonNullByDefault;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.mdsal.dom.api.DOMActionResult;
14 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
15 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
16 import org.opendaylight.yangtools.yang.common.RpcError;
17 import org.opendaylight.yangtools.yang.common.RpcResult;
18 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
21 * Utility methods for converting {@link RpcResult} to/from {@link DOMActionResult} and {@link DOMRpcResult}.
24 final class RpcResultUtil {
25 private RpcResultUtil() {
30 * DOMRpcResult does not have a notion of success, hence we have to reverse-engineer it by looking at reported
31 * errors and checking whether they are just warnings.
33 static <T> RpcResult<T> rpcResultFromDOM(final Collection<? extends RpcError> errors, final @Nullable T result) {
34 return RpcResultBuilder.<T>status(errors.stream().noneMatch(err -> err.getSeverity() == ErrorSeverity.ERROR))
35 .withResult(result).withRpcErrors(errors).build();