Remove Rfc8040 class
[netconf.git] / restconf / restconf-nb / 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.databind.DatabindProvider;
15 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
16 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfService;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.restconf.rev170126.Restconf;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary;
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     private static final String YANG_LIBRARY_REVISION = YangLibrary.QNAME.getRevision().orElseThrow().toString();
28
29     private final DatabindProvider databindProvider;
30
31     public RestconfImpl(final DatabindProvider databindProvider) {
32         this.databindProvider = requireNonNull(databindProvider);
33     }
34
35     @Override
36     public NormalizedNodePayload getLibraryVersion() {
37         final EffectiveModelContext context = databindProvider.currentContext().modelContext();
38
39         final SchemaInferenceStack stack = SchemaInferenceStack.of(context);
40         // FIXME: use rc:data instantiation once the stack supports it
41         stack.enterGrouping(Restconf.QNAME);
42         stack.enterDataTree(Restconf.QNAME);
43         stack.enterDataTree(YANG_LIBRARY_VERSION);
44
45         return NormalizedNodePayload.of(InstanceIdentifierContext.ofStack(stack),
46             ImmutableNodes.leafNode(YANG_LIBRARY_VERSION, YANG_LIBRARY_REVISION));
47     }
48 }