import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import javax.ws.rs.core.Response.Status;
+import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException;
import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation;
import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
private static final Splitter SLASH_SPLITTER = Splitter.on('/');
+ private static final YangInstanceIdentifier ROOT = YangInstanceIdentifier.builder().build();
+
private final AtomicReference<Map<QName, RpcDefinition>> qnameToRpc =
new AtomicReference<>(Collections.<QName, RpcDefinition>emptyMap());
private InstanceIdentifierContext toIdentifier(final String restconfInstance, final boolean toMountPointIdentifier) {
checkPreconditions();
+ if(restconfInstance == null) {
+ return new InstanceIdentifierContext<>(ROOT, globalSchema, null, globalSchema);
+ }
+
final List<String> pathArgs = urlPathArgsDecode(SLASH_SPLITTER.split(restconfInstance));
omitFirstAndLastEmptyString(pathArgs);
if (pathArgs.isEmpty()) {
return null;
}
- private static DataSchemaNode childByQName(final ChoiceNode container, final QName name) {
+ private static DataSchemaNode childByQName(final ChoiceSchemaNode container, final QName name) {
for (final ChoiceCaseNode caze : container.getCases()) {
final DataSchemaNode ret = ControllerContext.childByQName(caze, name);
if (ret != null) {
final DataSchemaNode ret = container.getDataChildByName(name);
if (ret == null) {
for (final DataSchemaNode node : container.getChildNodes()) {
- if ((node instanceof ChoiceNode)) {
- final ChoiceNode choiceNode = ((ChoiceNode) node);
+ if ((node instanceof ChoiceSchemaNode)) {
+ final ChoiceSchemaNode choiceNode = ((ChoiceSchemaNode) node);
final DataSchemaNode childByQName = ControllerContext.childByQName(choiceNode, name);
if (childByQName != null) {
return childByQName;
}
if (strings.isEmpty()) {
- return new InstanceIdentifierContext(builder.toInstance(), ((DataSchemaNode) parentNode), mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema);
+ return createContext(builder.toInstance(), ((DataSchemaNode) parentNode), mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema);
}
final String head = strings.iterator().next();
ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED);
}
- final YangInstanceIdentifier partialPath = builder.toInstance();
+ final YangInstanceIdentifier partialPath = dataNormalizer.toNormalized(builder.build());
final Optional<DOMMountPoint> mountOpt = mountService.getMountPoint(partialPath);
if (!mountOpt.isPresent()) {
LOG.debug("Instance identifier to missing mount point: {}", partialPath);
ErrorType.APPLICATION, ErrorTag.UNKNOWN_ELEMENT);
}
- if (returnJustMountPoint) {
- final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance();
- return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema);
- }
-
- if (strings.size() == 1) {
+ if (returnJustMountPoint || strings.size() == 1) {
final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance();
return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema);
}
}
targetNode = findInstanceDataChildByNameAndNamespace(parentNode, nodeName, module.getNamespace());
+
+ if (targetNode == null && parentNode instanceof Module) {
+ final RpcDefinition rpc = ControllerContext.getInstance().getRpcDefinition(head);
+ if (rpc != null) {
+ return new InstanceIdentifierContext<RpcDefinition>(builder.build(), rpc, mountPoint,
+ mountPoint != null ? mountPoint.getSchemaContext() : globalSchema);
+ }
+ }
+
if (targetNode == null) {
throw new RestconfDocumentedException("URI has bad format. Possible reasons:\n" + " 1. \"" + head
+ "\" was not found in parent data node.\n" + " 2. \"" + head
returnJustMountPoint);
}
- return new InstanceIdentifierContext(builder.toInstance(), targetNode, mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema);
+ return createContext(builder.build(), targetNode, mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema);
+ }
+
+ private InstanceIdentifierContext createContext(final YangInstanceIdentifier instance, final DataSchemaNode dataSchemaNode,
+ final DOMMountPoint mountPoint, final SchemaContext schemaContext) {
+
+ final YangInstanceIdentifier instanceIdentifier = new DataNormalizer(schemaContext).toNormalized(instance);
+ return new InstanceIdentifierContext(instanceIdentifier, dataSchemaNode, mountPoint,schemaContext);
}
public static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container, final String name,
return instantiatedDataNodeContainers;
}
- private static final Function<ChoiceNode, Set<ChoiceCaseNode>> CHOICE_FUNCTION = new Function<ChoiceNode, Set<ChoiceCaseNode>>() {
+ private static final Function<ChoiceSchemaNode, Set<ChoiceCaseNode>> CHOICE_FUNCTION = new Function<ChoiceSchemaNode, Set<ChoiceCaseNode>>() {
@Override
- public Set<ChoiceCaseNode> apply(final ChoiceNode node) {
+ public Set<ChoiceCaseNode> apply(final ChoiceSchemaNode node) {
return node.getCases();
}
};
}
}
- final Iterable<ChoiceNode> choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceNode.class);
+ final Iterable<ChoiceSchemaNode> choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceSchemaNode.class);
final Iterable<Set<ChoiceCaseNode>> map = Iterables.transform(choiceNodes, CHOICE_FUNCTION);
final Iterable<ChoiceCaseNode> allCases = Iterables.<ChoiceCaseNode> concat(map);
private CharSequence convertToRestconfIdentifier(final PathArgument argument, final DataNodeContainer node, final DOMMountPoint mount) {
if (argument instanceof NodeIdentifier && node instanceof ContainerSchemaNode) {
- return convertToRestconfIdentifier((NodeIdentifier) argument, (ContainerSchemaNode) node);
+ return convertToRestconfIdentifier((NodeIdentifier) argument, mount);
} else if (argument instanceof NodeIdentifierWithPredicates && node instanceof ListSchemaNode) {
- return convertToRestconfIdentifier(argument, node, mount);
+ return convertToRestconfIdentifierWithPredicates((NodeIdentifierWithPredicates) argument, (ListSchemaNode) node, mount);
} else if (argument != null && node != null) {
throw new IllegalArgumentException("Conversion of generic path argument is not supported");
} else {
}
}
- private CharSequence convertToRestconfIdentifier(final NodeIdentifier argument, final ContainerSchemaNode node) {
- return "/" + this.toRestconfIdentifier(argument.getNodeType());
+ private CharSequence convertToRestconfIdentifier(final NodeIdentifier argument, final DOMMountPoint node) {
+ return "/" + this.toRestconfIdentifier(argument.getNodeType(),node);
}
- private CharSequence convertToRestconfIdentifier(final NodeIdentifierWithPredicates argument,
+ private CharSequence convertToRestconfIdentifierWithPredicates(final NodeIdentifierWithPredicates argument,
final ListSchemaNode node, final DOMMountPoint mount) {
final QName nodeType = argument.getNodeType();
final CharSequence nodeIdentifier = this.toRestconfIdentifier(nodeType, mount);
private static DataSchemaNode childByQName(final Object container, final QName name) {
if (container instanceof ChoiceCaseNode) {
return childByQName((ChoiceCaseNode) container, name);
- } else if (container instanceof ChoiceNode) {
- return childByQName((ChoiceNode) container, name);
+ } else if (container instanceof ChoiceSchemaNode) {
+ return childByQName((ChoiceSchemaNode) container, name);
} else if (container instanceof ContainerSchemaNode) {
return childByQName((ContainerSchemaNode) container, name);
} else if (container instanceof ListSchemaNode) {
}
}
+ public YangInstanceIdentifier toXpathRepresentation(final YangInstanceIdentifier instanceIdentifier) {
+ try {
+ return dataNormalizer.toLegacy(instanceIdentifier);
+ } catch (final NullPointerException e) {
+ throw new RestconfDocumentedException("Data normalizer isn't set. Normalization isn't possible", e);
+ } catch (final DataNormalizationException e) {
+ throw new RestconfDocumentedException("Data normalizer failed. Normalization isn't possible", e);
+ }
+ }
+
+ public boolean isNodeMixin(final YangInstanceIdentifier path) {
+ final DataNormalizationOperation<?> operation;
+ try {
+ operation = dataNormalizer.getOperation(path);
+ } catch (final DataNormalizationException e) {
+ throw new RestconfDocumentedException("Data normalizer failed. Normalization isn't possible", e);
+ }
+ return operation.isMixin();
+ }
+
public DataNormalizationOperation<?> getRootOperation() {
return dataNormalizer.getRootOperation();
}