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

Jean-Noël Rouvignac
04.57.2016 3082bffd895391a94bd1600af3e5a954a9c30262
Code cleanups
3 files modified
156 ■■■■■ changed files
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSchemaElement.java 22 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java 45 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/CustomObjectClassPanel.java 89 ●●●●● patch | view | raw | blame | history
opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractSchemaElement.java
@@ -143,9 +143,9 @@
        }
        T extraProperties0(final String extensionName, final String... extensionValues) {
            if (this.extraProperties.get(extensionName) != null) {
                final List<String> tempExtraProperties =
                        new ArrayList<>(this.extraProperties.get(extensionName));
            List<String> extraProps = this.extraProperties.get(extensionName);
            if (extraProps != null) {
                final List<String> tempExtraProperties = new ArrayList<>(extraProps);
                tempExtraProperties.addAll(Arrays.asList(extensionValues));
                this.extraProperties.put(extensionName, tempExtraProperties);
            } else {
@@ -174,13 +174,15 @@
        }
        T removeExtraProperty0(final String extensionName, final String... extensionValues) {
            if (this.extraProperties.get(extensionName) != null && extensionValues.length > 0) {
                final List<String> tempExtraProperties =
                        new ArrayList<>(this.extraProperties.get(extensionName));
                tempExtraProperties.removeAll(Arrays.asList(extensionValues));
                this.extraProperties.put(extensionName, tempExtraProperties);
            } else if (this.extraProperties.get(extensionName) != null) {
                this.extraProperties.remove(extensionName);
            final List<String> extraProps = this.extraProperties.get(extensionName);
            if (extraProps != null) {
                if (extensionValues.length > 0) {
                    final List<String> tempExtraProperties = new ArrayList<>(extraProps);
                    tempExtraProperties.removeAll(Arrays.asList(extensionValues));
                    this.extraProperties.put(extensionName, tempExtraProperties);
                } else {
                    this.extraProperties.remove(extensionName);
                }
            }
            return getThis();
        }
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
@@ -40,6 +40,7 @@
import org.forgerock.i18n.LocalizableMessageDescriptor.Arg1;
import org.forgerock.opendj.ldap.ModificationType;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.SchemaElement;
import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
import org.opends.guitools.controlpanel.ui.ColorAndFontConstants;
import org.opends.guitools.controlpanel.ui.ProgressDialog;
@@ -48,7 +49,6 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.schema.SomeSchemaElement;
import org.opends.server.types.Attributes;
import org.opends.server.types.CommonSchemaElements;
import org.opends.server.types.Entry;
import org.opends.server.types.ExistingFileBehavior;
import org.opends.server.types.LDIFExportConfig;
@@ -488,16 +488,7 @@
  private ObjectClass getObjectClassToAdd(ObjectClass ocToDelete)
  {
    boolean containsAttribute = false;
    for (AttributeType attr : providedAttrsToDelete)
    {
      if(ocToDelete.getRequiredAttributes().contains(attr) ||
      ocToDelete.getOptionalAttributes().contains(attr))
      {
        containsAttribute = true;
        break;
      }
    }
    boolean containsAttribute = containsAttributeToDelete(ocToDelete);
    boolean hasSuperior = false;
    Set<ObjectClass> newSuperiors = new LinkedHashSet<>();
    for (ObjectClass sup : ocToDelete.getSuperiorClasses())
@@ -522,9 +513,7 @@
    if (containsAttribute || hasSuperior)
    {
      ArrayList<String> allNames = new ArrayList<>(ocToDelete.getNormalizedNames());
      Map<String, List<String>> extraProperties =
        cloneExtraProperties(ocToDelete);
      Map<String, List<String>> extraProperties = cloneExtraProperties(ocToDelete);
      Set<AttributeType> required;
      Set<AttributeType> optional;
      if (containsAttribute)
@@ -541,7 +530,7 @@
      }
      return new ObjectClass("",
          ocToDelete.getPrimaryName(),
          allNames,
          new ArrayList<>(ocToDelete.getNormalizedNames()),
          ocToDelete.getOID(),
          ocToDelete.getDescription(),
          newSuperiors,
@@ -558,6 +547,19 @@
    }
  }
  private boolean containsAttributeToDelete(ObjectClass ocToDelete)
  {
    for (AttributeType attr : providedAttrsToDelete)
    {
      if (ocToDelete.getRequiredAttributes().contains(attr)
          || ocToDelete.getOptionalAttributes().contains(attr))
      {
        return true;
      }
    }
    return false;
  }
  private Set<ObjectClass> getNewSuperiors(ObjectClass currentSup)
  {
    Set<ObjectClass> newSuperiors = new LinkedHashSet<>();
@@ -633,11 +635,8 @@
    {
      for (ObjectClass oc : schema.getObjectClasses().values())
      {
        if (oc.getRequiredAttributes().contains(attr))
        {
          dependentClasses.add(oc);
        }
        else if (oc.getOptionalAttributes().contains(attr))
        if (oc.getRequiredAttributes().contains(attr)
            || oc.getOptionalAttributes().contains(attr))
        {
          dependentClasses.add(oc);
        }
@@ -657,15 +656,13 @@
   * @param element the schema element.
   * @return the extra properties of the provided schema element.
   */
  public static Map<String, List<String>> cloneExtraProperties(
      CommonSchemaElements element)
  public static Map<String, List<String>> cloneExtraProperties(SchemaElement element)
  {
    Map<String, List<String>> extraProperties = new HashMap<>();
    Map<String, List<String>> props = element.getExtraProperties();
    for (String name : props.keySet())
    {
      List<String> values = new ArrayList<>(props.get(name));
      extraProperties.put(name, values);
      extraProperties.put(name, new ArrayList<>(props.get(name)));
    }
    return extraProperties;
  }
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/CustomObjectClassPanel.java
@@ -138,7 +138,6 @@
  private boolean ignoreChangeEvents;
  /** Default constructor of the panel. */
  public CustomObjectClassPanel()
  {
@@ -203,7 +202,7 @@
      public void actionPerformed(ActionEvent ev)
      {
        ArrayList<LocalizableMessage> errors = new ArrayList<>();
        saveChanges(false, errors);
        saveChanges(errors);
      }
    });
  }
@@ -451,12 +450,9 @@
    titlePanel.setDetails(LocalizableMessage.raw(n));
    name.setText(n);
    SortableListModel<AttributeType> modelRequired =
      attributes.getSelectedListModel1();
    SortableListModel<AttributeType> modelAvailable =
      attributes.getSelectedListModel2();
    SortableListModel<AttributeType> availableModel =
      attributes.getAvailableListModel();
    SortableListModel<AttributeType> modelRequired = attributes.getSelectedListModel1();
    SortableListModel<AttributeType> modelAvailable = attributes.getSelectedListModel2();
    SortableListModel<AttributeType> availableModel = attributes.getAvailableListModel();
    availableModel.addAll(modelRequired.getData());
    availableModel.addAll(modelAvailable.getData());
    modelRequired.clear();
@@ -535,31 +531,14 @@
  {
    final ServerDescriptor desc = ev.getNewDescriptor();
    Schema s = desc.getSchema();
    final boolean schemaChanged;
    if (schema != null && s != null)
    {
      schemaChanged = !ServerDescriptor.areSchemasEqual(s, schema);
    }
    else if (schema == null && s != null)
    {
      schemaChanged = true;
    }
    else if (s == null && schema != null)
    {
      schemaChanged = false;
    }
    else
    {
      schemaChanged = false;
    }
    final boolean schemaChanged = schemaChanged(s);
    if (schemaChanged)
    {
      schema = s;
      updateErrorPaneIfAuthRequired(desc,
          isLocal() ?
        INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_FOR_OBJECTCLASS_EDIT.get() :
      INFO_CTRL_PANEL_CANNOT_CONNECT_TO_REMOTE_DETAILS.get(desc.getHostname()));
      updateErrorPaneIfAuthRequired(desc, isLocal()
          ? INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_FOR_OBJECTCLASS_EDIT.get()
          : INFO_CTRL_PANEL_CANNOT_CONNECT_TO_REMOTE_DETAILS.get(desc.getHostname()));
    }
    else if (schema == null)
    {
@@ -574,14 +553,10 @@
      @Override
      public void run()
      {
        delete.setEnabled(!authenticationRequired(desc)
            && !authenticationRequired(desc)
            && schema != null);
        final boolean enabled = !authenticationRequired(desc) && schema != null;
        delete.setEnabled(enabled);
        checkEnableSaveChanges();
        saveChanges.setEnabled(saveChanges.isEnabled() &&
            !authenticationRequired(desc)
            && !authenticationRequired(desc)
            && schema != null);
        saveChanges.setEnabled(enabled && saveChanges.isEnabled());
        if (schemaChanged && schema != null)
        {
          superiors.setSchema(schema);
@@ -591,6 +566,15 @@
    });
  }
  private boolean schemaChanged(Schema s)
  {
    if (s != null)
    {
      return schema == null || !ServerDescriptor.areSchemasEqual(s, schema);
    }
    return false;
  }
  @Override
  public boolean mustCheckUnsavedChanges()
  {
@@ -612,8 +596,8 @@
    result = unsavedChangesDlg.getResult();
    if (result == UnsavedChangesDialog.Result.SAVE)
    {
      ArrayList<LocalizableMessage> errors = new ArrayList<>();
      saveChanges(true, errors);
      List<LocalizableMessage> errors = new ArrayList<>();
      saveChanges(errors);
      if (!errors.isEmpty())
      {
        result = UnsavedChangesDialog.Result.CANCEL;
@@ -706,7 +690,7 @@
    }
  }
  private void saveChanges(boolean modal, ArrayList<LocalizableMessage> errors)
  private void saveChanges(List<LocalizableMessage> errors)
  {
    for (JLabel label : labels)
    {
@@ -771,15 +755,7 @@
        }
        else
        {
          boolean notPreviouslyDefined = true;
          for (String oldAlias : oldAliases)
          {
            if (oldAlias.equalsIgnoreCase(alias))
            {
              notPreviouslyDefined = false;
              break;
            }
          }
          boolean notPreviouslyDefined = !containsIgnoreCase(oldAliases, alias);
          if (notPreviouslyDefined)
          {
            LocalizableMessage elementType =
@@ -794,7 +770,6 @@
      }
    }
   //validate the superiority.
    for(ObjectClass superior : getObjectClassSuperiors())
    {
@@ -841,9 +816,19 @@
    }
  }
  private boolean containsIgnoreCase(Collection<String> col, String toFind)
  {
    for (String s : col)
    {
      if (s.equalsIgnoreCase(toFind))
      {
        return true;
      }
    }
    return false;
  }
  private void validateSuperiority(ObjectClass superior,
          ArrayList<LocalizableMessage> errors)
  private void validateSuperiority(ObjectClass superior, List<LocalizableMessage> errors)
  {
    if(superior.getNameOrOID().equalsIgnoreCase(objectClass.getNameOrOID()))
    {
@@ -1008,7 +993,6 @@
    Collection<AttributeType> allAttrs = schema.getAttributeTypes();
    attributes.getAvailableListModel().addAll(allAttrs);
    HashSet<AttributeType> toDelete = new HashSet<>();
    for (AttributeType attr : attributes.getSelectedListModel1().getData())
    {
@@ -1122,7 +1106,6 @@
        attributes.getSelectedListModel2().getSize() - 1);
  }
  /**
   * A renderer for the attribute lists.  The renderer basically marks the
   * inherited attributes with an asterisk.