Upgrading surefire, failsafe and checkstyle plugins
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/4e0783e1 Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/4e0783e1 Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/4e0783e1 Branch: refs/heads/master Commit: 4e0783e1c331a763313b3cd4b82de8fc8b791e97 Parents: 1c459bf 503097d Author: Francesco Chicchiriccò <[email protected]> Authored: Mon Oct 19 16:36:06 2015 +0200 Committer: Francesco Chicchiriccò <[email protected]> Committed: Mon Oct 19 16:36:06 2015 +0200 ---------------------------------------------------------------------- .../syncope/client/cli/commands/ConfigurationCommand.java | 2 +- .../apache/syncope/client/cli/commands/DomainCommand.java | 2 +- .../org/apache/syncope/client/cli/commands/HelpCommand.java | 2 +- .../org/apache/syncope/client/cli/commands/InfoCommand.java | 2 +- .../apache/syncope/client/cli/commands/LoggerCommand.java | 2 +- .../syncope/client/cli/commands/NotificationCommand.java | 2 +- .../apache/syncope/client/cli/commands/PolicyCommand.java | 2 +- .../apache/syncope/client/cli/commands/ReportCommand.java | 2 +- .../apache/syncope/client/cli/commands/SchemaCommand.java | 2 +- .../org/apache/syncope/client/cli/commands/TaskCommand.java | 2 +- .../syncope/client/cli/commands/install/InstallCommand.java | 2 +- .../console/commons/SortableAnyProviderComparator.java | 2 +- .../apache/syncope/client/console/commons/status/Status.java | 2 +- .../java/org/apache/syncope/client/console/pages/Login.java | 4 ++-- .../syncope/client/console/pages/ProvisioningModalPage.java | 2 +- .../apache/syncope/client/console/pages/StatusModalPage.java | 2 +- .../syncope/client/console/panels/ResourceSecurityPanel.java | 2 +- .../org/apache/syncope/client/console/topology/Topology.java | 2 +- .../syncope/client/console/topology/WebSocketBehavior.java | 4 ++-- .../client/console/wicket/markup/html/form/ActionLink.java | 2 +- .../console/wizards/provision/ProvisionWizardBuilder.java | 6 +++--- .../apache/syncope/client/lib/SyncopeClientFactoryBean.java | 2 +- .../org/apache/syncope/common/lib/types/AnyTypeKind.java | 2 +- .../apache/syncope/common/lib/types/ClientExceptionType.java | 2 +- .../org/apache/syncope/common/lib/types/IntMappingType.java | 2 +- .../java/org/apache/syncope/common/lib/types/TaskType.java | 2 +- .../java/org/apache/syncope/common/rest/api/Preference.java | 2 +- .../java/org/apache/syncope/core/logic/AbstractAnyLogic.java | 2 +- .../org/apache/syncope/core/logic/init/LoggerLoader.java | 2 +- .../syncope/core/misc/jexl/ClassFreeUberspectImpl.java | 2 +- .../syncope/core/persistence/api/ImplementationLookup.java | 2 +- .../core/persistence/jpa/content/ContentLoaderHandler.java | 2 +- .../core/persistence/jpa/content/MultiParentNode.java | 2 +- .../syncope/core/persistence/jpa/dao/SearchSupport.java | 2 +- .../syncope/client/console/panels/CamelRoutePanel.java | 2 +- .../java/org/apache/syncope/installer/enums/Containers.java | 2 +- .../main/java/org/apache/syncope/installer/enums/DBs.java | 2 +- pom.xml | 8 ++++---- 38 files changed, 45 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/4e0783e1/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java ---------------------------------------------------------------------- diff --cc client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java index ee225d7,0000000..8a6c7b5 mode 100644,000000..100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java @@@ -1,319 -1,0 +1,319 @@@ +/* + * 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 java.io.FileNotFoundException; +import java.io.IOException; +import java.io.SequenceInputStream; +import java.util.ArrayList; +import java.util.List; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.ws.WebServiceException; +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.client.cli.util.XMLUtils; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AttrTO; +import org.apache.syncope.common.lib.to.ConfTO; +import org.apache.syncope.common.rest.api.service.ConfigurationService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.SAXException; + +@Command(name = "configuration") +public class ConfigurationCommand extends AbstractCommand { + + private static final Logger LOG = LoggerFactory.getLogger(ConfigurationCommand.class); + + private static final String EXPORT_FILE_NAME = "/content.xml"; + + private static final String HELP_MESSAGE = "Usage: configuration [options]\n" + + " Options:\n" + + " --help \n" + + " --list \n" + + " --read \n" + + " Syntax: --read {CONF-NAME} {CONF-NAME} [...] \n" + + " --update \n" + + " Syntax: --update {CONF-NAME}={CONF-VALUE} {CONF-NAME}={CONF-VALUE} [...]\n" + + " --create \n" + + " Syntax: --create {CONF-NAME}={CONF-VALUE} {CONF-NAME}={CONF-VALUE} [...]\n" + + " --delete \n" + + " Syntax: --delete {CONF-NAME} {CONF-NAME} [...]\n" + + " --export \n" + + " Syntax: --export {WHERE-DIR}"; + + @Override + public void execute(final Input input) { + LOG.debug("Logger service successfully created"); + 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 ConfigurationService configurationService = SyncopeServices.get(ConfigurationService.class); + switch (Options.fromName(input.getOption())) { + case LIST: + try { + final ConfTO confTO = configurationService.list(); + System.out.println("\n - Configuration key: " + confTO.getKey()); + System.out.println(""); + System.out.println("Plain attributes"); + for (final AttrTO attrTO : confTO.getPlainAttrMap().values()) { + System.out.println(" - Conf key: " + attrTO.getSchema()); + System.out.println(" - value(s): " + attrTO.getValues()); + System.out.println(" - readonly: " + attrTO.isReadonly()); + } + System.out.println(""); + System.out.println("Derived attributes"); + for (final AttrTO attrTO : confTO.getDerAttrMap().values()) { + System.out.println(" - Conf key: " + attrTO.getSchema()); + System.out.println(" - value(s): " + attrTO.getValues()); + System.out.println(" - readonly: " + attrTO.isReadonly()); + } + System.out.println(""); + System.out.println("Virtual attributes"); + for (final AttrTO attrTO : confTO.getVirAttrMap().values()) { + System.out.println(" - Conf key: " + attrTO.getSchema()); + System.out.println(" - value(s): " + attrTO.getValues()); + System.out.println(" - readonly: " + attrTO.isReadonly()); + } + System.out.println(""); + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case READ: + final String readErrorMessage = "configuration --read {CONF-NAME} {CONF-NAME} [...]"; + if (parameters.length >= 1) { + AttrTO attrTO; + for (final String parameter : parameters) { + try { + attrTO = configurationService.get(parameter); + System.out.println("\n - Conf key: " + attrTO.getSchema()); + System.out.println(" - value(s): " + attrTO.getValues()); + System.out.println(" - readonly: " + attrTO.isReadonly()); + System.out.println(""); + } catch (final SyncopeClientException | WebServiceException ex) { + if (ex.getMessage().startsWith("NotFound")) { + Messages.printNofFoundMessage("Logger", parameter); + } else { + Messages.printMessage(ex.getMessage()); + } + break; + } + } + } else { + Messages.printCommandOptionMessage(readErrorMessage); + } + break; + case UPDATE: + final String updateErrorMessage + = "configuration --update {CONF-NAME}={CONF-VALUE} {CONF-NAME}={CONF-VALUE} [...]"; + if (parameters.length >= 1) { + Input.PairParameter pairParameter = null; + AttrTO attrTO; + for (final String parameter : parameters) { + try { + pairParameter = input.toPairParameter(parameter); + attrTO = configurationService.get(pairParameter.getKey()); + attrTO.getValues().clear(); + attrTO.getValues().add(pairParameter.getValue()); + configurationService.set(attrTO); + System.out.println("\n - Conf key " + attrTO.getSchema() + " updated. New value is:"); + System.out.println(" - value(s): " + attrTO.getValues()); + System.out.println(" - readonly: " + attrTO.isReadonly()); + System.out.println(""); + } catch (final IllegalArgumentException ex) { + Messages.printMessage(ex.getMessage(), updateErrorMessage); + break; + } catch (final SyncopeClientException | WebServiceException ex) { + if (ex.getMessage().startsWith("NotFound")) { + Messages.printNofFoundMessage("Configuration", pairParameter.getKey()); + } else if (ex.getMessage().startsWith("InvalidValues")) { + Messages.printMessage( + pairParameter.getValue() + " is not a valid value for " + + pairParameter.getKey()); + } else { + Messages.printMessage(ex.getMessage()); + } + break; + } + } + } else { + Messages.printCommandOptionMessage(updateErrorMessage); + } + break; + case CREATE: + final String createErrorMessage + = "configuration --create {CONF-NAME}={CONF-VALUE} {CONF-NAME}={CONF-VALUE} [...]"; + if (parameters.length >= 1) { + Input.PairParameter pairParameter = null; + AttrTO attrTO; + for (final String parameter : parameters) { + try { + pairParameter = input.toPairParameter(parameter); + attrTO = new AttrTO(); + attrTO.setSchema(pairParameter.getKey()); + attrTO.getValues().add(pairParameter.getValue()); + configurationService.set(attrTO); + System.out.println("\n - Conf key " + attrTO.getSchema() + " created. Value is:"); + System.out.println(" - value(s): " + attrTO.getValues()); + System.out.println(" - readonly: " + attrTO.isReadonly()); + System.out.println(""); + } catch (final IllegalArgumentException ex) { + Messages.printMessage(ex.getMessage(), createErrorMessage); + break; + } catch (final SyncopeClientException | WebServiceException ex) { + if (ex.getMessage().startsWith("NotFound")) { + Messages.printNofFoundMessage("Configuration", pairParameter.getKey()); + System.out.println("Create it before."); + } else { + Messages.printMessage(ex.getMessage()); + } + break; + } + } + } else { + Messages.printCommandOptionMessage(createErrorMessage); + } + break; + case DELETE: + final String deleteErrorMessage = "configuration --delete {CONF-NAME} {CONF-NAME} [...]"; + if (parameters.length >= 1) { + for (final String parameter : parameters) { + try { + configurationService.delete(parameter); + Messages.printDeletedMessage("Configuration", parameter); + } catch (final SyncopeClientException | WebServiceException ex) { + if (ex.getMessage().startsWith("NotFound")) { + Messages.printNofFoundMessage("Configuration", parameter); + } else if (ex.getMessage().startsWith("DataIntegrityViolation")) { + Messages.printMessage("You cannot delete configuration", parameter); + } else { + Messages.printMessage(ex.getMessage()); + } + break; + } + } + } else { + Messages.printCommandOptionMessage(deleteErrorMessage); + } + break; + case EXPORT: + final String exportErrorMessage = "configuration --export {WHERE-DIR}"; + if (parameters.length == 1) { + try { + XMLUtils.createXMLFile((SequenceInputStream) configurationService.export().getEntity(), + parameters[0] + EXPORT_FILE_NAME); + System.out.println(" - " + parameters[0] + EXPORT_FILE_NAME + " successfully created"); + } catch (final IOException ex) { + Messages.printMessage(ex.getMessage()); + } catch (ParserConfigurationException | SAXException | TransformerConfigurationException ex) { + LOG.error("Error creating content.xml file in {} directory", parameters[0], ex); + Messages.printMessage( + "Error creating " + parameters[0] + EXPORT_FILE_NAME + " " + ex.getMessage()); + break; + } catch (final TransformerException ex) { + LOG.error("Error creating content.xml file in {} directory", parameters[0], ex); + if (ex.getCause() instanceof FileNotFoundException) { + Messages.printMessage("Permission denied on " + parameters[0]); + } else { + Messages.printMessage( + "Error creating " + parameters[0] + EXPORT_FILE_NAME + " " + ex.getMessage()); + } + break; + } catch (final SyncopeClientException ex) { + LOG.error("Error calling configuration service", ex); + Messages.printMessage("Error calling configuration service " + ex.getMessage()); + break; + } + } else { + Messages.printCommandOptionMessage(exportErrorMessage); + } + break; + case HELP: + System.out.println(HELP_MESSAGE); + break; + default: + Messages.printDefaultMessage(input.getOption(), HELP_MESSAGE); + break; + } + } + + @Override + public String getHelpMessage() { + return HELP_MESSAGE; + } + + private enum Options { + + HELP("--help"), + LIST("--list"), + READ("--read"), + UPDATE("--update"), + CREATE("--create"), + DELETE("--delete"), + EXPORT("--export"); + + private final String optionName; + - private Options(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/4e0783e1/client/cli/src/main/java/org/apache/syncope/client/cli/commands/DomainCommand.java ---------------------------------------------------------------------- diff --cc client/cli/src/main/java/org/apache/syncope/client/cli/commands/DomainCommand.java index a2a0977,0000000..3060ee1 mode 100644,000000..100644 --- 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 @@@ -1,164 -1,0 +1,164 @@@ +/* + * 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 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; + - private Options(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/4e0783e1/client/cli/src/main/java/org/apache/syncope/client/cli/commands/HelpCommand.java ---------------------------------------------------------------------- diff --cc client/cli/src/main/java/org/apache/syncope/client/cli/commands/HelpCommand.java index 85b7d73,0000000..027491a mode 100644,000000..100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/HelpCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/HelpCommand.java @@@ -1,113 -1,0 +1,113 @@@ +/* + * 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 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.messages.Messages; +import org.apache.syncope.client.cli.util.CommandUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Command(name = "help") +public class HelpCommand extends AbstractCommand { + + private static final Logger LOG = LoggerFactory.getLogger(HelpCommand.class); + + @Override + public void execute(final Input input) { + LOG.debug("Option: {}", input.getOption()); + LOG.debug("Parameters:"); + for (final String parameter : input.getParameters()) { + LOG.debug(" > " + parameter); + } + + if (StringUtils.isBlank(input.getOption())) { + input.setOption(Options.HELP.getOptionName()); + } + + switch (Options.fromName(input.getOption())) { + case HELP: + final StringBuilder generalHelpBuilder = new StringBuilder("General help\n"); + try { + for (final AbstractCommand command : CommandUtils.commands()) { + generalHelpBuilder.append("Command: ") + .append(command.getClass().getAnnotation(Command.class).name()) + .append("\n") + .append(command.getHelpMessage()) + .append("\n") + .append(" \n"); + } + System.out.println(generalHelpBuilder.toString()); + } catch (final IllegalAccessException | IllegalArgumentException | InstantiationException e) { + Messages.printMessage(e.getMessage()); + } + break; + default: + Messages.printDefaultMessage(input.getOption(), helpMessage("info", Options.toList())); + break; + } + } + + @Override + public String getHelpMessage() { + return helpMessage("help", Options.toList()); + } + + private enum Options { + + HELP("--print"); + + private final String optionName; + - private Options(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/4e0783e1/client/cli/src/main/java/org/apache/syncope/client/cli/commands/InfoCommand.java ---------------------------------------------------------------------- diff --cc client/cli/src/main/java/org/apache/syncope/client/cli/commands/InfoCommand.java index 07bb952,0000000..2ab4c29 mode 100644,000000..100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/InfoCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/InfoCommand.java @@@ -1,338 -1,0 +1,338 @@@ +/* + * 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 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.to.SyncopeTO; +import org.apache.syncope.common.rest.api.service.SyncopeService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Command(name = "info") +public class InfoCommand extends AbstractCommand { + + private static final Logger LOG = LoggerFactory.getLogger(InfoCommand.class); + + @Override + public void execute(final Input input) { + LOG.debug("Option: {}", input.getOption()); + LOG.debug("Parameters:"); + for (final String parameter : input.getParameters()) { + LOG.debug(" > " + parameter); + } + + if (StringUtils.isBlank(input.getOption())) { + input.setOption(Options.HELP.getOptionName()); + } + + final SyncopeService syncopeService = SyncopeServices.get(SyncopeService.class); + final SyncopeTO syncopeTO = syncopeService.info(); + switch (Options.fromName(input.getOption())) { + case VERSION: + try { + Messages.printMessage("Syncope version: " + syncopeTO.getVersion()); + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case PWD_RESET_ALLOWED: + try { + Messages.printMessage("Password reset allowed: " + syncopeTO.isPwdResetAllowed()); + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case PWD_RESET_WITH_SECURITY_QUESTION: + try { + Messages.printMessage("Password reset requiring security question: " + + syncopeTO.isPwdResetRequiringSecurityQuestions()); + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case SELF_REG_ALLOWED: + try { + Messages.printMessage("Self registration allowed: " + syncopeTO.isSelfRegAllowed()); + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case PROVISIONING_MANAGER: + try { + Messages.printMessage( + "Any object provisioning manager class: " + syncopeTO.getAnyObjectProvisioningManager(), + "User provisioning manager class: " + syncopeTO.getUserProvisioningManager(), + "Group provisioning manager class: " + syncopeTO.getGroupProvisioningManager()); + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case WORKFLOW_ADAPTER: + try { + Messages.printMessage( + "Any object workflow adapter class: " + syncopeTO.getAnyObjectWorkflowAdapter(), + "User workflow adapter class: " + syncopeTO.getUserWorkflowAdapter(), + "Group workflow adapter class: " + syncopeTO.getGroupWorkflowAdapter()); + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case ACCOUNT_RULES: + try { + for (final String accountRule : syncopeTO.getAccountRules()) { + Messages.printMessage("Account rule: " + accountRule); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case CONNID_LOCATION: + try { + for (final String location : syncopeTO.getConnIdLocations()) { + Messages.printMessage("ConnId location: " + location); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case LOGIC_ACTIONS: + try { + for (final String logic : syncopeTO.getLogicActions()) { + Messages.printMessage("Logic action: " + logic); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case MAIL_TEMPLATES: + try { + for (final String template : syncopeTO.getMailTemplates()) { + Messages.printMessage("Mail template: " + template); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case MAPPING_ITEM_TRANSFORMERS: + try { + for (final String tranformer : syncopeTO.getMappingItemTransformers()) { + Messages.printMessage("Mapping item tranformer: " + tranformer); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case PASSWORD_RULES: + try { + for (final String rules : syncopeTO.getPasswordRules()) { + Messages.printMessage("Password rule: " + rules); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case PROPAGATION_ACTIONS: + try { + for (final String action : syncopeTO.getPropagationActions()) { + Messages.printMessage("Propagation action: " + action); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case PUSH_ACTIONS: + try { + for (final String action : syncopeTO.getPushActions()) { + Messages.printMessage("Push action: " + action); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case PUSH_CORRELATION_ACTIONS: + try { + for (final String rule : syncopeTO.getPushCorrelationRules()) { + Messages.printMessage("Push correlation rule: " + rule); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case REPORTLETS: + try { + for (final String reportlet : syncopeTO.getReportlets()) { + Messages.printMessage("Reportlet: " + reportlet); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case SYNC_ACTIONS: + try { + for (final String action : syncopeTO.getSyncActions()) { + Messages.printMessage("Sync action: " + action); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case SYNC_CORRELATION_RULES: + try { + for (final String rule : syncopeTO.getSyncCorrelationRules()) { + Messages.printMessage("Sync correlation rule: " + rule); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case TASK_JOBS: + try { + for (final String job : syncopeTO.getTaskJobs()) { + Messages.printMessage("Task job: " + job); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case VALIDATORS: + try { + for (final String validator : syncopeTO.getValidators()) { + Messages.printMessage("Validator: " + validator); + } + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case PASSWORD_GENERATOR: + try { + Messages.printMessage( + "Password generator class: " + syncopeTO.getPasswordGenerator()); + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case VIR_ATTR_CACHE: + try { + Messages.printMessage( + "Virtual attribute cache class: " + syncopeTO.getVirAttrCache()); + } catch (final Exception ex) { + Messages.printMessage(ex.getMessage()); + break; + } + break; + case HELP: + System.out.println(helpMessage("info", Options.toList())); + break; + default: + Messages.printDefaultMessage(input.getOption(), helpMessage("info", Options.toList())); + break; + } + } + + @Override + public String getHelpMessage() { + return helpMessage("info", Options.toList()); + } + + private enum Options { + + VERSION("--version"), + PWD_RESET_ALLOWED("--pwd-reset-allowed"), + PWD_RESET_WITH_SECURITY_QUESTION("--pwd-reset-with-question"), + SELF_REG_ALLOWED("--self-reg-allowed"), + PROVISIONING_MANAGER("--provisioning-manager-classes"), + WORKFLOW_ADAPTER("--workflow-adapter-classes"), + ACCOUNT_RULES("--account-rules-classes"), + CONNID_LOCATION("--connid-locations"), + LOGIC_ACTIONS("--logic-actions"), + MAIL_TEMPLATES("--mail-templates"), + MAPPING_ITEM_TRANSFORMERS("--mapping-item-transformers"), + PASSWORD_RULES("--password-rules"), + PROPAGATION_ACTIONS("--propagation-actions"), + PUSH_ACTIONS("--push-actions"), + PUSH_CORRELATION_ACTIONS("--push-correlation-actions"), + REPORTLETS("--reportlets"), + SYNC_ACTIONS("--sync-actions"), + SYNC_CORRELATION_RULES("--sync-correlation-rules"), + TASK_JOBS("--task-jobs"), + VALIDATORS("--validators"), + PASSWORD_GENERATOR("--password-generator"), + VIR_ATTR_CACHE("--vir-attr-cache"), + HELP("--help"); + + private final String optionName; + - private Options(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/4e0783e1/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java ---------------------------------------------------------------------- diff --cc client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java index 6c11c6f,0000000..360c16b mode 100644,000000..100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java @@@ -1,267 -1,0 +1,267 @@@ +/* + * 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 java.util.ArrayList; +import java.util.List; +import javax.xml.ws.WebServiceException; +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.LoggerTO; +import org.apache.syncope.common.lib.types.LoggerLevel; +import org.apache.syncope.common.lib.types.LoggerType; +import org.apache.syncope.common.rest.api.service.LoggerService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Command(name = "logger") +public class LoggerCommand extends AbstractCommand { + + private static final Logger LOG = LoggerFactory.getLogger(LoggerCommand.class); + + private static final String HELP_MESSAGE = "Usage: logger [options]\n" + + " Options:\n" + + " --help \n" + + " --list \n" + + " --read \n" + + " Syntax: --read {LOG-NAME} {LOG-NAME} [...]\n" + + " --update \n" + + " Syntax: --update {LOG-NAME}={LOG-LEVEL} {LOG-NAME}={LOG-LEVEL} [...]\n" + + " --update-all \n" + + " Syntax: --update-all {LOG-LEVEL} \n" + + " --create \n" + + " Syntax: --create {LOG-NAME}={LOG-LEVEL} {LOG-NAME}={LOG-LEVEL} [...]\n" + + " --delete \n" + + " Syntax: --delete {LOG-NAME} {LOG-NAME} [...]"; + + @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 LoggerService loggerService = SyncopeServices.get(LoggerService.class); + switch (Options.fromName(input.getOption())) { + case LIST: + try { + for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) { + System.out.println(" - " + loggerTO.getKey() + " -> " + loggerTO.getLevel()); + System.out.println(""); + } + } catch (final SyncopeClientException ex) { + Messages.printMessage("Error: " + ex.getMessage()); + } + break; + case READ: + final String readErrorMessage = "logger --read {LOG-NAME} {LOG-NAME} [...]"; + if (parameters.length >= 1) { + for (final String parameter : parameters) { + try { + final LoggerTO loggerTO = loggerService.read(LoggerType.LOG, parameter); + System.out.println("\n - Logger"); + System.out.println(" - key: " + loggerTO.getKey()); + System.out.println(" - level: " + loggerTO.getLevel()); + System.out.println(""); + } catch (final SyncopeClientException | WebServiceException ex) { + if (ex.getMessage().startsWith("NotFound")) { + Messages.printNofFoundMessage("Logger", parameter); + } else { + Messages.printMessage("Error: " + ex.getMessage()); + } + } + } + } else { + Messages.printCommandOptionMessage(readErrorMessage); + } + break; + case UPDATE: + final String updateErrorMessage = "logger --update {LOG-NAME}={LOG-LEVEL} {LOG-NAME}={LOG-LEVEL} [...]"; + + if (parameters.length >= 1) { + Input.PairParameter pairParameter; + for (final String parameter : parameters) { + try { + pairParameter = input.toPairParameter(parameter); + final LoggerTO loggerTO = loggerService.read(LoggerType.LOG, pairParameter.getKey()); + loggerTO.setLevel(LoggerLevel.valueOf(pairParameter.getValue())); + loggerService.update(LoggerType.LOG, loggerTO); + System.out. + println("\n - Logger " + loggerTO.getKey() + " updated"); + System.out.println(" - new level: " + loggerTO.getLevel()); + System.out.println(""); + } catch (final WebServiceException | SyncopeClientException | IllegalArgumentException ex) { + if (ex.getMessage().startsWith("No enum constant org.apache.syncope.common.lib.types.")) { + Messages.printTypeNotValidMessage( + "logger level", input.firstParameter(), fromEnumToArray(LoggerLevel.class)); + } else if ("Parameter syntax error!".equalsIgnoreCase(ex.getMessage())) { + Messages.printMessage(ex.getMessage(), updateErrorMessage); + } else if (ex.getMessage().startsWith("NotFound")) { + Messages.printNofFoundMessage("Logger", parameter); + } else { + Messages.printMessage(ex.getMessage(), updateErrorMessage); + } + break; + } + } + } else { + Messages.printCommandOptionMessage(updateErrorMessage); + } + break; + case UPDATE_ALL: + final String updateAllErrorMessage = "logger --update-all {LOG-LEVEL}"; + + if (parameters.length == 1) { + for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) { + try { + loggerTO.setLevel(LoggerLevel.valueOf(parameters[0])); + loggerService.update(LoggerType.LOG, loggerTO); + System.out. + println("\n - Logger " + loggerTO.getKey() + " updated"); + System.out.println(" - new level: " + loggerTO.getLevel()); + System.out.println(""); + } catch (final WebServiceException | SyncopeClientException | IllegalArgumentException ex) { + if (ex.getMessage().startsWith("No enum constant org.apache.syncope.common.lib.types.")) { + Messages.printTypeNotValidMessage( + "logger level", input.firstParameter(), fromEnumToArray(LoggerLevel.class)); + } else { + Messages.printMessage(ex.getMessage(), updateAllErrorMessage); + } + break; + } + } + } else { + Messages.printCommandOptionMessage(updateAllErrorMessage); + } + break; + case CREATE: + final String createErrorMessage = "logger --create {LOG-NAME}={LOG-LEVEL} {LOG-NAME}={LOG-LEVEL} [...]"; + + if (parameters.length >= 1) { + Input.PairParameter pairParameter; + LoggerTO loggerTO; + for (final String parameter : parameters) { + loggerTO = new LoggerTO(); + try { + pairParameter = input.toPairParameter(parameter); + loggerTO.setKey(pairParameter.getKey()); + loggerTO.setLevel(LoggerLevel.valueOf(pairParameter.getValue())); + loggerService.update(LoggerType.LOG, loggerTO); + System.out. + println("\n - Logger " + loggerTO.getKey() + " updated"); + System.out.println(" - level: " + loggerTO.getLevel()); + System.out.println(""); + } catch (final WebServiceException | SyncopeClientException | IllegalArgumentException ex) { + Messages.printTypeNotValidMessage( + "logger level", input.firstParameter(), fromEnumToArray(LoggerLevel.class)); + break; + } + } + } else { + Messages.printCommandOptionMessage(createErrorMessage); + } + break; + case DELETE: + final String deleteErrorMessage = "logger --delete {LOG-NAME} {LOG-NAME} [...]"; + + if (parameters.length >= 1) { + for (final String parameter : parameters) { + try { + loggerService.delete(LoggerType.LOG, parameter); + Messages.printDeletedMessage("Logger", parameter); + } catch (final WebServiceException | SyncopeClientException ex) { + if (ex.getMessage().startsWith("NotFound")) { + Messages.printNofFoundMessage("Logger", 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"), + UPDATE("--update"), + UPDATE_ALL("--update-all"), + CREATE("--create"), + DELETE("--delete"); + + private final String optionName; + - private Options(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/4e0783e1/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java ---------------------------------------------------------------------- diff --cc client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java index 194ee11,0000000..28ae8c5 mode 100644,000000..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 @@@ -1,169 -1,0 +1,169 @@@ +/* + * 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 java.util.ArrayList; +import java.util.List; +import javax.xml.ws.WebServiceException; +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.NotificationTO; +import org.apache.syncope.common.rest.api.service.NotificationService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Command(name = "notification") +public class NotificationCommand extends AbstractCommand { + + private static final Logger LOG = LoggerFactory.getLogger(NotificationCommand.class); + + private static final String HELP_MESSAGE = "Usage: notification [options]\n" + + " Options:\n" + + " --help \n" + + " --list \n" + + " --read \n" + + " Syntax: --read {NOTIFICATION-ID} \n" + + " --delete \n" + + " Syntax: --delete {NOTIFICATION-ID}"; + + @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 NotificationService notificationService = SyncopeServices.get(NotificationService.class); + switch (Options.fromName(input.getOption())) { + case LIST: + try { + for (final NotificationTO notificationTO : notificationService.list()) { + System.out.println(notificationTO); + } + } catch (final SyncopeClientException ex) { + Messages.printMessage(ex.getMessage()); + } + break; + case READ: + final String readErrorMessage = "notification --read {NOTIFICATION-ID} {NOTIFICATION-ID} [...]"; + if (parameters.length >= 1) { + for (final String parameter : parameters) { + try { + System.out.println(notificationService.read(Long.valueOf(parameter))); + } catch (final NumberFormatException ex) { + Messages.printIdNotNumberDeletedMessage("notification", parameter); + } catch (final WebServiceException | SyncopeClientException ex) { + if (ex.getMessage().startsWith("NotFound")) { + Messages.printNofFoundMessage("Notification", parameter); + } else { + Messages.printMessage(ex.getMessage()); + } + } + } + } else { + Messages.printCommandOptionMessage(readErrorMessage); + } + break; + case DELETE: + final String deleteErrorMessage = "notification --delete {NOTIFICATION-ID} {NOTIFICATION-ID} [...]"; + + if (parameters.length >= 1) { + for (final String parameter : parameters) { + try { + notificationService.delete(Long.valueOf(parameter)); + Messages.printDeletedMessage("Notification", parameter); + } catch (final WebServiceException | SyncopeClientException ex) { + if (ex.getMessage().startsWith("NotFound")) { + Messages.printNofFoundMessage("Notification", parameter); + } else { + Messages.printMessage(ex.getMessage()); + } + } catch (final NumberFormatException ex) { + Messages.printIdNotNumberDeletedMessage("notification", parameter); + } + } + } 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; + - private Options(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/4e0783e1/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java ---------------------------------------------------------------------- diff --cc client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java index a69be18,0000000..a5017cf mode 100644,000000..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 @@@ -1,186 -1,0 +1,186 @@@ +/* + * 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 java.util.ArrayList; +import java.util.List; +import javax.xml.ws.WebServiceException; +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.policy.AbstractPolicyTO; +import org.apache.syncope.common.lib.types.PolicyType; +import org.apache.syncope.common.rest.api.service.PolicyService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Command(name = "policy") +public class PolicyCommand extends AbstractCommand { + + private static final Logger LOG = LoggerFactory.getLogger(PolicyCommand.class); + + private static final String HELP_MESSAGE = "Usage: policy [options]\n" + + " Options:\n" + + " --help \n" + + " --list-policy \n" + + " Syntax: --list-policy {POLICY-TYPE} \n" + + " Policy type: ACCOUNT / PASSWORD / SYNC / PUSH\n" + + " --read \n" + + " 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()); + 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 PolicyService policyService = SyncopeServices.get(PolicyService.class); + switch (Options.fromName(input.getOption())) { + case LIST_POLICY: + final String listPolicyErrorMessage = "policy --list-policy {POLICY-TYPE}\n" + + " Policy type: ACCOUNT / PASSWORD / SYNC / PUSH"; + + if (parameters.length == 1) { + try { + for (final AbstractPolicyTO policyTO : policyService.list(PolicyType.valueOf(parameters[0]))) { + System.out.println(policyTO); + } + } catch (final SyncopeClientException ex) { + Messages.printMessage(ex.getMessage()); + } catch (final IllegalArgumentException ex) { + Messages.printTypeNotValidMessage( + "policy", input.firstParameter(), fromEnumToArray(PolicyType.class)); + } + } else { + Messages.printCommandOptionMessage(listPolicyErrorMessage); + } + break; + case READ: + final String readErrorMessage = "policy --read {POLICY-ID} {POLICY-ID} [...]"; + + if (parameters.length >= 1) { + for (final String parameter : parameters) { + try { + System.out.println(policyService.read(Long.valueOf(parameter))); + } catch (final NumberFormatException ex) { + Messages.printIdNotNumberDeletedMessage("policy", parameter); + } catch (final WebServiceException | SyncopeClientException ex) { + if (ex.getMessage().startsWith("NotFound")) { + Messages.printNofFoundMessage("Policy", parameter); + } else { + Messages.printMessage(ex.getMessage()); + } + } + } + } else { + Messages.printCommandOptionMessage(readErrorMessage); + } + break; + case DELETE: + final String deleteErrorMessage = "policy --delete {POLICY-ID} {POLICY-ID} [...]"; + + if (parameters.length >= 1) { + for (final String parameter : parameters) { + try { + policyService.delete(Long.valueOf(parameter)); + Messages.printDeletedMessage("Policy", parameter); + } catch (final WebServiceException | SyncopeClientException ex) { + System.out.println("Error:"); + if (ex.getMessage().startsWith("NotFound")) { + Messages.printNofFoundMessage("Policy", parameter); + } else if (ex.getMessage().startsWith("DataIntegrityViolation")) { + Messages.printMessage("You cannot delete policy " + parameter); + } else { + Messages.printMessage(ex.getMessage()); + } + } catch (final NumberFormatException ex) { + Messages.printIdNotNumberDeletedMessage("policy", parameter); + } + } + } 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_POLICY("--list-policy"), + READ("--read"), + DELETE("--delete"); + + private final String optionName; + - private Options(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; + } + } + +}
