X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb-rfc8040%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fnb%2Frfc8040%2Frests%2Fservices%2Fimpl%2FRestconfInvokeOperationsServiceImpl.java;h=725404041b38082c2070c0f99dbc7d3b059aca02;hb=c894986ef8b0b40d7457c8c0c54a656ea0e9a521;hp=bce3b528abb537e3759d1fec635e23fd8b1f3c38;hpb=f402dcd49a468e018192c96151bef3a0cdf70d62;p=netconf.git diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java index bce3b528ab..725404041b 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfInvokeOperationsServiceImpl.java @@ -8,12 +8,14 @@ package org.opendaylight.restconf.nb.rfc8040.rests.services.impl; import java.net.URI; +import java.util.Optional; import javax.ws.rs.Path; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import org.opendaylight.mdsal.dom.api.DOMMountPoint; import org.opendaylight.mdsal.dom.api.DOMRpcResult; +import org.opendaylight.mdsal.dom.api.DOMSchemaService; import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.common.context.NormalizedNodeContext; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; @@ -21,15 +23,14 @@ import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag; import org.opendaylight.restconf.common.errors.RestconfError.ErrorType; import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler; import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler; -import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef; import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfInvokeOperationsService; -import org.opendaylight.restconf.nb.rfc8040.rests.utils.CreateStreamUtil; import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfInvokeOperationsUtil; import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; /** * Implementation of {@link RestconfInvokeOperationsService}. @@ -61,14 +62,13 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat @Override public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) { - final SchemaContextRef refSchemaCtx = new SchemaContextRef(this.schemaContextHandler.get()); - final SchemaPath schemaPath = payload.getInstanceIdentifierContext().getSchemaNode().getPath(); + final EffectiveModelContext refSchemaCtx = this.schemaContextHandler.get(); + final QName schemaPath = payload.getInstanceIdentifierContext().getSchemaNode().getQName(); final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint(); final URI namespace = payload.getInstanceIdentifierContext().getSchemaNode().getQName().getNamespace(); - DOMRpcResult response; - - SchemaContextRef schemaContextRef; + final DOMRpcResult response; + final EffectiveModelContext schemaContextRef; if (mountPoint == null) { if (namespace.equals(RestconfStreamsConstants.SAL_REMOTE_NAMESPACE.getNamespace())) { if (identifier.contains(RestconfStreamsConstants.CREATE_DATA_SUBSCRIPTION)) { @@ -81,10 +81,10 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat response = RestconfInvokeOperationsUtil.invokeRpc(payload.getData(), schemaPath, this.rpcServiceHandler); } - schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get()); + schemaContextRef = this.schemaContextHandler.get(); } else { response = RestconfInvokeOperationsUtil.invokeRpcViaMountPoint(mountPoint, payload.getData(), schemaPath); - schemaContextRef = new SchemaContextRef(mountPoint.getEffectiveModelContext()); + schemaContextRef = modelContext(mountPoint); } final DOMRpcResult result = RestconfInvokeOperationsUtil.checkResponse(response); @@ -99,8 +99,14 @@ public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperat if (resultData != null && ((ContainerNode) resultData).getValue().isEmpty()) { throw new WebApplicationException(Response.Status.NO_CONTENT); } else { - return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, resultNodeSchema, - mountPoint, schemaContextRef.get()), resultData); + return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, resultNodeSchema, mountPoint, + schemaContextRef), resultData); } } + + private static EffectiveModelContext modelContext(final DOMMountPoint mountPoint) { + return mountPoint.getService(DOMSchemaService.class) + .flatMap(svc -> Optional.ofNullable(svc.getGlobalContext())) + .orElse(null); + } }