package org.opendaylight.restconf.nb.rfc8040.rests.utils;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Optional;
import java.util.concurrent.CancellationException;
-import javax.ws.rs.core.Response.Status;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMActionResult;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
-import org.opendaylight.restconf.nb.rfc8040.handlers.ActionServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* schema path of data
* @return {@link DOMRpcResult}
*/
- public static DOMRpcResult invokeRpcViaMountPoint(final DOMMountPoint mountPoint, final NormalizedNode<?, ?> data,
- final SchemaPath schemaPath) {
+ public static DOMRpcResult invokeRpcViaMountPoint(final DOMMountPoint mountPoint, final NormalizedNode data,
+ final QName schemaPath) {
final Optional<DOMRpcService> mountPointService = mountPoint.getService(DOMRpcService.class);
if (mountPointService.isPresent()) {
return prepareResult(mountPointService.get().invokeRpc(schemaPath, nonnullInput(schemaPath, data)));
*
* @param data
* input data
- * @param schemaPath
- * schema path of data
- * @param rpcServiceHandler
- * rpc service handler to invoke rpc
+ * @param rpc
+ * RPC type
+ * @param rpcService
+ * rpc service to invoke rpc
* @return {@link DOMRpcResult}
*/
- public static DOMRpcResult invokeRpc(final NormalizedNode<?, ?> data, final SchemaPath schemaPath,
- final RpcServiceHandler rpcServiceHandler) {
- final DOMRpcService rpcService = rpcServiceHandler.get();
- if (rpcService == null) {
- throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE);
- }
-
- return prepareResult(rpcService.invokeRpc(schemaPath, nonnullInput(schemaPath, data)));
+ public static DOMRpcResult invokeRpc(final NormalizedNode data, final QName rpc, final DOMRpcService rpcService) {
+ return prepareResult(rpcService.invokeRpc(rpc, nonnullInput(rpc, data)));
}
- private static @NonNull NormalizedNode<?, ?> nonnullInput(final SchemaPath type, final NormalizedNode<?, ?> input) {
+ private static @NonNull NormalizedNode nonnullInput(final QName type, final NormalizedNode input) {
return input != null ? input
- : ImmutableNodes.containerNode(YangConstants.operationInputQName(type.getLastComponent().getModule()));
+ : ImmutableNodes.containerNode(YangConstants.operationInputQName(type.getModule()));
}
/**
private static DOMRpcResult prepareResult(final ListenableFuture<? extends DOMRpcResult> rpc) {
final RpcResultFactory dataFactory = new RpcResultFactory();
- FutureCallbackTx.addCallback(rpc, RestconfDataServiceConstant.PostData.POST_TX_TYPE, dataFactory);
+ FutureCallbackTx.addCallback(rpc, PostDataTransactionUtil.POST_TX_TYPE, dataFactory);
return dataFactory.build();
}
* @return {@link DOMActionResult}
*/
public static DOMActionResult invokeActionViaMountPoint(final DOMMountPoint mountPoint, final ContainerNode data,
- final SchemaPath schemaPath, final YangInstanceIdentifier yangIId) {
+ final Absolute schemaPath, final YangInstanceIdentifier yangIId) {
final Optional<DOMActionService> mountPointService = mountPoint.getService(DOMActionService.class);
- if (!mountPointService.isPresent()) {
+ if (mountPointService.isEmpty()) {
throw new RestconfDocumentedException("DomAction service is missing.");
}
-
- return prepareActionResult(mountPointService.get().invokeAction(schemaPath,
- prepareDataTreeId(yangIId, schemaPath), data));
+ return prepareActionResult(mountPointService.get().invokeAction(schemaPath, prepareDataTreeId(yangIId), data));
}
/**
* input data
* @param schemaPath
* schema path of data
- * @param actionServiceHandler
- * action service handler to invoke action
+ * @param actionService
+ * action service to invoke action
* @return {@link DOMActionResult}
*/
- public static DOMActionResult invokeAction(final ContainerNode data, final SchemaPath schemaPath,
- final ActionServiceHandler actionServiceHandler, final YangInstanceIdentifier yangIId) {
- return prepareActionResult(actionServiceHandler.get().invokeAction(schemaPath,
- prepareDataTreeId(yangIId, schemaPath), data));
+ // FIXME: eliminate this method
+ public static DOMActionResult invokeAction(final ContainerNode data, final Absolute schemaPath,
+ final DOMActionService actionService, final YangInstanceIdentifier yangIId) {
+ return prepareActionResult(actionService.invokeAction(schemaPath, prepareDataTreeId(yangIId), data));
}
/**
*/
private static DOMActionResult prepareActionResult(final ListenableFuture<? extends DOMActionResult> actionResult) {
final ActionResultFactory dataFactory = new ActionResultFactory();
- FutureCallbackTx.addCallback(actionResult, RestconfDataServiceConstant.PostData.POST_TX_TYPE, dataFactory);
+ FutureCallbackTx.addCallback(actionResult, PostDataTransactionUtil.POST_TX_TYPE, dataFactory);
return dataFactory.build();
}
/**
* Prepare DOMDataTree Identifier.
*
- * @param yangIId
- * {@link YangInstanceIdentifier}
- * @param schemaPath
- * {@link SchemaPath}
+ * @param yangIId {@link YangInstanceIdentifier}
* @return {@link DOMDataTreeIdentifier} domDataTreeIdentifier
*/
- private static DOMDataTreeIdentifier prepareDataTreeId(final YangInstanceIdentifier yangIId,
- final SchemaPath schemaPath) {
- final List<PathArgument> pathArg = new ArrayList<>();
- for (PathArgument path : yangIId.getPathArguments()) {
- if (path.getNodeType().getLocalName().equals(schemaPath.getLastComponent().getLocalName())) {
- break;
- }
- pathArg.add(path);
- }
- YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.builder().append(pathArg).build();
- DOMDataTreeIdentifier domDataTreeIdentifier = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL,
- yangInstanceIdentifier);
- return domDataTreeIdentifier;
+ private static DOMDataTreeIdentifier prepareDataTreeId(final YangInstanceIdentifier yangIId) {
+ return new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, yangIId.getParent());
}
}