Eliminate NormalizedNodePayload
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / rests / transactions / MdsalNormalizedNodeWriterFactory.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech, s.r.o. 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.transactions;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import java.util.List;
14 import java.util.Set;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.restconf.api.query.DepthParam;
18 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.RestconfNormalizedNodeWriter;
19 import org.opendaylight.restconf.server.spi.NormalizedNodeWriterFactory;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
22
23 /**
24  * A {@link NormalizedNodeWriterFactory} which restricts output to specified fields and potentially the specified depth.
25  */
26 @NonNullByDefault
27 final class MdsalNormalizedNodeWriterFactory extends NormalizedNodeWriterFactory {
28     private final @Nullable DepthParam depth;
29     private final List<Set<QName>> fields;
30
31     MdsalNormalizedNodeWriterFactory(final List<Set<QName>> fields,  final @Nullable DepthParam depth) {
32         this.fields = requireNonNull(fields);
33         this.depth = depth;
34     }
35
36     @Override
37     protected RestconfNormalizedNodeWriter newWriter(final NormalizedNodeStreamWriter streamWriter) {
38         return RestconfNormalizedNodeWriter.forStreamWriter(streamWriter, depth, fields);
39     }
40
41     @Override
42     protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
43         final var local = depth;
44         if (local != null) {
45             helper.add("depth", local.value());
46         }
47         return helper.add("fields", fields);
48     }
49 }