opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/ArgumentExceptionFactory.java
@@ -115,15 +115,10 @@ public static void displayManagedObjectDecodingException(ConsoleApplication app, ManagedObjectDecodingException e) { AbstractManagedObjectDefinition<?, ?> d = e.getPartialManagedObject().getManagedObjectDefinition(); LocalizableMessage ufn = d.getUserFriendlyName(); LocalizableMessage msg; if (e.getCauses().size() == 1) { msg = ERR_GET_HEADING_MODE_SINGLE.get(ufn); } else { msg = ERR_GET_HEADING_MODE_PLURAL.get(ufn); } app.println(msg); app.println(); LocalizableMessage msg = e.getCauses().size() == 1 ? ERR_GET_HEADING_MODE_SINGLE.get(ufn) : ERR_GET_HEADING_MODE_PLURAL.get(ufn); app.errPrintln(msg); app.errPrintln(); TableBuilder builder = new TableBuilder(); for (PropertyException pe : e.getCauses()) { ArgumentException ae = adaptPropertyException(pe, d); @@ -151,22 +146,17 @@ MissingMandatoryPropertiesException e) { LocalizableMessage ufn = e.getUserFriendlyName(); LocalizableMessage msg; final boolean onePropertyMissing = e.getCauses().size() == 1; if (e.isCreate()) { if (e.getCauses().size() == 1) { msg = ERR_CREATE_HEADING_MMPE_SINGLE.get(ufn); } else { msg = ERR_CREATE_HEADING_MMPE_PLURAL.get(ufn); } msg = onePropertyMissing ? ERR_CREATE_HEADING_MMPE_SINGLE.get(ufn) : ERR_CREATE_HEADING_MMPE_PLURAL.get(ufn); } else { if (e.getCauses().size() == 1) { msg = ERR_MODIFY_HEADING_MMPE_SINGLE.get(ufn); } else { msg = ERR_MODIFY_HEADING_MMPE_PLURAL.get(ufn); } msg = onePropertyMissing ? ERR_MODIFY_HEADING_MMPE_SINGLE.get(ufn) : ERR_MODIFY_HEADING_MMPE_PLURAL.get(ufn); } app.println(msg); app.println(); app.errPrintln(msg); app.errPrintln(); TableBuilder builder = new TableBuilder(); builder.addSortKey(0); builder.appendHeading(INFO_DSCFG_HEADING_PROPERTY_NAME.get()); @@ -198,32 +188,25 @@ public static void displayOperationRejectedException(ConsoleApplication app, OperationRejectedException e) { LocalizableMessage ufn = e.getUserFriendlyName(); LocalizableMessage msg; final boolean singleMessage = e.getMessages().size() == 1; switch (e.getOperationType()) { case CREATE: if (e.getMessages().size() == 1) { msg = ERR_DSCFG_ERROR_CREATE_ORE_SINGLE.get(ufn); } else { msg = ERR_DSCFG_ERROR_CREATE_ORE_PLURAL.get(ufn); } msg = singleMessage ? ERR_DSCFG_ERROR_CREATE_ORE_SINGLE.get(ufn) : ERR_DSCFG_ERROR_CREATE_ORE_PLURAL.get(ufn); break; case DELETE: if (e.getMessages().size() == 1) { msg = ERR_DSCFG_ERROR_DELETE_ORE_SINGLE.get(ufn); } else { msg = ERR_DSCFG_ERROR_DELETE_ORE_PLURAL.get(ufn); } msg = singleMessage ? ERR_DSCFG_ERROR_DELETE_ORE_SINGLE.get(ufn) : ERR_DSCFG_ERROR_DELETE_ORE_PLURAL.get(ufn); break; default: if (e.getMessages().size() == 1) { msg = ERR_DSCFG_ERROR_MODIFY_ORE_SINGLE.get(ufn); } else { msg = ERR_DSCFG_ERROR_MODIFY_ORE_PLURAL.get(ufn); } msg = singleMessage ? ERR_DSCFG_ERROR_MODIFY_ORE_SINGLE.get(ufn) : ERR_DSCFG_ERROR_MODIFY_ORE_PLURAL.get(ufn); break; } app.println(msg); app.println(); app.errPrintln(msg); app.errPrintln(); TableBuilder builder = new TableBuilder(); for (LocalizableMessage reason : e.getMessages()) { builder.startRow(); opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/CreateSubCommandHandler.java
@@ -27,10 +27,12 @@ package org.forgerock.opendj.config.dsconfig; import static com.forgerock.opendj.cli.CliMessages.*; import static com.forgerock.opendj.cli.ReturnCode.*; import static com.forgerock.opendj.cli.ArgumentConstants.LIST_TABLE_SEPARATOR; import static com.forgerock.opendj.dsconfig.DsconfigMessages.*; import static org.forgerock.opendj.config.dsconfig.ArgumentExceptionFactory.displayMissingMandatoryPropertyException; import static org.forgerock.opendj.config.dsconfig.ArgumentExceptionFactory.displayOperationRejectedException; import static org.forgerock.opendj.config.dsconfig.ArgumentExceptionFactory.*; import static org.forgerock.opendj.config.dsconfig.DSConfig.*; import java.util.Collection; import java.util.Collections; @@ -542,9 +544,9 @@ isBadReference = false; } catch (MissingMandatoryPropertiesException e) { // Give the user the chance to fix the problems. app.println(); app.errPrintln(); displayMissingMandatoryPropertyException(app, e); app.println(); app.errPrintln(); if (app.confirmAction(INFO_DSCFG_PROMPT_EDIT.get(rufn), true)) { MenuResult<Void> result = SetPropSubCommandHandler.modifyManagedObject(app, context, ref, handler); @@ -561,9 +563,9 @@ throw new ClientException(ReturnCode.CONSTRAINT_VIOLATION, msg); } catch (OperationRejectedException e) { // Give the user the chance to fix the problems. app.println(); app.errPrintln(); displayOperationRejectedException(app, e); app.println(); app.errPrintln(); if (app.confirmAction(INFO_DSCFG_PROMPT_EDIT.get(rufn), true)) { MenuResult<Void> result = SetPropSubCommandHandler.modifyManagedObject(app, context, ref, handler); @@ -599,9 +601,9 @@ // the user refused to modify it, then give the used the // option of editing the referencing component. if (isBadReference) { app.println(); app.println(ERR_SET_REFERENCED_COMPONENT_DISABLED.get(ufn, rufn)); app.println(); app.errPrintln(); app.errPrintln(ERR_SET_REFERENCED_COMPONENT_DISABLED.get(ufn, rufn)); app.errPrintln(); if (app.confirmAction(INFO_DSCFG_PROMPT_EDIT_AGAIN.get(ufn), true)) { return MenuResult.again(); } @@ -693,9 +695,9 @@ if (app.isInteractive()) { // If interactive, give the user the chance to fix the // problems. app.println(); app.errPrintln(); displayMissingMandatoryPropertyException(app, e); app.println(); app.errPrintln(); if (!app.confirmAction(INFO_DSCFG_PROMPT_EDIT_AGAIN.get(ufn), true)) { return MenuResult.cancel(); } @@ -710,11 +712,10 @@ throw new ClientException(ReturnCode.CONSTRAINT_VIOLATION, msg); } catch (OperationRejectedException e) { if (app.isInteractive()) { // If interactive, give the user the chance to fix the // problems. app.println(); // If interactive, give the user the chance to fix the problems. app.errPrintln(); displayOperationRejectedException(app, e); app.println(); app.errPrintln(); if (!app.confirmAction(INFO_DSCFG_PROMPT_EDIT_AGAIN.get(ufn), true)) { return MenuResult.cancel(); } @@ -722,23 +723,11 @@ throw new ClientException(ReturnCode.CONSTRAINT_VIOLATION, e.getMessageObject(), e); } } catch (LdapException e) { final LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_CE.get(ufn, e.getMessage()); if (app.isInteractive()) { app.println(); app.printVerboseMessage(msg); return MenuResult.cancel(); } else { throw new ClientException(ReturnCode.CLIENT_SIDE_SERVER_DOWN, msg); } LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_CE.get(ufn, e.getMessage()); return interactivePrintOrThrowError(app, msg, CLIENT_SIDE_SERVER_DOWN); } catch (ManagedObjectAlreadyExistsException e) { final LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_MOAEE.get(ufn); if (app.isInteractive()) { app.println(); app.printVerboseMessage(msg); return MenuResult.cancel(); } else { throw new ClientException(ReturnCode.ENTRY_ALREADY_EXISTS, msg); } LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_MOAEE.get(ufn); return interactivePrintOrThrowError(app, msg, ENTRY_ALREADY_EXISTS); } } } @@ -763,10 +752,9 @@ try { child = parent.createChild(irelation, d, input, exceptions); } catch (IllegalManagedObjectNameException e) { ClientException ae = ArgumentExceptionFactory.adaptIllegalManagedObjectNameException(e, d); app.println(); app.println(ae.getMessageObject()); app.println(); app.errPrintln(); app.errPrintln(adaptIllegalManagedObjectNameException(e, d).getMessageObject()); app.errPrintln(); return null; } @@ -795,11 +783,10 @@ } // A child with the specified name must already exist. LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_NAME_ALREADY_EXISTS.get( irelation.getUserFriendlyName(), input); app.println(); app.println(msg); app.println(); app.errPrintln(); app.errPrintln( ERR_DSCFG_ERROR_CREATE_NAME_ALREADY_EXISTS.get(irelation.getUserFriendlyName(), input)); app.errPrintln(); return null; } }; @@ -868,8 +855,7 @@ // If there is only one choice then return immediately. if (filteredTypes.size() == 0) { LocalizableMessage msg = ERR_DSCFG_ERROR_NO_AVAILABLE_TYPES.get(d.getUserFriendlyName()); app.println(msg); app.errPrintln(ERR_DSCFG_ERROR_NO_AVAILABLE_TYPES.get(d.getUserFriendlyName())); return MenuResult.<ManagedObjectDefinition<? extends C, ? extends S>> cancel(); } else if (filteredTypes.size() == 1) { ManagedObjectDefinition<? extends C, ? extends S> type = filteredTypes.iterator().next(); @@ -1050,13 +1036,7 @@ } catch (ManagedObjectNotFoundException e) { LocalizableMessage pufn = path.getManagedObjectDefinition().getUserFriendlyName(); LocalizableMessage msg = ERR_DSCFG_ERROR_GET_PARENT_MONFE.get(pufn); if (app.isInteractive()) { app.println(); app.printVerboseMessage(msg); return MenuResult.cancel(); } else { throw new ClientException(ReturnCode.NO_SUCH_OBJECT, msg); } return interactivePrintOrThrowError(app, msg, NO_SUCH_OBJECT); } catch (LdapException e) { throw new ClientException(ReturnCode.OTHER, LocalizableMessage.raw(e.getLocalizedMessage())); } opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/DSConfig.java
@@ -138,10 +138,10 @@ return MenuResult.again(); } } catch (ArgumentException e) { app.println(e.getMessageObject()); app.errPrintln(e.getMessageObject()); return MenuResult.success(1); } catch (ClientException e) { app.println(e.getMessageObject()); app.errPrintln(e.getMessageObject()); return MenuResult.success(e.getReturnCode()); } } @@ -239,7 +239,7 @@ } return result; } catch (ClientException e) { app.println(e.getMessageObject()); app.errPrintln(e.getMessageObject()); return MenuResult.success(1); } } @@ -257,6 +257,32 @@ */ public static final String GENERIC_TYPE = "generic"; /** * Prints the provided error message if the provided application is * interactive, throws a {@link ClientException} with provided error code * and message otherwise. * * @param app * The console application where the message should be printed. * @param msg * The human readable error message. * @param errorCode * The operation error code. * @return A generic cancel menu result if application is interactive. * @throws ClientException * If the application is not interactive. */ static <T> MenuResult<T> interactivePrintOrThrowError(ConsoleApplication app, LocalizableMessage msg, ReturnCode errorCode) throws ClientException { if (app.isInteractive()) { app.errPrintln(); app.errPrintln(msg); return MenuResult.cancel(); } else { throw new ClientException(errorCode, msg); } } private long sessionStartTime; private boolean sessionStartTimePrinted; private int sessionEquivalentOperationNumber; @@ -294,7 +320,7 @@ try { ConfigurationFramework.getInstance().initialize(); } catch (ConfigException e) { app.println(e.getMessageObject()); app.errPrintln(e.getMessageObject()); return ReturnCode.ERROR_INITIALIZING_SERVER.get(); } } @@ -418,11 +444,11 @@ return verboseArgument.isPresent(); } /** Displays the provided message followed by a help usage reference. */ private void displayMessageAndUsageReference(LocalizableMessage message) { println(message); println(); println(parser.getHelpUsageReference()); /** Displays the provided error message followed by a help usage reference. */ private void displayErrorMessageAndUsageReference(LocalizableMessage message) { errPrintln(message); errPrintln(); errPrintln(parser.getHelpUsageReference()); } /** @@ -560,7 +586,7 @@ initializeGlobalArguments(args); initializeSubCommands(); } catch (ArgumentException e) { println(ERR_CANNOT_INITIALIZE_ARGS.get(e.getMessage())); errPrintln(ERR_CANNOT_INITIALIZE_ARGS.get(e.getMessage())); return ReturnCode.ERROR_USER_DATA.get(); } @@ -574,7 +600,7 @@ parser.parseArguments(args); checkForConflictingArguments(); } catch (ArgumentException ae) { displayMessageAndUsageReference(ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); displayErrorMessageAndUsageReference(ERR_ERROR_PARSING_ARGS.get(ae.getMessage())); return ReturnCode.CONFLICTING_ARGS.get(); } @@ -589,10 +615,10 @@ if (equivalentCommandFileArgument.isPresent()) { final String file = equivalentCommandFileArgument.getValue(); if (!canWrite(file)) { println(ERR_DSCFG_CANNOT_WRITE_EQUIVALENT_COMMAND_LINE_FILE.get(file)); errPrintln(ERR_DSCFG_CANNOT_WRITE_EQUIVALENT_COMMAND_LINE_FILE.get(file)); return ReturnCode.ERROR_UNEXPECTED.get(); } else if (new File(file).isDirectory()) { println(ERR_DSCFG_EQUIVALENT_COMMAND_LINE_FILE_DIRECTORY.get(file)); errPrintln(ERR_DSCFG_EQUIVALENT_COMMAND_LINE_FILE_DIRECTORY.get(file)); return ReturnCode.ERROR_UNEXPECTED.get(); } } @@ -601,35 +627,30 @@ try { factory = new LDAPManagementContextFactory(cfp); } catch (ArgumentException e) { displayMessageAndUsageReference(ERR_ERROR_PARSING_ARGS.get(e.getMessage())); displayErrorMessageAndUsageReference(ERR_ERROR_PARSING_ARGS.get(e.getMessage())); return ReturnCode.CONFLICTING_ARGS.get(); } // Handle batch file if any if (batchFileArgument.isPresent()) { handleBatchFile(args); // don't need to do anything else return ReturnCode.SUCCESS.get(); } int retCode = 0; if (parser.getSubCommand() == null) { hasSubCommand = false; hasSubCommand = parser.getSubCommand() != null; if (!hasSubCommand) { if (isInteractive()) { // Top-level interactive mode. retCode = runInteractiveMode(); } else { LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ERR_DSCFG_ERROR_MISSING_SUBCOMMAND.get()); displayMessageAndUsageReference(message); displayErrorMessageAndUsageReference( ERR_ERROR_PARSING_ARGS.get(ERR_DSCFG_ERROR_MISSING_SUBCOMMAND.get())); retCode = ReturnCode.ERROR_USER_DATA.get(); } } else { hasSubCommand = true; // Retrieve the sub-command implementation and run it. SubCommandHandler handler = handlers.get(parser.getSubCommand()); retCode = runSubCommand(handler); retCode = runSubCommand(handlers.get(parser.getSubCommand())); } factory.close(); @@ -749,10 +770,10 @@ // Force retrieval of management context. factory.getManagementContext(app); } catch (ArgumentException e) { app.println(e.getMessageObject()); app.errPrintln(e.getMessageObject()); return ReturnCode.ERROR_UNEXPECTED.get(); } catch (ClientException e) { app.println(e.getMessageObject()); app.errPrintln(e.getMessageObject()); return ReturnCode.ERROR_UNEXPECTED.get(); } @@ -768,7 +789,7 @@ return result.getValue(); } } catch (ClientException e) { app.println(e.getMessageObject()); app.errPrintln(e.getMessageObject()); return ReturnCode.ERROR_UNEXPECTED.get(); } } @@ -788,11 +809,11 @@ return ReturnCode.ERROR_UNEXPECTED.get(); } } catch (ArgumentException e) { println(e.getMessageObject()); errPrintln(e.getMessageObject()); return ReturnCode.ERROR_UNEXPECTED.get(); } catch (ClientException e) { Throwable cause = e.getCause(); println(); errPrintln(); if (cause instanceof ManagedObjectDecodingException) { displayManagedObjectDecodingException(this, (ManagedObjectDecodingException) cause); } else if (cause instanceof MissingMandatoryPropertiesException) { @@ -801,13 +822,13 @@ displayOperationRejectedException(this, (OperationRejectedException) cause); } else { // Just display the default message. println(e.getMessageObject()); errPrintln(e.getMessageObject()); } println(); errPrintln(); return ReturnCode.ERROR_UNEXPECTED.get(); } catch (Exception e) { println(LocalizableMessage.raw(stackTraceToSingleLineString(e, true))); errPrintln(LocalizableMessage.raw(stackTraceToSingleLineString(e, true))); return ReturnCode.ERROR_UNEXPECTED.get(); } } @@ -901,7 +922,7 @@ writer.flush(); } catch (IOException ioe) { println(ERR_DSCFG_ERROR_WRITING_EQUIVALENT_COMMAND_LINE.get(file, ioe)); errPrintln(ERR_DSCFG_ERROR_WRITING_EQUIVALENT_COMMAND_LINE.get(file, ioe)); } finally { closeSilently(writer); } @@ -993,7 +1014,7 @@ errPrintln(); } } catch (IOException ex) { println(ERR_DSCFG_ERROR_READING_BATCH_FILE.get(ex)); errPrintln(ERR_DSCFG_ERROR_READING_BATCH_FILE.get(ex)); } finally { closeSilently(bReader); } opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/DeleteSubCommandHandler.java
@@ -26,6 +26,7 @@ */ package org.forgerock.opendj.config.dsconfig; import static com.forgerock.opendj.cli.ReturnCode.*; import static com.forgerock.opendj.dsconfig.DsconfigMessages.*; import java.util.List; @@ -60,6 +61,8 @@ import com.forgerock.opendj.cli.TableBuilder; import com.forgerock.opendj.cli.TextTablePrinter; import static org.forgerock.opendj.config.dsconfig.DSConfig.*; /** * A sub-command handler which is used to delete existing managed objects. * <p> @@ -223,13 +226,7 @@ if (!forceArgument.isPresent()) { LocalizableMessage pufn = path.getManagedObjectDefinition().getUserFriendlyName(); LocalizableMessage msg = ERR_DSCFG_ERROR_GET_PARENT_MONFE.get(pufn); if (app.isInteractive()) { app.println(); app.printVerboseMessage(msg); return MenuResult.cancel(); } else { throw new ClientException(ReturnCode.NO_SUCH_OBJECT, msg); } return interactivePrintOrThrowError(app, msg, NO_SUCH_OBJECT); } else { return MenuResult.success(0); } @@ -311,18 +308,14 @@ LocalizableMessage msg = ERR_DSCFG_ERROR_DELETE_AUTHZ.get(ufn); throw new ClientException(ReturnCode.INSUFFICIENT_ACCESS_RIGHTS, msg); } catch (OperationRejectedException e) { LocalizableMessage msg; if (e.getMessages().size() == 1) { msg = ERR_DSCFG_ERROR_DELETE_ORE_SINGLE.get(ufn); } else { msg = ERR_DSCFG_ERROR_DELETE_ORE_PLURAL.get(ufn); } LocalizableMessage msg = e.getMessages().size() == 1 ? ERR_DSCFG_ERROR_DELETE_ORE_SINGLE.get(ufn) : ERR_DSCFG_ERROR_DELETE_ORE_PLURAL.get(ufn); if (app.isInteractive()) { // If interactive, let the user go back to the main menu. app.println(); app.println(msg); app.println(); app.errPrintln(); app.errPrintln(msg); app.errPrintln(); TableBuilder builder = new TableBuilder(); for (LocalizableMessage reason : e.getMessages()) { builder.startRow(); @@ -369,12 +362,9 @@ /** Confirm deletion. */ private boolean confirmDeletion(ConsoleApplication app) throws ClientException { if (app.isInteractive()) { LocalizableMessage prompt = INFO_DSCFG_CONFIRM_DELETE.get(relation.getUserFriendlyName()); app.println(); if (!app.confirmAction(prompt, false)) { // Output failure message. LocalizableMessage msg = INFO_DSCFG_CONFIRM_DELETE_FAIL.get(relation.getUserFriendlyName()); app.println(msg); if (!app.confirmAction(INFO_DSCFG_CONFIRM_DELETE.get(relation.getUserFriendlyName()), false)) { app.errPrintln(INFO_DSCFG_CONFIRM_DELETE_FAIL.get(relation.getUserFriendlyName())); return false; } } opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/HelpSubCommandHandler.java
@@ -436,11 +436,11 @@ // Display the property synopsis and description. app.println(); app.errPrintln(pd.getSynopsis(), 4); app.println(pd.getSynopsis(), 4); if (pd.getDescription() != null) { app.println(); app.errPrintln(pd.getDescription(), 4); app.println(pd.getDescription(), 4); } if (pd instanceof AggregationPropertyDefinition) { opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/ListSubCommandHandler.java
@@ -25,9 +25,6 @@ */ package org.forgerock.opendj.config.dsconfig; import static com.forgerock.opendj.dsconfig.DsconfigMessages.*; import static com.forgerock.opendj.cli.ArgumentConstants.LIST_TABLE_SEPARATOR; import java.io.PrintStream; import java.util.List; import java.util.Set; @@ -40,7 +37,6 @@ import org.forgerock.opendj.config.InstantiableRelationDefinition; import org.forgerock.opendj.config.ManagedObjectDefinition; import org.forgerock.opendj.config.ManagedObjectNotFoundException; import org.forgerock.opendj.config.ManagedObjectOption; import org.forgerock.opendj.config.ManagedObjectPath; import org.forgerock.opendj.config.OptionalRelationDefinition; import org.forgerock.opendj.config.PropertyDefinition; @@ -65,6 +61,13 @@ import com.forgerock.opendj.cli.TablePrinter; import com.forgerock.opendj.cli.TextTablePrinter; import static org.forgerock.opendj.config.ManagedObjectOption.*; import static org.forgerock.opendj.config.dsconfig.DSConfig.*; import static com.forgerock.opendj.cli.ArgumentConstants.*; import static com.forgerock.opendj.cli.ReturnCode.*; import static com.forgerock.opendj.dsconfig.DsconfigMessages.*; /** * A sub-command handler which is used to list existing managed objects. * <p> @@ -232,13 +235,7 @@ } catch (ManagedObjectNotFoundException e) { ufn = path.getManagedObjectDefinition().getUserFriendlyName(); LocalizableMessage msg = ERR_DSCFG_ERROR_GET_PARENT_MONFE.get(ufn); if (app.isInteractive()) { app.println(); app.printVerboseMessage(msg); return MenuResult.cancel(); } else { throw new ClientException(ReturnCode.NO_SUCH_OBJECT, msg); } return interactivePrintOrThrowError(app, msg, NO_SUCH_OBJECT); } catch (LdapException e) { throw new ClientException(ReturnCode.OTHER, LocalizableMessage.raw(e.getLocalizedMessage())); } @@ -319,14 +316,8 @@ children.put(child.getManagedObjectDefinition().getName(), child); } else { // Indicate that the managed object does not exist. LocalizableMessage msg = ERR_DSCFG_ERROR_FINDER_NO_CHILDREN.get(ufn); if (app.isInteractive()) { app.println(); app.printVerboseMessage(msg); return MenuResult.cancel(); } else { throw new ClientException(ReturnCode.NO_SUCH_OBJECT, msg); } return interactivePrintOrThrowError( app, ERR_DSCFG_ERROR_FINDER_NO_CHILDREN.get(ufn), NO_SUCH_OBJECT); } } catch (AuthorizationException e) { LocalizableMessage msg = ERR_DSCFG_ERROR_LIST_AUTHZ.get(ufn); @@ -353,21 +344,10 @@ if (app.isScriptFriendly()) { // Output just the names of the children. for (String name : children.keySet()) { // Skip advanced and hidden components in non-advanced mode. if (!app.isAdvancedMode()) { ManagedObject<?> child = children.get(name); ManagedObjectDefinition<?, ?> d = child.getManagedObjectDefinition(); if (d.hasOption(ManagedObjectOption.HIDDEN)) { continue; } if (d.hasOption(ManagedObjectOption.ADVANCED)) { continue; } ManagedObjectDefinition<?, ?> d = children.get(name).getManagedObjectDefinition(); if (!canDisplay(app, d)) { app.println(LocalizableMessage.raw(name)); } app.println(LocalizableMessage.raw(name)); } } else { // Create a table of their properties containing the name, type (if @@ -391,15 +371,8 @@ ManagedObject<?> child = children.get(name); ManagedObjectDefinition<?, ?> d = child.getManagedObjectDefinition(); // Skip advanced and hidden components in non-advanced mode. if (!app.isAdvancedMode()) { if (d.hasOption(ManagedObjectOption.HIDDEN)) { continue; } if (d.hasOption(ManagedObjectOption.ADVANCED)) { continue; } if (canDisplay(app, d)) { continue; } // First output the name. @@ -468,6 +441,10 @@ return MenuResult.success(0); } private boolean canDisplay(ConsoleApplication app, ManagedObjectDefinition<?, ?> d) { return !app.isAdvancedMode() && (d.hasOption(HIDDEN) || d.hasOption(ADVANCED)); } /** Display the set of values associated with a property. */ private <T> void displayProperty(ConsoleApplication app, TableBuilder builder, ManagedObject<?> mo, PropertyDefinition<T> pd, PropertyValuePrinter valuePrinter) { opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/PropertyValueEditor.java
@@ -26,6 +26,7 @@ */ package org.forgerock.opendj.config.dsconfig; import static com.forgerock.opendj.cli.ReturnCode.*; import static com.forgerock.opendj.dsconfig.DsconfigMessages.*; import java.util.ArrayList; @@ -80,6 +81,8 @@ import com.forgerock.opendj.cli.TableBuilder; import com.forgerock.opendj.cli.TextTablePrinter; import static org.forgerock.opendj.config.dsconfig.DSConfig.*; /** * Common methods used for interactively editing properties. */ @@ -131,13 +134,7 @@ } catch (ManagedObjectNotFoundException e) { LocalizableMessage pufn = path.getManagedObjectDefinition().getUserFriendlyName(); LocalizableMessage msg = ERR_DSCFG_ERROR_GET_PARENT_MONFE.get(pufn); if (app.isInteractive()) { app.println(); app.printVerboseMessage(msg); return MenuResult.cancel(); } else { throw new ClientException(ReturnCode.NO_SUCH_OBJECT, msg); } return interactivePrintOrThrowError(app, msg, NO_SUCH_OBJECT); } // Now let the user create the child component. @@ -148,9 +145,9 @@ // FIXME: should really do something better with the exception // handling here. For example, if a authz or communications // exception occurs then the application should exit. app.println(); app.println(e.getMessageObject()); app.println(); app.errPrintln(); app.errPrintln(e.getMessageObject()); app.errPrintln(); app.pressReturnToContinue(); return MenuResult.cancel(); } @@ -1710,10 +1707,10 @@ app.println(); app.println(INFO_EDITOR_HEADING_CONFIGURE_PROPERTY.get(pd.getName())); app.println(); app.errPrintln(pd.getSynopsis(), 4); app.println(pd.getSynopsis(), 4); if (pd.getDescription() != null) { app.println(); app.errPrintln(pd.getDescription(), 4); app.println(pd.getDescription(), 4); } } @@ -1850,8 +1847,8 @@ break; } catch (PropertyException e) { app.println(); app.println(ArgumentExceptionFactory.adaptPropertyException(e, d).getMessageObject()); app.errPrintln(); app.errPrintln(ArgumentExceptionFactory.adaptPropertyException(e, d).getMessageObject()); } } } @@ -1877,9 +1874,9 @@ values.add(value); } } catch (PropertyException e) { app.println(); app.println(ArgumentExceptionFactory.adaptPropertyException(e, d).getMessageObject()); app.println(); app.errPrintln(); app.errPrintln(ArgumentExceptionFactory.adaptPropertyException(e, d).getMessageObject()); app.errPrintln(); } } } opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/SetPropSubCommandHandler.java
@@ -308,9 +308,9 @@ if (app.isInteractive()) { // If interactive, give the user the chance to fix the // problems. app.println(); app.errPrintln(); displayMissingMandatoryPropertyException(app, e); app.println(); app.errPrintln(); if (!app.confirmAction(INFO_DSCFG_PROMPT_EDIT_AGAIN.get(ufn), true)) { return MenuResult.cancel(); } @@ -327,9 +327,9 @@ if (app.isInteractive()) { // If interactive, give the user the chance to fix the // problems. app.println(); app.errPrintln(); displayOperationRejectedException(app, e); app.println(); app.errPrintln(); if (!app.confirmAction(INFO_DSCFG_PROMPT_EDIT_AGAIN.get(ufn), true)) { return MenuResult.cancel(); } @@ -442,9 +442,9 @@ isBadReference = false; } catch (MissingMandatoryPropertiesException e) { // Give the user the chance to fix the problems. app.println(); app.errPrintln(); displayMissingMandatoryPropertyException(app, e); app.println(); app.errPrintln(); if (app.confirmAction(INFO_DSCFG_PROMPT_EDIT.get(rufn), true)) { MenuResult<Void> result = modifyManagedObject(app, context, ref, handler); if (result.isQuit()) { @@ -460,9 +460,9 @@ throw new ClientException(ReturnCode.CONSTRAINT_VIOLATION, msg); } catch (OperationRejectedException e) { // Give the user the chance to fix the problems. app.println(); app.errPrintln(); displayOperationRejectedException(app, e); app.println(); app.errPrintln(); if (app.confirmAction(INFO_DSCFG_PROMPT_EDIT.get(rufn), true)) { MenuResult<Void> result = modifyManagedObject(app, context, ref, handler); if (result.isQuit()) { @@ -497,9 +497,9 @@ // the user refused to modify it, then give the used the // option of editing the referencing component. if (isBadReference) { app.println(); app.println(ERR_SET_REFERENCED_COMPONENT_DISABLED.get(ufn, rufn)); app.println(); app.errPrintln(); app.errPrintln(ERR_SET_REFERENCED_COMPONENT_DISABLED.get(ufn, rufn)); app.errPrintln(); if (app.confirmAction(INFO_DSCFG_PROMPT_EDIT_AGAIN.get(ufn), true)) { return MenuResult.again(); } else { @@ -655,8 +655,8 @@ except = ArgumentExceptionFactory.unknownValueForChildComponent("\"" + objName + "\""); } if (app.isInteractive()) { app.println(); app.printVerboseMessage(except.getMessageObject()); app.errPrintln(); app.errPrintln(except.getMessageObject()); return MenuResult.cancel(); } else { throw except; opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/SubCommandHandler.java
@@ -1025,8 +1025,7 @@ switch (children.size()) { case 0: { // No options available - abort. LocalizableMessage msg = ERR_DSCFG_ERROR_FINDER_NO_CHILDREN.get(d.getUserFriendlyPluralName()); app.println(msg); app.errPrintln(ERR_DSCFG_ERROR_FINDER_NO_CHILDREN.get(d.getUserFriendlyPluralName())); return MenuResult.cancel(); } case 1: {