import java.net.URI;
import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.with.defaults.rev110601.WithDefaultsMode;
/**
* Enumeration of possible {@code with-defaults} parameter values as defined by
- * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.8.9">RFC8040, section 4.8.9</a>.
+ * <a href="https://www.rfc-editor.org/rfc/rfc8040#section-4.8.9">RFC8040, section 4.8.9</a>. This is an equivalent
+ * of with-defaults retrieval mode as defined by
+ * <a href="https://www.rfc-editor.org/rfc/rfc6243#section-3">RFC6243 section 3</a> and expressed as the
+ * {@code typedef with-defaults-mode}} in the corresponding YANG model.
*/
public enum WithDefaultsParam implements RestconfQueryParam<WithDefaultsParam> {
/**
* Data nodes set to the YANG default by the client are reported.
*/
- EXPLICIT("explicit"),
+ EXPLICIT(WithDefaultsMode.Explicit),
/**
* All data nodes are reported.
*/
- REPORT_ALL("report-all"),
+ REPORT_ALL(WithDefaultsMode.ReportAll),
/**
* All data nodes are reported, and defaults are tagged.
*/
- REPORT_ALL_TAGGED("report-all-tagged"),
+ REPORT_ALL_TAGGED(WithDefaultsMode.ReportAllTagged),
/**
* Data nodes set to the YANG default are not reported.
*/
- TRIM("trim");
+ TRIM(WithDefaultsMode.Trim);
// API consistency: must not be confused with enum constants
@SuppressWarnings("checkstyle:ConstantName")
private static final @NonNull URI CAPABILITY = URI.create("urn:ietf:params:restconf:capability:with-defaults:1.0");
- private final @NonNull String uriValue;
+ private final @NonNull WithDefaultsMode mode;
- WithDefaultsParam(final String uriValue) {
- this.uriValue = requireNonNull(uriValue);
+ WithDefaultsParam(final WithDefaultsMode mode) {
+ this.mode = requireNonNull(mode);
+ }
+
+ public static @NonNull WithDefaultsParam of(final WithDefaultsMode mode) {
+ return switch (mode) {
+ case Explicit -> EXPLICIT;
+ case ReportAll -> REPORT_ALL;
+ case ReportAllTagged -> REPORT_ALL_TAGGED;
+ case Trim -> TRIM;
+ };
+ }
+
+ public static @NonNull WithDefaultsParam forUriValue(final String uriValue) {
+ return of(WithDefaultsMode.ofName(uriValue));
}
@Override
@Override
public String paramValue() {
- return uriValue;
+ return mode.getName();
}
- public static @NonNull WithDefaultsParam forUriValue(final String uriValue) {
- return switch (uriValue) {
- case "explicit" -> EXPLICIT;
- case "report-all" -> REPORT_ALL;
- case "report-all-tagged" -> REPORT_ALL_TAGGED;
- case "trim" -> TRIM;
- default -> throw new IllegalArgumentException(
- "Value can be 'explicit', 'report-all', 'report-all-tagged' or 'trim', not '" + uriValue + "'");
- };
+ public @NonNull WithDefaultsMode mode() {
+ return mode;
}
public static @NonNull URI capabilityUri() {
import org.opendaylight.restconf.api.query.WithDefaultsParam;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.nb.rfc8040.rests.transactions.RestconfStrategy;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.with.defaults.rev110601.WithDefaultsMode;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
* @param content type of data to read (config, state, all)
* @param path the path to read
* @param strategy {@link RestconfStrategy} - object that perform the actual DS operations
- * @param withDefa value of with-defaults parameter
+ * @param defaultsMode value of with-defaults parameter
* @param ctx schema context
* @return {@link NormalizedNode}
*/
public static @Nullable NormalizedNode readData(final @NonNull ContentParam content,
final @NonNull YangInstanceIdentifier path, final @NonNull RestconfStrategy strategy,
- final WithDefaultsParam withDefa, final EffectiveModelContext ctx) {
+ final WithDefaultsParam defaultsMode, final EffectiveModelContext ctx) {
return switch (content) {
case ALL -> {
// PREPARE STATE DATA NODE
// PREPARE CONFIG DATA NODE
final var configDataNode = readDataViaTransaction(strategy, LogicalDatastoreType.CONFIGURATION, path);
- yield mergeConfigAndSTateDataIfNeeded(stateDataNode, withDefa == null ? configDataNode
- : prepareDataByParamWithDef(configDataNode, path, withDefa, ctx));
+ yield mergeConfigAndSTateDataIfNeeded(stateDataNode, defaultsMode == null ? configDataNode
+ : prepareDataByParamWithDef(configDataNode, path, defaultsMode.mode(), ctx));
}
case CONFIG -> {
final var read = readDataViaTransaction(strategy, LogicalDatastoreType.CONFIGURATION, path);
- yield withDefa == null ? read : prepareDataByParamWithDef(read, path, withDefa, ctx);
+ yield defaultsMode == null ? read : prepareDataByParamWithDef(read, path, defaultsMode.mode(), ctx);
}
case NONCONFIG -> readDataViaTransaction(strategy, LogicalDatastoreType.OPERATIONAL, path);
};
fields);
yield mergeConfigAndSTateDataIfNeeded(stateDataNode, withDefa == null ? configDataNode
- : prepareDataByParamWithDef(configDataNode, path, withDefa, ctx));
+ : prepareDataByParamWithDef(configDataNode, path, withDefa.mode(), ctx));
}
case CONFIG -> {
final var read = readDataViaTransaction(strategy, LogicalDatastoreType.CONFIGURATION, path, fields);
- yield withDefa == null ? read : prepareDataByParamWithDef(read, path, withDefa, ctx);
+ yield withDefa == null ? read : prepareDataByParamWithDef(read, path, withDefa.mode(), ctx);
}
case NONCONFIG -> readDataViaTransaction(strategy, LogicalDatastoreType.OPERATIONAL, path, fields);
};
}
private static NormalizedNode prepareDataByParamWithDef(final NormalizedNode readData,
- final YangInstanceIdentifier path, final WithDefaultsParam withDefa, final EffectiveModelContext ctx) {
- final boolean trim = switch (withDefa) {
- case TRIM -> true;
- case EXPLICIT -> false;
- case REPORT_ALL, REPORT_ALL_TAGGED -> throw new RestconfDocumentedException(
- "Unsupported with-defaults value " + withDefa.paramValue());
+ final YangInstanceIdentifier path, final WithDefaultsMode defaultsMode, final EffectiveModelContext ctx) {
+ final boolean trim = switch (defaultsMode) {
+ case Trim -> true;
+ case Explicit -> false;
+ case ReportAll, ReportAllTagged -> throw new RestconfDocumentedException(
+ "Unsupported with-defaults value " + defaultsMode.getName());
};
final var ctxNode = DataSchemaContextTree.from(ctx).findChild(path).orElseThrow();