private void setTargetDatasetAndVersionInRestRequestIfNeeded(RestRequest restRequest)
      throws RestServiceException {
    if (RestUtils.isDatasetVersionQueryEnabled(restRequest.getArgs())) {
      DatasetVersionPath datasetVersionPath =
          DatasetVersionPath.parse(getRequestPath(restRequest), restRequest.getArgs());
      String accountName = datasetVersionPath.getAccountName();
      String containerName = datasetVersionPath.getContainerName();
      String datasetName = datasetVersionPath.getDatasetName();
      // listing dataset versions do not need to provide version.
      String version = null;
      if (datasetVersionPath.getVersion() != null) {
        version = datasetVersionPath.getVersion();
      }
      try {
        Dataset dataset = accountService.getDataset(accountName, containerName, datasetName);
        restRequest.setArg(InternalKeys.TARGET_DATASET, dataset);
        if (version != null) {
          restRequest.setArg(InternalKeys.TARGET_DATASET_VERSION, version);
        }
      } catch (AccountServiceException e) {
        frontendMetrics.unrecognizedDatasetNameCount.inc();
        logger.error(
            "Dataset get failed for accountName " + accountName + " containerName " + containerName + " datasetName "
                + datasetName);
        throw new RestServiceException(e.getMessage(), RestServiceErrorCode.getRestServiceErrorCode(e.getErrorCode()));
      }
    }
  }
Set target {@link Dataset} objects and its version in the {@link RestRequest}.
@param restRequest The {@link RestRequest} to set.
@throws RestServiceException
ambry-frontend/src/main/java/com/github/ambry/frontend/AccountAndContainerInjector.java