This reverts commit
b395c683332c037acec4eecde1b079811ab5d2a3. The
assumptsions being made are just not correct.
Change-Id: Ic7abe61c7b74383f9f8891ac0acdb281188f8b6c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
*/
package org.opendaylight.netconf.sal.rest.impl;
*/
package org.opendaylight.netconf.sal.rest.impl;
+import static com.google.common.base.Verify.verify;
+
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.gson.stream.JsonReader;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.gson.stream.JsonReader;
import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
import org.opendaylight.yangtools.yang.data.impl.schema.ResultAlreadySetException;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
import org.opendaylight.yangtools.yang.data.impl.schema.ResultAlreadySetException;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
-import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack.Inference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
case "target" :
// target can be specified completely in request URI
final String target = in.nextString();
case "target" :
// target can be specified completely in request URI
final String target = in.nextString();
- final SchemaInferenceStack stack = SchemaInferenceStack.of(path.getSchemaContext());
if (target.equals("/")) {
edit.setTarget(path.getInstanceIdentifier());
if (target.equals("/")) {
edit.setTarget(path.getInstanceIdentifier());
- edit.setTargetInference(stack.toInference());
+ edit.setTargetSchemaNode(path.getSchemaContext());
} else {
edit.setTarget(codec.deserialize(codec.serialize(path.getInstanceIdentifier()).concat(target)));
} else {
edit.setTarget(codec.deserialize(codec.serialize(path.getInstanceIdentifier()).concat(target)));
- edit.getTarget().getPathArguments().stream()
- .filter(arg -> !(arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates))
- .filter(arg -> !(arg instanceof YangInstanceIdentifier.AugmentationIdentifier))
- .forEach(p -> stack.enterSchemaTree(p.getNodeType()));
- stack.exit();
- edit.setTargetInference(stack.toInference());
+
+ final EffectiveStatement<?, ?> parentStmt = SchemaInferenceStack.ofInstantiatedPath(
+ path.getSchemaContext(),
+ codec.getDataContextTree().findChild(edit.getTarget()).orElseThrow().getDataSchemaNode()
+ .getPath().getParent())
+ .currentStatement();
+ verify(parentStmt instanceof SchemaNode, "Unexpected parent %s", parentStmt);
+ edit.setTargetSchemaNode((SchemaNode) parentStmt);
break;
case "value" :
// save data defined in value node for next (later) processing, because target needs to be read
break;
case "value" :
// save data defined in value node for next (later) processing, because target needs to be read
// read saved data to normalized node when target schema is already known
edit.setData(readEditData(new JsonReader(
// read saved data to normalized node when target schema is already known
edit.setData(readEditData(new JsonReader(
- new StringReader(value.toString())), edit.getTargetInference(), path));
+ new StringReader(value.toString())), edit.getTargetSchemaNode(), path));
* @return NormalizedNode representing data
*/
private static NormalizedNode readEditData(final @NonNull JsonReader in,
* @return NormalizedNode representing data
*/
private static NormalizedNode readEditData(final @NonNull JsonReader in,
- final @NonNull Inference inference, final @NonNull InstanceIdentifierContext<?> path) {
+ final @NonNull SchemaNode targetSchemaNode, final @NonNull InstanceIdentifierContext<?> path) {
final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
final EffectiveModelContext context = path.getSchemaContext();
JsonParserStream.create(writer, JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(context),
final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
final EffectiveModelContext context = path.getSchemaContext();
JsonParserStream.create(writer, JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(context),
+ SchemaInferenceStack.ofInstantiatedPath(context, targetSchemaNode.getPath()).toInference())
+ .parse(in);
return resultHolder.getResult();
}
return resultHolder.getResult();
}
* @return PatchEntity Patch entity
*/
private static PatchEntity prepareEditOperation(final @NonNull PatchEdit edit) {
* @return PatchEntity Patch entity
*/
private static PatchEntity prepareEditOperation(final @NonNull PatchEdit edit) {
- if (edit.getOperation() != null && edit.getTargetInference() != null
+ if (edit.getOperation() != null && edit.getTargetSchemaNode() != null
&& checkDataPresence(edit.getOperation(), edit.getData() != null)) {
if (edit.getOperation().isWithValue()) {
// for lists allow to manipulate with list items through their parent
&& checkDataPresence(edit.getOperation(), edit.getData() != null)) {
if (edit.getOperation().isWithValue()) {
// for lists allow to manipulate with list items through their parent
private String id;
private PatchEditOperation operation;
private YangInstanceIdentifier target;
private String id;
private PatchEditOperation operation;
private YangInstanceIdentifier target;
- private Inference targetInference;
+ private SchemaNode targetSchemaNode;
private NormalizedNode data;
public String getId() {
private NormalizedNode data;
public String getId() {
- public Inference getTargetInference() {
- return this.targetInference;
+ public SchemaNode getTargetSchemaNode() {
+ return this.targetSchemaNode;
- public void setTargetInference(final Inference targetInference) {
- this.targetInference = targetInference;
+ public void setTargetSchemaNode(final SchemaNode targetSchemaNode) {
+ this.targetSchemaNode = targetSchemaNode;
}
public NormalizedNode getData() {
}
public NormalizedNode getData() {
this.id = null;
this.operation = null;
this.target = null;
this.id = null;
this.operation = null;
this.target = null;
- this.targetInference = null;
+ this.targetSchemaNode = null;