/**
  * add new proxy to descriptor to configuration descriptor
  *
  * @param proxyDescriptor - new proxy descriptor
  */
 private void addNewProxy(ProxyDescriptor proxyDescriptor) {
   boolean isDefaultProxy = proxyDescriptor.isDefaultProxy();
   MutableCentralConfigDescriptor configDescriptor = centralConfigService.getMutableDescriptor();
   configDescriptor.proxyChanged(proxyDescriptor, isDefaultProxy);
   configDescriptor.addProxy(proxyDescriptor, isDefaultProxy);
   centralConfigService.saveEditedDescriptorAndReload(configDescriptor);
 }
  public LdapCreateUpdatePanel(CreateUpdateAction action, LdapSetting ldapDescriptor) {
    /**
     * Creating a local copy of the original descriptor so that we can fool around with it without
     * changing the original until we need to save
     */
    super(action, new LdapSetting(ldapDescriptor));
    originalDescriptor = ldapDescriptor;
    setWidth(500);

    add(form);

    TitledBorder border = new TitledBorder("border");
    form.add(border);

    // Ldap key
    RequiredTextField<String> ldapKeyField = new RequiredTextField<String>("key");
    setDefaultFocusField(ldapKeyField);
    ldapKeyField.setEnabled(isCreate()); // don't allow key update
    if (isCreate()) {
      ldapKeyField.add(new XsdNCNameValidator("Invalid LDAP key '%s'"));
      ldapKeyField.add(new UniqueXmlIdValidator(centralConfigService.getMutableDescriptor()));
    }
    border.add(ldapKeyField);
    border.add(new SchemaHelpBubble("key.help"));

    border.add(new StyledCheckbox("enabled"));

    TextField<String> ldapUrlField = new RequiredTextField<String>("ldapUrl");
    ldapUrlField.add(new UriValidator("ldap", "ldaps"));
    border.add(ldapUrlField);
    border.add(new SchemaHelpBubble("ldapUrl.help"));

    TitledBorder borderDn = new TitledBorder("borderDn");
    form.add(borderDn);
    borderDn.add(new TextField("userDnPattern"));
    borderDn.add(new TextField("emailAttribute"));
    borderDn.add(new SchemaHelpBubble("emailAttribute.help"));
    borderDn.add(new StyledCheckbox("autoCreateUser"));
    borderDn.add(new SchemaHelpBubble("autoCreateUser.help"));
    borderDn.add(new SchemaHelpBubble("userDnPattern.help"));

    addSearchFields(borderDn);

    addTestConnectionFields();

    // Cancel button
    form.add(new ModalCloseLink("cancel"));

    // Submit button
    TitledAjaxSubmitLink submitButton = createSubmitButton();
    form.add(submitButton);
    form.add(new DefaultButtonBehavior(submitButton));

    add(form);
  }
 /**
  * @param layoutName
  * @return
  */
 private RepoLayout getLayout(String layoutName) {
   RepoLayout layout = null;
   List<RepoLayout> repoLayouts = centralConfigService.getDescriptor().getRepoLayouts();
   for (RepoLayout repoLayout : repoLayouts) {
     if (repoLayout.getName().equals(layoutName)) {
       layout = repoLayout;
       break;
     }
   }
   return layout;
 }
 private P2Repo resolveLocalP2RepoFromUrl(String url) {
   String rpp = StringUtils.removeStart(url, "local://");
   // rpp = rpp.substring(0, rpp.indexOf('/'));
   RepoPath repoPath = RepoPathFactory.create(rpp);
   LocalRepoDescriptor localRepoDescriptor =
       centralConfig.getMutableDescriptor().getLocalRepositoriesMap().get(repoPath.getRepoKey());
   if (localRepoDescriptor != null) {
     return new P2Repo(null, repoPath.getRepoKey(), url);
   }
   return null;
 }
  /** Populate model configuration from remote repository descriptor */
  public void populateRemoteRepositoryConfigValuesToModel(
      HttpRepoDescriptor descriptor, RemoteRepositoryConfigModel model) {
    GeneralRepositoryConfigModel general = createGeneralConfig(descriptor);
    model.setGeneral(general);

    RemoteBasicRepositoryConfigModel basic = createRemoteBasicConfig(descriptor);
    model.setBasic(basic);

    RemoteReplicationDescriptor replicationDescriptor =
        centralConfig.getDescriptor().getRemoteReplication(descriptor.getKey());
    if (replicationDescriptor != null) {
      RemoteReplicationConfigModel replication =
          createRemoteReplicationConfigModel(replicationDescriptor);
      model.setReplications(Lists.newArrayList(replication));
    }
    RemoteAdvancedRepositoryConfigModel advanced = createRemoteAdvancedConfig(descriptor);
    model.setAdvanced(advanced);
    TypeSpecificConfigModel typeSpecific =
        createRemoteTypeSpecific(descriptor.getType(), descriptor);
    model.setTypeSpecific(typeSpecific);
  }
  /** Populate model configuration from local repository descriptor */
  public void populateLocalDescriptorValuesToModel(
      LocalRepoDescriptor descriptor, LocalRepositoryConfigModel model) {
    GeneralRepositoryConfigModel general = createGeneralConfig(descriptor);
    LocalBasicRepositoryConfigModel basic = createLocalBasicConfig(descriptor);
    LocalAdvancedRepositoryConfigModel advanced = createLocalAdvancedConfig(descriptor);
    TypeSpecificConfigModel typeSpecific =
        createLocalTypeSpecific(descriptor.getType(), descriptor);

    List<LocalReplicationDescriptor> replicationDescriptors =
        centralConfig.getDescriptor().getMultiLocalReplications(descriptor.getKey());
    List<LocalReplicationConfigModel> replications =
        replicationDescriptors
            .stream()
            .map(this::createLocalReplicationConfig)
            .collect(Collectors.toList());

    model.setGeneral(general);
    model.setBasic(basic);
    model.setAdvanced(advanced);
    model.setTypeSpecific(typeSpecific);
    model.setReplications(replications);
  }