NewBaseDNPanel.java revision 58821a211f38cf48a75a9cbc36b472d95b035ce2
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2008-2009 Sun Microsystems, Inc.
* Portions Copyright 2011-2015 ForgeRock AS
*/
/**
* The class that appears when the user clicks on 'New Base DN'.
*/
public class NewBaseDNPanel extends StatusGenericPanel
{
private static final int MAX_ENTRIES_NUMBER_GENERATED = 1000;
private static final int MAX_ENTRIES_NUMBER_GENERATED_LOCAL = 20000;
private static final long serialVersionUID = -2680821576362341119L;
private JTextField newBackend;
private JTextField baseDN;
private JRadioButton onlyCreateBaseEntry;
private JRadioButton leaveDatabaseEmpty;
private JRadioButton importDataFromLDIF;
private JRadioButton importAutomaticallyGenerated;
private JTextField path;
private JTextField numberOfEntries;
private JLabel lRemoteFileHelp;
private JButton browseImportPath;
private JLabel lDirectoryBaseDN;
private JLabel lNumberOfEntries;
private JLabel lDirectoryData;
private JLabel lNewBackendType;
private DocumentListener documentListener;
/** Default constructor. */
public NewBaseDNPanel()
{
super();
createLayout();
}
/** {@inheritDoc} */
public LocalizableMessage getTitle()
{
return INFO_CTRL_PANEL_NEW_BASE_DN_TITLE.get();
}
/** {@inheritDoc} */
public Component getPreferredFocusComponent()
{
return baseDN;
}
/** {@inheritDoc} */
public void toBeDisplayed(boolean visible)
{
if (visible)
{
}
}
/** Creates the layout of the panel (but the contents are not populated here). */
private void createLayout()
{
}
{
}
{
}
{
}
{
lNewBackendType = Utilities.createPrimaryLabel(INFO_CTRL_PANEL_BASE_DN_NEW_BACKEND_TYPE_LABEL.get());
}
@SuppressWarnings("unchecked")
{
}
{
}
{
{
{
}
};
}
{
}
{
documentListener = new DocumentListener()
{
{
}
{
}
{
}
};
}
{
}
{
}
{
onlyCreateBaseEntry = Utilities.createRadioButton(INFO_CTRL_PANEL_ONLY_CREATE_BASE_ENTRY_LABEL.get());
onlyCreateBaseEntry.setSelected(false);
leaveDatabaseEmpty.setSelected(false);
importDataFromLDIF.setSelected(false);
{
/** {@inheritDoc} */
{
}
};
while (buttons.hasMoreElements())
{
}
onlyCreateBaseEntry.setSelected(true);
}
/** {@inheritDoc} */
{
{
if (!backend.isConfigBackend())
{
}
}
if (!sortedBackends.isEmpty())
{
}
{
public void run()
{
}
});
}
private JPanel createPathPanel()
{
return panel;
}
private JPanel createNumberOfUsersPanel()
{
lNumberOfEntries = Utilities.createDefaultLabel(INFO_CTRL_PANEL_NUMBER_OF_USER_ENTRIES_LABEL.get());
return panel;
}
/** {@inheritDoc} */
public void cancelClicked()
{
super.cancelClicked();
}
private void resetLabelAsValid()
{
}
/** {@inheritDoc} */
protected void checkOKButtonEnable()
{
}
/** {@inheritDoc} */
public void okClicked()
{
{
{
}
{
null,
progressDialog.setVisible(true);
}
}
{
}
}
/** Returns the existing or the new backend name, once user have clicked on 'OK' button. */
private String validateBackendName(
{
{
return selectedItem.toString();
}
{
return backendName;
}
// Check that the backend is not already defined.
{
{
}
}
return backendName;
}
private String validateBaseDN(final String backendName, final Set<BackendDescriptor> existingBackends,
{
{
return dn;
}
try
{
{
{
{
}
else if (baseDN.getDn().isAncestorOf(theDN) && backendName.equalsIgnoreCase(backend.getBackendID()))
{
}
else if (theDN.isAncestorOf(baseDN.getDn()) && backendName.equalsIgnoreCase(backend.getBackendID()))
{
}
}
}
}
catch (OpenDsException oe)
{
}
return dn;
}
/** Mark the provided base DN as invalid with the provided reason and return it. */
{
return dn;
}
{
// TODO: what happens with sub-suffixes?
if (importDataFromLDIF.isSelected())
{
{
}
{
}
}
}
{
{
final int minValue = 1;
{
}
}
}
private String getBackendName()
{
{
}
else if (backendName != null)
{
return backendName.toString();
}
return null;
}
private BackendTypeUIAdapter getSelectedBackendType()
{
}
private boolean isNewBackend()
{
}
/** The task in charge of creating the base DN (and if required, the backend). */
protected class NewBaseDNTask extends Task
{
private int progressAfterConfigurationUpdate = -1;
/**
* The constructor of the task.
*
* @param info
* the control panel info.
* @param dlg
* the progress dialog that shows the progress of the task.
*/
{
backendSet = new HashSet<>();
if (onlyCreateBaseEntry.isSelected())
{
}
else if (leaveDatabaseEmpty.isSelected())
{
}
else if (importAutomaticallyGenerated.isSelected())
{
if (nEntries < 500)
{
}
else if (nEntries < 3000)
{
}
else
{
}
}
}
/** {@inheritDoc} */
{
return Type.NEW_BASEDN;
}
/** {@inheritDoc} */
public LocalizableMessage getTaskDescription()
{
}
/** {@inheritDoc} */
public boolean canLaunch(Task taskToBeLaunched, Collection<LocalizableMessage> incompatibilityReasons)
{
boolean canLaunch = true;
{
// All the operations are incompatible if they apply to this backend.
{
canLaunch = false;
}
}
return canLaunch;
}
private String getDataCommandLineToDisplay()
{
Collection<String> args = getObfuscatedCommandLineArguments(getDataCommandLineArguments(path.getText(), false));
{
}
}
private String getDataCommandLineName()
{
if (!leaveDatabaseEmpty.isSelected())
{
}
return null;
}
/**
* Returns the arguments of the command-line that can be used to generate
* the data.
*
* @param ldifFile
* the LDIF file.
* @param useTemplate
* whether to use a template or not.
* @return the arguments of the command-line that can be used to generate
* the data.
*/
{
if (!leaveDatabaseEmpty.isSelected())
{
if (isLocal())
{
if (!useTemplate)
{
}
else
{
}
}
else
{
// If we are not local, we use ldapmodify to update the contents.
}
if (isServerRunning() && isLocal())
{
}
}
return args;
}
private void updateConfigurationOnline() throws OpenDsException
{
{
public void run()
{
}
});
performTask();
if (isNewBackend())
{
}
}
private void updateConfigurationOffline() throws OpenDsException
{
boolean configHandlerUpdated = false;
try
{
getInfo().stopPooling();
if (getInfo().mustDeregisterConfig())
{
}
getInfo().setMustDeregisterConfig(true);
configHandlerUpdated = true;
performTask();
}
finally
{
if (configHandlerUpdated)
{
DirectoryServer.getInstance().initializeConfiguration(ConfigReader.configClassName, ConfigReader.configFile);
getInfo().startPooling();
}
}
}
{
{
public void run()
{
}
});
}
private void performTask() throws OpenDsException
{
if (isNewBackend())
{
}
else
{
}
}
{
if (!isServerRunning())
{
return;
}
//FIXME GB This could be replaced by a call to BackendCreationHelper.createBackend(...)
// once the new configuration framework migration will be done
final BackendCfgClient backend =
backend.setEnabled(true);
}
{
try
{
Set<org.forgerock.opendj.ldap.DN> baseDN = Collections.singleton(Converters.from(DN.valueOf(newBaseDN)));
BackendCreationHelper.createBackendOffline(backendName, baseDN, getSelectedBackendType().getBackend());
}
catch (Exception e)
{
throw new OfflineUpdateException(ERROR_CTRL_PANEL_CREATE_NEW_BACKEND.get(backendName, e.getMessage()), e);
}
}
private RootCfgClient getRootConfigurationClient()
{
}
{
if (!isServerRunning())
{
return;
}
}
{
try
{
}
catch (Exception e)
{
}
}
private void createAdditionalIndexes() throws OpenDsException
{
if (isLocalDBBackend())
{
}
else
{
}
}
private void addJEDefaultIndexes(final LocalDBBackendCfgClient jeBackendCfgClient) throws AdminException
{
{
final LocalDBIndexCfgClient jeIndex =
jeBackendCfgClient.createLocalDBIndex(LocalDBIndexCfgDefn.getInstance(), defaultIndex.getName(), null);
{
}
}
}
private void addBackendDefaultIndexes(PluggableBackendCfgClient backendCfgClient) throws AdminException
{
{
{
}
}
}
{
{
public void run()
{
}
});
}
private void printTaskDone()
{
{
public void run()
{
}
});
}
private void refreshProgressBar()
{
if (progressAfterConfigurationUpdate > 0)
{
{
public void run()
{
}
});
}
}
private void displayCreateAdditionalIndexesDsConfigCmdLine()
{
{
}
{
sb.append(getEquivalentCommandLine(getCommandLinePath("dsconfig"), getObfuscatedCommandLineArguments(args)));
}
{
public void run()
{
}
});
}
{
{
}
return args;
}
private void displayCreateAdditionalIndexesDone()
{
{
public void run()
{
}
});
}
private boolean isLocalDBBackend()
{
return getSelectedBackendType().getBackend()
}
/**
* Creates the data in the new base DN.
*
* @throws OpenDsException
* if there is an error importing contents.
* @throws IOException
* if there is an err
*/
{
if (leaveEmpty)
{
}
else
{
if (importLDIF)
{
{
public void run()
{
}
});
}
else if (createBaseEntry)
{
{
public void run()
{
}
});
ldifFile = f.getAbsolutePath();
}
else
{
{
public void run()
{
if (isLocal())
{
}
else
{
}
}
});
if (!isLocal())
{
// Create the LDIF file locally using make-ldif
f.delete();
if (returnCode != 0)
{
}
}
else
{
ldifFile = f.getAbsolutePath();
}
}
if (createBaseEntry || !isLocal())
{
outPrintStream.setNotifyListeners(false);
errorPrintStream.setNotifyListeners(false);
}
try
{
if (isServerRunning())
{
if (isLocal() || importLDIF)
{
}
else
{
}
}
else
{
}
}
finally
{
outPrintStream.setNotifyListeners(true);
}
if (returnCode != 0)
{
}
else
{
{
{
public void run()
{
}
});
}
}
}
}
/** {@inheritDoc} */
protected String getCommandLinePath()
{
return null;
}
/** {@inheritDoc} */
{
return new ArrayList<>();
}
private String getConfigCommandLineFullPath()
{
}
{
if (isServerRunning())
{
if (isNewBackend())
{
args.add(BackendTypeHelper.filterSchemaBackendName(getSelectedBackendType().getBackend().getName()));
}
else
{
}
}
return args;
}
/** {@inheritDoc} */
public void runTask()
{
try
{
if (isServerRunning())
{
}
else
{
}
updateData();
}
catch (Throwable t)
{
lastException = t;
}
}
/** {@inheritDoc} */
{
return backendSet;
}
}
}