- throw new UnsupportedOperationException("Util class.");
- }
-
- /**
- * Parse parameters from URI request and check their types and values.
- *
- *
- * @param identifier
- * {@link InstanceIdentifierContext}
- * @param uriInfo
- * URI info
- * @param tagged
- * set tagged for {@link WriterParameters}
- * @return {@link WriterParameters}
- */
- public static @NonNull WriterParameters parseUriParameters(final @NonNull InstanceIdentifierContext<?> identifier,
- final @Nullable UriInfo uriInfo, final boolean tagged) {
- return parseParams(identifier, uriInfo, tagged);
- }
-
- /**
- * Parse parameters from URI request and check their types and values.
- *
- *
- * @param identifier
- * {@link InstanceIdentifierContext}
- * @param uriInfo
- * URI info
- * @return {@link WriterParameters}
- */
- public static @NonNull WriterParameters parseUriParameters(final @NonNull InstanceIdentifierContext<?> identifier,
- final @Nullable UriInfo uriInfo) {
- return parseParams(identifier, uriInfo, false);
- }
-
- private static WriterParameters parseParams(final InstanceIdentifierContext<?> identifier, final UriInfo uriInfo,
- final boolean tagged) {
- final WriterParametersBuilder builder = new WriterParametersBuilder();
- builder.setTagged(tagged);
-
- if (uriInfo == null) {
- return builder.build();
- }
-
- // check only allowed parameters
- ParametersUtil.checkParametersTypes(
- RestconfDataServiceConstant.ReadData.READ_TYPE_TX,
- uriInfo.getQueryParameters().keySet(),
- RestconfDataServiceConstant.ReadData.CONTENT,
- RestconfDataServiceConstant.ReadData.DEPTH,
- RestconfDataServiceConstant.ReadData.FIELDS, RestconfDataServiceConstant.ReadData.WITH_DEFAULTS);
-
- // read parameters from URI or set default values
- final List<String> content = uriInfo.getQueryParameters().getOrDefault(
- RestconfDataServiceConstant.ReadData.CONTENT,
- Collections.singletonList(RestconfDataServiceConstant.ReadData.ALL));
- final List<String> depth = uriInfo.getQueryParameters().getOrDefault(
- RestconfDataServiceConstant.ReadData.DEPTH,
- Collections.singletonList(RestconfDataServiceConstant.ReadData.UNBOUNDED));
- // fields
- final List<String> fields = uriInfo.getQueryParameters().getOrDefault(
- RestconfDataServiceConstant.ReadData.FIELDS,
- Collections.emptyList());
-
- // parameter can be in URI at most once
- ParametersUtil.checkParameterCount(content, RestconfDataServiceConstant.ReadData.CONTENT);
- ParametersUtil.checkParameterCount(depth, RestconfDataServiceConstant.ReadData.DEPTH);
- ParametersUtil.checkParameterCount(fields, RestconfDataServiceConstant.ReadData.FIELDS);
-
- // check and set content
- final String contentValue = content.get(0);
- if (!contentValue.equals(RestconfDataServiceConstant.ReadData.ALL)) {
- if (!contentValue.equals(RestconfDataServiceConstant.ReadData.CONFIG)
- && !contentValue.equals(RestconfDataServiceConstant.ReadData.NONCONFIG)) {
- throw new RestconfDocumentedException(
- new RestconfError(RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
- "Invalid content parameter: " + contentValue, null,
- "The content parameter value must be either config, nonconfig or all (default)"));
- }
- }
-
- builder.setContent(content.get(0));
-
- // check and set depth
- if (!depth.get(0).equals(RestconfDataServiceConstant.ReadData.UNBOUNDED)) {
- final Integer value = Ints.tryParse(depth.get(0));
-
- if (value == null
- || !(value >= RestconfDataServiceConstant.ReadData.MIN_DEPTH
- && value <= RestconfDataServiceConstant.ReadData.MAX_DEPTH)) {
- throw new RestconfDocumentedException(
- new RestconfError(RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE,
- "Invalid depth parameter: " + depth, null,
- "The depth parameter must be an integer between 1 and 65535 or \"unbounded\""));
- } else {
- builder.setDepth(value);
- }
- }
-
- // check and set fields
- if (!fields.isEmpty()) {
- builder.setFields(ParserFieldsParameter.parseFieldsParameter(identifier, fields.get(0)));
- }
-
- return builder.build();
- }
-
- /**
- * Read specific type of data from data store via transaction.
- *
- * @param valueOfContent
- * type of data to read (config, state, all)
- * @param transactionNode
- * {@link TransactionVarsWrapper} - wrapper for variables
- * @param schemaContext
- * schema context
- * @return {@link NormalizedNode}
- */
- public static @Nullable NormalizedNode<?, ?> readData(final @NonNull String valueOfContent,
- final @NonNull TransactionVarsWrapper transactionNode, final SchemaContext schemaContext) {
- return readData(valueOfContent, transactionNode, null, schemaContext);