+ /**
+ * Read specific type of data from data store via transaction with specified subtrees that should only be read.
+ * Close {@link DOMTransactionChain} inside of object {@link RestconfStrategy} provided as a parameter.
+ *
+ * @param valueOfContent type of data to read (config, state, all)
+ * @param path the parent path to read
+ * @param strategy {@link RestconfStrategy} - object that perform the actual DS operations
+ * @param withDefa value of with-defaults parameter
+ * @param ctx schema context
+ * @param fields paths to selected subtrees which should be read, relative to to the parent path
+ * @return {@link NormalizedNode}
+ */
+ public static @Nullable NormalizedNode readData(final @NonNull String valueOfContent,
+ final @NonNull YangInstanceIdentifier path, final @NonNull RestconfStrategy strategy,
+ final @Nullable String withDefa, @NonNull final EffectiveModelContext ctx,
+ final @NonNull List<YangInstanceIdentifier> fields) {
+ switch (valueOfContent) {
+ case RestconfDataServiceConstant.ReadData.CONFIG:
+ if (withDefa == null) {
+ return readDataViaTransaction(strategy, LogicalDatastoreType.CONFIGURATION, path, true, fields);
+ } else {
+ return prepareDataByParamWithDef(
+ readDataViaTransaction(strategy, LogicalDatastoreType.CONFIGURATION, path, true, fields),
+ path, withDefa, ctx);
+ }
+ case RestconfDataServiceConstant.ReadData.NONCONFIG:
+ return readDataViaTransaction(strategy, LogicalDatastoreType.OPERATIONAL, path, true, fields);
+ case RestconfDataServiceConstant.ReadData.ALL:
+ return readAllData(strategy, path, withDefa, ctx, fields);
+ default:
+ throw new RestconfDocumentedException(new RestconfError(RestconfError.ErrorType.PROTOCOL,
+ RestconfError.ErrorTag.INVALID_VALUE, "Invalid content parameter: " + valueOfContent, null,
+ "The content parameter value must be either config, nonconfig or all (default)"));
+ }
+ }
+
+ /**
+ * Check if URI does not contain value for the same parameter more than once.
+ *
+ * @param parameterValues URI parameter values
+ * @param parameterName URI parameter name
+ */
+ @VisibleForTesting
+ static void checkParameterCount(final @NonNull List<String> parameterValues, final @NonNull String parameterName) {
+ if (parameterValues.size() > 1) {
+ throw new RestconfDocumentedException(
+ "Parameter " + parameterName + " can appear at most once in request URI",
+ ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
+ }
+ }
+
+ /**
+ * Check if URI does not contain not allowed parameters for specified operation.
+ *
+ * @param usedParameters parameters used in URI request
+ * @param allowedParameters allowed parameters for operation
+ */
+ @VisibleForTesting
+ static void checkParametersTypes(final @NonNull Set<String> usedParameters,
+ final @NonNull Set<String> allowedParameters) {
+ if (!allowedParameters.containsAll(usedParameters)) {
+ final Set<String> notAllowedParameters = usedParameters.stream()
+ .filter(param -> !allowedParameters.contains(param))
+ .collect(Collectors.toSet());
+ throw new RestconfDocumentedException(
+ "Not allowed parameters for " + READ_TYPE_TX + " operation: " + notAllowedParameters,
+ RestconfError.ErrorType.PROTOCOL, RestconfError.ErrorTag.INVALID_VALUE);
+ }
+ }
+
+ private static NormalizedNode prepareDataByParamWithDef(final NormalizedNode result,
+ final YangInstanceIdentifier path, final String withDefa, final EffectiveModelContext ctx) {