Exemplo n.º 1
0
  /** Creates a user data object with default values. */
  public UserData() {
    interactive = true;
    startServer = true;
    enableWindowsService = false;
    forceOnError = true;
    verbose = false;

    LinkedList<String> baseDn = new LinkedList<>();
    baseDn.add("dc=example,dc=com");
    NewSuffixOptions defaultNewSuffixOptions = NewSuffixOptions.createEmpty(baseDn);
    setNewSuffixOptions(defaultNewSuffixOptions);

    // See what we can propose as port
    int defaultLdapPort = getDefaultPort();
    if (defaultLdapPort != -1) {
      setServerPort(defaultLdapPort);
    }

    //  See what we can propose as port
    int defaultAdminPort = getDefaultAdminConnectorPort();
    if (defaultAdminPort != -1) {
      setAdminConnectorPort(defaultAdminPort);
    }

    setHostName(getDefaultHostName());

    setDirectoryManagerDn(Constants.DIRECTORY_MANAGER_DN);

    setNewSuffixOptions(defaultNewSuffixOptions);
    DataReplicationOptions repl = DataReplicationOptions.createStandalone();
    setReplicationOptions(repl);
    setGlobalAdministratorUID(Constants.GLOBAL_ADMIN_UID);

    SuffixesToReplicateOptions suffixes =
        new SuffixesToReplicateOptions(
            SuffixesToReplicateOptions.Type.REPLICATE_WITH_EXISTING_SUFFIXES,
            new HashSet<SuffixDescriptor>(),
            new HashSet<SuffixDescriptor>());
    setSuffixesToReplicateOptions(suffixes);
    SecurityOptions sec = SecurityOptions.createNoCertificateOptions();
    sec.setSslPort(getDefaultSslPort(defaultLdapPort));
    setSecurityOptions(sec);

    remoteWithNoReplicationPort = new HashMap<>();

    createDefaultJavaArguments();
  }
  private void updateWarningMessage(UserData uData) {
    Message msg = null;

    DataReplicationOptions repl = uData.getReplicationOptions();
    SuffixesToReplicateOptions suf = uData.getSuffixesToReplicateOptions();
    boolean createSuffix =
        repl.getType() == DataReplicationOptions.Type.FIRST_IN_TOPOLOGY
            || repl.getType() == DataReplicationOptions.Type.STANDALONE
            || suf.getType() == SuffixesToReplicateOptions.Type.NEW_SUFFIX_IN_TOPOLOGY;

    if (createSuffix) {
      NewSuffixOptions options = uData.getNewSuffixOptions();

      switch (options.getType()) {
        case IMPORT_FROM_LDIF_FILE:
          File ldifFile = new File(options.getLDIFPaths().getFirst());
          if (ldifFile.length() > WARNING_THRESOLD_FOR_IMPORT) {
            msg = INFO_IMPORT_FILE_WARNING_UPDATE_RUNTIME_ARGS.get();
          }
          break;

        case IMPORT_AUTOMATICALLY_GENERATED_DATA:
          if (options.getNumberEntries() > WARNING_THRESOLD_AUTOMATICALLY_GENERATED_IMPORT) {
            msg = INFO_AUTOMATICALLY_GENERATED_DATA_WARNING_UPDATE_RUNTIME_ARGS.get();
          }
          break;
      }
    } else if (repl.getType() == DataReplicationOptions.Type.IN_EXISTING_TOPOLOGY) {
      int maxReplicatedEntries = 0;

      Set<SuffixDescriptor> suffixes = suf.getSuffixes();
      for (SuffixDescriptor suffix : suffixes) {
        int suffixEntries = 0;
        for (ReplicaDescriptor replica : suffix.getReplicas()) {
          suffixEntries = Math.max(suffixEntries, replica.getEntries());
        }
        maxReplicatedEntries += suffixEntries;
      }

      if (maxReplicatedEntries > WARNING_THRESOLD_REPLICATED_ENTRIES) {
        msg = INFO_REPLICATED_ENTRIES_WARNING_UPDATE_RUNTIME_ARGS.get();
      }
    }

    if (msg != null) {
      HtmlProgressMessageFormatter formatter = new HtmlProgressMessageFormatter();
      StringBuilder buf = new StringBuilder();
      String space = formatter.getSpace().toString();
      String lBreak = formatter.getLineBreak().toString();
      String title =
          UIFactory.applyFontToHtml(INFO_GENERAL_WARNING.get().toString(), UIFactory.TITLE_FONT);
      String details =
          UIFactory.applyFontToHtml(msg.toString(), UIFactory.SECONDARY_FIELD_VALID_FONT);
      buf.append(UIFactory.getIconHtml(UIFactory.IconType.WARNING_LARGE))
          .append(space)
          .append(space)
          .append(title)
          .append(lBreak)
          .append(lBreak)
          .append(details);
      String s = "<form>" + UIFactory.applyErrorBackgroundToHtml(buf.toString()) + "</form>";

      warning.setText(s);
      warning.setVisible(true);
    } else {
      warning.setText("");
      warning.setVisible(false);
    }
  }