| | |
| | | import org.opends.server.admin.client.ManagedObject; |
| | | import org.opends.server.admin.client.ManagedObjectDecodingException; |
| | | import org.opends.server.admin.client.ManagementContext; |
| | | import org.opends.server.protocols.ldap.LDAPResultCode; |
| | | import org.opends.server.tools.ClientException; |
| | | import org.forgerock.util.Reject; |
| | | import com.forgerock.opendj.cli.CLIException; |
| | | |
| | | import com.forgerock.opendj.cli.ClientException; |
| | | import com.forgerock.opendj.cli.ReturnCode; |
| | | |
| | | import org.opends.server.util.cli.HelpCallback; |
| | | import org.opends.server.util.cli.Menu; |
| | | import org.opends.server.util.cli.MenuBuilder; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public MenuResult<String> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | try { |
| | | // First get the parent managed object. |
| | | InstantiableRelationDefinition<?, ?> rd = pd.getRelationDefinition(); |
| | |
| | | parent = context.getManagedObject(path); |
| | | } catch (AuthorizationException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_AUTHZ.get(ufn); |
| | | throw new ClientException(LDAPResultCode.INSUFFICIENT_ACCESS_RIGHTS, |
| | | throw new ClientException(ReturnCode.INSUFFICIENT_ACCESS_RIGHTS, |
| | | msg); |
| | | } catch (DefinitionDecodingException e) { |
| | | LocalizableMessage pufn = path.getManagedObjectDefinition() |
| | | .getUserFriendlyName(); |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_GET_PARENT_DDE.get(pufn, pufn, pufn); |
| | | throw new ClientException(LDAPResultCode.OTHER, msg); |
| | | throw new ClientException(ReturnCode.OTHER, msg); |
| | | } catch (ManagedObjectDecodingException e) { |
| | | LocalizableMessage pufn = path.getManagedObjectDefinition() |
| | | .getUserFriendlyName(); |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_GET_PARENT_MODE.get(pufn); |
| | | throw new ClientException(LDAPResultCode.OTHER, msg, e); |
| | | throw new ClientException(ReturnCode.OTHER, msg, e); |
| | | } catch (CommunicationException e) { |
| | | LocalizableMessage msg = ERR_DSCFG_ERROR_CREATE_CE.get(ufn, e.getMessage()); |
| | | throw new ClientException(LDAPResultCode.CLIENT_SIDE_SERVER_DOWN, |
| | | throw new ClientException(ReturnCode.CLIENT_SIDE_SERVER_DOWN, |
| | | msg); |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | LocalizableMessage pufn = path.getManagedObjectDefinition() |
| | |
| | | app.printVerboseMessage(msg); |
| | | return MenuResult.cancel(); |
| | | } else { |
| | | throw new ClientException(LDAPResultCode.NO_SUCH_OBJECT, msg); |
| | | throw new ClientException(ReturnCode.NO_SUCH_OBJECT, msg); |
| | | } |
| | | } |
| | | |
| | |
| | | MenuCallback<Void> { |
| | | |
| | | // Any exception that was caught during processing. |
| | | private CLIException e = null; |
| | | private ClientException e = null; |
| | | |
| | | // The managed object being edited. |
| | | private final ManagedObject<?> mo; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public MenuResult<Void> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | displayPropertyHeader(app, pd); |
| | | |
| | | MenuResult<Void> result = pd.accept(this, null); |
| | |
| | | try { |
| | | values.addAll(Arrays.asList(context.listManagedObjects(path, rd))); |
| | | } catch (AuthorizationException e) { |
| | | this.e = new CLIException(e.getMessageObject()); |
| | | this.e = new ClientException(ReturnCode.TODO, e.getMessageObject()); |
| | | return MenuResult.quit(); |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | this.e = new CLIException(e.getMessageObject()); |
| | | this.e = new ClientException(ReturnCode.TODO, e.getMessageObject()); |
| | | return MenuResult.cancel(); |
| | | } catch (CommunicationException e) { |
| | | this.e = new CLIException(e.getMessageObject()); |
| | | this.e = new ClientException(ReturnCode.TODO, e.getMessageObject()); |
| | | return MenuResult.quit(); |
| | | } |
| | | |
| | |
| | | oldValues); |
| | | return MenuResult.success(); |
| | | } |
| | | } catch (CLIException e) { |
| | | } catch (ClientException e) { |
| | | this.e = e; |
| | | return MenuResult.cancel(); |
| | | } |
| | |
| | | oldValues); |
| | | return MenuResult.success(); |
| | | } |
| | | } catch (CLIException e) { |
| | | } catch (ClientException e) { |
| | | this.e = e; |
| | | return MenuResult.cancel(); |
| | | } |
| | |
| | | registerModification(d, new TreeSet<E>(newValues), oldValues); |
| | | return MenuResult.success(); |
| | | } |
| | | } catch (CLIException e) { |
| | | } catch (ClientException e) { |
| | | this.e = e; |
| | | return MenuResult.cancel(); |
| | | } |
| | |
| | | isLastChoiceReset = false; |
| | | registerModification(d, values, oldValues); |
| | | return MenuResult.success(); |
| | | } catch (CLIException e) { |
| | | } catch (ClientException e) { |
| | | this.e = e; |
| | | return MenuResult.cancel(); |
| | | } |
| | |
| | | implements MenuCallback<Boolean> { |
| | | |
| | | // Any exception that was caught during processing. |
| | | private CLIException e = null; |
| | | private ClientException e = null; |
| | | |
| | | // The managed object being edited. |
| | | private final ManagedObject<?> mo; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public MenuResult<Boolean> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | displayPropertyHeader(app, pd); |
| | | |
| | | MenuResult<Boolean> result = pd.accept(this, null); |
| | |
| | | try { |
| | | values.addAll(Arrays.asList(context.listManagedObjects(path, rd))); |
| | | } catch (AuthorizationException e) { |
| | | this.e = new CLIException(e.getMessageObject()); |
| | | this.e = new ClientException(ReturnCode.TODO, e.getMessageObject()); |
| | | return MenuResult.quit(); |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | this.e = new CLIException(e.getMessageObject()); |
| | | this.e = new ClientException(ReturnCode.TODO, e.getMessageObject()); |
| | | return MenuResult.cancel(); |
| | | } catch (CommunicationException e) { |
| | | this.e = new CLIException(e.getMessageObject()); |
| | | this.e = new ClientException(ReturnCode.TODO, e.getMessageObject()); |
| | | return MenuResult.quit(); |
| | | } |
| | | |
| | |
| | | addCallback = new MenuCallback<Boolean>() { |
| | | |
| | | public MenuResult<Boolean> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | MenuBuilder<String> builder = new MenuBuilder<String>(app); |
| | | |
| | | builder.setPrompt(INFO_EDITOR_PROMPT_SELECT_COMPONENTS_ADD |
| | |
| | | MenuCallback<Boolean> removeCallback = new MenuCallback<Boolean>() { |
| | | |
| | | public MenuResult<Boolean> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | MenuBuilder<String> builder = new MenuBuilder<String>(app); |
| | | |
| | | builder.setPrompt(INFO_EDITOR_PROMPT_SELECT_COMPONENTS_REMOVE |
| | |
| | | addCallback = new MenuCallback<Boolean>() { |
| | | |
| | | public MenuResult<Boolean> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | MenuBuilder<T> builder = new MenuBuilder<T>(app); |
| | | |
| | | builder.setPrompt(INFO_EDITOR_PROMPT_SELECT_VALUES_ADD.get()); |
| | |
| | | MenuCallback<Boolean> removeCallback = new MenuCallback<Boolean>() { |
| | | |
| | | public MenuResult<Boolean> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | MenuBuilder<T> builder = new MenuBuilder<T>(app); |
| | | |
| | | builder.setPrompt(INFO_EDITOR_PROMPT_SELECT_VALUES_REMOVE.get()); |
| | |
| | | MenuCallback<Boolean> addCallback = new MenuCallback<Boolean>() { |
| | | |
| | | public MenuResult<Boolean> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | app.println(); |
| | | SortedSet<T> previousValues = new TreeSet<T>(currentValues); |
| | | readPropertyValues(app, mo.getManagedObjectDefinition(), d, |
| | |
| | | MenuCallback<Boolean> removeCallback = new MenuCallback<Boolean>() { |
| | | |
| | | public MenuResult<Boolean> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | MenuBuilder<T> builder = new MenuBuilder<T>(app); |
| | | |
| | | builder.setPrompt(INFO_EDITOR_PROMPT_SELECT_VALUES_REMOVE.get()); |
| | |
| | | MenuCallback<Boolean> callback = new MenuCallback<Boolean>() { |
| | | |
| | | public MenuResult<Boolean> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | isLastChoiceReset = false; |
| | | currentValues.clear(); |
| | | app.println(); |
| | |
| | | MenuCallback<Boolean> callback = new MenuCallback<Boolean>() { |
| | | |
| | | public MenuResult<Boolean> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | currentValues.clear(); |
| | | currentValues.addAll(defaultValues); |
| | | isLastChoiceReset = true; |
| | |
| | | MenuCallback<Boolean> callback = new MenuCallback<Boolean>() { |
| | | |
| | | public MenuResult<Boolean> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | currentValues.clear(); |
| | | currentValues.addAll(oldValues); |
| | | isLastChoiceReset = false; |
| | |
| | | try { |
| | | app.println(); |
| | | result = menu.run(); |
| | | } catch (CLIException e) { |
| | | } catch (ClientException e) { |
| | | this.e = e; |
| | | return null; |
| | | } |
| | |
| | | MenuCallback<Boolean> { |
| | | |
| | | // Any exception that was caught during processing. |
| | | private CLIException e = null; |
| | | private ClientException e = null; |
| | | |
| | | // The managed object being edited. |
| | | private final ManagedObject<?> mo; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public MenuResult<Boolean> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | MenuResult<Boolean> result = pd.accept(this, null); |
| | | if (e != null) { |
| | | throw e; |
| | |
| | | boolean result; |
| | | try { |
| | | result = app.confirmAction(INFO_EDITOR_PROMPT_READ_ONLY.get(), false); |
| | | } catch (CLIException e) { |
| | | } catch (ClientException e) { |
| | | this.e = e; |
| | | return null; |
| | | } |
| | |
| | | implements MenuCallback<Boolean> { |
| | | |
| | | // Any exception that was caught during processing. |
| | | private CLIException e = null; |
| | | private ClientException e = null; |
| | | |
| | | // The managed object being edited. |
| | | private final ManagedObject<?> mo; |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public MenuResult<Boolean> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | displayPropertyHeader(app, pd); |
| | | |
| | | MenuResult<Boolean> result = pd.accept(this, null); |
| | |
| | | try { |
| | | values.addAll(Arrays.asList(context.listManagedObjects(path, rd))); |
| | | } catch (AuthorizationException e) { |
| | | this.e = new CLIException(e.getMessageObject()); |
| | | this.e = new ClientException(ReturnCode.TODO, e.getMessageObject()); |
| | | return MenuResult.quit(); |
| | | } catch (ManagedObjectNotFoundException e) { |
| | | this.e = new CLIException(e.getMessageObject()); |
| | | this.e = new ClientException(ReturnCode.TODO, e.getMessageObject()); |
| | | return MenuResult.cancel(); |
| | | } catch (CommunicationException e) { |
| | | this.e = new CLIException(e.getMessageObject()); |
| | | this.e = new ClientException(ReturnCode.TODO, e.getMessageObject()); |
| | | return MenuResult.quit(); |
| | | } |
| | | |
| | |
| | | new MenuCallback<T>() { |
| | | |
| | | public MenuResult<T> invoke(ConsoleApplication app) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | app.println(); |
| | | Set<T> values = readPropertyValues(app, mo |
| | | .getManagedObjectDefinition(), d); |
| | |
| | | try { |
| | | app.println(); |
| | | result = menu.run(); |
| | | } catch (CLIException e) { |
| | | } catch (ClientException e) { |
| | | this.e = e; |
| | | return null; |
| | | } |
| | |
| | | // Read new values for a property. |
| | | private static <T> SortedSet<T> readPropertyValues(ConsoleApplication app, |
| | | ManagedObjectDefinition<?, ?> d, PropertyDefinition<T> pd) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | SortedSet<T> values = new TreeSet<T>(pd); |
| | | readPropertyValues(app, d, pd, values); |
| | | return values; |
| | |
| | | // Add values to a property. |
| | | private static <T> void readPropertyValues(ConsoleApplication app, |
| | | ManagedObjectDefinition<?, ?> d, PropertyDefinition<T> pd, |
| | | SortedSet<T> values) throws CLIException { |
| | | SortedSet<T> values) throws ClientException { |
| | | // Make sure there is at least one value if mandatory and empty. |
| | | if (values.isEmpty()) { |
| | | while (true) { |
| | |
| | | * {@code MenuResult.cancel()} if the user to chose to |
| | | * cancel any changes, or {@code MenuResult.quit()} if the |
| | | * user chose to quit the application. |
| | | * @throws CLIException |
| | | * @throws ClientException |
| | | * If the user input could not be retrieved for some |
| | | * reason. |
| | | */ |
| | | public MenuResult<Void> edit(ManagedObject<?> mo, |
| | | Collection<PropertyDefinition<?>> c, boolean isCreate) |
| | | throws CLIException { |
| | | throws ClientException { |
| | | |
| | | // Get values for this missing mandatory property. |
| | | for (PropertyDefinition<?> pd : c) { |