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 public class QueryBuilderExamples {
24 private QueryFactory factory;
27 * Return all of /foo. Equivalent to a read() of the same identifier.
29 public QueryExpression<Foo> selectFoo() {
31 .querySubtree(InstanceIdentifier.create(Foo.class))
36 * Read all of /foo/system[name="some"]. Equivalent to a read() of the same identifier.
38 public QueryExpression<System> selectFooSystemSome() {
40 .querySubtree(InstanceIdentifier.create(Foo.class).child(System.class, new SystemKey("some")))
45 * Read all entries in /foo/system. Equivalent to a read(/foo).get().nonnullSystem().
47 public QueryExpression<System> selectFooSystem() {
49 .querySubtree(InstanceIdentifier.create(Foo.class))
50 .extractChild(System.class)
55 * Read all entries in /foo/system, which have 'alias' set to 'some'.
57 public QueryExpression<System> selectFooSystemAliasSome() {
59 .querySubtree(InstanceIdentifier.create(Foo.class))
60 .extractChild(System.class)
62 .leaf(System::getAlias)
68 * Read all entries in /foo/system, which have 'alias' containing the string 'needle'.
70 public QueryExpression<System> selectFooSystemAliasWithNeedle() {
72 .querySubtree(InstanceIdentifier.create(Foo.class))
73 .extractChild(System.class)
75 .leaf(System::getAlias)
81 * Read all entries in /foo/system/alarms, which have 'critical' leaf present.
83 public QueryExpression<Alarms> selectFooSystemAlarmsCritical() {
85 .querySubtree(InstanceIdentifier.create(Foo.class))
86 .extractChild(System.class)
87 .extractChild(Alarms.class)
89 .leaf(Alarms::getCritical)
95 * Read all entries in /foo/system/alarms, which have 'critical' leaf present and have an entry in 'affected-users'
96 * with 'uid' larger than 10.
98 * Note this is the same expression as selectFooSystemCriticalUid(), but selects Alarms objects.
100 public QueryExpression<Alarms> selectFooSystemAlarmsCriticalUid() {
102 .querySubtree(InstanceIdentifier.create(Foo.class))
103 .extractChild(System.class)
104 .extractChild(Alarms.class)
106 .leaf(Alarms::getCritical)
109 .childObject(AffectedUsers.class)
110 .leaf(AffectedUsers::getUid)
111 .greaterThan(Uint64.TEN)
117 * Read all entries in /foo/system, which have 'critical' leaf present and have an entry in 'affected-users'
118 * with 'uid' larger than 10.
120 * Note this is the same expression as selectFooSystemAlarmsCriticalUid(), but selects System objects.
122 public QueryExpression<System> selectFooSystemCriticalUid() {
124 .querySubtree(InstanceIdentifier.create(Foo.class))
125 .extractChild(System.class)
127 .childObject(Alarms.class)
128 .leaf(Alarms::getCritical)
131 .childObject(Alarms.class)
132 .childObject(AffectedUsers.class)
133 .leaf(AffectedUsers::getUid)
134 .greaterThan(Uint64.TEN)
138 public QueryExpression<BooleanCont> selectBoolean() {
140 .querySubtree(InstanceIdentifier.create(BooleanCont.class))
142 .leaf(BooleanCont::isIsFoo)
147 public QueryExpression<DecimalContainer> selectDecimal64() {
149 .querySubtree(InstanceIdentifier.create(DecimalContainer.class))
151 .leaf(DecimalContainer::getDecimalLeaf5)
152 .valueEquals(BigDecimal.ONE)