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

Jean-Noël Rouvignac
05.47.2016 56159257192f85039e301f0e445e156576bd05be
control-panel: Replace server's Entry by SDK's Entry
7 files modified
97 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/event/LDAPEntryChangedEvent.java 8 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java 31 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LDAPEntryPanel.java 9 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LDIFViewEntryPanel.java 11 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java 13 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java 13 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java 12 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/event/LDAPEntryChangedEvent.java
@@ -12,16 +12,14 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2008 Sun Microsystems, Inc.
 * Portions Copyright 2016 ForgeRock AS.
 */
package org.opends.guitools.controlpanel.event;
import org.opends.server.types.Entry;
import org.forgerock.opendj.ldap.Entry;
/**
 * Method that describes that an entry has changed.  This is used by the LDAP
 * entry editors.
 *
 * Method that describes that an entry has changed. This is used by the LDAP entry editors.
 */
public class LDAPEntryChangedEvent
{
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyEntryTask.java
@@ -33,9 +33,11 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.AVA;
import org.forgerock.opendj.ldap.Attribute;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.Entry;
import org.forgerock.opendj.ldap.LdapException;
import org.forgerock.opendj.ldap.LinkedAttribute;
import org.forgerock.opendj.ldap.Modification;
@@ -56,7 +58,6 @@
import org.opends.guitools.controlpanel.ui.nodes.BasicNode;
import org.opends.guitools.controlpanel.util.Utilities;
import org.opends.messages.AdminToolMessages;
import org.opends.server.types.Entry;
import org.opends.server.types.Schema;
/** The task that is called when we must modify an entry. */
@@ -65,7 +66,7 @@
  private Set<String> backendSet;
  private boolean mustRename;
  private boolean hasModifications;
  private org.forgerock.opendj.ldap.Entry oldEntry;
  private Entry oldEntry;
  private DN oldDn;
  private List<Modification> modifications;
  private Modification passwordModification;
@@ -85,7 +86,7 @@
   * want to modify.
   */
  public ModifyEntryTask(ControlPanelInfo info, ProgressDialog dlg,
      Entry newEntry, org.forgerock.opendj.ldap.Entry oldEntry,
      Entry newEntry, Entry oldEntry,
      BrowserController controller, TreePath path)
  {
    super(info, dlg);
@@ -296,7 +297,7 @@
   * @throws LdapException if an error performing the modification occurs.
   */
  private void modifyAndRename(ConnectionWithControls conn, final DN oldDN,
      org.forgerock.opendj.ldap.Entry originalEntry,
      Entry originalEntry,
      final Entry newEntry, final List<Modification> originalMods)
      throws CannotRenameException, LdapException
  {
@@ -430,11 +431,11 @@
    return false;
  }
  private boolean entryContainsRdnTypes(org.forgerock.opendj.ldap.Entry entry, RDN rdn)
  private boolean entryContainsRdnTypes(Entry entry, RDN rdn)
  {
    for (AVA ava : rdn)
    {
      org.forgerock.opendj.ldap.Attribute attr = entry.getAttribute(ava.getAttributeName());
      Attribute attr = entry.getAttribute(ava.getAttributeName());
      if (attr == null || attr.isEmpty())
      {
        return false;
@@ -450,14 +451,12 @@
   * @param info the ControlPanelInfo, used to retrieve the schema for instance.
   * @return the modifications to apply between two entries.
   */
  public static List<Modification> getModifications(Entry newEntry,
      org.forgerock.opendj.ldap.Entry oldEntry, ControlPanelInfo info) {
  public static List<Modification> getModifications(Entry newEntry, Entry oldEntry, ControlPanelInfo info)
  {
    List<Modification> modifications = new ArrayList<>();
    Schema schema = info.getServerDescriptor().getSchema();
    List<org.opends.server.types.Attribute> newAttrs = newEntry.getAttributes();
    newAttrs.add(newEntry.getObjectClassAttribute());
    for (org.opends.server.types.Attribute attr : newAttrs)
    for (Attribute attr : newEntry.getAllAttributes())
    {
      AttributeDescription attrDesc = attr.getAttributeDescription();
      if (!ViewEntryPanel.isEditable(attrDesc, schema))
@@ -469,7 +468,7 @@
      {
        newValues.add(v);
      }
      org.forgerock.opendj.ldap.Attribute oldAttr = oldEntry.getAttribute(attrDesc);
      Attribute oldAttr = oldEntry.getAttribute(attrDesc);
      ByteString rdnValue = null;
      for (AVA ava : newEntry.getName().rdn())
@@ -563,16 +562,16 @@
    }
    /* Check if there are attributes to delete */
    for (org.forgerock.opendj.ldap.Attribute attr : oldEntry.getAllAttributes())
    for (Attribute attr : oldEntry.getAllAttributes())
    {
      AttributeDescription attrDesc = attr.getAttributeDescription();
      if (!ViewEntryPanel.isEditable(attrDesc, schema))
      {
        continue;
      }
      org.forgerock.opendj.ldap.Attribute oldAttr = oldEntry.getAttribute(attrDesc);
      Attribute oldAttr = oldEntry.getAttribute(attrDesc);
      if (!newEntry.hasAttribute(AttributeDescription.valueOf(attrDesc.getNameOrOID())) && !oldAttr.isEmpty())
      if (!newEntry.containsAttribute(attrDesc.getNameOrOID()) && !oldAttr.isEmpty())
      {
        modifications.add(newModification(DELETE, attrDesc));
      }
@@ -591,7 +590,7 @@
    return new Modification(modType, new LinkedAttribute(attrDesc, values));
  }
  private static List<ByteString> toList(org.forgerock.opendj.ldap.Attribute oldAttr)
  private static List<ByteString> toList(Attribute oldAttr)
  {
    List<ByteString> results = new ArrayList<>();
    for (ByteString v : oldAttr)
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LDAPEntryPanel.java
@@ -182,7 +182,8 @@
            !authenticationRequired(getInfo().getServerDescriptor());
        if (enable)
        {
          if (ev.getEntry() == null)
          Entry entry = ev .getEntry();
          if (entry == null)
          {
            // Something changed that is wrong: assume the entry has been
            // modified, when the user tries to save we will inform of the
@@ -191,8 +192,8 @@
          }
          else
          {
            boolean modified = !ev.getEntry().getName().equals(searchResult.getName())
                || !ModifyEntryTask.getModifications(ev .getEntry(), searchResult, getInfo()).isEmpty();
            boolean modified = !entry.getName().equals(searchResult.getName())
                || !ModifyEntryTask.getModifications(entry, searchResult, getInfo()).isEmpty();
            enable = modified;
          }
        }
@@ -497,7 +498,7 @@
          Utilities.getFrame(this),
          INFO_CTRL_PANEL_MODIFYING_ENTRY_CHANGES_TITLE.get(), getInfo());
      dlg.setModal(modal);
      org.opends.server.types.Entry entry = displayedEntryPanel.getEntry();
      Entry entry = displayedEntryPanel.getEntry();
      newTask = new ModifyEntryTask(getInfo(), dlg, entry, searchResult, controller, treePath);
      for (Task task : getInfo().getTasks())
      {
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LDIFViewEntryPanel.java
@@ -22,7 +22,6 @@
import java.awt.GridBagConstraints;
import java.awt.Point;
import java.io.IOException;
import java.io.StringReader;
import java.util.List;
import javax.swing.JLabel;
@@ -37,11 +36,10 @@
import org.forgerock.opendj.ldap.Attribute;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.Entry;
import org.forgerock.opendj.ldif.LDIFEntryReader;
import org.opends.guitools.controlpanel.task.OfflineUpdateException;
import org.opends.guitools.controlpanel.util.Utilities;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.OpenDsException;
import org.opends.server.util.LDIFReader;
/** The panel displaying an LDIF view of an entry. */
public class LDIFViewEntryPanel extends ViewEntryPanel
@@ -258,13 +256,12 @@
  }
  @Override
  public org.opends.server.types.Entry getEntry() throws OpenDsException
  public Entry getEntry() throws OpenDsException
  {
    String ldif = getLDIF();
    try (LDIFImportConfig ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
        LDIFReader reader = new LDIFReader(ldifImportConfig))
    try (LDIFEntryReader reader = new LDIFEntryReader(ldif))
    {
      org.opends.server.types.Entry entry = reader.readEntry(checkSchema());
      Entry entry = reader.readEntry();
      addValuesInRDN(entry);
      return entry;
    }
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/SimplifiedViewEntryPanel.java
@@ -18,6 +18,7 @@
import static com.forgerock.opendj.cli.Utils.*;
import static org.forgerock.opendj.ldap.schema.SchemaValidationPolicy.*;
import static org.opends.messages.AdminToolMessages.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
@@ -38,7 +39,6 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.StringReader;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -84,6 +84,7 @@
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.forgerock.opendj.ldap.schema.Syntax;
import org.forgerock.opendj.ldif.LDIFEntryReader;
import org.opends.guitools.controlpanel.datamodel.BinaryValue;
import org.opends.guitools.controlpanel.datamodel.CheckEntrySyntaxException;
import org.opends.guitools.controlpanel.datamodel.ObjectClassValue;
@@ -95,10 +96,8 @@
import org.opends.guitools.controlpanel.ui.nodes.DndBrowserNodes;
import org.opends.guitools.controlpanel.util.Utilities;
import org.opends.server.schema.SchemaConstants;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.OpenDsException;
import org.opends.server.types.Schema;
import org.opends.server.util.LDIFReader;
/** The panel displaying a simplified view of an entry. */
class SimplifiedViewEntryPanel extends ViewEntryPanel
@@ -1166,7 +1165,7 @@
  }
  @Override
  public org.opends.server.types.Entry getEntry() throws OpenDsException
  public Entry getEntry() throws OpenDsException
  {
    final List<LocalizableMessage> errors = new ArrayList<>();
@@ -1215,10 +1214,10 @@
    }
    final String ldif = getLDIF();
    try (LDIFImportConfig ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
        LDIFReader reader = new LDIFReader(ldifImportConfig))
    try (LDIFEntryReader reader = new LDIFEntryReader(ldif)
        .setSchemaValidationPolicy(checkSchema() ? defaultPolicy():ignoreAll()))
    {
      final org.opends.server.types.Entry entry = reader.readEntry(checkSchema());
      final Entry entry = reader.readEntry();
      addValuesInRDN(entry);
      return entry;
    }
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TableViewEntryPanel.java
@@ -17,6 +17,7 @@
package org.opends.guitools.controlpanel.ui;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.forgerock.opendj.ldap.schema.SchemaValidationPolicy.*;
import static org.opends.messages.AdminToolMessages.*;
import java.awt.Component;
@@ -26,7 +27,6 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
@@ -57,6 +57,7 @@
import org.forgerock.opendj.ldap.RDN;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.forgerock.opendj.ldif.LDIFEntryReader;
import org.opends.guitools.controlpanel.datamodel.BinaryValue;
import org.opends.guitools.controlpanel.datamodel.ObjectClassValue;
import org.opends.guitools.controlpanel.datamodel.SortableTableModel;
@@ -64,10 +65,8 @@
import org.opends.guitools.controlpanel.ui.renderer.AttributeCellEditor;
import org.opends.guitools.controlpanel.ui.renderer.LDAPEntryTableCellRenderer;
import org.opends.guitools.controlpanel.util.Utilities;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.OpenDsException;
import org.opends.server.types.Schema;
import org.opends.server.util.LDIFReader;
import org.opends.server.util.ServerConstants;
/** The panel displaying a table view of an LDAP entry. */
@@ -200,7 +199,7 @@
  }
  @Override
  public org.opends.server.types.Entry getEntry() throws OpenDsException
  public Entry getEntry() throws OpenDsException
  {
    if (SwingUtilities.isEventDispatchThread())
    {
@@ -225,10 +224,10 @@
      }
    }
    String ldif = getLDIF();
    try (LDIFImportConfig ldifImportConfig = new LDIFImportConfig(new StringReader(ldif));
        LDIFReader reader = new LDIFReader(ldifImportConfig))
    try (LDIFEntryReader reader = new LDIFEntryReader(ldif)
        .setSchemaValidationPolicy(checkSchema() ? defaultPolicy() : ignoreAll()))
    {
      org.opends.server.types.Entry entry = reader.readEntry(checkSchema());
      Entry entry = reader.readEntry();
      addValuesInRDN(entry);
      return entry;
    }
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
@@ -53,7 +53,6 @@
import org.opends.guitools.controlpanel.ui.nodes.BasicNode;
import org.opends.guitools.controlpanel.util.Utilities;
import org.opends.server.schema.SchemaConstants;
import org.opends.server.types.Attributes;
import org.opends.server.types.OpenDsException;
import org.opends.server.types.Schema;
import org.opends.server.util.Base64;
@@ -93,7 +92,7 @@
   * @throws OpenDsException if the entry cannot be generated (in particular if
   * the user provided invalid data).
   */
  public abstract org.opends.server.types.Entry getEntry() throws OpenDsException;
  public abstract Entry getEntry() throws OpenDsException;
  /**
   * Updates the contents of the panel.
@@ -274,7 +273,7 @@
   * Adds the values in the RDN to the entry definition.
   * @param entry the entry to be updated.
   */
  protected void addValuesInRDN(org.opends.server.types.Entry entry)
  protected void addValuesInRDN(Entry entry)
  {
    // Add the values in the RDN if they are not there
    for (AVA ava : entry.getName().rdn())
@@ -282,7 +281,7 @@
      String attrName = ava.getAttributeName();
      ByteString value = ava.getAttributeValue();
      boolean done = false;
      for (org.opends.server.types.Attribute attr : entry.getAttribute(attrName))
      for (Attribute attr : entry.getAllAttributes(attrName))
      {
        // TODO JNR use Entry.getAttribute(AttributeDescription) instead?
        if (attr.getAttributeDescription().toString().equals(attrName))
@@ -296,12 +295,13 @@
      }
      if (!done)
      {
        entry.addAttribute(Attributes.create(ava.getAttributeType(), value), newArrayList(value));
        AttributeDescription attrDesc = AttributeDescription.create(ava.getAttributeType());
        entry.addAttribute(new LinkedAttribute(attrDesc, value), newArrayList(value));
      }
    }
  }
  private List<ByteString> getValues(org.opends.server.types.Attribute attr)
  private List<ByteString> getValues(Attribute attr)
  {
    List<ByteString> newValues = new ArrayList<>();
    Iterator<ByteString> it = attr.iterator();