Split Restconf implementations (draft02 and RFC) - Application
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / restconf / base / 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.base.services.impl;
9
10 import org.opendaylight.restconf.Rfc8040.IetfYangLibrary;
11 import org.opendaylight.restconf.Rfc8040.RestconfModule;
12 import org.opendaylight.restconf.base.services.api.RestconfService;
13 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
14 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
15 import org.opendaylight.restconf.handlers.SchemaContextHandler;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
20 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
25
26 /**
27  * Implementation of RestconfService.
28  *
29  * @deprecated move to splitted module restconf-nb-rfc8040
30  */
31 @Deprecated
32 public class RestconfImpl implements RestconfService {
33
34     private final SchemaContextHandler schemaContextHandler;
35
36     public RestconfImpl(final SchemaContextHandler schemaContextHandler) {
37         this.schemaContextHandler = schemaContextHandler;
38     }
39
40     @Override
41     public NormalizedNodeContext getLibraryVersion() {
42         final SchemaContext context = this.schemaContextHandler.get();
43         SchemaNode schemaNode = null;
44         for (final GroupingDefinition groupingDefinition : context
45                 .findModuleByNamespaceAndRevision(RestconfModule.URI_MODULE, RestconfModule.DATE).getGroupings()) {
46             if (groupingDefinition.getQName().equals(RestconfModule.RESTCONF_GROUPING_QNAME)) {
47                 schemaNode = ((ContainerSchemaNode) groupingDefinition
48                         .getDataChildByName(RestconfModule.RESTCONF_CONTAINER_QNAME))
49                                 .getDataChildByName(RestconfModule.LIB_VER_LEAF_QNAME);
50             }
51         }
52         final YangInstanceIdentifier yangIId = YangInstanceIdentifier.of(
53                 QName.create(RestconfModule.NAME, RestconfModule.REVISION, RestconfModule.LIB_VER_LEAF_SCHEMA_NODE));
54         final InstanceIdentifierContext<? extends SchemaNode> iid =
55                 new InstanceIdentifierContext<SchemaNode>(yangIId, schemaNode, null, context);
56         final NormalizedNode<?, ?> data =
57                 Builders.leafBuilder((LeafSchemaNode) schemaNode).withValue(IetfYangLibrary.REVISION).build();
58         return new NormalizedNodeContext(iid, data);
59     }
60 }