refactoring of the schema and notification stack + bugfixing, SYNCOPE-158
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/80f2548a Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/80f2548a Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/80f2548a Branch: refs/heads/SYNCOPE-156 Commit: 80f2548a004db0970fbfbd0773a068a8f9c9a836 Parents: 171c0ae Author: massi <massimiliano.perr...@tirasa.net> Authored: Thu Oct 22 11:12:50 2015 +0200 Committer: massi <massimiliano.perr...@tirasa.net> Committed: Thu Oct 22 11:12:50 2015 +0200 ---------------------------------------------------------------------- .../cli/commands/CommonsResultManager.java | 10 +- .../client/cli/commands/HelpCommand.java | 113 ------- .../client/cli/commands/InfoCommand.java | 339 ------------------- .../cli/commands/NotificationCommand.java | 169 --------- .../client/cli/commands/SchemaCommand.java | 309 ----------------- .../AbstractConfigurationCommand.java | 2 +- .../commands/domain/AbstractDomainCommand.java | 2 +- .../syncope/client/cli/commands/help/Help.java | 43 +++ .../client/cli/commands/help/HelpCommand.java | 90 +++++ .../cli/commands/help/HelpResultManager.java | 25 ++ .../syncope/client/cli/commands/info/Info.java | 243 +++++++++++++ .../client/cli/commands/info/InfoCommand.java | 180 ++++++++++ .../cli/commands/info/InfoResultManager.java | 25 ++ .../commands/logger/AbstractLoggerCommand.java | 2 +- .../cli/commands/logger/LoggerCreate.java | 4 +- .../cli/commands/logger/LoggerUpdate.java | 6 +- .../cli/commands/logger/LoggerUpdateAll.java | 6 +- .../AbstractNotificationCommand.java | 30 ++ .../notification/NotificationCommand.java | 109 ++++++ .../notification/NotificationDelete.java | 56 +++ .../commands/notification/NotificationList.java | 35 ++ .../commands/notification/NotificationRead.java | 54 +++ .../notification/NotificationResultManager.java | 25 ++ .../commands/schema/AbstractSchemaCommand.java | 30 ++ .../cli/commands/schema/SchemaCommand.java | 127 +++++++ .../cli/commands/schema/SchemaDelete.java | 64 ++++ .../client/cli/commands/schema/SchemaList.java | 70 ++++ .../cli/commands/schema/SchemaListAll.java | 55 +++ .../cli/commands/schema/SchemaListDerived.java | 40 +++ .../cli/commands/schema/SchemaListPlain.java | 40 +++ .../cli/commands/schema/SchemaListVirtual.java | 40 +++ .../client/cli/commands/schema/SchemaRead.java | 78 +++++ .../commands/schema/SchemaResultManager.java | 96 ++++++ .../syncope/client/cli/messages/Table.java | 12 +- 34 files changed, 1585 insertions(+), 944 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/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 255b99b..c316e13 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 @@ -19,8 +19,6 @@ package org.apache.syncope.client.cli.commands; import org.apache.syncope.client.cli.messages.Messages; -import org.apache.syncope.client.cli.util.CommandUtils; -import org.apache.syncope.common.lib.types.LoggerLevel; public abstract class CommonsResultManager { @@ -32,8 +30,12 @@ public abstract class CommonsResultManager { Messages.printNofFoundMessage(what, parameter); } - public void typeNotValidError(final String parameter) { - Messages.printTypeNotValidMessage("logger level", parameter, CommandUtils.fromEnumToArray(LoggerLevel.class)); + public void notBooleanDeletedError(final String what, final String key) { + Messages.printNotBooleanDeletedMessage(what, key); + } + + public void typeNotValidError(final String what, final String parameter, final String[] options) { + Messages.printTypeNotValidMessage(what, parameter, options); } public void commandOptionError(final String message) { http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/HelpCommand.java ---------------------------------------------------------------------- diff --git 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 deleted file mode 100644 index d167de4..0000000 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/HelpCommand.java +++ /dev/null @@ -1,113 +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 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(), CommandUtils.helpMessage("info", Options.toList())); - break; - } - } - - @Override - public String getHelpMessage() { - return CommandUtils.helpMessage("help", Options.toList()); - } - - private enum Options { - - HELP("--print"); - - 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/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/InfoCommand.java ---------------------------------------------------------------------- diff --git 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 deleted file mode 100644 index 8868f9b..0000000 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/InfoCommand.java +++ /dev/null @@ -1,339 +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 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.client.cli.util.CommandUtils; -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(CommandUtils.helpMessage("info", Options.toList())); - break; - default: - Messages.printDefaultMessage(input.getOption(), CommandUtils.helpMessage("info", Options.toList())); - break; - } - } - - @Override - public String getHelpMessage() { - return CommandUtils.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; - - 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/80f2548a/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 deleted file mode 100644 index 3d1866b..0000000 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java +++ /dev/null @@ -1,169 +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 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; - - 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/80f2548a/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 deleted file mode 100644 index e00ae3f..0000000 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java +++ /dev/null @@ -1,309 +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 java.util.ArrayList; -import java.util.Arrays; -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.client.cli.util.CommandUtils; -import org.apache.syncope.common.lib.SyncopeClientException; -import org.apache.syncope.common.lib.to.AbstractSchemaTO; -import org.apache.syncope.common.lib.to.DerSchemaTO; -import org.apache.syncope.common.lib.to.PlainSchemaTO; -import org.apache.syncope.common.lib.to.VirSchemaTO; -import org.apache.syncope.common.lib.types.SchemaType; -import org.apache.syncope.common.rest.api.service.SchemaService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Command(name = "schema") -public class SchemaCommand extends AbstractCommand { - - private static final Logger LOG = LoggerFactory.getLogger(SchemaCommand.class); - - private static final String HELP_MESSAGE = "Usage: schema [options]\n" - + " Options:\n" - + " --help \n" - + " --list-all\n" - + " --list-plain\n" - + " --list-derived\n" - + " --list-virtual\n" - + " --read {SCHEMA-TYPE} {SCHEMA-KEY}\n" - + " Schema type: PLAIN / DERIVED / VIRTUAL\n" - + " --delete {SCHEMA-TYPE} {SCHEMA-KEY}\n" - + " Schema type: PLAIN / DERIVED / VIRTUAL"; - - @Override - public void execute(final Input input) { - LOG.debug("Option: {}", input.getOption()); - LOG.debug("Parameters:"); - for (final String parameter : input.getParameters()) { - LOG.debug(" > " + parameter); - } - - String[] parameters = input.getParameters(); - - if (StringUtils.isBlank(input.getOption())) { - input.setOption(Options.HELP.getOptionName()); - } - - final SchemaService schemaService = SyncopeServices.get(SchemaService.class); - switch (Options.fromName(input.getOption())) { - case LIST: - final String listErrorMessage = "schema --list {SCHEMA-TYPE}\n" - + " Schema type: PLAIN / DERIVED / VIRTUAL"; - if (parameters.length == 1) { - try { - final SchemaType schemaType = SchemaType.valueOf(input.firstParameter()); - System.out.println(""); - for (final AbstractSchemaTO schemaTO : schemaService.list(schemaType)) { - switch (schemaType) { - case PLAIN: - System.out.println(" - Schema key: " + ((PlainSchemaTO) schemaTO).getKey()); - System.out.println(" type: " + ((PlainSchemaTO) schemaTO).getType()); - System.out.println(" is mandatory: " - + ((PlainSchemaTO) schemaTO).getMandatoryCondition()); - break; - case DERIVED: - System.out.println(" - Schema key: " + ((DerSchemaTO) schemaTO).getKey()); - System.out.println(" expression: " + ((DerSchemaTO) schemaTO).getExpression()); - break; - case VIRTUAL: - System.out.println(" - Schema key: " + ((VirSchemaTO) schemaTO).getKey()); - break; - default: - break; - } - } - System.out.println(""); - } catch (final SyncopeClientException ex) { - Messages.printMessage(ex.getMessage()); - } catch (final IllegalArgumentException ex) { - Messages.printTypeNotValidMessage( - "schema", input.firstParameter(), CommandUtils.fromEnumToArray(SchemaType.class)); - } - } else { - Messages.printCommandOptionMessage(listErrorMessage); - } - break; - case LIST_ALL: - try { - for (final SchemaType value : SchemaType.values()) { - System.out.println(""); - System.out.println(value + " schemas"); - for (final AbstractSchemaTO schemaTO : schemaService.list(value)) { - System.out.println(" - Name: " + schemaTO.getKey() + " type: " - + schemaTO.getAnyTypeClass()); - } - System.out.println(""); - } - } catch (final SyncopeClientException | WebServiceException ex) { - Messages.printMessage(ex.getMessage()); - } - break; - case LIST_PLAIN: - try { - System.out.println(""); - for (final AbstractSchemaTO schemaTO : schemaService.list(SchemaType.PLAIN)) { - System.out.println(" - Schema key: " + ((PlainSchemaTO) schemaTO).getKey()); - System.out.println(" type: " + ((PlainSchemaTO) schemaTO).getType()); - System.out.println(" is mandatory: " - + ((PlainSchemaTO) schemaTO).getMandatoryCondition()); - } - System.out.println(""); - } catch (final SyncopeClientException | WebServiceException ex) { - Messages.printMessage(ex.getMessage()); - } - break; - case LIST_DERIVED: - try { - System.out.println(""); - for (final AbstractSchemaTO schemaTO : schemaService.list(SchemaType.DERIVED)) { - System.out.println(" - Schema key: " + ((DerSchemaTO) schemaTO).getKey()); - System.out.println(" expression: " + ((DerSchemaTO) schemaTO).getExpression()); - } - System.out.println(""); - } catch (final SyncopeClientException | WebServiceException ex) { - Messages.printMessage(ex.getMessage()); - } - break; - case LIST_VIRTUAL: - try { - System.out.println(""); - for (final AbstractSchemaTO schemaTO : schemaService.list(SchemaType.VIRTUAL)) { - System.out.println(" - Schema key: " + ((VirSchemaTO) schemaTO).getKey()); - } - System.out.println(""); - } catch (final SyncopeClientException | WebServiceException ex) { - Messages.printMessage(ex.getMessage()); - } - break; - case READ: - final String readErrorMessage = "schema --read {SCHEMA-TYPE} {SCHEMA-KEY}\n" - + " Schema type: PLAIN / DERIVED / VIRTUAL"; - if (parameters.length >= 2) { - parameters = Arrays.copyOfRange(parameters, 1, parameters.length); - try { - final SchemaType schemaType = SchemaType.valueOf(input.firstParameter()); - System.out.println(""); - for (final String parameter : parameters) { - final AbstractSchemaTO schemaTO = schemaService.read(schemaType, parameter); - switch (schemaType) { - case PLAIN: - System.out.println(" - Schema key: " + ((PlainSchemaTO) schemaTO).getKey()); - System.out.println(" any type class: " - + ((PlainSchemaTO) schemaTO).getAnyTypeClass()); - System.out.println(" conversion pattern: " - + ((PlainSchemaTO) schemaTO).getConversionPattern()); - System.out.println(" enumeration keys: " - + ((PlainSchemaTO) schemaTO).getEnumerationKeys()); - System.out.println(" enumeration values: " - + ((PlainSchemaTO) schemaTO).getEnumerationValues()); - System.out.println(" mandatory condition: " - + ((PlainSchemaTO) schemaTO).getMandatoryCondition()); - System.out.println(" mime type: " + ((PlainSchemaTO) schemaTO).getMimeType()); - System.out.println(" secret key: " - + ((PlainSchemaTO) schemaTO).getSecretKey()); - System.out.println(" validator class: " - + ((PlainSchemaTO) schemaTO).getValidatorClass()); - System.out.println(" cipher algorithm: " - + ((PlainSchemaTO) schemaTO).getCipherAlgorithm()); - System.out.println(" TYPE: " - + ((PlainSchemaTO) schemaTO).getType()); - break; - case DERIVED: - System.out.println(" - Schema key: " + ((DerSchemaTO) schemaTO).getKey()); - System.out.println(" any type class: " - + ((DerSchemaTO) schemaTO).getAnyTypeClass()); - System.out.println(" expression: " + ((DerSchemaTO) schemaTO).getExpression()); - break; - case VIRTUAL: - System.out.println(" - Schema key: " + ((VirSchemaTO) schemaTO).getKey()); - System.out.println(" any type class: " - + ((VirSchemaTO) schemaTO).getAnyTypeClass()); - break; - default: - break; - } - System.out.println(""); - } - } catch (final SyncopeClientException | WebServiceException ex) { - if (ex.getMessage().startsWith("NotFound")) { - Messages.printNofFoundMessage("Schema", parameters[0]); - } else { - Messages.printMessage(ex.getMessage()); - } - } catch (final IllegalArgumentException ex) { - Messages.printTypeNotValidMessage( - "schema", input.firstParameter(), CommandUtils.fromEnumToArray(SchemaType.class)); - } - } else { - Messages.printCommandOptionMessage(readErrorMessage); - } - break; - case DELETE: - final String deleteErrorMessage = "schema --delete {SCHEMA-TYPE} {SCHEMA-KEY}\n" - + " Schema type: PLAIN / DERIVED / VIRTUAL"; - if (parameters.length >= 2) { - parameters = Arrays.copyOfRange(parameters, 1, parameters.length); - try { - for (final String parameter : parameters) { - schemaService.delete(SchemaType.valueOf(input.firstParameter()), parameter); - Messages.printDeletedMessage("Schema", parameter); - } - } catch (final SyncopeClientException | WebServiceException ex) { - if (ex.getMessage().startsWith("NotFound")) { - Messages.printNofFoundMessage("Schema", parameters[0]); - } else if (ex.getMessage().startsWith("DataIntegrityViolation")) { - Messages.printMessage( - "You cannot delete schema " + parameters[0]); - } else { - Messages.printMessage(ex.getMessage()); - } - } catch (final IllegalArgumentException ex) { - Messages.printTypeNotValidMessage( - "schema", input.firstParameter(), CommandUtils.fromEnumToArray(SchemaType.class)); - } - } 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"), - LIST_ALL("--list-all"), - LIST_PLAIN("--list-plain"), - LIST_DERIVED("--list-derived"), - LIST_VIRTUAL("--list-virtual"), - 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/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/AbstractConfigurationCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/AbstractConfigurationCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/AbstractConfigurationCommand.java index 59fc423..2942c07 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/AbstractConfigurationCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/AbstractConfigurationCommand.java @@ -21,7 +21,7 @@ package org.apache.syncope.client.cli.commands.configuration; import org.apache.syncope.client.cli.SyncopeServices; import org.apache.syncope.common.rest.api.service.ConfigurationService; -public class AbstractConfigurationCommand { +public abstract class AbstractConfigurationCommand { protected final ConfigurationService configurationService = SyncopeServices.get(ConfigurationService.class); http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/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 index 8650ef7..b5bfca5 100644 --- 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 @@ -21,7 +21,7 @@ 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 { +public abstract class AbstractDomainCommand { protected final DomainService domainService = SyncopeServices.get(DomainService.class); http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/help/Help.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/help/Help.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/help/Help.java new file mode 100644 index 0000000..c658beb --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/help/Help.java @@ -0,0 +1,43 @@ +/* + * 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.help; + +import org.apache.syncope.client.cli.Command; +import org.apache.syncope.client.cli.commands.AbstractCommand; +import org.apache.syncope.client.cli.util.CommandUtils; + +public class Help { + + public void 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) { + new HelpResultManager().generic(e.getMessage()); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/help/HelpCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/help/HelpCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/help/HelpCommand.java new file mode 100644 index 0000000..eed0924 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/help/HelpCommand.java @@ -0,0 +1,90 @@ +/* + * 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.help; + +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; +import org.apache.syncope.client.cli.util.CommandUtils; + +@Command(name = "help") +public class HelpCommand extends AbstractCommand { + + @Override + public void execute(final Input input) { + if (StringUtils.isBlank(input.getOption())) { + input.setOption(Options.HELP.getOptionName()); + } + + switch (Options.fromName(input.getOption())) { + case HELP: + new Help().help(); + break; + default: + new HelpResultManager().defaultError( + input.getOption(), CommandUtils.helpMessage("info", Options.toList())); + break; + } + } + + @Override + public String getHelpMessage() { + return CommandUtils.helpMessage("help", Options.toList()); + } + + private enum Options { + + HELP("--print"); + + 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/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/help/HelpResultManager.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/help/HelpResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/help/HelpResultManager.java new file mode 100644 index 0000000..7a67943 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/help/HelpResultManager.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.help; + +import org.apache.syncope.client.cli.commands.CommonsResultManager; + +public class HelpResultManager extends CommonsResultManager { + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/Info.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/Info.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/Info.java new file mode 100644 index 0000000..ccf9170 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/Info.java @@ -0,0 +1,243 @@ +/* + * 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.info; + +import org.apache.syncope.client.cli.SyncopeServices; +import org.apache.syncope.common.lib.to.SyncopeTO; +import org.apache.syncope.common.rest.api.service.SyncopeService; + +public class Info { + + private final SyncopeTO syncopeTO = SyncopeServices.get(SyncopeService.class).info(); + + private final InfoResultManager infoResultManager = new InfoResultManager(); + + public void version() { + try { + infoResultManager.generic("Syncope version: " + syncopeTO.getVersion()); + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void pwdResetAllowed() { + try { + infoResultManager.generic("Password reset allowed: " + syncopeTO.isPwdResetAllowed()); + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void resetWithSecurityQuestion() { + try { + infoResultManager.generic("Password reset requiring security question: " + + syncopeTO.isPwdResetRequiringSecurityQuestions()); + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void selfRegistrationAllowed() { + try { + infoResultManager.generic("Self registration allowed: " + syncopeTO.isSelfRegAllowed()); + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void provisioningManager() { + try { + infoResultManager.generic( + "Any object provisioning manager class: " + syncopeTO.getAnyObjectProvisioningManager(), + "User provisioning manager class: " + syncopeTO.getUserProvisioningManager(), + "Group provisioning manager class: " + syncopeTO.getGroupProvisioningManager()); + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void workflowAdapter() { + try { + infoResultManager.generic( + "Any object workflow adapter class: " + syncopeTO.getAnyObjectWorkflowAdapter(), + "User workflow adapter class: " + syncopeTO.getUserWorkflowAdapter(), + "Group workflow adapter class: " + syncopeTO.getGroupWorkflowAdapter()); + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void accountRules() { + try { + for (final String accountRule : syncopeTO.getAccountRules()) { + infoResultManager.generic("Account rule: " + accountRule); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void connidLocation() { + try { + for (final String location : syncopeTO.getConnIdLocations()) { + infoResultManager.generic("ConnId location: " + location); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void logicActions() { + try { + for (final String logic : syncopeTO.getLogicActions()) { + infoResultManager.generic("Logic action: " + logic); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void mailTemplates() { + try { + for (final String template : syncopeTO.getMailTemplates()) { + infoResultManager.generic("Mail template: " + template); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void mappingItemTransformers() { + try { + for (final String tranformer : syncopeTO.getMappingItemTransformers()) { + infoResultManager.generic("Mapping item tranformer: " + tranformer); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void passwordRules() { + try { + for (final String rules : syncopeTO.getPasswordRules()) { + infoResultManager.generic("Password rule: " + rules); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void propagationActions() { + try { + for (final String action : syncopeTO.getPropagationActions()) { + infoResultManager.generic("Propagation action: " + action); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void pushActions() { + try { + for (final String action : syncopeTO.getPushActions()) { + infoResultManager.generic("Push action: " + action); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void pushCorrelationActions() { + try { + for (final String rule : syncopeTO.getPushCorrelationRules()) { + infoResultManager.generic("Push correlation rule: " + rule); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void reportlets() { + try { + for (final String reportlet : syncopeTO.getReportlets()) { + infoResultManager.generic("Reportlet: " + reportlet); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void syncActions() { + try { + for (final String action : syncopeTO.getSyncActions()) { + infoResultManager.generic("Sync action: " + action); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void syncCorrelationRules() { + try { + for (final String rule : syncopeTO.getSyncCorrelationRules()) { + infoResultManager.generic("Sync correlation rule: " + rule); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void taskJobs() { + try { + for (final String job : syncopeTO.getTaskJobs()) { + infoResultManager.generic("Task job: " + job); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void validators() { + try { + for (final String validator : syncopeTO.getValidators()) { + infoResultManager.generic("Validator: " + validator); + } + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void passwordGenerators() { + try { + infoResultManager.generic( + "Password generator class: " + syncopeTO.getPasswordGenerator()); + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } + + public void virAttrCache() { + try { + infoResultManager.generic( + "Virtual attribute cache class: " + syncopeTO.getVirAttrCache()); + } catch (final Exception ex) { + infoResultManager.generic(ex.getMessage()); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/InfoCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/InfoCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/InfoCommand.java new file mode 100644 index 0000000..31b9aaa --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/InfoCommand.java @@ -0,0 +1,180 @@ +/* + * 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.info; + +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; +import org.apache.syncope.client.cli.util.CommandUtils; + +@Command(name = "info") +public class InfoCommand extends AbstractCommand { + + private final Info info = new Info(); + + @Override + public void execute(final Input input) { + if (StringUtils.isBlank(input.getOption())) { + input.setOption(Options.HELP.getOptionName()); + } + + switch (Options.fromName(input.getOption())) { + case VERSION: + info.version(); + break; + case PWD_RESET_ALLOWED: + info.pwdResetAllowed(); + break; + case PWD_RESET_WITH_SECURITY_QUESTION: + info.resetWithSecurityQuestion(); + break; + case SELF_REG_ALLOWED: + info.selfRegistrationAllowed(); + break; + case PROVISIONING_MANAGER: + info.provisioningManager(); + break; + case WORKFLOW_ADAPTER: + info.workflowAdapter(); + break; + case ACCOUNT_RULES: + info.accountRules(); + break; + case CONNID_LOCATION: + info.connidLocation(); + break; + case LOGIC_ACTIONS: + info.logicActions(); + break; + case MAIL_TEMPLATES: + info.mailTemplates(); + break; + case MAPPING_ITEM_TRANSFORMERS: + info.mappingItemTransformers(); + break; + case PASSWORD_RULES: + info.passwordRules(); + break; + case PROPAGATION_ACTIONS: + info.propagationActions(); + break; + case PUSH_ACTIONS: + info.pushActions(); + break; + case PUSH_CORRELATION_ACTIONS: + info.pushCorrelationActions(); + break; + case REPORTLETS: + info.reportlets(); + break; + case SYNC_ACTIONS: + info.syncActions(); + break; + case SYNC_CORRELATION_RULES: + info.syncCorrelationRules(); + break; + case TASK_JOBS: + info.taskJobs(); + break; + case VALIDATORS: + info.validators(); + break; + case PASSWORD_GENERATOR: + info.passwordGenerators(); + break; + case VIR_ATTR_CACHE: + info.virAttrCache(); + break; + case HELP: + System.out.println(CommandUtils.helpMessage("info", Options.toList())); + break; + default: + new InfoResultManager().defaultError( + input.getOption(), CommandUtils.helpMessage("info", Options.toList())); + break; + } + } + + @Override + public String getHelpMessage() { + return CommandUtils.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; + + 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/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/InfoResultManager.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/InfoResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/InfoResultManager.java new file mode 100644 index 0000000..237af64 --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/InfoResultManager.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.info; + +import org.apache.syncope.client.cli.commands.CommonsResultManager; + +public class InfoResultManager extends CommonsResultManager { + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/AbstractLoggerCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/AbstractLoggerCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/AbstractLoggerCommand.java index 3782eac..a8703a9 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/AbstractLoggerCommand.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/AbstractLoggerCommand.java @@ -21,7 +21,7 @@ package org.apache.syncope.client.cli.commands.logger; import org.apache.syncope.client.cli.SyncopeServices; import org.apache.syncope.common.rest.api.service.LoggerService; -public class AbstractLoggerCommand { +public abstract class AbstractLoggerCommand { protected final LoggerService loggerService = SyncopeServices.get(LoggerService.class); http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCreate.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCreate.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCreate.java index 29d60ad..6a51e95 100644 --- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCreate.java +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCreate.java @@ -21,6 +21,7 @@ package org.apache.syncope.client.cli.commands.logger; import java.util.LinkedList; import javax.xml.ws.WebServiceException; import org.apache.syncope.client.cli.Input; +import org.apache.syncope.client.cli.util.CommandUtils; import org.apache.syncope.common.lib.SyncopeClientException; import org.apache.syncope.common.lib.to.LoggerTO; import org.apache.syncope.common.lib.types.LoggerLevel; @@ -52,7 +53,8 @@ public class LoggerCreate extends AbstractLoggerCommand { loggerService.update(LoggerType.LOG, loggerTO); loggerTOs.add(loggerTO); } catch (final WebServiceException | SyncopeClientException | IllegalArgumentException ex) { - loggerResultManager.typeNotValidError(input.firstParameter()); + loggerResultManager.typeNotValidError( + "logger level", input.firstParameter(), CommandUtils.fromEnumToArray(LoggerLevel.class)); failed = true; break; } http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/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 7279b96..03de917 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 @@ -21,6 +21,7 @@ package org.apache.syncope.client.cli.commands.logger; import java.util.LinkedList; import javax.xml.ws.WebServiceException; import org.apache.syncope.client.cli.Input; +import org.apache.syncope.client.cli.util.CommandUtils; import org.apache.syncope.common.lib.SyncopeClientException; import org.apache.syncope.common.lib.to.LoggerTO; import org.apache.syncope.common.lib.types.LoggerLevel; @@ -52,7 +53,10 @@ public class LoggerUpdate extends AbstractLoggerCommand { loggerTOs.add(loggerTO); } catch (final WebServiceException | SyncopeClientException | IllegalArgumentException ex) { if (ex.getMessage().startsWith("No enum constant org.apache.syncope.common.lib.types.")) { - loggerResultManager.typeNotValidError(input.firstParameter()); + loggerResultManager.typeNotValidError( + "logger level", + input.firstParameter(), + CommandUtils.fromEnumToArray(LoggerLevel.class)); } else if ("Parameter syntax error!".equalsIgnoreCase(ex.getMessage())) { loggerResultManager.generic(ex.getMessage(), UPDATE_HELP_MESSAGE); } else if (ex.getMessage().startsWith("NotFound")) { http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/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 f1c25c2..55c2e60 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 @@ -21,6 +21,7 @@ package org.apache.syncope.client.cli.commands.logger; import java.util.LinkedList; import javax.xml.ws.WebServiceException; import org.apache.syncope.client.cli.Input; +import org.apache.syncope.client.cli.util.CommandUtils; import org.apache.syncope.common.lib.SyncopeClientException; import org.apache.syncope.common.lib.to.LoggerTO; import org.apache.syncope.common.lib.types.LoggerLevel; @@ -47,7 +48,10 @@ public class LoggerUpdateAll extends AbstractLoggerCommand { loggerTOs.add(loggerTO); } catch (final WebServiceException | SyncopeClientException | IllegalArgumentException ex) { if (ex.getMessage().startsWith("No enum constant org.apache.syncope.common.lib.types.")) { - loggerResultManager.typeNotValidError(input.firstParameter()); + loggerResultManager.typeNotValidError( + "logger level", + input.firstParameter(), + CommandUtils.fromEnumToArray(LoggerLevel.class)); } else { loggerResultManager.generic(ex.getMessage(), UPDATE_ALL_HELP_MESSAGE); } http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/AbstractNotificationCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/AbstractNotificationCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/AbstractNotificationCommand.java new file mode 100644 index 0000000..2b862ed --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/AbstractNotificationCommand.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.notification; + +import org.apache.syncope.client.cli.SyncopeServices; +import org.apache.syncope.common.rest.api.service.NotificationService; + +public abstract class AbstractNotificationCommand { + + protected final NotificationService notificationService = SyncopeServices.get(NotificationService.class); + + protected final NotificationResultManager notificationResultManager = new NotificationResultManager(); + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/80f2548a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationCommand.java ---------------------------------------------------------------------- diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationCommand.java new file mode 100644 index 0000000..d5197ac --- /dev/null +++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/notification/NotificationCommand.java @@ -0,0 +1,109 @@ +/* + * 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.notification; + +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 = "notification") +public class NotificationCommand extends AbstractCommand { + + 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) { + if (StringUtils.isBlank(input.getOption())) { + input.setOption(Options.HELP.getOptionName()); + } + + switch (Options.fromName(input.getOption())) { + case LIST: + new NotificationList().list(); + break; + case READ: + new NotificationRead(input).read(); + break; + case DELETE: + new NotificationDelete(input).delete(); + break; + case HELP: + System.out.println(HELP_MESSAGE); + break; + default: + new NotificationResultManager().deletedMessage(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; + } + } + +}