syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject syncope git commit: Fixed SYNCOPE-711, messages improvement SYNCOPE-158
Date Thu, 15 Oct 2015 09:07:35 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 4133c2402 -> e98d2b252


Fixed SYNCOPE-711, messages improvement SYNCOPE-158


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/e98d2b25
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/e98d2b25
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/e98d2b25

Branch: refs/heads/master
Commit: e98d2b252d5464b10c9423e56a245dad356debf0
Parents: 4133c24
Author: massi <massimiliano.perrone@tirasa.net>
Authored: Thu Oct 15 11:07:20 2015 +0200
Committer: massi <massimiliano.perrone@tirasa.net>
Committed: Thu Oct 15 11:07:20 2015 +0200

----------------------------------------------------------------------
 .../apache/syncope/client/cli/SyncopeAdm.java   |   1 +
 .../cli/commands/ConfigurationCommand.java      |  47 +++---
 .../client/cli/commands/DomainCommand.java      | 166 +++++++++++++++++++
 .../client/cli/commands/LoggerCommand.java      |  39 ++---
 .../cli/commands/NotificationCommand.java       |  20 +--
 .../client/cli/commands/PolicyCommand.java      |  29 ++--
 .../client/cli/commands/ReportCommand.java      |  60 +++----
 .../client/cli/commands/SchemaCommand.java      |  28 ++--
 .../syncope/client/cli/messages/Messages.java   |  16 +-
 9 files changed, 274 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/e98d2b25/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java b/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java
index 0340043..3a66baa 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java
@@ -38,6 +38,7 @@ public final class SyncopeAdm {
             + "    schema --help \n"
             + "    install --help \n"
             + "    info --help\n"
+            + "    domain --help\n"
             + "    help\n";
 
     public static void main(final String[] args) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/e98d2b25/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java
----------------------------------------------------------------------
diff --git 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
index 51e7cb8..4b082ee 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
@@ -112,8 +112,7 @@ public class ConfigurationCommand extends AbstractCommand {
                 }
                 break;
             case READ:
-                final String readErrorMessage = Messages.optionCommandMessage(
-                        "configuration --read {CONF-NAME} {CONF-NAME} [...]");
+                final String readErrorMessage = "configuration --read {CONF-NAME} {CONF-NAME} [...]";
                 if (parameters.length >= 1) {
                     AttrTO attrTO;
                     for (final String parameter : parameters) {
@@ -125,9 +124,7 @@ public class ConfigurationCommand extends AbstractCommand {
                             System.out.println("");
                         } catch (final SyncopeClientException | WebServiceException ex) {
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage("Configuration " + parameters[0] + " doesn't exist!");
-                            } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
-                                Messages.printMessage("You cannot delete configuration " + parameters[0]);
+                                Messages.printNofFoundMessage("Logger", parameter);
                             } else {
                                 Messages.printMessage(ex.getMessage());
                             }
@@ -135,12 +132,12 @@ public class ConfigurationCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(readErrorMessage);
+                    Messages.printCommandOptionMessage(readErrorMessage);
                 }
                 break;
             case UPDATE:
-                final String updateErrorMessage = Messages.optionCommandMessage(
-                        "configuration --update {CONF-NAME}={CONF-VALUE} {CONF-NAME}={CONF-VALUE} [...]");
+                final String updateErrorMessage
+                        = "configuration --update {CONF-NAME}={CONF-VALUE} {CONF-NAME}={CONF-VALUE} [...]";
                 if (parameters.length >= 1) {
                     Input.PairParameter pairParameter = null;
                     AttrTO attrTO;
@@ -160,14 +157,11 @@ public class ConfigurationCommand extends AbstractCommand {
                             break;
                         } catch (final SyncopeClientException | WebServiceException ex) {
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage(
-                                        "Configuration " + pairParameter.getKey() + " doesn't exist!");
+                                Messages.printNofFoundMessage("Configuration", pairParameter.getKey());
                             } else if (ex.getMessage().startsWith("InvalidValues")) {
                                 Messages.printMessage(
                                         pairParameter.getValue() + " is not a valid value for "
                                         + pairParameter.getKey());
-                            } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
-                                Messages.printMessage("You cannot delete configuration " + parameters[0]);
                             } else {
                                 Messages.printMessage(ex.getMessage());
                             }
@@ -175,12 +169,12 @@ public class ConfigurationCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(updateErrorMessage);
+                    Messages.printCommandOptionMessage(updateErrorMessage);
                 }
                 break;
             case CREATE:
-                final String createErrorMessage = Messages.optionCommandMessage(
-                        "configuration --create {CONF-NAME}={CONF-VALUE} {CONF-NAME}={CONF-VALUE} [...]");
+                final String createErrorMessage
+                        = "configuration --create {CONF-NAME}={CONF-VALUE} {CONF-NAME}={CONF-VALUE} [...]";
                 if (parameters.length >= 1) {
                     Input.PairParameter pairParameter = null;
                     AttrTO attrTO;
@@ -200,9 +194,8 @@ public class ConfigurationCommand extends AbstractCommand {
                             break;
                         } catch (final SyncopeClientException | WebServiceException ex) {
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage(
-                                        "Configuration schema "
-                                        + pairParameter.getKey() + " doesn't exist! Create it before.");
+                                Messages.printNofFoundMessage("Configuration", pairParameter.getKey());
+                                System.out.println("Create it before.");
                             } else {
                                 Messages.printMessage(ex.getMessage());
                             }
@@ -210,20 +203,19 @@ public class ConfigurationCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(createErrorMessage);
+                    Messages.printCommandOptionMessage(createErrorMessage);
                 }
                 break;
             case DELETE:
-                final String deleteErrorMessage = Messages.optionCommandMessage(
-                        "configuration --delete {CONF-NAME} {CONF-NAME} [...]");
+                final String deleteErrorMessage = "configuration --delete {CONF-NAME} {CONF-NAME} [...]";
                 if (parameters.length >= 1) {
                     for (final String parameter : parameters) {
                         try {
                             configurationService.delete(parameter);
-                            System.out.println("\n - Conf " + parameter + " deleted!\n");
+                            Messages.printDeletedMessage("Configuration", parameter);
                         } catch (final SyncopeClientException | WebServiceException ex) {
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage("Configuration " + parameter + " doesn't exist!");
+                                Messages.printNofFoundMessage("Configuration", parameter);
                             } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
                                 Messages.printMessage("You cannot delete configuration", parameter);
                             } else {
@@ -233,12 +225,11 @@ public class ConfigurationCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(deleteErrorMessage);
+                    Messages.printCommandOptionMessage(deleteErrorMessage);
                 }
                 break;
             case EXPORT:
-                final String exportErrorMessage = Messages.optionCommandMessage(
-                        "configuration --export {WHERE-DIR}");
+                final String exportErrorMessage = "configuration --export {WHERE-DIR}";
                 if (parameters.length == 1) {
                     try {
                         XMLUtils.createXMLFile((SequenceInputStream) configurationService.export().getEntity(),
@@ -266,7 +257,7 @@ public class ConfigurationCommand extends AbstractCommand {
                         break;
                     }
                 } else {
-                    System.out.println(exportErrorMessage);
+                    Messages.printCommandOptionMessage(exportErrorMessage);
                 }
                 break;
             case HELP:
@@ -279,7 +270,7 @@ public class ConfigurationCommand extends AbstractCommand {
                 break;
         }
     }
-    
+
     @Override
     public String getHelpMessage() {
         return HELP_MESSAGE;

http://git-wip-us.apache.org/repos/asf/syncope/blob/e98d2b25/client/cli/src/main/java/org/apache/syncope/client/cli/commands/DomainCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/DomainCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/DomainCommand.java
new file mode 100644
index 0000000..e733156
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/DomainCommand.java
@@ -0,0 +1,166 @@
+/*
+ * 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:
+                System.out.println(input.getOption() + " is not a valid option.");
+                System.out.println("");
+                System.out.println(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) {
+            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/e98d2b25/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java
----------------------------------------------------------------------
diff --git 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
index e1ab746..6a5cde6 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
@@ -72,7 +72,6 @@ public class LoggerCommand extends AbstractCommand {
         switch (Options.fromName(input.getOption())) {
             case LIST:
                 try {
-                    System.out.println("\n");
                     for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) {
                         System.out.println(" - " + loggerTO.getKey() + " -> " + loggerTO.getLevel());
                         System.out.println("");
@@ -82,8 +81,7 @@ public class LoggerCommand extends AbstractCommand {
                 }
                 break;
             case READ:
-                final String readErrorMessage = Messages.optionCommandMessage(
-                        "logger --read {LOG-NAME} {LOG-NAME} [...]");
+                final String readErrorMessage = "logger --read {LOG-NAME} {LOG-NAME} [...]";
                 if (parameters.length >= 1) {
                     for (final String parameter : parameters) {
                         try {
@@ -94,20 +92,18 @@ public class LoggerCommand extends AbstractCommand {
                             System.out.println("");
                         } catch (final SyncopeClientException | WebServiceException ex) {
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage(
-                                        "Logger " + parameter + " doesn't exist!");
+                                Messages.printNofFoundMessage("Logger", parameter);
                             } else {
                                 Messages.printMessage("Error: " + ex.getMessage());
                             }
                         }
                     }
                 } else {
-                    System.out.println(readErrorMessage);
+                    Messages.printCommandOptionMessage(readErrorMessage);
                 }
                 break;
             case UPDATE:
-                final String updateErrorMessage = Messages.optionCommandMessage(
-                        "logger --update {LOG-NAME}={LOG-LEVEL} {LOG-NAME}={LOG-LEVEL} [...]");
+                final String updateErrorMessage = "logger --update {LOG-NAME}={LOG-LEVEL} {LOG-NAME}={LOG-LEVEL} [...]";
 
                 if (parameters.length >= 1) {
                     Input.PairParameter pairParameter = null;
@@ -132,8 +128,7 @@ public class LoggerCommand extends AbstractCommand {
                             } else if ("Parameter syntax error!".equalsIgnoreCase(ex.getMessage())) {
                                 Messages.printMessage(ex.getMessage(), updateErrorMessage);
                             } else if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage(
-                                        "Logger " + pairParameter.getKey() + " doesn't exists!");
+                                Messages.printNofFoundMessage("Logger", parameter);
                             } else {
                                 Messages.printMessage(ex.getMessage(), updateErrorMessage);
                             }
@@ -141,12 +136,11 @@ public class LoggerCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(updateErrorMessage);
+                    Messages.printCommandOptionMessage(updateErrorMessage);
                 }
                 break;
             case UPDATE_ALL:
-                final String updateAllErrorMessage = Messages.optionCommandMessage(
-                        "logger --update-all {LOG-LEVEL}");
+                final String updateAllErrorMessage = "logger --update-all {LOG-LEVEL}";
 
                 if (parameters.length == 1) {
                     for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) {
@@ -172,12 +166,11 @@ public class LoggerCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(updateAllErrorMessage);
+                    Messages.printCommandOptionMessage(updateAllErrorMessage);
                 }
                 break;
             case CREATE:
-                final String createErrorMessage = Messages.optionCommandMessage(
-                        "logger --create {LOG-NAME}={LOG-LEVEL} {LOG-NAME}={LOG-LEVEL} [...]");
+                final String createErrorMessage = "logger --create {LOG-NAME}={LOG-LEVEL} {LOG-NAME}={LOG-LEVEL} [...]";
 
                 if (parameters.length >= 1) {
                     Input.PairParameter pairParameter;
@@ -208,29 +201,27 @@ public class LoggerCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(createErrorMessage);
+                    Messages.printCommandOptionMessage(createErrorMessage);
                 }
                 break;
             case DELETE:
-                final String deleteErrorMessage = Messages.optionCommandMessage(
-                        "logger --delete {LOG-NAME} {LOG-NAME} [...]");
+                final String deleteErrorMessage = "logger --delete {LOG-NAME} {LOG-NAME} [...]";
 
                 if (parameters.length >= 1) {
                     for (final String parameter : parameters) {
                         try {
                             loggerService.delete(LoggerType.LOG, parameter);
-                            System.out.println("\n - Logger " + parameter + " deleted!\n");
+                            Messages.printDeletedMessage("Logger", parameter);
                         } catch (final WebServiceException | SyncopeClientException ex) {
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage(
-                                        "Logger " + parameter + " doesn't exists!");
+                                Messages.printNofFoundMessage("Logger", parameter);
                             } else {
                                 Messages.printMessage(ex.getMessage());
                             }
                         }
                     }
                 } else {
-                    System.out.println(deleteErrorMessage);
+                    Messages.printCommandOptionMessage(deleteErrorMessage);
                 }
                 break;
             case HELP:
@@ -242,7 +233,7 @@ public class LoggerCommand extends AbstractCommand {
                 System.out.println(HELP_MESSAGE);
         }
     }
-    
+
     @Override
     public String getHelpMessage() {
         return HELP_MESSAGE;

http://git-wip-us.apache.org/repos/asf/syncope/blob/e98d2b25/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java
index a903268..49cc2e2 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
@@ -72,8 +72,7 @@ public class NotificationCommand extends AbstractCommand {
                 }
                 break;
             case READ:
-                final String readErrorMessage = Messages.optionCommandMessage(
-                        "notification --read {NOTIFICATION-ID} {NOTIFICATION-ID} [...]");
+                final String readErrorMessage = "notification --read {NOTIFICATION-ID} {NOTIFICATION-ID} [...]";
                 if (parameters.length >= 1) {
                     for (final String parameter : parameters) {
                         try {
@@ -82,28 +81,27 @@ public class NotificationCommand extends AbstractCommand {
                             System.out.println("Error reading " + parameter + ". It isn't a valid notification id");
                         } catch (final WebServiceException | SyncopeClientException ex) {
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage("Notification " + parameter + " doesn't exists!");
+                                Messages.printNofFoundMessage("Notification", parameter);
                             } else {
                                 Messages.printMessage(ex.getMessage());
                             }
                         }
                     }
                 } else {
-                    System.out.println(readErrorMessage);
+                    Messages.printCommandOptionMessage(readErrorMessage);
                 }
                 break;
             case DELETE:
-                final String deleteErrorMessage = Messages.optionCommandMessage(
-                        "notification --delete {NOTIFICATION-ID} {NOTIFICATION-ID} [...]");
+                final String deleteErrorMessage = "notification --delete {NOTIFICATION-ID} {NOTIFICATION-ID} [...]";
 
                 if (parameters.length >= 1) {
                     for (final String parameter : parameters) {
                         try {
                             notificationService.delete(Long.valueOf(parameter));
-                            System.out.println("\n - Notification " + parameter + " deleted!\n");
+                            Messages.printDeletedMessage("Notification", parameter);
                         } catch (final WebServiceException | SyncopeClientException ex) {
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage("Notification " + parameter + " doesn't exists!");
+                                Messages.printNofFoundMessage("Notification", parameter);
                             } else {
                                 Messages.printMessage(ex.getMessage());
                             }
@@ -113,7 +111,7 @@ public class NotificationCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(deleteErrorMessage);
+                    Messages.printCommandOptionMessage(deleteErrorMessage);
                 }
                 break;
             case HELP:
@@ -125,7 +123,7 @@ public class NotificationCommand extends AbstractCommand {
                 System.out.println(HELP_MESSAGE);
         }
     }
-    
+
     @Override
     public String getHelpMessage() {
         return HELP_MESSAGE;
@@ -161,7 +159,7 @@ public class NotificationCommand extends AbstractCommand {
             }
             return optionToReturn;
         }
-        
+
         public static List<String> toList() {
             final List<String> options = new ArrayList<>();
             for (final Options value : values()) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/e98d2b25/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java
index 11d59b8..cd043ce 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
@@ -66,9 +66,9 @@ public class PolicyCommand extends AbstractCommand {
         final PolicyService policyService = SyncopeServices.get(PolicyService.class);
         switch (Options.fromName(input.getOption())) {
             case LIST_POLICY:
-                final String listPolicyErrorMessage = Messages.optionCommandMessage(
-                        "Usage: policy --list-policy {POLICY-TYPE}\n"
-                        + "   Policy type: ACCOUNT / PASSWORD / SYNC / PUSH");
+                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]))) {
@@ -85,12 +85,12 @@ public class PolicyCommand extends AbstractCommand {
                         System.out.println("");
                     }
                 } else {
-                    System.out.println(listPolicyErrorMessage);
+                    Messages.printCommandOptionMessage(listPolicyErrorMessage);
                 }
                 break;
             case READ:
-                final String readErrorMessage = Messages.optionCommandMessage(
-                        "Usage: policy --read {POLICY-ID} {POLICY-ID} [...]");
+                final String readErrorMessage = "policy --read {POLICY-ID} {POLICY-ID} [...]";
+
                 if (parameters.length >= 1) {
                     for (final String parameter : parameters) {
                         try {
@@ -100,29 +100,28 @@ public class PolicyCommand extends AbstractCommand {
                                     "Error reading " + parameter + ". It isn't a valid policy id");
                         } catch (final WebServiceException | SyncopeClientException ex) {
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage("Policy " + parameter + " doesn't exists!");
+                                Messages.printNofFoundMessage("Policy", parameter);
                             } else {
                                 Messages.printMessage(ex.getMessage());
                             }
                         }
                     }
                 } else {
-                    System.out.println(readErrorMessage);
+                    Messages.printCommandOptionMessage(readErrorMessage);
                 }
                 break;
             case DELETE:
-                final String deleteErrorMessage = Messages.optionCommandMessage(
-                        "Usage: policy --delete {POLICY-ID} {POLICY-ID} [...]");
+                final String deleteErrorMessage = "policy --delete {POLICY-ID} {POLICY-ID} [...]";
 
                 if (parameters.length >= 1) {
                     for (final String parameter : parameters) {
                         try {
                             policyService.delete(Long.valueOf(parameter));
-                            System.out.println(" - Policy " + parameter + " deleted!");
+                            Messages.printDeletedMessage("Policy", parameter);
                         } catch (final WebServiceException | SyncopeClientException ex) {
                             System.out.println("Error:");
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage("Policy " + parameter + " doesn't exists!");
+                                Messages.printNofFoundMessage("Policy", parameter);
                             } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
                                 Messages.printMessage("You cannot delete policy " + parameter);
                             } else {
@@ -134,7 +133,7 @@ public class PolicyCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(deleteErrorMessage);
+                    Messages.printCommandOptionMessage(deleteErrorMessage);
                 }
                 break;
             case HELP:
@@ -146,7 +145,7 @@ public class PolicyCommand extends AbstractCommand {
                 System.out.println(HELP_MESSAGE);
         }
     }
-    
+
     @Override
     public String getHelpMessage() {
         return HELP_MESSAGE;
@@ -182,7 +181,7 @@ public class PolicyCommand extends AbstractCommand {
             }
             return optionToReturn;
         }
-        
+
         public static List<String> toList() {
             final List<String> options = new ArrayList<>();
             for (final Options value : values()) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/e98d2b25/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java
index dfd8d46..3d9770e 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java
@@ -109,8 +109,7 @@ public class ReportCommand extends AbstractCommand {
                 }
                 break;
             case READ:
-                final String readErrorMessage = Messages.optionCommandMessage(
-                        "Usage: report --read {REPORT-ID} {REPORT-ID} [...]");
+                final String readErrorMessage = "Usage: report --read {REPORT-ID} {REPORT-ID} [...]";
                 if (parameters.length >= 1) {
                     for (final String parameter : parameters) {
                         try {
@@ -120,28 +119,27 @@ public class ReportCommand extends AbstractCommand {
                                     "Error reading " + parameter + ". It isn't a valid report id");
                         } catch (final WebServiceException | SyncopeClientException ex) {
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage("Report " + parameter + " doesn't exists!");
+                                Messages.printNofFoundMessage("Report", parameter);
                             } else {
                                 Messages.printMessage(ex.getMessage());
                             }
                         }
                     }
                 } else {
-                    System.out.println(readErrorMessage);
+                    Messages.printCommandOptionMessage(readErrorMessage);
                 }
                 break;
             case DELETE:
-                final String deleteErrorMessage = Messages.optionCommandMessage(
-                        "Usage: report --execute {REPORT-ID}");
+                final String deleteErrorMessage = "report --execute {REPORT-ID}";
 
                 if (parameters.length == 1) {
                     for (final String parameter : parameters) {
                         try {
                             reportService.delete(Long.valueOf(parameter));
-                            System.out.println(" - Report " + parameter + " deleted!");
+                            Messages.printDeletedMessage("Report", parameter);
                         } catch (final WebServiceException | SyncopeClientException ex) {
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage("Report " + parameter + " doesn't exists!");
+                                Messages.printNofFoundMessage("Report", parameter);
                             } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
                                 Messages.printMessage("You cannot delete report " + parameter);
                             } else {
@@ -153,12 +151,11 @@ public class ReportCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(deleteErrorMessage);
+                    Messages.printCommandOptionMessage(deleteErrorMessage);
                 }
                 break;
             case EXECUTE:
-                final String executeErrorMessage = Messages.optionCommandMessage(
-                        "Usage: report --execute {REPORT-ID}");
+                final String executeErrorMessage = "Usage: report --execute {REPORT-ID}";
 
                 if (parameters.length == 1) {
 
@@ -174,7 +171,7 @@ public class ReportCommand extends AbstractCommand {
                     } catch (final WebServiceException | SyncopeClientException ex) {
                         System.out.println("Error:");
                         if (ex.getMessage().startsWith("NotFound")) {
-                            Messages.printMessage("Report " + parameters[0] + " doesn't exists!");
+                            Messages.printNofFoundMessage("Report", parameters[0]);
                         } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
                             Messages.printMessage("You cannot delete report " + parameters[0]);
                         } else {
@@ -185,12 +182,11 @@ public class ReportCommand extends AbstractCommand {
                                 "Error reading " + parameters[0] + ". It isn't a valid report id");
                     }
                 } else {
-                    System.out.println(executeErrorMessage);
+                    Messages.printCommandOptionMessage(executeErrorMessage);
                 }
                 break;
             case READ_EXECUTION:
-                final String readExecutionErrorMessage = Messages.optionCommandMessage(
-                        "Usage: report --read-execution {EXECUTION-ID} {EXECUTION-ID} [...]");
+                final String readExecutionErrorMessage = "report --read-execution {EXECUTION-ID} {EXECUTION-ID} [...]";
 
                 if (parameters.length >= 1) {
                     for (final String parameter : parameters) {
@@ -204,9 +200,7 @@ public class ReportCommand extends AbstractCommand {
                         } catch (final WebServiceException | SyncopeClientException ex) {
                             System.out.println("Error:");
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage(" - Report " + parameter + " doesn't exists!");
-                            } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
-                                Messages.printMessage("You cannot delete report " + parameter);
+                                Messages.printNofFoundMessage("Report", parameter);
                             } else {
                                 Messages.printMessage(ex.getMessage());
                             }
@@ -216,23 +210,22 @@ public class ReportCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(readExecutionErrorMessage);
+                    Messages.printCommandOptionMessage(readExecutionErrorMessage);
                 }
                 break;
             case DELETE_EXECUTION:
-                final String deleteExecutionErrorMessage = Messages.optionCommandMessage(
-                        "Usage: report --delete-execution {EXECUTION-ID} {EXECUTION-ID} [...]");
+                final String deleteExecutionErrorMessage
+                        = "report --delete-execution {EXECUTION-ID} {EXECUTION-ID} [...]";
 
                 if (parameters.length >= 1) {
                     for (final String parameter : parameters) {
 
                         try {
                             reportService.deleteExecution(Long.valueOf(parameter));
-                            System.out.println(" - Report execution " + parameter + "successfully deleted!");
+                            Messages.printDeletedMessage("Report execution", parameter);
                         } catch (final WebServiceException | SyncopeClientException ex) {
-                            System.out.println("Error:");
                             if (ex.getMessage().startsWith("NotFound")) {
-                                System.out.println(" - Report " + parameter + " doesn't exists!");
+                                Messages.printNofFoundMessage("Report", parameter);
                             } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
                                 System.out.println(" - You cannot delete report " + parameter);
                             } else {
@@ -243,13 +236,13 @@ public class ReportCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(deleteExecutionErrorMessage);
+                    Messages.printCommandOptionMessage(deleteExecutionErrorMessage);
                 }
                 break;
             case EXPORT_EXECUTION_RESULT:
-                final String exportExecutionErrorMessage = Messages.optionCommandMessage(
-                        "Usage: report --export-execution-result {EXECUTION-ID} {EXECUTION-ID} [...] {FORMAT}\n"
-                        + "          Format: CSV / HTML / PDF / XML / RTF");
+                final String exportExecutionErrorMessage
+                        = "Usage: report --export-execution-result {EXECUTION-ID} {EXECUTION-ID} [...] {FORMAT}\n"
+                        + "          Format: CSV / HTML / PDF / XML / RTF";
 
                 if (parameters.length >= 2) {
                     parameters = Arrays.copyOf(parameters, parameters.length - 1);
@@ -282,11 +275,8 @@ public class ReportCommand extends AbstractCommand {
                                     break;
                             }
                         } catch (final WebServiceException | SyncopeClientException ex) {
-                            System.out.println("Error:");
                             if (ex.getMessage().startsWith("NotFound")) {
-                                Messages.printMessage("Report " + parameter + " doesn't exists!");
-                            } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
-                                System.out.println(" - You cannot delete report " + parameter);
+                                Messages.printNofFoundMessage("Report", parameter);
                             } else {
                                 System.out.println(ex.getMessage());
                             }
@@ -306,7 +296,7 @@ public class ReportCommand extends AbstractCommand {
                         }
                     }
                 } else {
-                    System.out.println(exportExecutionErrorMessage);
+                    Messages.printCommandOptionMessage(exportExecutionErrorMessage);
                 }
                 break;
             case HELP:
@@ -318,7 +308,7 @@ public class ReportCommand extends AbstractCommand {
                 System.out.println(HELP_MESSAGE);
         }
     }
-    
+
     @Override
     public String getHelpMessage() {
         return HELP_MESSAGE;
@@ -359,7 +349,7 @@ public class ReportCommand extends AbstractCommand {
             }
             return optionToReturn;
         }
-        
+
         public static List<String> toList() {
             final List<String> options = new ArrayList<>();
             for (final Options value : values()) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/e98d2b25/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java
index 3b9cf18..28e66de 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/SchemaCommand.java
@@ -69,9 +69,8 @@ public class SchemaCommand extends AbstractCommand {
         final SchemaService schemaService = SyncopeServices.get(SchemaService.class);
         switch (Options.fromName(input.getOption())) {
             case LIST:
-                final String listErrorMessage = Messages.optionCommandMessage(
-                        "schema --list {SCHEMA-TYPE}\n"
-                        + "   Schema type: PLAIN / DERIVED / VIRTUAL");
+                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());
@@ -107,7 +106,7 @@ public class SchemaCommand extends AbstractCommand {
                         System.out.println("");
                     }
                 } else {
-                    System.out.println(listErrorMessage);
+                    Messages.printCommandOptionMessage(listErrorMessage);
                 }
                 break;
             case LIST_ALL:
@@ -163,9 +162,8 @@ public class SchemaCommand extends AbstractCommand {
                 }
                 break;
             case READ:
-                final String readErrorMessage = Messages.optionCommandMessage(
-                        "schema --read {SCHEMA-TYPE} {SCHEMA-KEY}\n"
-                        + "   Schema type: PLAIN / DERIVED / VIRTUAL");
+                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 {
@@ -214,10 +212,7 @@ public class SchemaCommand extends AbstractCommand {
                         }
                     } catch (final SyncopeClientException | WebServiceException ex) {
                         if (ex.getMessage().startsWith("NotFound")) {
-                            Messages.printMessage(
-                                    "Schema " + parameters[0] + " doesn't exists!");
-                        } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
-                            Messages.printMessage("You cannot delete schema " + parameters[0]);
+                            Messages.printNofFoundMessage("Schema", parameters[0]);
                         } else {
                             Messages.printMessage(ex.getMessage());
                         }
@@ -230,23 +225,22 @@ public class SchemaCommand extends AbstractCommand {
                         System.out.println("");
                     }
                 } else {
-                    System.out.println(readErrorMessage);
+                    Messages.printCommandOptionMessage(readErrorMessage);
                 }
                 break;
             case DELETE:
-                final String deleteErrorMessage = "Usage: schema --delete {SCHEMA-TYPE} {SCHEMA-KEY}\n"
+                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);
-                            System.out.println("Schema " + parameter + " successfully deleted!");
+                            Messages.printDeletedMessage("Schema", parameter);
                         }
                     } catch (final SyncopeClientException | WebServiceException ex) {
                         if (ex.getMessage().startsWith("NotFound")) {
-                            Messages.printMessage(
-                                    "Schema " + parameters[0] + " doesn't exists!");
+                            Messages.printNofFoundMessage("Schema", parameters[0]);
                         } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
                             Messages.printMessage(
                                     "You cannot delete schema " + parameters[0]);
@@ -262,7 +256,7 @@ public class SchemaCommand extends AbstractCommand {
                         System.out.println("");
                     }
                 } else {
-                    System.out.println(deleteErrorMessage);
+                    Messages.printCommandOptionMessage(deleteErrorMessage);
                 }
                 break;
             case HELP:

http://git-wip-us.apache.org/repos/asf/syncope/blob/e98d2b25/client/cli/src/main/java/org/apache/syncope/client/cli/messages/Messages.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/messages/Messages.java b/client/cli/src/main/java/org/apache/syncope/client/cli/messages/Messages.java
index 9be3813..d1a9fdc 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/messages/Messages.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/messages/Messages.java
@@ -22,8 +22,12 @@ public final class Messages {
 
     private static final String OPTION_COMMAND_MESSAGE_TEMPLATE = "\n - Usage: %s\n";
 
-    public static String optionCommandMessage(final String message) {
-        return String.format(OPTION_COMMAND_MESSAGE_TEMPLATE, message);
+    private static final String DELETED_MESSAGE_TEMPLATE = "%s %s successfully deleted";
+
+    private static final String DOESNT_EXIST_MESSAGE_TEMPLATE = "%s %s doesn't exist";
+
+    public static void printCommandOptionMessage(final String message) {
+        System.out.println(String.format(OPTION_COMMAND_MESSAGE_TEMPLATE, message));
     }
 
     public static void printMessage(final String... messages) {
@@ -34,6 +38,14 @@ public final class Messages {
         System.out.println(messageBuilder.toString());
     }
 
+    public static void printNofFoundMessage(final String what, final String key) {
+        printMessage(String.format(DOESNT_EXIST_MESSAGE_TEMPLATE, what, key));
+    }
+
+    public static void printDeletedMessage(final String what, final String key) {
+        printMessage(String.format(DELETED_MESSAGE_TEMPLATE, what, key));
+    }
+
     private Messages() {
 
     }


Mime
View raw message