/**
   * Restore the configuration. Depending on reset-configuration this is going to replace the
   * original files with the backup, otherwise it will create a restored-configuration folder the
   * configuration directories.
   *
   * <p>TODO log a warning if the restored configuration files are different from the current one?
   * or should we check that before rolling back the patch to give the user a chance to save the
   * changes
   *
   * @param rollingBackPatchID the patch id
   * @param resetConfiguration whether to override the configuration files or not
   * @throws IOException for any error
   */
  void restoreConfiguration(final String rollingBackPatchID, final boolean resetConfiguration)
      throws IOException {

    final File backupConfigurationDir =
        new File(installedImage.getPatchHistoryDir(rollingBackPatchID), Constants.CONFIGURATION);
    final File ba = new File(backupConfigurationDir, Constants.APP_CLIENT);
    final File bd = new File(backupConfigurationDir, Constants.DOMAIN);
    final File bs = new File(backupConfigurationDir, Constants.STANDALONE);

    final String configuration;
    if (resetConfiguration) {
      configuration = Constants.CONFIGURATION;
    } else {
      configuration = Constants.CONFIGURATION + File.separator + Constants.RESTORED_CONFIGURATION;
    }

    if (ba.exists()) {
      final File a = new File(installedImage.getAppClientDir(), configuration);
      backupDirectory(ba, a);
    }
    if (bd.exists()) {
      final File d = new File(installedImage.getDomainDir(), configuration);
      backupDirectory(bd, d);
    }
    if (bs.exists()) {
      final File s = new File(installedImage.getStandaloneDir(), configuration);
      backupDirectory(bs, s);
    }
  }
  /**
   * Backup the current configuration as part of the patch history.
   *
   * @throws IOException for any error
   */
  void backupConfiguration() throws IOException {

    final String configuration = Constants.CONFIGURATION;

    final File a = new File(installedImage.getAppClientDir(), configuration);
    final File d = new File(installedImage.getDomainDir(), configuration);
    final File s = new File(installedImage.getStandaloneDir(), configuration);

    if (a.exists()) {
      final File ab = new File(configBackup, Constants.APP_CLIENT);
      backupDirectory(a, ab);
    }
    if (d.exists()) {
      final File db = new File(configBackup, Constants.DOMAIN);
      backupDirectory(d, db);
    }
    if (s.exists()) {
      final File sb = new File(configBackup, Constants.STANDALONE);
      backupDirectory(s, sb);
    }
  }