2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.api.query;
10 import java.math.BigDecimal;
11 import org.mockito.Mock;
12 import org.opendaylight.yang.gen.v1.mdsal.query.norev.Foo;
13 import org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.System;
14 import org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.SystemKey;
15 import org.opendaylight.yang.gen.v1.mdsal.query.norev.second.grp.Alarms;
16 import org.opendaylight.yang.gen.v1.mdsal.query.norev.third.grp.AffectedUsers;
17 import org.opendaylight.yang.gen.v1.mdsal426.norev.BooleanCont;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns._default.value.test.norev.DecimalContainer;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.opendaylight.yangtools.yang.common.Uint64;
22 @SuppressWarnings("exports")
23 public class QueryBuilderExamples {
25 private QueryFactory factory;
28 * Return all of /foo. Equivalent to a read() of the same identifier.
30 public QueryExpression<Foo> selectFoo() {
32 .querySubtree(InstanceIdentifier.create(Foo.class))
37 * Read all of /foo/system[name="some"]. Equivalent to a read() of the same identifier.
39 public QueryExpression<System> selectFooSystemSome() {
41 .querySubtree(InstanceIdentifier.create(Foo.class).child(System.class, new SystemKey("some")))
46 * Read all entries in /foo/system. Equivalent to a read(/foo).get().nonnullSystem().
48 public QueryExpression<System> selectFooSystem() {
50 .querySubtree(InstanceIdentifier.create(Foo.class))
51 .extractChild(System.class)
56 * Read all entries in /foo/system, which have 'alias' set to 'some'.
58 public QueryExpression<System> selectFooSystemAliasSome() {
60 .querySubtree(InstanceIdentifier.create(Foo.class))
61 .extractChild(System.class)
63 .leaf(System::getAlias)
69 * Read all entries in /foo/system, which have 'alias' containing the string 'needle'.
71 public QueryExpression<System> selectFooSystemAliasWithNeedle() {
73 .querySubtree(InstanceIdentifier.create(Foo.class))
74 .extractChild(System.class)
76 .leaf(System::getAlias)
82 * Read all entries in /foo/system/alarms, which have 'critical' leaf present.
84 public QueryExpression<Alarms> selectFooSystemAlarmsCritical() {
86 .querySubtree(InstanceIdentifier.create(Foo.class))
87 .extractChild(System.class)
88 .extractChild(Alarms.class)
90 .leaf(Alarms::getCritical)
96 * Read all entries in /foo/system/alarms, which have 'critical' leaf present and have an entry in 'affected-users'
97 * with 'uid' larger than 10.
99 * Note this is the same expression as selectFooSystemCriticalUid(), but selects Alarms objects.
101 public QueryExpression<Alarms> selectFooSystemAlarmsCriticalUid() {
103 .querySubtree(InstanceIdentifier.create(Foo.class))
104 .extractChild(System.class)
105 .extractChild(Alarms.class)
107 .leaf(Alarms::getCritical)
110 .childObject(AffectedUsers.class)
111 .leaf(AffectedUsers::getUid)
112 .greaterThan(Uint64.TEN)
118 * Read all entries in /foo/system, which have 'critical' leaf present and have an entry in 'affected-users'
119 * with 'uid' larger than 10.
121 * Note this is the same expression as selectFooSystemAlarmsCriticalUid(), but selects System objects.
123 public QueryExpression<System> selectFooSystemCriticalUid() {
125 .querySubtree(InstanceIdentifier.create(Foo.class))
126 .extractChild(System.class)
128 .childObject(Alarms.class)
129 .leaf(Alarms::getCritical)
132 .childObject(Alarms.class)
133 .childObject(AffectedUsers.class)
134 .leaf(AffectedUsers::getUid)
135 .greaterThan(Uint64.TEN)
139 public QueryExpression<BooleanCont> selectBoolean() {
141 .querySubtree(InstanceIdentifier.create(BooleanCont.class))
143 .leaf(BooleanCont::getIsFoo)
148 public QueryExpression<DecimalContainer> selectDecimal64() {
150 .querySubtree(InstanceIdentifier.create(DecimalContainer.class))
152 .leaf(DecimalContainer::getDecimalLeaf5)
153 .valueEquals(BigDecimal.ONE)