mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
18.32.2008 348b156e4ab1f209b181d68698ec1068ed9a7277
Fix for issue 3614 (control panel: restore fails when the available backup is a directory)

When rendering the table of backups take into account the directory used to find the backups.

Update the restore code so that it takes into account the path of the backup and not the path specified by the user in the text field (which might not be the parent path of the backup).
5 files modified
83 ■■■■ changed files
opends/src/guitools/org/opends/guitools/controlpanel/datamodel/BackupTableModel.java 1 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupListPanel.java 30 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupPanel.java 8 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/RestorePanel.java 2 ●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/ui/renderer/BackupTableCellRenderer.java 42 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/datamodel/BackupTableModel.java
@@ -40,6 +40,7 @@
  private static final long serialVersionUID = -3511425157550147124L;
  private ArrayList<BackupDescriptor> backups =
    new ArrayList<BackupDescriptor>();
  /**
   * Clears the contents ot the table model.
   *
opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupListPanel.java
@@ -57,7 +57,6 @@
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import org.opends.guitools.controlpanel.datamodel.BackupDescriptor;
@@ -139,6 +138,8 @@
   */
  private boolean backupDirectoryInitialized;
  private BackupTableCellRenderer renderer;
  private static final Logger LOG =
    Logger.getLogger(RestorePanel.class.getName());
@@ -246,7 +247,8 @@
        ListSelectionModel.SINGLE_SELECTION);
    backupList.setShowGrid(false);
    backupList.setIntercellSpacing(new Dimension(0, 0));
    TableCellRenderer renderer = new BackupTableCellRenderer();
    renderer = new BackupTableCellRenderer();
    renderer.setParentPath(new File(DUMMY_PARENT_PATH));
    for (int i=0; i<model.getColumnCount(); i++)
    {
      TableColumn col = backupList.getColumn(model.getColumnName(i));
@@ -341,6 +343,7 @@
    lRefreshingList.setVisible(true);
    final int lastSelectedRow = backupList.getSelectedRow();
    final String parentPath = parentDirectory.getText();
    BackgroundTask<Set<BackupInfo>> worker =
      new BackgroundTask<Set<BackupInfo>>()
    {
@@ -355,16 +358,19 @@
        try
        {
          BackupDirectory backupDir =
            BackupDirectory.readBackupDirectoryDescriptor(
                parentDirectory.getText());
            BackupDirectory.readBackupDirectoryDescriptor(parentPath);
          backups.addAll(backupDir.getBackups().values());
        }
        catch (Throwable t)
        {
          firstThrowable = t;
        }
          // Check the subdirectories
          File f = new File(parentDirectory.getText());
        File f = new File(parentPath);
        // Check the first level of directories (we might have done a backup
        // of one backend and then a backup of several backends under the
        // same directory).
          if (f.isDirectory())
          {
            File[] children = f.listFiles();
@@ -382,7 +388,8 @@
                }
                catch (Throwable t2)
                {
                  if (!children[i].getName().equals("tasks"))
                if (!children[i].getName().equals("tasks") &&
                    (firstThrowable != null))
                  {
                    LOG.log(Level.WARNING, "Error searching backup: "+t2, t2);
                  }
@@ -390,11 +397,10 @@
              }
            }
          }
          if (backups.size() == 0)
        if ((backups.size() == 0) && (firstThrowable != null))
          {
            throw firstThrowable;
          }
        }
        return backups;
      }
      /**
@@ -405,6 +411,7 @@
      {
        BackupTableModel model = (BackupTableModel)backupList.getModel();
        model.clear();
        renderer.setParentPath(new File(parentPath));
        if (t == null)
        {
          if (returnValue.size() > 0)
@@ -482,6 +489,7 @@
    worker.startBackgroundTask();
  }
  private final String DUMMY_PARENT_PATH = "/local/OpenDS-X.X.X/bak";
  /**
   * Creates a list with backup descriptor.  This is done simply to have a good
   * initial size for the table.
@@ -491,15 +499,15 @@
  {
    ArrayList<BackupDescriptor> list = new ArrayList<BackupDescriptor>();
    list.add(new BackupDescriptor(
        new File("/local/OpenDS-0.9.0/bak/200704201567Z"),
        new File(DUMMY_PARENT_PATH+"/200704201567Z"),
        new GregorianCalendar(2007, 5, 20, 8, 10).getTime(),
        BackupDescriptor.Type.FULL, "id"));
    list.add(new BackupDescriptor(
        new File("/local/OpenDS-0.9.0/bak/200704201567Z"),
        new File(DUMMY_PARENT_PATH+"/200704201567Z"),
        new GregorianCalendar(2007, 5, 22, 8, 10).getTime(),
        BackupDescriptor.Type.INCREMENTAL, "id"));
    list.add(new BackupDescriptor(
        new File("/local/OpenDS-0.9.0/bak/200704221567Z"),
        new File(DUMMY_PARENT_PATH+"/200704221567Z"),
        new GregorianCalendar(2007, 5, 25, 8, 10).getTime(),
        BackupDescriptor.Type.INCREMENTAL, "id"));
    return list;
opends/src/guitools/org/opends/guitools/controlpanel/ui/BackupPanel.java
@@ -602,8 +602,16 @@
          }
        }
      }
      if (incrementalBackup.isSelected())
      {
        BackupDescriptor backup = getSelectedBackup();
        dir = backup.getPath().getAbsolutePath();
      }
      else
      {
      dir = parentDirectory.getText();
    }
    }
    /**
     * {@inheritDoc}
opends/src/guitools/org/opends/guitools/controlpanel/ui/RestorePanel.java
@@ -312,8 +312,8 @@
    {
      super(info, dlg);
      this.verify = verify;
      dir = parentDirectory.getText();
      BackupDescriptor backup = getSelectedBackup();
      dir = backup.getPath().getAbsolutePath();
      backupID = backup.getID();
      backendSet = new HashSet<String>();
      for (BackendDescriptor backend : info.getServerDescriptor().getBackends())
opends/src/guitools/org/opends/guitools/controlpanel/ui/renderer/BackupTableCellRenderer.java
@@ -51,6 +51,7 @@
{
  private static final long serialVersionUID = -4645902129785751854L;
  private DateFormat formatter = DateFormat.getDateInstance(DateFormat.FULL);
  private File backupParentPath;
  private final static Border fullBorder = BorderFactory.createCompoundBorder(
      BorderFactory.createMatteBorder(1, 0, 0, 0,
          ColorAndFontConstants.gridColor),
@@ -68,6 +69,16 @@
    setBackground(ColorAndFontConstants.tableBackground);
  }
  /**
   * Sets the path to which the backups are relative.
   * @param backupParentPath the path to which the backups are relative.
   */
  public void setParentPath(File backupParentPath)
  {
    this.backupParentPath = backupParentPath;
  }
  /**
   * {@inheritDoc}
   */
@@ -80,12 +91,41 @@
    == BackupDescriptor.Type.FULL;
    if (value instanceof File)
    {
      s = "..."+File.separator+((File)value).getName();
      File f = (File)value;
      s = "";
      boolean isParent = false;
      while (f != null)
      {
        if (!f.equals(backupParentPath))
        {
          if (s.length() == 0)
          {
            s = f.getName();
          }
          else
          {
            s = f.getName() + File.separator + s;
          }
        }
        else
        {
          isParent = true;
          break;
        }
        f = f.getParentFile();
      }
      if (isParent)
      {
      if (!isFull)
      {
        s = "  "+s;
      }
    }
      else
      {
        s = value.toString();
      }
    }
    else if (value instanceof Date)
    {
      isDate = true;