Search in sources :

Example 26 with SystemMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.

the class OrderingEqualityTest method testUserMap.

@Test
public void testUserMap() {
    final UserMapNode firstMap = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).build();
    final UserMapNode secondMap = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).build();
    assertEquals(firstMap.asMap(), secondMap.asMap());
    assertFalse(firstMap.equals(secondMap));
    assertFalse(secondMap.equals(firstMap));
    final UserMapNode thirdMap = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).build();
    assertEquals(secondMap.asMap(), thirdMap.asMap());
    assertFalse(firstMap.equals(thirdMap));
    assertTrue(secondMap.equals(thirdMap));
    assertArrayEquals(secondMap.body().toArray(), thirdMap.body().toArray());
    assertEquals(secondMap.hashCode(), thirdMap.hashCode());
    // Although this map looks as secondMap, it is not equal
    final SystemMapNode systemMap = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).build();
    assertEquals(secondMap.asMap(), systemMap.asMap());
    assertFalse(firstMap.equals(systemMap));
    assertFalse(secondMap.equals(systemMap));
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) Test(org.junit.Test)

Example 27 with SystemMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.

the class OrderingEqualityTest method testSystemMap.

@Test
public void testSystemMap() {
    final SystemMapNode firstMap = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).build();
    final SystemMapNode secondMap = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).build();
    assertEquals(firstMap.asMap(), secondMap.asMap());
    // Order does not matter
    assertTrue(firstMap.equals(secondMap));
    assertTrue(secondMap.equals(firstMap));
    assertEquals(firstMap.hashCode(), secondMap.hashCode());
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) Test(org.junit.Test)

Example 28 with SystemMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project netconf by opendaylight.

the class RestconfDocumentedExceptionMapper method toResponse.

@Override
public Response toResponse(final RestconfDocumentedException exception) {
    LOG.debug("In toResponse: {}", exception.getMessage());
    final List<MediaType> mediaTypeList = new ArrayList<>();
    if (headers.getMediaType() != null) {
        mediaTypeList.add(headers.getMediaType());
    }
    mediaTypeList.addAll(headers.getAcceptableMediaTypes());
    final MediaType mediaType = mediaTypeList.stream().filter(type -> !type.equals(MediaType.WILDCARD_TYPE)).findFirst().orElse(MediaType.APPLICATION_JSON_TYPE);
    LOG.debug("Using MediaType: {}", mediaType);
    final List<RestconfError> errors = exception.getErrors();
    if (errors.isEmpty()) {
        return Response.status(exception.getStatus()).type(MediaType.TEXT_PLAIN_TYPE).entity(" ").build();
    }
    final Status status = ErrorTags.statusOf(errors.iterator().next().getErrorTag());
    final DataNodeContainer errorsSchemaNode = (DataNodeContainer) controllerContext.getRestconfModuleErrorsSchemaNode();
    if (errorsSchemaNode == null) {
        return Response.status(status).type(MediaType.TEXT_PLAIN_TYPE).entity(exception.getMessage()).build();
    }
    checkState(errorsSchemaNode instanceof ContainerSchemaNode, "Found Errors SchemaNode isn't ContainerNode");
    final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> errContBuild = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) errorsSchemaNode);
    final List<DataSchemaNode> schemaList = ControllerContext.findInstanceDataChildrenByName(errorsSchemaNode, RestConfModule.ERROR_LIST_SCHEMA_NODE);
    final DataSchemaNode errListSchemaNode = Iterables.getFirst(schemaList, null);
    checkState(errListSchemaNode instanceof ListSchemaNode, "Found Error SchemaNode isn't ListSchemaNode");
    final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listErorsBuilder = SchemaAwareBuilders.mapBuilder((ListSchemaNode) errListSchemaNode);
    for (final RestconfError error : errors) {
        listErorsBuilder.withChild(toErrorEntryNode(error, errListSchemaNode));
    }
    errContBuild.withChild(listErorsBuilder.build());
    final NormalizedNodeContext errContext = new NormalizedNodeContext(new InstanceIdentifierContext<>(ERRORS, (DataSchemaNode) errorsSchemaNode, null, controllerContext.getGlobalSchema()), errContBuild.build());
    Object responseBody;
    if (mediaType.getSubtype().endsWith("json")) {
        responseBody = toJsonResponseBody(errContext, errorsSchemaNode);
    } else {
        responseBody = toXMLResponseBody(errContext, errorsSchemaNode);
    }
    return Response.status(status).type(mediaType).entity(responseBody).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) ArrayList(java.util.ArrayList) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) RestconfError(org.opendaylight.restconf.common.errors.RestconfError) MediaType(javax.ws.rs.core.MediaType) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 29 with SystemMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project netconf by opendaylight.

the class RestconfImpl method makeModuleMapNode.

private MapNode makeModuleMapNode(final Collection<? extends Module> modules) {
    requireNonNull(modules);
    final Module restconfModule = getRestconfModule();
    final DataSchemaNode moduleSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule, RestConfModule.MODULE_LIST_SCHEMA_NODE);
    checkState(moduleSchemaNode instanceof ListSchemaNode);
    final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listModuleBuilder = SchemaAwareBuilders.mapBuilder((ListSchemaNode) moduleSchemaNode);
    for (final Module module : modules) {
        listModuleBuilder.withChild(toModuleEntryNode(module, moduleSchemaNode));
    }
    return listModuleBuilder.build();
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) RestConfModule(org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Example 30 with SystemMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project netconf by opendaylight.

the class CutDataToCorrectDepthTest method mapNode.

private static MapNode mapNode(final String localName, final MapEntryNode... entryNodes) {
    final CollectionNodeBuilder<MapEntryNode, SystemMapNode> builder = Builders.mapBuilder();
    builder.withNodeIdentifier(toIdentifier(localName));
    for (final MapEntryNode mapEntryNode : entryNodes) {
        builder.withChild(mapEntryNode);
    }
    return builder.build();
}
Also used : SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Aggregations

SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)34 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)23 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)21 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)21 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)12 Test (org.junit.Test)11 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)9 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)8 UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)8 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)8 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)7 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)7 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)6 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)6 CollectionNodeBuilder (org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder)5 DataTree (org.opendaylight.yangtools.yang.data.tree.api.DataTree)5 QName (org.opendaylight.yangtools.yang.common.QName)4 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)4