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 org.mockito.Mock;
11 import org.opendaylight.yang.gen.v1.mdsal.query.norev.Foo;
12 import org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.System;
13 import org.opendaylight.yang.gen.v1.mdsal.query.norev.first.grp.SystemKey;
14 import org.opendaylight.yang.gen.v1.mdsal.query.norev.second.grp.Alarms;
15 import org.opendaylight.yang.gen.v1.mdsal.query.norev.third.grp.AffectedUsers;
16 import org.opendaylight.yang.gen.v1.mdsal426.norev.BooleanCont;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.opendaylight.yangtools.yang.common.Uint64;
20 @SuppressWarnings("exports")
21 public class QueryBuilderExamples {
23 private QueryFactory factory;
26 * Return all of /foo. Equivalent to a read() of the same identifier.
28 public QueryExpression<Foo> selectFoo() {
30 .querySubtree(InstanceIdentifier.create(Foo.class))
35 * Read all of /foo/system[name="some"]. Equivalent to a read() of the same identifier.
37 public QueryExpression<System> selectFooSystemSome() {
39 .querySubtree(InstanceIdentifier.create(Foo.class).child(System.class, new SystemKey("some")))
44 * Read all entries in /foo/system. Equivalent to a read(/foo).get().nonnullSystem().
46 public QueryExpression<System> selectFooSystem() {
48 .querySubtree(InstanceIdentifier.create(Foo.class))
49 .extractChild(System.class)
54 * Read all entries in /foo/system, which have 'alias' set to 'some'.
56 public QueryExpression<System> selectFooSystemAliasSome() {
58 .querySubtree(InstanceIdentifier.create(Foo.class))
59 .extractChild(System.class)
61 .leaf(System::getAlias)
67 * Read all entries in /foo/system, which have 'alias' containing the string 'needle'.
69 public QueryExpression<System> selectFooSystemAliasWithNeedle() {
71 .querySubtree(InstanceIdentifier.create(Foo.class))
72 .extractChild(System.class)
74 .leaf(System::getAlias)
80 * Read all entries in /foo/system/alarms, which have 'critical' leaf present.
82 public QueryExpression<Alarms> selectFooSystemAlarmsCritical() {
84 .querySubtree(InstanceIdentifier.create(Foo.class))
85 .extractChild(System.class)
86 .extractChild(Alarms.class)
88 .leaf(Alarms::getCritical)
94 * Read all entries in /foo/system/alarms, which have 'critical' leaf present and have an entry in 'affected-users'
95 * with 'uid' larger than 10.
97 * Note this is the same expression as selectFooSystemCriticalUid(), but selects Alarms objects.
99 public QueryExpression<Alarms> selectFooSystemAlarmsCriticalUid() {
101 .querySubtree(InstanceIdentifier.create(Foo.class))
102 .extractChild(System.class)
103 .extractChild(Alarms.class)
105 .leaf(Alarms::getCritical)
108 .childObject(AffectedUsers.class)
109 .leaf(AffectedUsers::getUid)
110 .greaterThan(Uint64.TEN)
116 * Read all entries in /foo/system, which have 'critical' leaf present and have an entry in 'affected-users'
117 * with 'uid' larger than 10.
119 * Note this is the same expression as selectFooSystemAlarmsCriticalUid(), but selects System objects.
121 public QueryExpression<System> selectFooSystemCriticalUid() {
123 .querySubtree(InstanceIdentifier.create(Foo.class))
124 .extractChild(System.class)
126 .childObject(Alarms.class)
127 .leaf(Alarms::getCritical)
130 .childObject(Alarms.class)
131 .childObject(AffectedUsers.class)
132 .leaf(AffectedUsers::getUid)
133 .greaterThan(Uint64.TEN)
137 public QueryExpression<BooleanCont> selectBoolean() {
139 .querySubtree(InstanceIdentifier.create(BooleanCont.class))
141 .leaf(BooleanCont::getIsFoo)