X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb-bierman02%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Frestconf%2Fimpl%2FRestconfImpl.java;h=5576469c14f1c71c7208c382329a1c3c0b15645e;hb=86e8b0bb2c9e0f10f7d679cf70495c3d4249e547;hp=715d66c9552ceb43b6aa0b4c5e61c5bff89f5735;hpb=2295d50e7212d80a9bc752f655fa66790ad45022;p=netconf.git diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java index 715d66c955..5576469c14 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java @@ -100,7 +100,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNo import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder; import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.FeatureDefinition; import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; @@ -468,9 +467,12 @@ public final class RestconfImpl implements RestconfService { final DOMRpcResult result = checkRpcResponse(response); RpcDefinition resultNodeSchema = null; - final NormalizedNode resultData = result.getResult(); + final NormalizedNode resultData; if (result != null && result.getResult() != null) { + resultData = result.getResult(); resultNodeSchema = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode(); + } else { + resultData = null; } return new NormalizedNodeContext( @@ -525,8 +527,8 @@ public final class RestconfImpl implements RestconfService { if (!rpc.getInput().getChildNodes().isEmpty()) { LOG.debug("RPC " + rpc + " does not need input value."); - // FIXME : find a correct Error from specification - throw new IllegalStateException("RPC " + rpc + " does'n need input value!"); + throw new RestconfDocumentedException("RPC " + rpc + " does not take any input value.", + ErrorType.RPC, ErrorTag.INVALID_VALUE); } final CheckedFuture response; @@ -553,7 +555,7 @@ public final class RestconfImpl implements RestconfService { } try { final DOMRpcResult retValue = response.get(); - if (retValue.getErrors() == null || retValue.getErrors().isEmpty()) { + if (retValue.getErrors().isEmpty()) { return retValue; } LOG.debug("RpcError message", retValue.getErrors()); @@ -699,11 +701,11 @@ public final class RestconfImpl implements RestconfService { } boolean tagged = false; if (withDefaUsed) { - if (withDefa.equals("report-all-tagged")) { + if ("report-all-tagged".equals(withDefa)) { tagged = true; withDefa = null; } - if (withDefa.equals("report-all")) { + if ("report-all".equals(withDefa)) { withDefa = null; } } @@ -933,26 +935,28 @@ public final class RestconfImpl implements RestconfService { String insert = null; String point = null; - for (final Entry> entry : uriInfo.getQueryParameters().entrySet()) { - switch (entry.getKey()) { - case "insert": - if (!insertUsed) { - insertUsed = true; - insert = entry.getValue().iterator().next(); - } else { - throw new RestconfDocumentedException("Insert parameter can be used only once."); - } - break; - case "point": - if (!pointUsed) { - pointUsed = true; - point = entry.getValue().iterator().next(); - } else { - throw new RestconfDocumentedException("Point parameter can be used only once."); - } - break; - default: - throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey()); + if (uriInfo != null) { + for (final Entry> entry : uriInfo.getQueryParameters().entrySet()) { + switch (entry.getKey()) { + case "insert": + if (!insertUsed) { + insertUsed = true; + insert = entry.getValue().iterator().next(); + } else { + throw new RestconfDocumentedException("Insert parameter can be used only once."); + } + break; + case "point": + if (!pointUsed) { + pointUsed = true; + point = entry.getValue().iterator().next(); + } else { + throw new RestconfDocumentedException("Point parameter can be used only once."); + } + break; + default: + throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey()); + } } } @@ -993,37 +997,6 @@ public final class RestconfImpl implements RestconfService { return responseBuilder.build(); } - // FIXME create RestconfIdetifierHelper and move this method there - private static YangInstanceIdentifier checkConsistencyOfNormalizedNodeContext(final NormalizedNodeContext payload) { - Preconditions.checkArgument(payload != null); - Preconditions.checkArgument(payload.getData() != null); - Preconditions.checkArgument(payload.getData().getNodeType() != null); - Preconditions.checkArgument(payload.getInstanceIdentifierContext() != null); - Preconditions.checkArgument(payload.getInstanceIdentifierContext().getInstanceIdentifier() != null); - - final QName payloadNodeQname = payload.getData().getNodeType(); - final YangInstanceIdentifier yangIdent = payload.getInstanceIdentifierContext().getInstanceIdentifier(); - if (payloadNodeQname.compareTo(yangIdent.getLastPathArgument().getNodeType()) > 0) { - return yangIdent; - } - final InstanceIdentifierContext parentContext = payload.getInstanceIdentifierContext(); - final SchemaNode parentSchemaNode = parentContext.getSchemaNode(); - if (parentSchemaNode instanceof DataNodeContainer) { - final DataNodeContainer cast = (DataNodeContainer) parentSchemaNode; - for (final DataSchemaNode child : cast.getChildNodes()) { - if (payloadNodeQname.compareTo(child.getQName()) == 0) { - return YangInstanceIdentifier.builder(yangIdent).node(child.getQName()).build(); - } - } - } - if (parentSchemaNode instanceof RpcDefinition) { - return yangIdent; - } - final String errMsg = "Error parsing input: DataSchemaNode has not children "; - LOG.info(errMsg + yangIdent); - throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE); - } - @SuppressWarnings("checkstyle:IllegalCatch") private URI resolveLocation(final UriInfo uriInfo, final String uriBehindBase, final DOMMountPoint mountPoint, final YangInstanceIdentifier normalizedII) { @@ -1526,6 +1499,7 @@ public final class RestconfImpl implements RestconfService { final List paths = new ArrayList<>(); String streamName = CREATE_NOTIFICATION_STREAM + "/"; + StringBuilder streamNameBuilder = new StringBuilder(streamName); final Iterator iterator = entryNodes.iterator(); while (iterator.hasNext()) { final QName valueQName = QName.create((String) iterator.next().getValue()); @@ -1544,12 +1518,14 @@ public final class RestconfImpl implements RestconfService { Preconditions.checkNotNull(notifiDef, "Notification " + valueQName + "doesn't exist in module " + moduleName); paths.add(notifiDef.getPath()); - streamName = streamName + moduleName + ":" + valueQName.getLocalName(); + streamNameBuilder.append(moduleName).append(':').append(valueQName.getLocalName()); if (iterator.hasNext()) { - streamName = streamName + ","; + streamNameBuilder.append(','); } } + streamName = streamNameBuilder.toString(); + final QName rpcQName = payload.getInstanceIdentifierContext().getSchemaNode().getQName(); final QName outputQname = QName.create(rpcQName, "output"); final QName streamNameQname = QName.create(rpcQName, "notification-stream-identifier");