From ae171bffab3d4c19c00de9a0c78e42a8f4bb9627 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Mon, 02 Apr 2007 22:25:59 +0000
Subject: [PATCH] - Succeeded in removing the Utils.isUninstall() method. All the logic that was being controlled by if statements using this method has been moved to the applications themselves (except for a few hacks that I've documented in the code)
---
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java | 623 ++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 552 insertions(+), 71 deletions(-)
diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java b/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
index b9690c0..47b6a25 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -26,14 +26,11 @@
*/
package org.opends.quicksetup.installer;
-import static org.opends.quicksetup.Step.WELCOME;
+import static org.opends.quicksetup.Step.*;
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.Set;
-import java.util.EnumSet;
+import java.util.*;
import java.awt.event.WindowEvent;
import org.opends.quicksetup.ui.*;
@@ -65,6 +62,19 @@
/* Indicates that we've detected that there is something installed */
boolean forceToDisplaySetup = false;
+ // Constants used to do checks
+ private static final int MIN_DIRECTORY_MANAGER_PWD = 1;
+
+ private static final int MIN_PORT_VALUE = 1;
+
+ private static final int MAX_PORT_VALUE = 65535;
+
+ private static final int MIN_NUMBER_ENTRIES = 1;
+
+ private static final int MAX_NUMBER_ENTRIES = 10000;
+
+ private List<WizardStep> lstSteps = new ArrayList<WizardStep>();
+
/**
* An static String that contains the class name of ConfigFileHandler.
*/
@@ -72,6 +82,17 @@
"org.opends.server.extensions.ConfigFileHandler";
/**
+ * Creates a default instance.
+ */
+ public Installer() {
+ lstSteps.add(WELCOME);
+ lstSteps.add(SERVER_SETTINGS);
+ lstSteps.add(DATA_OPTIONS);
+ lstSteps.add(REVIEW);
+ lstSteps.add(PROGRESS);
+ }
+
+ /**
* {@inheritDoc}
*/
public void forceToDisplay() {
@@ -81,6 +102,127 @@
/**
* {@inheritDoc}
*/
+ public boolean canGoBack(WizardStep step) {
+ return step != WELCOME &&
+ step != PROGRESS;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canGoForward(WizardStep step) {
+ return step != REVIEW &&
+ step != PROGRESS;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canFinish(WizardStep step) {
+ return step == REVIEW;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canQuit(WizardStep step) {
+ return step != PROGRESS;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canClose(WizardStep step) {
+ return step == PROGRESS;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canCancel(WizardStep step) {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void previousClicked(WizardStep cStep) {
+ if (cStep == WELCOME) {
+ throw new IllegalStateException(
+ "Cannot click on previous from progress step");
+ } else if (cStep == PROGRESS) {
+ throw new IllegalStateException(
+ "Cannot click on previous from progress step");
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void finishClicked(final WizardStep cStep, final QuickSetup qs) {
+ if (cStep == Step.REVIEW) {
+ updateUserDataForReviewPanel(qs);
+ qs.launchInstallation();
+ qs.setCurrentStep(Step.PROGRESS);
+ } else {
+ throw new IllegalStateException(
+ "Cannot click on finish when we are not in the Review window");
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void nextClicked(WizardStep cStep, QuickSetup qs) {
+ if (cStep == PROGRESS) {
+ throw new IllegalStateException(
+ "Cannot click on next from progress step");
+ } else if (cStep == REVIEW) {
+ throw new IllegalStateException("Cannot click on next from review step");
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void closeClicked(WizardStep cStep, QuickSetup qs) {
+ if (cStep == PROGRESS) {
+ if (isFinished()
+ || qs.displayConfirmation(getMsg("confirm-close-install-msg"),
+ getMsg("confirm-close-install-title"))) {
+ qs.quit();
+ }
+ } else {
+ throw new IllegalStateException(
+ "Close only can be clicked on PROGRESS step");
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void cancelClicked(WizardStep cStep, QuickSetup qs) {
+ // do nothing;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void quitClicked(WizardStep cStep, QuickSetup qs) {
+ if (cStep == PROGRESS) {
+ throw new IllegalStateException(
+ "Cannot click on quit from progress step");
+ } else if (installStatus.isInstalled()) {
+ qs.quit();
+ } else if (qs.displayConfirmation(getMsg("confirm-quit-install-msg"),
+ getMsg("confirm-quit-install-title"))) {
+ qs.quit();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public ButtonName getInitialFocusButtonName() {
ButtonName name = null;
if (!installStatus.isInstalled() || forceToDisplaySetup)
@@ -118,35 +260,25 @@
/**
* {@inheritDoc}
*/
- public Set<Step> getWizardSteps() {
- return EnumSet.of(WELCOME,
- Step.SERVER_SETTINGS,
- Step.DATA_OPTIONS,
- Step.REVIEW,
- Step.PROGRESS);
+ public Set<WizardStep> getWizardSteps() {
+ return Collections.unmodifiableSet(new HashSet<WizardStep>(lstSteps));
}
/**
* {@inheritDoc}
*/
- public QuickSetupStepPanel createWizardStepPanel(Step step) {
+ public QuickSetupStepPanel createWizardStepPanel(WizardStep step) {
QuickSetupStepPanel p = null;
- switch (step) {
- case WELCOME:
+ if (step == WELCOME) {
p = new InstallWelcomePanel();
- break;
- case SERVER_SETTINGS:
+ } else if (step == SERVER_SETTINGS) {
p = new ServerSettingsPanel(getUserData());
- break;
- case DATA_OPTIONS:
+ } else if (step == DATA_OPTIONS) {
p = new DataOptionsPanel(getUserData());
- break;
- case REVIEW:
+ } else if (step == REVIEW) {
p = new ReviewPanel(getUserData());
- break;
- case PROGRESS:
+ } else if (step == PROGRESS) {
p = new ProgressPanel();
- break;
}
return p;
}
@@ -173,6 +305,27 @@
/**
* {@inheritDoc}
*/
+ public String getCloseButtonToolTip() {
+ return "close-button-install-tooltip";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getFinishButtonToolTip() {
+ return "finish-button-install-tooltip";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void previousClicked(WizardStep cStep, QuickSetup qs) {
+ // do nothing;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public String getFrameTitle() {
return getMsg("frame-install-title");
}
@@ -186,45 +339,28 @@
*/
protected void setWizardDialogState(QuickSetupDialog dlg,
UserData userData,
- Step step) {
+ WizardStep step) {
if (!installStatus.isInstalled() || forceToDisplaySetup) {
// Set the default button for the frame
- switch (step) {
- case REVIEW:
+ if (step == REVIEW) {
dlg.setDefaultButton(ButtonName.FINISH);
- break;
-
- case PROGRESS:
- dlg.setDefaultButton(ButtonName.CLOSE);
- break;
-
- default:
- dlg.setDefaultButton(ButtonName.NEXT);
- }
-
- // Set the focus for the current step
- switch (step) {
- case WELCOME:
- dlg.setFocusOnButton(ButtonName.NEXT);
- break;
-
- case SERVER_SETTINGS:
- // The focus is set by the panel itself
- break;
-
- case DATA_OPTIONS:
- // The focus is set by the panel itself
- break;
-
- case REVIEW:
dlg.setFocusOnButton(ButtonName.FINISH);
- break;
-
- case PROGRESS:
- dlg.setFocusOnButton(ButtonName.CLOSE);
- dlg.setButtonEnabled(ButtonName.CLOSE, false);
- break;
+ } else if (step == PROGRESS) {
+ dlg.setDefaultButton(ButtonName.CLOSE);
+ } else if (step == WELCOME) {
+ dlg.setFocusOnButton(ButtonName.NEXT);
+ } else if (step == SERVER_SETTINGS) {
+ // The focus is set by the panel itself
+ } else if (step == DATA_OPTIONS) {
+ // The focus is set by the panel itself
+ } else if (step == REVIEW) {
+ // do nothing?
+ } else if (step == PROGRESS) {
+ dlg.setFocusOnButton(ButtonName.CLOSE);
+ dlg.setButtonEnabled(ButtonName.CLOSE, false);
+ } else {
+ dlg.setDefaultButton(ButtonName.NEXT);
}
}
}
@@ -240,27 +376,32 @@
/**
* {@inheritDoc}
*/
- public Step getFirstWizardStep() {
+ public WizardStep getFirstWizardStep() {
return WELCOME;
}
/**
* {@inheritDoc}
*/
- public Step getNextWizardStep(Step step) {
- Step nextStep = null;
- if (step != null) {
- if (step.equals(Step.WELCOME)) {
- nextStep = Step.SERVER_SETTINGS;
- } else if (step.equals(Step.SERVER_SETTINGS)) {
- nextStep = Step.DATA_OPTIONS;
- } else if (step.equals(Step.DATA_OPTIONS)) {
- nextStep = Step.REVIEW;
- } else if (step.equals(Step.REVIEW)) {
- nextStep = Step.PROGRESS;
- }
+ public WizardStep getNextWizardStep(WizardStep step) {
+ WizardStep next = null;
+ int i = lstSteps.indexOf(step);
+ if (i != -1 && i + 1 < lstSteps.size()) {
+ next = lstSteps.get(i + 1);
}
- return nextStep;
+ return next;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public WizardStep getPreviousWizardStep(WizardStep step) {
+ WizardStep prev = null;
+ int i = lstSteps.indexOf(step);
+ if (i != -1 && i > 0) {
+ prev = lstSteps.get(i - 1);
+ }
+ return prev;
}
/**
@@ -559,6 +700,29 @@
}
/**
+ * These methods validate the data provided by the user in the panels and
+ * update the userData object according to that content.
+ *
+ * @param cStep
+ * the current step of the wizard
+ * @param qs QuickStart controller
+ * @throws UserDataException if the data provided by the user is not
+ * valid.
+ *
+ */
+ protected void updateUserData(WizardStep cStep, QuickSetup qs)
+ throws UserDataException
+ {
+ if (cStep == SERVER_SETTINGS) {
+ updateUserDataForServerSettingsPanel(qs);
+ } else if (cStep == DATA_OPTIONS) {
+ updateUserDataForDataOptionsPanel(qs);
+ } else if (cStep == REVIEW) {
+ updateUserDataForReviewPanel(qs);
+ }
+ }
+
+ /**
* Returns the default backend name (the one that will be created).
* @return the default backend name (the one that will be created).
*/
@@ -575,4 +739,321 @@
return Utils.getPath(getInstallationPath(),
Utils.getBinariesRelativePath());
}
+
+ /**
+ * Validate the data provided by the user in the server settings panel and
+ * update the userData object according to that content.
+ *
+ * @throws UserDataException if the data provided by the user is not
+ * valid.
+ *
+ */
+ private void updateUserDataForServerSettingsPanel(QuickSetup qs)
+ throws UserDataException {
+ ArrayList<String> errorMsgs = new ArrayList<String>();
+
+ if (Utils.isWebStart())
+ {
+ // Check the server location
+ String serverLocation = qs.getFieldStringValue(FieldName.SERVER_LOCATION);
+
+ if ((serverLocation == null) || ("".equals(serverLocation.trim())))
+ {
+ errorMsgs.add(getMsg("empty-server-location"));
+ qs.displayFieldInvalid(FieldName.SERVER_LOCATION, true);
+ } else if (!Utils.parentDirectoryExists(serverLocation))
+ {
+ String[] arg =
+ { serverLocation };
+ errorMsgs.add(getMsg("parent-directory-does-not-exist", arg));
+ qs.displayFieldInvalid(FieldName.SERVER_LOCATION, true);
+ } else if (Utils.fileExists(serverLocation))
+ {
+ String[] arg =
+ { serverLocation };
+ errorMsgs.add(getMsg("file-exists", arg));
+ qs.displayFieldInvalid(FieldName.SERVER_LOCATION, true);
+ } else if (Utils.directoryExistsAndIsNotEmpty(serverLocation))
+ {
+ String[] arg =
+ { serverLocation };
+ errorMsgs.add(getMsg("directory-exists-not-empty", arg));
+ qs.displayFieldInvalid(FieldName.SERVER_LOCATION, true);
+ } else if (!Utils.canWrite(serverLocation))
+ {
+ String[] arg =
+ { serverLocation };
+ errorMsgs.add(getMsg("directory-not-writable", arg));
+ qs.displayFieldInvalid(FieldName.SERVER_LOCATION, true);
+
+ } else if (!Utils.hasEnoughSpace(serverLocation,
+ getRequiredInstallSpace()))
+ {
+ long requiredInMb = getRequiredInstallSpace() / (1024 * 1024);
+ String[] args =
+ { serverLocation, String.valueOf(requiredInMb) };
+ errorMsgs.add(getMsg("not-enough-disk-space", args));
+ qs.displayFieldInvalid(FieldName.SERVER_LOCATION, true);
+
+ } else
+ {
+ getUserData().setServerLocation(serverLocation);
+ qs.displayFieldInvalid(FieldName.SERVER_LOCATION, false);
+ }
+ }
+
+ // Check the port
+ String sPort = qs.getFieldStringValue(FieldName.SERVER_PORT);
+ try
+ {
+ int port = Integer.parseInt(sPort);
+ if ((port < MIN_PORT_VALUE) || (port > MAX_PORT_VALUE))
+ {
+ String[] args =
+ { String.valueOf(MIN_PORT_VALUE), String.valueOf(MAX_PORT_VALUE) };
+ errorMsgs.add(getMsg("invalid-port-value-range", args));
+ qs.displayFieldInvalid(FieldName.SERVER_PORT, true);
+ } else if (!Utils.canUseAsPort(port))
+ {
+ if (Utils.isPriviledgedPort(port))
+ {
+ errorMsgs.add(getMsg("cannot-bind-priviledged-port", new String[]
+ { String.valueOf(port) }));
+ } else
+ {
+ errorMsgs.add(getMsg("cannot-bind-port", new String[]
+ { String.valueOf(port) }));
+ }
+ qs.displayFieldInvalid(FieldName.SERVER_PORT, true);
+
+ } else
+ {
+ getUserData().setServerPort(port);
+ qs.displayFieldInvalid(FieldName.SERVER_PORT, false);
+ }
+
+ } catch (NumberFormatException nfe)
+ {
+ String[] args =
+ { String.valueOf(MIN_PORT_VALUE), String.valueOf(MAX_PORT_VALUE) };
+ errorMsgs.add(getMsg("invalid-port-value-range", args));
+ qs.displayFieldInvalid(FieldName.SERVER_PORT, true);
+ }
+
+ // Check the Directory Manager DN
+ String dmDn = qs.getFieldStringValue(FieldName.DIRECTORY_MANAGER_DN);
+
+ if ((dmDn == null) || (dmDn.trim().length() == 0))
+ {
+ errorMsgs.add(getMsg("empty-directory-manager-dn"));
+ qs.displayFieldInvalid(FieldName.DIRECTORY_MANAGER_DN, true);
+ } else if (!Utils.isDn(dmDn))
+ {
+ errorMsgs.add(getMsg("not-a-directory-manager-dn"));
+ qs.displayFieldInvalid(FieldName.DIRECTORY_MANAGER_DN, true);
+ } else if (Utils.isConfigurationDn(dmDn))
+ {
+ errorMsgs.add(getMsg("directory-manager-dn-is-config-dn"));
+ qs.displayFieldInvalid(FieldName.DIRECTORY_MANAGER_DN, true);
+ } else
+ {
+ getUserData().setDirectoryManagerDn(dmDn);
+ qs.displayFieldInvalid(FieldName.DIRECTORY_MANAGER_DN, false);
+ }
+
+ // Check the provided passwords
+ String pwd1 = qs.getFieldStringValue(FieldName.DIRECTORY_MANAGER_PWD);
+ String pwd2 =
+ qs.getFieldStringValue(FieldName.DIRECTORY_MANAGER_PWD_CONFIRM);
+ if (pwd1 == null)
+ {
+ pwd1 = "";
+ }
+
+ boolean pwdValid = true;
+ if (!pwd1.equals(pwd2))
+ {
+ errorMsgs.add(getMsg("not-equal-pwd"));
+ qs.displayFieldInvalid(FieldName.DIRECTORY_MANAGER_PWD_CONFIRM, true);
+ pwdValid = false;
+
+ }
+ if (pwd1.length() < MIN_DIRECTORY_MANAGER_PWD)
+ {
+ errorMsgs.add(getMsg(("pwd-too-short"), new String[]
+ { String.valueOf(MIN_DIRECTORY_MANAGER_PWD) }));
+ qs.displayFieldInvalid(FieldName.DIRECTORY_MANAGER_PWD, true);
+ if ((pwd2 == null) || (pwd2.length() < MIN_DIRECTORY_MANAGER_PWD))
+ {
+ qs.displayFieldInvalid(FieldName.DIRECTORY_MANAGER_PWD_CONFIRM, true);
+ }
+ pwdValid = false;
+ }
+
+ if (pwdValid)
+ {
+ getUserData().setDirectoryManagerPwd(pwd1);
+ qs.displayFieldInvalid(FieldName.DIRECTORY_MANAGER_PWD, false);
+ qs.displayFieldInvalid(FieldName.DIRECTORY_MANAGER_PWD_CONFIRM, false);
+ }
+
+ int defaultJMXPort = UserData.getDefaultJMXPort();
+ if (defaultJMXPort != -1)
+ {
+ getUserData().setServerJMXPort(defaultJMXPort);
+ }
+
+ if (errorMsgs.size() > 0)
+ {
+ throw new UserDataException(Step.SERVER_SETTINGS,
+ Utils.getStringFromCollection(errorMsgs, "\n"));
+ }
+ }
+
+ /**
+ * Validate the data provided by the user in the data options panel and update
+ * the userData object according to that content.
+ *
+ * @throws UserDataException if the data provided by the user is not
+ * valid.
+ *
+ */
+ private void updateUserDataForDataOptionsPanel(QuickSetup qs)
+ throws UserDataException {
+ ArrayList<String> errorMsgs = new ArrayList<String>();
+
+ DataOptions dataOptions = null;
+
+ // Check the base dn
+ boolean validBaseDn = false;
+ String baseDn = qs.getFieldStringValue(FieldName.DIRECTORY_BASE_DN);
+ if ((baseDn == null) || (baseDn.trim().length() == 0))
+ {
+ errorMsgs.add(getMsg("empty-base-dn"));
+ qs.displayFieldInvalid(FieldName.DIRECTORY_BASE_DN, true);
+ } else if (!Utils.isDn(baseDn))
+ {
+ errorMsgs.add(getMsg("not-a-base-dn"));
+ qs.displayFieldInvalid(FieldName.DIRECTORY_BASE_DN, true);
+ } else if (Utils.isConfigurationDn(baseDn))
+ {
+ errorMsgs.add(getMsg("base-dn-is-configuration-dn"));
+ qs.displayFieldInvalid(FieldName.DIRECTORY_BASE_DN, true);
+ } else
+ {
+ qs.displayFieldInvalid(FieldName.DIRECTORY_BASE_DN, false);
+ validBaseDn = true;
+ }
+
+ // Check the data options
+ DataOptions.Type type =
+ (DataOptions.Type) qs.getFieldValue(FieldName.DATA_OPTIONS);
+
+ switch (type)
+ {
+ case IMPORT_FROM_LDIF_FILE:
+ String ldifPath = qs.getFieldStringValue(FieldName.LDIF_PATH);
+ if ((ldifPath == null) || (ldifPath.trim().equals("")))
+ {
+ errorMsgs.add(getMsg("no-ldif-path"));
+ qs.displayFieldInvalid(FieldName.LDIF_PATH, true);
+ } else if (!Utils.fileExists(ldifPath))
+ {
+ errorMsgs.add(getMsg("ldif-file-does-not-exist"));
+ qs.displayFieldInvalid(FieldName.LDIF_PATH, true);
+ } else if (validBaseDn)
+ {
+ dataOptions = new DataOptions(type, baseDn, ldifPath);
+ qs.displayFieldInvalid(FieldName.LDIF_PATH, false);
+ }
+ break;
+
+ case IMPORT_AUTOMATICALLY_GENERATED_DATA:
+ // variable used to know if everything went ok during these
+ // checks
+ int startErrors = errorMsgs.size();
+
+ // Check the number of entries
+ String nEntries = qs.getFieldStringValue(FieldName.NUMBER_ENTRIES);
+ if ((nEntries == null) || (nEntries.trim().equals("")))
+ {
+ errorMsgs.add(getMsg("no-number-entries"));
+ qs.displayFieldInvalid(FieldName.NUMBER_ENTRIES, true);
+ } else
+ {
+ boolean nEntriesValid = false;
+ try
+ {
+ int n = Integer.parseInt(nEntries);
+
+ nEntriesValid = n >= MIN_NUMBER_ENTRIES && n <= MAX_NUMBER_ENTRIES;
+ } catch (NumberFormatException nfe)
+ {
+ }
+
+ if (!nEntriesValid)
+ {
+ String[] args =
+ { String.valueOf(MIN_NUMBER_ENTRIES),
+ String.valueOf(MAX_NUMBER_ENTRIES) };
+ errorMsgs.add(getMsg("invalid-number-entries-range", args));
+ qs.displayFieldInvalid(FieldName.NUMBER_ENTRIES, true);
+ } else
+ {
+ qs.displayFieldInvalid(FieldName.NUMBER_ENTRIES, false);
+ }
+ }
+ if (startErrors == errorMsgs.size() && validBaseDn)
+ {
+ // No validation errors
+ dataOptions = new DataOptions(type, baseDn, new Integer(nEntries));
+ }
+ break;
+
+ default:
+ qs.displayFieldInvalid(FieldName.LDIF_PATH, false);
+ qs.displayFieldInvalid(FieldName.NUMBER_ENTRIES, false);
+ if (validBaseDn)
+ {
+ dataOptions = new DataOptions(type, baseDn);
+ }
+ }
+
+ if (dataOptions != null)
+ {
+ getUserData().setDataOptions(dataOptions);
+ }
+
+ if (errorMsgs.size() > 0)
+ {
+ throw new UserDataException(Step.DATA_OPTIONS,
+ Utils.getStringFromCollection(errorMsgs, "\n"));
+ }
+ }
+
+ /**
+ * Update the userData object according to the content of the review
+ * panel.
+ *
+ */
+ private void updateUserDataForReviewPanel(QuickSetup qs)
+ {
+ Boolean b = (Boolean) qs.getFieldValue(FieldName.SERVER_START);
+ getUserData().setStartServer(b.booleanValue());
+ }
+
+ /**
+ * Returns the number of free disk space in bytes required to install Open DS
+ *
+ * For the moment we just return 15 Megabytes. TODO we might want to have
+ * something dynamic to calculate the required free disk space for the
+ * installation.
+ *
+ * @return the number of free disk space required to install Open DS.
+ */
+ private long getRequiredInstallSpace()
+ {
+ return 15 * 1024 * 1024;
+ }
+
}
--
Gitblit v1.10.0