- try (InputStream in = connection.getInputStream()) {
- final Optional<NormalizedNode<?, ?>> optionalModulesStateNode =
- contentType.equals("application/json") ? readJson(in) : readXml(in);
-
- if (!optionalModulesStateNode.isPresent()) {
- return new LibraryModulesSchemas(Collections.<QName, URL>emptyMap());
- }
-
- final NormalizedNode<?, ?> modulesStateNode = optionalModulesStateNode.get();
- Preconditions.checkState(modulesStateNode.getNodeType().equals(ModulesState.QNAME),
- "Wrong QName %s", modulesStateNode.getNodeType());
- Preconditions.checkState(modulesStateNode instanceof ContainerNode,
- "Expecting container containing module list, but was %s", modulesStateNode);
-
- final YangInstanceIdentifier.NodeIdentifier moduleListNodeId =
- new YangInstanceIdentifier.NodeIdentifier(Module.QNAME);
- final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> moduleListNode =
- ((ContainerNode) modulesStateNode).getChild(moduleListNodeId);
- Preconditions.checkState(moduleListNode.isPresent(),
- "Unable to find list: %s in %s", moduleListNodeId, modulesStateNode);
- Preconditions.checkState(moduleListNode.get() instanceof MapNode,
- "Unexpected structure for container: %s in : %s. Expecting a list",
- moduleListNodeId, modulesStateNode);
-
- final ImmutableMap.Builder<QName, URL> schemasMapping = new ImmutableMap.Builder<>();
- for (final MapEntryNode moduleNode : ((MapNode) moduleListNode.get()).getValue()) {
- final Optional<Map.Entry<QName, URL>> schemaMappingEntry = createFromEntry(moduleNode);
- if (schemaMappingEntry.isPresent()) {
- schemasMapping.put(createFromEntry(moduleNode).get());
- }
- }