Ejemplo n.º 1
0
  private void deleteObjectclass() {
    ArrayList<LocalizableMessage> errors = new ArrayList<>();
    ProgressDialog dlg =
        new ProgressDialog(
            Utilities.createFrame(),
            Utilities.getParentDialog(this),
            INFO_CTRL_PANEL_DELETE_OBJECTCLASS_TITLE.get(),
            getInfo());
    LinkedHashSet<ObjectClass> ocsToDelete = new LinkedHashSet<>();
    ocsToDelete.add(objectClass);
    LinkedHashSet<AttributeType> attrsToDelete = new LinkedHashSet<>(0);

    DeleteSchemaElementsTask newTask =
        new DeleteSchemaElementsTask(getInfo(), dlg, ocsToDelete, attrsToDelete);
    for (Task task : getInfo().getTasks()) {
      task.canLaunch(newTask, errors);
    }
    Schema schema = getInfo().getServerDescriptor().getSchema();
    ArrayList<String> childClasses = new ArrayList<>();
    if (schema != null) {
      for (ObjectClass o : schema.getObjectClasses().values()) {
        for (ObjectClass superior : o.getSuperiorClasses()) {
          if (objectClass.equals(superior)) {
            childClasses.add(o.getNameOrOID());
          }
        }
      }
    } else {
      errors.add(ERR_CTRL_PANEL_SCHEMA_NOT_FOUND_DETAILS.get());
    }
    if (errors.isEmpty()) {
      LocalizableMessageBuilder mb = new LocalizableMessageBuilder();

      if (!childClasses.isEmpty()) {
        mb.append(
            INFO_OBJECTCLASS_IS_SUPERIOR.get(
                ocName, Utilities.getStringFromCollection(childClasses, ", ")));
        mb.append("<br>");
      }
      LocalizableMessage confirmationMessage =
          INFO_CTRL_PANEL_CONFIRMATION_DELETE_OBJECTCLASS_DETAILS.get(ocName);
      mb.append(confirmationMessage);
      if (displayConfirmationDialog(
          INFO_CTRL_PANEL_CONFIRMATION_REQUIRED_SUMMARY.get(), confirmationMessage)) {
        launchOperation(
            newTask,
            INFO_CTRL_PANEL_DELETING_OBJECTCLASS_SUMMARY.get(ocName),
            INFO_CTRL_PANEL_DELETING_OBJECTCLASS_COMPLETE.get(),
            INFO_CTRL_PANEL_DELETING_OBJECTCLASS_SUCCESSFUL.get(ocName),
            ERR_CTRL_PANEL_DELETING_OBJECTCLASS_ERROR_SUMMARY.get(),
            ERR_CTRL_PANEL_DELETING_OBJECTCLASS_ERROR_DETAILS.get(ocName),
            null,
            dlg);
        dlg.setVisible(true);
      }
    } else {
      displayErrorDialog(errors);
    }
  }
Ejemplo n.º 2
0
  private void saveChanges(boolean modal, ArrayList<LocalizableMessage> errors) {
    for (JLabel label : labels) {
      setPrimaryValid(label);
    }
    String n = getObjectClassName();
    LocalizableMessageBuilder err = new LocalizableMessageBuilder();
    if (n.length() == 0) {
      errors.add(ERR_CTRL_PANEL_OBJECTCLASS_NAME_REQUIRED.get());
      setPrimaryInvalid(lName);
    } else if (!n.equalsIgnoreCase(objectClass.getNameOrOID())) {
      if (!StaticUtils.isValidSchemaElement(n, 0, n.length(), err)) {
        errors.add(ERR_CTRL_PANEL_INVALID_OBJECTCLASS_NAME.get(err));
        setPrimaryInvalid(lName);
        err = new LocalizableMessageBuilder();
      } else {
        LocalizableMessage elementType = NewAttributePanel.getSchemaElementType(n, schema);
        if (elementType != null) {
          errors.add(ERR_CTRL_PANEL_OBJECTCLASS_NAME_ALREADY_IN_USE.get(n, elementType));
          setPrimaryInvalid(lName);
        }
      }
    }
    n = oid.getText().trim();
    if (n.length() > 0 && !n.equalsIgnoreCase(objectClass.getOID())) {
      if (!StaticUtils.isValidSchemaElement(n, 0, n.length(), err)) {
        errors.add(ERR_CTRL_PANEL_OID_NOT_VALID.get(err));
        setPrimaryInvalid(lOID);
        err = new LocalizableMessageBuilder();
      } else {
        LocalizableMessage elementType = NewAttributePanel.getSchemaElementType(n, schema);
        if (elementType != null) {
          errors.add(ERR_CTRL_PANEL_OID_ALREADY_IN_USE.get(n, elementType));
          setPrimaryInvalid(lOID);
        }
      }
    }

    Collection<String> aliases = getAliases();
    Collection<String> oldAliases = getAliases(objectClass);

    if (!aliases.equals(oldAliases)) {
      for (String alias : aliases) {
        if (alias.trim().length() == 0) {
          errors.add(ERR_CTRL_PANEL_EMPTY_ALIAS.get());
          setPrimaryInvalid(lAliases);
        } else {
          boolean notPreviouslyDefined = true;
          for (String oldAlias : oldAliases) {
            if (oldAlias.equalsIgnoreCase(alias)) {
              notPreviouslyDefined = false;
              break;
            }
          }
          if (notPreviouslyDefined) {
            LocalizableMessage elementType = NewAttributePanel.getSchemaElementType(alias, schema);
            if (elementType != null) {
              errors.add(ERR_CTRL_PANEL_ALIAS_ALREADY_IN_USE.get(n, elementType));
              setPrimaryInvalid(lAliases);
            }
          }
        }
      }
    }

    // validate the superiority.
    for (ObjectClass superior : getObjectClassSuperiors()) {
      validateSuperiority(superior, errors);
    }
    checkCompatibleSuperiors(getObjectClassSuperiors(), getObjectClassType(), errors);

    if (errors.isEmpty()) {
      ProgressDialog dlg =
          new ProgressDialog(
              Utilities.createFrame(),
              Utilities.getParentDialog(this),
              INFO_CTRL_PANEL_MODIFY_ATTRIBUTE_TITLE.get(),
              getInfo());

      ModifyObjectClassTask newTask =
          new ModifyObjectClassTask(getInfo(), dlg, objectClass, getNewObjectClass());
      for (ConfigurationElementCreatedListener listener :
          getConfigurationElementCreatedListeners()) {
        newTask.addConfigurationElementCreatedListener(listener);
      }
      for (Task task : getInfo().getTasks()) {
        task.canLaunch(newTask, errors);
      }
      if (errors.isEmpty()) {
        launchOperation(
            newTask,
            INFO_CTRL_PANEL_MODIFYING_OBJECTCLASS_SUMMARY.get(ocName),
            INFO_CTRL_PANEL_MODIFYING_OBJECTCLASS_COMPLETE.get(),
            INFO_CTRL_PANEL_MODIFYING_OBJECTCLASS_SUCCESSFUL.get(ocName),
            ERR_CTRL_PANEL_MODIFYING_OBJECTCLASS_ERROR_SUMMARY.get(),
            ERR_CTRL_PANEL_MODIFYING_OBJECTCLASS_ERROR_DETAILS.get(ocName),
            null,
            dlg);
        dlg.setVisible(true);
      }
    }

    if (!errors.isEmpty()) {
      displayErrorDialog(errors);
    }
  }