Repository: syncope Updated Branches: refs/heads/master 469b7497c -> 171c0ae36
refactoring of the domain stack, SYNCOPE-158 Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/dfc1df48 Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/dfc1df48 Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/dfc1df48 Branch: refs/heads/master Commit: dfc1df48398e9b1421d23c1fb2ab8c3c6cb03ad8 Parents: 469b749 Author: massi <[email protected]> Authored: Wed Oct 21 13:28:46 2015 +0200 Committer: massi <[email protected]> Committed: Wed Oct 21 13:28:46 2015 +0200 ---------------------------------------------------------------------- .../syncope/client/cli/ResultManager.java | 25 +++ .../apache/syncope/client/cli/SyncopeAdm.java | 9 +- .../cli/commands/CommonsResultManager.java | 2 +- .../client/cli/commands/DomainCommand.java | 165 ------------------- .../cli/commands/NotificationCommand.java | 2 +- .../client/cli/commands/PolicyCommand.java | 2 +- .../client/cli/commands/ReportCommand.java | 2 +- .../client/cli/commands/SchemaCommand.java | 1 - .../client/cli/commands/TaskCommand.java | 2 +- .../configuration/ConfigurationCommand.java | 4 - .../configuration/ConfigurationDelete.java | 4 +- .../configuration/ConfigurationExport.java | 12 +- .../configuration/ConfigurationGet.java | 2 +- .../configuration/ConfigurationRead.java | 2 +- .../configuration/ConfigurationUpdate.java | 6 +- .../commands/domain/AbstractDomainCommand.java | 30 ++++ .../cli/commands/domain/DomainCommand.java | 101 ++++++++++++ .../cli/commands/domain/DomainDelete.java | 53 ++++++ .../client/cli/commands/domain/DomainList.java | 38 +++++ .../client/cli/commands/domain/DomainRead.java | 53 ++++++ .../commands/domain/DomainResultManager.java | 25 +++ .../cli/commands/install/InstallCommand.java | 5 - .../cli/commands/install/InstallSetup.java | 3 + .../cli/commands/logger/LoggerDelete.java | 2 +- .../client/cli/commands/logger/LoggerList.java | 2 +- .../client/cli/commands/logger/LoggerRead.java | 2 +- .../cli/commands/logger/LoggerUpdate.java | 4 +- .../cli/commands/logger/LoggerUpdateAll.java | 2 +- 28 files changed, 357 insertions(+), 203 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/ResultManager.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/ResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/ResultManager.java new file mode 100644 index 0000000..de3d0f1 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/ResultManager.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli; + +import org.apache.syncope.client.cli.commands.CommonsResultManager; + +public class ResultManager extends CommonsResultManager { + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java b/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java index b5a1365..ea11a22 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java @@ -20,7 +20,6 @@ package org.apache.syncope.client.cli; import javax.ws.rs.ProcessingException; import org.apache.syncope.client.cli.commands.AbstractCommand; -import org.apache.syncope.client.cli.commands.logger.LoggerResultManager; import org.apache.syncope.client.cli.util.CommandUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,6 +27,8 @@ import org.slf4j.LoggerFactory; public final class SyncopeAdm { private static final Logger LOG = LoggerFactory.getLogger(SyncopeAdm.class); + + private static final ResultManager resultManager = new ResultManager(); public static void main(final String[] args) { LOG.debug("Starting with args \n"); @@ -49,12 +50,12 @@ public final class SyncopeAdm { System.out.println(helpMessage()); } catch (final IllegalArgumentException ex) { LOG.error("Error in main", ex); - new LoggerResultManager().genericError(ex.getMessage()); + resultManager.generic(ex.getMessage()); if (!ex.getMessage().startsWith("It seems you")) { System.out.println(helpMessage()); } } catch (final ProcessingException e) { - new LoggerResultManager().genericError("Syncope server offline", e.getCause().getMessage()); + resultManager.generic("Syncope server offline", e.getCause().getMessage()); } } @@ -72,7 +73,7 @@ public final class SyncopeAdm { helpMessageBuilder.append("\n"); } } catch (final IllegalAccessException | IllegalArgumentException | InstantiationException ex) { - new LoggerResultManager().genericError(ex.getMessage()); + resultManager.generic(ex.getMessage()); } return helpMessageBuilder.toString(); http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java index 9bfde8d..255b99b 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java @@ -44,7 +44,7 @@ public abstract class CommonsResultManager { Messages.printDefaultMessage(option, helpMessage); } - public void genericError(final String... messages) { + public void generic(final String... messages) { Messages.printMessage(messages); } } http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/DomainCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/DomainCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/DomainCommand.java deleted file mode 100644 index 8d4cfdf..0000000 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/DomainCommand.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.syncope.client.cli.commands; - -import org.apache.syncope.client.cli.commands.logger.LoggerCommand; -import java.util.ArrayList; -import java.util.List; -import org.apache.commons.lang3.StringUtils; -import org.apache.syncope.client.cli.Command; -import org.apache.syncope.client.cli.Input; -import org.apache.syncope.client.cli.SyncopeServices; -import org.apache.syncope.client.cli.messages.Messages; -import org.apache.syncope.common.lib.SyncopeClientException; -import org.apache.syncope.common.lib.to.DomainTO; -import org.apache.syncope.common.rest.api.service.DomainService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Command(name = "domain") -public class DomainCommand extends AbstractCommand { - - private static final Logger LOG = LoggerFactory.getLogger(LoggerCommand.class); - - private static final String HELP_MESSAGE = "Usage: domain [options]\n" - + " Options:\n" - + " --help \n" - + " --list \n" - + " --read \n" - + " Syntax: --read {DOMAIN-KEY} {DOMAIN-KEY} [...]\n" - + " --delete \n" - + " Syntax: --delete {DOMAIN-KEY} {DOMAIN-KEY} [...]\n"; - - @Override - public void execute(final Input input) { - LOG.debug("Option: {}", input.getOption()); - LOG.debug("Parameters:"); - for (final String parameter : input.getParameters()) { - LOG.debug(" > " + parameter); - } - - final String[] parameters = input.getParameters(); - - if (StringUtils.isBlank(input.getOption())) { - input.setOption(Options.HELP.getOptionName()); - } - - final DomainService domainService = SyncopeServices.get(DomainService.class); - switch (Options.fromName(input.getOption())) { - case LIST: - try { - for (final DomainTO domainTO : domainService.list()) { - Messages.printMessage("Domain key: " + domainTO.getKey()); - } - } catch (final SyncopeClientException ex) { - Messages.printMessage("Error: " + ex.getMessage()); - } - break; - case READ: - final String readErrorMessage = "domain --read {DOMAIN-KEY} {DOMAIN-KEY} [...]"; - if (parameters.length >= 1) { - for (final String parameter : parameters) { - try { - final DomainTO domainTO = domainService.read(parameter); - Messages.printMessage("Domain key: " + domainTO.getKey()); - } catch (final SyncopeClientException ex) { - if (ex.getMessage().startsWith("NotFound")) { - Messages.printNofFoundMessage("Domain", parameter); - } else { - Messages.printMessage(ex.getMessage()); - } - } - } - } else { - Messages.printCommandOptionMessage(readErrorMessage); - } - break; - case DELETE: - final String deleteErrorMessage = "domain --delete {DOMAIN-KEY} {DOMAIN-KEY} [...]"; - if (parameters.length >= 1) { - for (final String parameter : parameters) { - try { - domainService.delete(parameter); - Messages.printDeletedMessage("Domain", parameter); - } catch (final SyncopeClientException ex) { - if (ex.getMessage().startsWith("NotFound")) { - Messages.printNofFoundMessage("Domain", parameter); - } else { - Messages.printMessage(ex.getMessage()); - } - } - } - } else { - Messages.printCommandOptionMessage(deleteErrorMessage); - } - break; - case HELP: - System.out.println(HELP_MESSAGE); - break; - default: - Messages.printDefaultMessage(input.getOption(), HELP_MESSAGE); - } - - } - - @Override - public String getHelpMessage() { - return HELP_MESSAGE; - } - - private enum Options { - - HELP("--help"), - LIST("--list"), - READ("--read"), - DELETE("--delete"); - - private final String optionName; - - Options(final String optionName) { - this.optionName = optionName; - } - - public String getOptionName() { - return optionName; - } - - public boolean equalsOptionName(final String otherName) { - return (otherName == null) ? false : optionName.equals(otherName); - } - - public static Options fromName(final String name) { - Options optionToReturn = HELP; - for (final Options option : Options.values()) { - if (option.equalsOptionName(name)) { - optionToReturn = option; - } - } - return optionToReturn; - } - - public static List<String> toList() { - final List<String> options = new ArrayList<>(); - for (final Options value : values()) { - options.add(value.getOptionName()); - } - return options; - } - } -} http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java index 28ae8c5..3d1866b 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java @@ -45,7 +45,7 @@ public class NotificationCommand extends AbstractCommand { + " Syntax: --read {NOTIFICATION-ID} \n" + " --delete \n" + " Syntax: --delete {NOTIFICATION-ID}"; - + @Override public void execute(final Input input) { LOG.debug("Option: {}", input.getOption()); http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java index 689b304..fc3a8c0 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java @@ -49,7 +49,7 @@ public class PolicyCommand extends AbstractCommand { + " Syntax: --read {POLICY-ID} {POLICY-ID} [...]\n" + " --delete \n" + " Syntax: --delete {POLICY-ID} {POLICY-ID} [...]"; - + @Override public void execute(final Input input) { LOG.debug("Option: {}", input.getOption()); http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java index 40ecd54..30be7fb 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java @@ -66,7 +66,7 @@ public class ReportCommand extends AbstractCommand { + " Syntax: --export-execution-result {EXECUTION-ID} {EXECUTION-ID} [...] {FORMAT}\n" + " Format: CSV / HTML / PDF / XML / RTF" + " --reportlet-class"; - + @Override public void execute(final Input input) { LOG.debug("Option: {}", input.getOption()); http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java index 6838d0a..e00ae3f 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java @@ -56,7 +56,6 @@ public class SchemaCommand extends AbstractCommand { + " Schema type: PLAIN / DERIVED / VIRTUAL"; @Override - public void execute(final Input input) { LOG.debug("Option: {}", input.getOption()); LOG.debug("Parameters:"); http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/TaskCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/TaskCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/TaskCommand.java index 3b50b15..deb00bf 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/TaskCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/TaskCommand.java @@ -69,7 +69,7 @@ public class TaskCommand extends AbstractCommand { + " --execute \n" + " Syntax: --execute {TASK-ID} {DRY-RUN}" + " Dry run: true / false"; - + @Override public void execute(final Input input) { LOG.debug("Option: {}", input.getOption()); http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationCommand.java index d74ea78..00fe6fa 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationCommand.java @@ -24,14 +24,10 @@ import org.apache.commons.lang3.StringUtils; import org.apache.syncope.client.cli.Command; import org.apache.syncope.client.cli.Input; import org.apache.syncope.client.cli.commands.AbstractCommand; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @Command(name = "configuration") public class ConfigurationCommand extends AbstractCommand { - private static final Logger LOG = LoggerFactory.getLogger(ConfigurationCommand.class); - private static final String HELP_MESSAGE = "Usage: configuration [options]\n" + " Options:\n" + " --help \n" http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationDelete.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationDelete.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationDelete.java index 4f8c227..f308aa9 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationDelete.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationDelete.java @@ -42,9 +42,9 @@ public class ConfigurationDelete extends AbstractConfigurationCommand { if (ex.getMessage().startsWith("NotFound")) { configurationResultManager.notFoundError("Configuration", parameter); } else if (ex.getMessage().startsWith("DataIntegrityViolation")) { - configurationResultManager.genericError("You cannot delete configuration", parameter); + configurationResultManager.generic("You cannot delete configuration", parameter); } else { - configurationResultManager.genericError(ex.getMessage()); + configurationResultManager.generic(ex.getMessage()); } break; } http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationExport.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationExport.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationExport.java index 0bc274f..2e61c4f 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationExport.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationExport.java @@ -47,22 +47,22 @@ public class ConfigurationExport extends AbstractConfigurationCommand { XMLUtils.createXMLFile( (SequenceInputStream) configurationService.export().getEntity(), input.firstParameter() + EXPORT_FILE_NAME); - configurationResultManager.genericError( + configurationResultManager.generic( input.firstParameter() + EXPORT_FILE_NAME + " successfully created"); } catch (final IOException ex) { - configurationResultManager.genericError(ex.getMessage()); + configurationResultManager.generic(ex.getMessage()); } catch (ParserConfigurationException | SAXException | TransformerConfigurationException ex) { - configurationResultManager.genericError( + configurationResultManager.generic( "Error creating " + input.firstParameter() + EXPORT_FILE_NAME + " " + ex.getMessage()); } catch (final TransformerException ex) { if (ex.getCause() instanceof FileNotFoundException) { - configurationResultManager.genericError("Permission denied on " + input.firstParameter()); + configurationResultManager.generic("Permission denied on " + input.firstParameter()); } else { - configurationResultManager.genericError( + configurationResultManager.generic( "Error creating " + input.firstParameter() + EXPORT_FILE_NAME + " " + ex.getMessage()); } } catch (final SyncopeClientException ex) { - configurationResultManager.genericError("Error calling configuration service " + ex.getMessage()); + configurationResultManager.generic("Error calling configuration service " + ex.getMessage()); } } else { configurationResultManager.commandOptionError(EXPORT_HELP_MESSAGE); http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationGet.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationGet.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationGet.java index 472e40f..2aa3ff4 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationGet.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationGet.java @@ -29,7 +29,7 @@ public class ConfigurationGet extends AbstractConfigurationCommand { try { configurationResultManager.fromGet(new LinkedList<>(configurationService.list())); } catch (final Exception ex) { - configurationResultManager.genericError(ex.getMessage()); + configurationResultManager.generic(ex.getMessage()); } } http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationRead.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationRead.java index 801f01d..c4294e7 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationRead.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationRead.java @@ -45,7 +45,7 @@ public class ConfigurationRead extends AbstractConfigurationCommand { if (ex.getMessage().startsWith("NotFound")) { configurationResultManager.notFoundError("Configuration", parameter); } else { - configurationResultManager.genericError(ex.getMessage()); + configurationResultManager.generic(ex.getMessage()); } failed = true; break; http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationUpdate.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationUpdate.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationUpdate.java index 9be74e2..295ebd1 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationUpdate.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationUpdate.java @@ -50,17 +50,17 @@ public class ConfigurationUpdate extends AbstractConfigurationCommand { configurationService.set(attrTO); attrList.add(attrTO); } catch (final IllegalArgumentException ex) { - configurationResultManager.genericError(ex.getMessage(), UPDATE_HELP_MESSAGE); + configurationResultManager.generic(ex.getMessage(), UPDATE_HELP_MESSAGE); failed = true; break; } catch (final SyncopeClientException | WebServiceException ex) { if (ex.getMessage().startsWith("NotFound")) { configurationResultManager.notFoundError("Configuration", pairParameter.getKey()); } else if (ex.getMessage().startsWith("InvalidValues")) { - configurationResultManager.genericError( + configurationResultManager.generic( pairParameter.getValue() + " is not a valid value for " + pairParameter.getKey()); } else { - configurationResultManager.genericError(ex.getMessage()); + configurationResultManager.generic(ex.getMessage()); } failed = true; break; http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/AbstractDomainCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/AbstractDomainCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/AbstractDomainCommand.java new file mode 100644 index 0000000..8650ef7 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/AbstractDomainCommand.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands.domain; + +import org.apache.syncope.client.cli.SyncopeServices; +import org.apache.syncope.common.rest.api.service.DomainService; + +public class AbstractDomainCommand { + + protected final DomainService domainService = SyncopeServices.get(DomainService.class); + + protected final DomainResultManager domainResultManager = new DomainResultManager(); + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainCommand.java new file mode 100644 index 0000000..e709b81 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainCommand.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands.domain; + +import java.util.ArrayList; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.cli.Command; +import org.apache.syncope.client.cli.Input; +import org.apache.syncope.client.cli.commands.AbstractCommand; + +@Command(name = "domain") +public class DomainCommand extends AbstractCommand { + + private static final String HELP_MESSAGE = "Usage: domain [options]\n" + + " Options:\n" + + " --help \n" + + " --list \n" + + " --delete \n" + + " Syntax: --delete {DOMAIN-KEY} {DOMAIN-KEY} [...]\n"; + + @Override + public void execute(final Input input) { + if (StringUtils.isBlank(input.getOption())) { + input.setOption(Options.HELP.getOptionName()); + } + switch (Options.fromName(input.getOption())) { + case LIST: + new DomainList().list(); + break; + case DELETE: + new DomainDelete(input).delete(); + break; + case HELP: + System.out.println(HELP_MESSAGE); + break; + default: + new DomainResultManager().deletedMessage(input.getOption(), HELP_MESSAGE); + } + } + + @Override + public String getHelpMessage() { + return HELP_MESSAGE; + } + + private enum Options { + + HELP("--help"), + LIST("--list"), + DELETE("--delete"); + + private final String optionName; + + Options(final String optionName) { + this.optionName = optionName; + } + + public String getOptionName() { + return optionName; + } + + public boolean equalsOptionName(final String otherName) { + return (otherName == null) ? false : optionName.equals(otherName); + } + + public static Options fromName(final String name) { + Options optionToReturn = HELP; + for (final Options option : Options.values()) { + if (option.equalsOptionName(name)) { + optionToReturn = option; + } + } + return optionToReturn; + } + + public static List<String> toList() { + final List<String> options = new ArrayList<>(); + for (final Options value : values()) { + options.add(value.getOptionName()); + } + return options; + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainDelete.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainDelete.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainDelete.java new file mode 100644 index 0000000..1b0c235 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainDelete.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands.domain; + +import org.apache.syncope.client.cli.Input; +import org.apache.syncope.common.lib.SyncopeClientException; + +public class DomainDelete extends AbstractDomainCommand { + + private static final String DELETE_HELP_MESSAGE = "domain --delete {DOMAIN-KEY} {DOMAIN-KEY} [...]"; + + private final Input input; + + public DomainDelete(final Input input) { + this.input = input; + } + + public void delete() { + if (input.parameterNumber() >= 1) { + for (final String parameter : input.getParameters()) { + try { + domainService.delete(parameter); + domainResultManager.deletedMessage("Domain", parameter); + } catch (final SyncopeClientException ex) { + if (ex.getMessage().startsWith("NotFound")) { + domainResultManager.notFoundError("Domain", parameter); + } else { + domainResultManager.generic(ex.getMessage()); + } + } + } + } else { + domainResultManager.commandOptionError(DELETE_HELP_MESSAGE); + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainList.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainList.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainList.java new file mode 100644 index 0000000..94329d2 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainList.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands.domain; + +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.DomainTO; + +public class DomainList extends AbstractDomainCommand { + + public DomainList() { + } + + public void list() { + try { + for (final DomainTO domainTO : domainService.list()) { + domainResultManager.generic(domainTO.getKey()); + } + } catch (final SyncopeClientException ex) { + domainResultManager.generic("Error: " + ex.getMessage()); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainRead.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainRead.java new file mode 100644 index 0000000..a76711d --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainRead.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands.domain; + +import org.apache.syncope.client.cli.Input; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.DomainTO; + +public class DomainRead extends AbstractDomainCommand { + + private static final String READ_HELP_MESSAGE = "domain --read {DOMAIN-KEY} {DOMAIN-KEY} [...]"; + + private final Input input; + + public DomainRead(final Input input) { + this.input = input; + } + + public void read() { + if (input.parameterNumber() >= 1) { + for (final String parameter : input.getParameters()) { + try { + final DomainTO domainTO = domainService.read(parameter); + domainResultManager.generic(domainTO.getKey()); + } catch (final SyncopeClientException ex) { + if (ex.getMessage().startsWith("NotFound")) { + domainResultManager.notFoundError("Domain", parameter); + } else { + domainResultManager.generic(ex.getMessage()); + } + } + } + } else { + domainResultManager.commandOptionError(READ_HELP_MESSAGE); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainResultManager.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainResultManager.java new file mode 100644 index 0000000..6066c5d --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/domain/DomainResultManager.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands.domain; + +import org.apache.syncope.client.cli.commands.CommonsResultManager; + +public class DomainResultManager extends CommonsResultManager { + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java index 0caba9f..7ebd554 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallCommand.java @@ -22,15 +22,10 @@ import org.apache.commons.lang3.StringUtils; import org.apache.syncope.client.cli.Command; import org.apache.syncope.client.cli.Input; import org.apache.syncope.client.cli.commands.AbstractCommand; -import org.apache.syncope.client.cli.commands.logger.LoggerCommand; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; @Command(name = "install") public class InstallCommand extends AbstractCommand { - private static final Logger LOG = LoggerFactory.getLogger(LoggerCommand.class); - private static final String HELP_MESSAGE = "Usage: install [options]\n" + " Options:\n" + " --help \n" http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallSetup.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallSetup.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallSetup.java index 1486b48..10995b0 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallSetup.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/install/InstallSetup.java @@ -44,6 +44,9 @@ public class InstallSetup { private String syncopeServerRestContext = "/syncope/rest/"; + public InstallSetup() { + } + public void setup() { final Scanner scanIn = new Scanner(System.in); http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerDelete.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerDelete.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerDelete.java index 6614f07..5815b71 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerDelete.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerDelete.java @@ -43,7 +43,7 @@ public class LoggerDelete extends AbstractLoggerCommand { if (ex.getMessage().startsWith("NotFound")) { loggerResultManager.notFoundError("Logger", parameter); } else { - loggerResultManager.genericError(ex.getMessage()); + loggerResultManager.generic(ex.getMessage()); } } } http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerList.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerList.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerList.java index f65da34..d9d4f81 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerList.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerList.java @@ -31,7 +31,7 @@ public class LoggerList extends AbstractLoggerCommand { try { loggerResultManager.fromList(new LinkedList<>(loggerService.list(LoggerType.LOG))); } catch (final SyncopeClientException ex) { - loggerResultManager.genericError("Error: " + ex.getMessage()); + loggerResultManager.generic("Error: " + ex.getMessage()); } } } http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerRead.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerRead.java index c796c47..6e2447d 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerRead.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerRead.java @@ -46,7 +46,7 @@ public class LoggerRead extends AbstractLoggerCommand { if (ex.getMessage().startsWith("NotFound")) { loggerResultManager.notFoundError("Logger", parameter); } else { - loggerResultManager.genericError("Error: " + ex.getMessage()); + loggerResultManager.generic("Error: " + ex.getMessage()); } failed = true; break; http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdate.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdate.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdate.java index cbfc196..7279b96 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdate.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdate.java @@ -54,11 +54,11 @@ public class LoggerUpdate extends AbstractLoggerCommand { if (ex.getMessage().startsWith("No enum constant org.apache.syncope.common.lib.types.")) { loggerResultManager.typeNotValidError(input.firstParameter()); } else if ("Parameter syntax error!".equalsIgnoreCase(ex.getMessage())) { - loggerResultManager.genericError(ex.getMessage(), UPDATE_HELP_MESSAGE); + loggerResultManager.generic(ex.getMessage(), UPDATE_HELP_MESSAGE); } else if (ex.getMessage().startsWith("NotFound")) { loggerResultManager.notFoundError("Logger", parameter); } else { - loggerResultManager.genericError(ex.getMessage(), UPDATE_HELP_MESSAGE); + loggerResultManager.generic(ex.getMessage(), UPDATE_HELP_MESSAGE); } failed = true; break; http://git-wip-us.apache.org/repos/asf/syncope/blob/dfc1df48/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdateAll.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdateAll.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdateAll.java index 305fa30..f1c25c2 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdateAll.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdateAll.java @@ -49,7 +49,7 @@ public class LoggerUpdateAll extends AbstractLoggerCommand { if (ex.getMessage().startsWith("No enum constant org.apache.syncope.common.lib.types.")) { loggerResultManager.typeNotValidError(input.firstParameter()); } else { - loggerResultManager.genericError(ex.getMessage(), UPDATE_ALL_HELP_MESSAGE); + loggerResultManager.generic(ex.getMessage(), UPDATE_ALL_HELP_MESSAGE); } failed = true; break;
