d0b58c84ef4e9f34e154a89814cf18fa6b9ccf4e
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / impl / RestconfImpl.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import javax.ws.rs.Path;
13 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
14 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
15 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
16 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
17 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfService;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.Restconf;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
21 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
22 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
23
24 @Path("/")
25 public class RestconfImpl implements RestconfService {
26     private static final QName YANG_LIBRARY_VERSION = QName.create(Restconf.QNAME, "yang-library-version").intern();
27
28     private final SchemaContextHandler schemaContextHandler;
29
30     public RestconfImpl(final SchemaContextHandler schemaContextHandler) {
31         this.schemaContextHandler = requireNonNull(schemaContextHandler);
32     }
33
34     @Override
35     public NormalizedNodePayload getLibraryVersion() {
36         final EffectiveModelContext context = schemaContextHandler.get();
37
38         final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
39         // FIXME: use rc:data instantiation once the stack supports it
40         stack.enterGrouping(Restconf.QNAME);
41         stack.enterDataTree(Restconf.QNAME);
42         stack.enterDataTree(YANG_LIBRARY_VERSION);
43
44         return NormalizedNodePayload.of(InstanceIdentifierContext.ofStack(stack),
45             ImmutableNodes.leafNode(YANG_LIBRARY_VERSION, IetfYangLibrary.REVISION.toString()));
46     }
47 }