opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPDriver.java
@@ -64,6 +64,8 @@ import org.forgerock.opendj.ldap.ResultCode; import org.forgerock.opendj.ldap.SearchResultReferenceIOException; import org.forgerock.opendj.ldap.SearchScope; import org.forgerock.opendj.ldap.requests.Requests; import org.forgerock.opendj.ldap.requests.SearchRequest; import org.forgerock.opendj.ldap.responses.SearchResultEntry; import org.forgerock.opendj.ldif.ConnectionEntryReader; @@ -524,18 +526,15 @@ } private Collection<DN> listEntries(DN dn, Filter filter) throws LdapException { List<DN> names = new LinkedList<>(); ConnectionEntryReader reader = connection.search(dn.toString(), SearchScope.SINGLE_LEVEL, filter.toString()); try { final SearchRequest searchRequest = Requests.newSearchRequest(dn, SearchScope.SINGLE_LEVEL, filter); try (ConnectionEntryReader reader = connection.search(searchRequest)) { List<DN> names = new LinkedList<>(); while (reader.hasNext()) { names.add(reader.readEntry().getName()); } } catch (SearchResultReferenceIOException e) { // Ignore. } finally { reader.close(); return names; } catch (SearchResultReferenceIOException ignore) { return Collections.emptyList(); } return names; } } opendj-config/src/main/java/org/forgerock/opendj/config/client/ldap/LDAPManagementContext.java
@@ -179,23 +179,19 @@ return context; } private static ManagementContext newLDIFManagementContext(final File ldifFile, final LDAPProfile profile, final List<IOException> exceptions) throws IOException { final BufferedReader configReader = new BufferedReader(new FileReader(ldifFile)); try { private static ManagementContext newLDIFManagementContext(final File ldifFile, final List<IOException> exceptions) throws IOException { try (final FileReader fileReader = new FileReader(ldifFile); final BufferedReader configReader = new BufferedReader(fileReader)) { final MemoryBackend memoryBackend = new MemoryBackend(new LDIFEntryReader(configReader)); final Connection co = new AbstractConnectionWrapper<Connection>(newInternalConnection(memoryBackend)) { @Override public void close() { try { final BufferedWriter configWriter = new BufferedWriter(new FileWriter(ldifFile)); try { final Iterator<Entry> entries = memoryBackend.getAll().iterator(); entries.next(); // skip RootDSE LDIF.copyTo(LDIF.newEntryIteratorReader(entries), new LDIFEntryWriter(configWriter)); } finally { configWriter.close(); } try (final FileWriter fileWriter = new FileWriter(ldifFile); final BufferedWriter configWriter = new BufferedWriter(fileWriter)) { final Iterator<Entry> entries = memoryBackend.getAll().iterator(); entries.next(); // skip RootDSE LDIF.copyTo(LDIF.newEntryIteratorReader(entries), new LDIFEntryWriter(configWriter)); } catch (IOException e) { if (exceptions != null) { exceptions.add(e); @@ -215,8 +211,6 @@ // We need to add the root dse entry to make the configuration framework work. co.add(LDIFEntryReader.valueOfLDIFEntry("dn:", "objectClass:top", "objectClass:ds-root-dse")); return LDAPManagementContext.newManagementContext(co, LDAPProfile.getInstance()); } finally { configReader.close(); } } @@ -225,16 +219,13 @@ * * @param ldifFile * The LDIF file to manage * @param profile * The LDAP profile * @return A LDIF file management context * @throws IOException * If problems occurs while reading the file. */ public static ManagementContext newLDIFManagementContext(final File ldifFile, final LDAPProfile profile) throws IOException { public static ManagementContext newLDIFManagementContext(final File ldifFile) throws IOException { final List<IOException> exceptions = new ArrayList<>(); return new ManagementContextWrapper(newLDIFManagementContext(ldifFile, profile, exceptions), exceptions); return new ManagementContextWrapper(newLDIFManagementContext(ldifFile, exceptions), exceptions); } /** The LDAP management context driver. */ opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractIndexPanel.java
@@ -38,10 +38,10 @@ import javax.swing.JTextField; import org.forgerock.i18n.LocalizableMessage; import org.forgerock.opendj.config.LDAPProfile; import org.forgerock.opendj.config.PropertyException; import org.forgerock.opendj.config.client.ManagementContext; import org.forgerock.opendj.config.client.ldap.LDAPManagementContext; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.server.config.client.BackendIndexCfgClient; import org.forgerock.opendj.server.config.client.PluggableBackendCfgClient; import org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn; @@ -52,7 +52,6 @@ import org.opends.guitools.controlpanel.util.Utilities; import org.opends.quicksetup.Installation; import org.opends.server.config.ConfigException; import org.forgerock.opendj.ldap.schema.AttributeType; import org.opends.server.types.OpenDsException; /** @@ -374,8 +373,7 @@ { getInfo().initializeConfigurationFramework(); final File configFile = Installation.getLocal().getCurrentConfigurationFile(); final LDAPProfile ldapProfile = LDAPProfile.getInstance(); try (ManagementContext context = LDAPManagementContext.newLDIFManagementContext(configFile, ldapProfile)) try (ManagementContext context = LDAPManagementContext.newLDIFManagementContext(configFile)) { final PluggableBackendCfgClient backend = (PluggableBackendCfgClient) context.getRootConfiguration().getBackend(backendName); opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractVLVIndexPanel.java
@@ -54,7 +54,6 @@ import org.forgerock.i18n.LocalizableMessage; import org.forgerock.i18n.LocalizedIllegalArgumentException; import org.forgerock.opendj.config.LDAPProfile; import org.forgerock.opendj.config.PropertyException; import org.forgerock.opendj.config.client.ManagementContext; import org.forgerock.opendj.config.client.ldap.LDAPManagementContext; @@ -120,7 +119,7 @@ /** Name text field. */ protected final JTextField name = Utilities.createMediumTextField(); /** Base DNs combo box. */ protected final JComboBox baseDNs = Utilities.createComboBox(); protected final JComboBox<CharSequence> baseDNs = Utilities.createComboBox(); /** Subtree text field. */ protected final JTextField baseDN = Utilities.createLongTextField(); @@ -153,7 +152,7 @@ protected final JButton remove = Utilities.createButton(INFO_CTRL_PANEL_VLV_INDEX_REMOVE_BUTTON_LABEL.get()); /** Ascending order combo box. */ private final JComboBox ascendingOrder = Utilities.createComboBox(); private final JComboBox<LocalizableMessage> ascendingOrder = Utilities.createComboBox(); /** Combo box containing the sort order. */ protected DefaultListModel<VLVSortOrder> sortOrderModel; @@ -780,8 +779,8 @@ c.add(p, gbc); gbc.gridy++; DefaultComboBoxModel model = new DefaultComboBoxModel(new Object[] { COMBO_SEPARATOR, OTHER_BASE_DN }); baseDNs.setModel(model); baseDNs.setModel(new DefaultComboBoxModel<CharSequence>( new CharSequence[] { COMBO_SEPARATOR, OTHER_BASE_DN })); baseDNs.setRenderer(new CustomListCellRenderer(baseDNs)); ItemListener listener = new IgnoreItemListener(baseDNs); baseDNs.addItemListener(listener); @@ -851,7 +850,8 @@ c.add(attributes, gbc); gbc.gridx++; ascendingOrder.setModel(new DefaultComboBoxModel(new Object[] { ASCENDING, DESCENDING })); ascendingOrder.setModel(new DefaultComboBoxModel<LocalizableMessage>( new LocalizableMessage[] { ASCENDING, DESCENDING })); c.add(ascendingOrder, gbc); gbc.gridy++; @@ -1089,8 +1089,7 @@ { getInfo().initializeConfigurationFramework(); final File configFile = Installation.getLocal().getCurrentConfigurationFile(); final LDAPProfile ldapProfile = LDAPProfile.getInstance(); try (ManagementContext context = LDAPManagementContext.newLDIFManagementContext(configFile, ldapProfile)) try (ManagementContext context = LDAPManagementContext.newLDIFManagementContext(configFile)) { final PluggableBackendCfgClient backend = (PluggableBackendCfgClient) context.getRootConfiguration().getBackend(backendName); opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
@@ -57,7 +57,6 @@ import org.forgerock.i18n.LocalizableMessage; import org.forgerock.i18n.LocalizedIllegalArgumentException; import org.forgerock.opendj.config.LDAPProfile; import org.forgerock.opendj.config.client.ManagementContext; import org.forgerock.opendj.config.client.ldap.LDAPManagementContext; import org.forgerock.opendj.ldap.DN; @@ -974,8 +973,7 @@ { getInfo().initializeConfigurationFramework(); final File config = Installation.getLocal().getCurrentConfigurationFile(); final LDAPProfile profile = LDAPProfile.getInstance(); try (ManagementContext context = LDAPManagementContext.newLDIFManagementContext(config, profile)) try (ManagementContext context = LDAPManagementContext.newLDIFManagementContext(config)) { final BackendCfgClient backend = context.getRootConfiguration().getBackend(backendName); final SortedSet<DN> baseDNs = backend.getBaseDN(); opendj-server-legacy/src/main/java/org/opends/server/tools/BackendCreationHelper.java
@@ -11,7 +11,7 @@ * Header, with the fields enclosed by brackets [] replaced by your own identifying * information: "Portions Copyright [year] [name of copyright owner]". * * Copyright 2015 ForgeRock AS. * Copyright 2015-2016 ForgeRock AS. */ package org.opends.server.tools; @@ -20,7 +20,6 @@ import java.util.LinkedList; import java.util.List; import org.forgerock.opendj.config.LDAPProfile; import org.forgerock.opendj.config.ManagedObjectDefinition; import org.forgerock.opendj.config.client.ManagementContext; import org.forgerock.opendj.config.client.ldap.LDAPManagementContext; @@ -113,8 +112,7 @@ { Utilities.initializeConfigurationFramework(); final File configFile = Installation.getLocal().getCurrentConfigurationFile(); final LDAPProfile ldapProfile = LDAPProfile.getInstance(); try (ManagementContext context = LDAPManagementContext.newLDIFManagementContext(configFile, ldapProfile)) try (ManagementContext context = LDAPManagementContext.newLDIFManagementContext(configFile)) { createBackend(context.getRootConfiguration(), backendName, baseDNs, backendType); }