syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ilgro...@apache.org
Subject [06/12] syncope git commit: Fixed #SYNCOPE-587
Date Mon, 26 Jan 2015 14:48:12 GMT
Fixed #SYNCOPE-587


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

Branch: refs/heads/2_0_X
Commit: f32528c1fb798ec51a6da7a43abaa1f52b1efe28
Parents: 344a940
Author: massi <massimiliano.perrone@tirasa.net>
Authored: Mon Jan 26 15:41:01 2015 +0100
Committer: massi <massimiliano.perrone@tirasa.net>
Committed: Mon Jan 26 15:41:01 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/syncope/cli/SyncopeAdm.java |  29 ++-
 .../syncope/cli/commands/AbstractCommand.java   |   7 +-
 .../cli/commands/ConfigurationCommand.java      |  27 +--
 .../syncope/cli/commands/LoggerCommand.java     |  59 +++---
 .../cli/commands/NotificationCommand.java       |  95 +++++++++
 .../syncope/cli/commands/PolicyCommand.java     | 107 ++++++++++
 .../syncope/cli/commands/ReportCommand.java     | 195 +++++++++++++++++++
 .../org/apache/syncope/cli/util/XmlUtils.java   |  28 +++
 cli/src/main/resources/syncope.properties       |   4 +-
 .../core/services/ReportServiceImpl.java        |   2 +-
 10 files changed, 504 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/f32528c1/cli/src/main/java/org/apache/syncope/cli/SyncopeAdm.java
----------------------------------------------------------------------
diff --git a/cli/src/main/java/org/apache/syncope/cli/SyncopeAdm.java b/cli/src/main/java/org/apache/syncope/cli/SyncopeAdm.java
index 296614f..da87d46 100644
--- a/cli/src/main/java/org/apache/syncope/cli/SyncopeAdm.java
+++ b/cli/src/main/java/org/apache/syncope/cli/SyncopeAdm.java
@@ -22,6 +22,9 @@ import com.beust.jcommander.JCommander;
 import com.beust.jcommander.ParameterException;
 import org.apache.syncope.cli.commands.ConfigurationCommand;
 import org.apache.syncope.cli.commands.LoggerCommand;
+import org.apache.syncope.cli.commands.NotificationCommand;
+import org.apache.syncope.cli.commands.PolicyCommand;
+import org.apache.syncope.cli.commands.ReportCommand;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -32,7 +35,10 @@ public class SyncopeAdm {
     private static final String helpMessage = "Usage: Main [options]\n"
             + "  Options:\n"
             + "    logger --help \n"
-            + "    config --help \n";
+            + "    config --help \n"
+            + "    notification --help \n"
+            + "    report --help \n"
+            + "    policy --help \n";
 
     private static final JCommander jcommander = new JCommander();
 
@@ -40,6 +46,12 @@ public class SyncopeAdm {
 
     private static ConfigurationCommand configurationCommand;
 
+    private static NotificationCommand notificationCommand;
+
+    private static ReportCommand reportCommand;
+
+    private static PolicyCommand policyCommand;
+
     public static void main(final String[] args) {
         LOG.debug("Starting with args \n");
 
@@ -71,6 +83,15 @@ public class SyncopeAdm {
         configurationCommand = new ConfigurationCommand();
         jcommander.addCommand(configurationCommand);
         LOG.debug("Added ConfigurationCommand");
+        notificationCommand = new NotificationCommand();
+        jcommander.addCommand(notificationCommand);
+        LOG.debug("Added NotificationCommand");
+        reportCommand = new ReportCommand();
+        jcommander.addCommand(reportCommand);
+        LOG.debug("Added ReportCommand");
+        policyCommand = new PolicyCommand();
+        jcommander.addCommand(policyCommand);
+        LOG.debug("Added PolicyCommand");
     }
 
     private static void executeCommand() {
@@ -82,6 +103,12 @@ public class SyncopeAdm {
             loggerCommand.execute();
         } else if ("config".equalsIgnoreCase(command)) {
             configurationCommand.execute();
+        } else if ("notification".equalsIgnoreCase(command)) {
+            notificationCommand.execute();
+        } else if ("report".equalsIgnoreCase(command)) {
+            reportCommand.execute();
+        } else if ("policy".equalsIgnoreCase(command)) {
+            policyCommand.execute();
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/f32528c1/cli/src/main/java/org/apache/syncope/cli/commands/AbstractCommand.java
----------------------------------------------------------------------
diff --git a/cli/src/main/java/org/apache/syncope/cli/commands/AbstractCommand.java b/cli/src/main/java/org/apache/syncope/cli/commands/AbstractCommand.java
index 290f974..e7cddd4 100644
--- a/cli/src/main/java/org/apache/syncope/cli/commands/AbstractCommand.java
+++ b/cli/src/main/java/org/apache/syncope/cli/commands/AbstractCommand.java
@@ -24,6 +24,9 @@ public abstract class AbstractCommand {
 
     @Parameter(names = {"-h", "--help"})
     protected boolean help = false;
-    
-    public abstract void execute();
+
+    @Parameter(names = {"-l", "--list"})
+    protected boolean list = false;
+
+    protected abstract void execute();
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/f32528c1/cli/src/main/java/org/apache/syncope/cli/commands/ConfigurationCommand.java
----------------------------------------------------------------------
diff --git a/cli/src/main/java/org/apache/syncope/cli/commands/ConfigurationCommand.java b/cli/src/main/java/org/apache/syncope/cli/commands/ConfigurationCommand.java
index f0f54ee..5aea462 100644
--- a/cli/src/main/java/org/apache/syncope/cli/commands/ConfigurationCommand.java
+++ b/cli/src/main/java/org/apache/syncope/cli/commands/ConfigurationCommand.java
@@ -21,22 +21,16 @@ package org.apache.syncope.cli.commands;
 import com.beust.jcommander.DynamicParameter;
 import com.beust.jcommander.Parameter;
 import com.beust.jcommander.Parameters;
-import java.io.File;
 import java.io.IOException;
 import java.io.SequenceInputStream;
-import java.io.StringReader;
 import java.util.HashMap;
 import java.util.Map;
-import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.cxf.helpers.IOUtils;
 import org.apache.syncope.cli.SyncopeServices;
+import org.apache.syncope.cli.util.XmlUtils;
 import org.apache.syncope.common.SyncopeClientException;
 import org.apache.syncope.common.services.ConfigurationService;
 import org.apache.syncope.common.to.AttributeTO;
@@ -45,7 +39,6 @@ import org.apache.syncope.common.wrap.MailTemplate;
 import org.apache.syncope.common.wrap.Validator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 @Parameters(
@@ -78,9 +71,6 @@ public class ConfigurationCommand extends AbstractCommand {
             + "    -e, --export \n"
             + "       Syntax: -e={WHERE-DIR} \n";
 
-    @Parameter(names = {"-l", "--list"})
-    public boolean list = false;
-
     @Parameter(names = {"-r", "--read"})
     public String confNameToRead;
 
@@ -171,8 +161,9 @@ public class ConfigurationCommand extends AbstractCommand {
         } else if (validators) {
             LOG.debug("- configuration validators command");
             try {
+                System.out.println("Conf validator class: ");
                 for (final Validator validator : configurationService.getValidators()) {
-                    System.out.println(" - Conf validator class: " + validator.getElement());
+                    System.out.println("  *** " + validator.getElement());
                 }
             } catch (final SyncopeClientException ex) {
                 System.out.println(" - Error: " + ex.getMessage());
@@ -180,9 +171,9 @@ public class ConfigurationCommand extends AbstractCommand {
         } else if (mailTemplates) {
             LOG.debug("- configuration mailTemplates command");
             try {
-                System.out.println(" - Conf mail template for:");
+                System.out.println("Conf mail template for:");
                 for (final MailTemplate mailTemplate : configurationService.getMailTemplates())
{
-                    System.out.println("    *** " + mailTemplate.getElement());
+                    System.out.println("  *** " + mailTemplate.getElement());
                 }
             } catch (final SyncopeClientException ex) {
                 System.out.println(" - Error: " + ex.getMessage());
@@ -191,12 +182,8 @@ public class ConfigurationCommand extends AbstractCommand {
             LOG.debug("- configuration export command, directory where xml will be export:
{}", export);
 
             try {
-                TransformerFactory.newInstance().newTransformer()
-                        .transform(new DOMSource(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
-                                                new InputSource(new StringReader(IOUtils.toString(
-                                                                        (SequenceInputStream)
configurationService.
-                                                                        export().getEntity()))))),
-                                new StreamResult(new File(export + EXPORT_FILE_NAME)));
+                XmlUtils.createXMLFile((SequenceInputStream) configurationService.export().getEntity(),
export
+                        + EXPORT_FILE_NAME);
                 System.out.println(" - " + export + EXPORT_FILE_NAME + " successfully created");
             } catch (final IOException ex) {
                 LOG.error("Error creating content.xml file in {} directory", export, ex);

http://git-wip-us.apache.org/repos/asf/syncope/blob/f32528c1/cli/src/main/java/org/apache/syncope/cli/commands/LoggerCommand.java
----------------------------------------------------------------------
diff --git a/cli/src/main/java/org/apache/syncope/cli/commands/LoggerCommand.java b/cli/src/main/java/org/apache/syncope/cli/commands/LoggerCommand.java
index e4d3a1c..f6007dd 100644
--- a/cli/src/main/java/org/apache/syncope/cli/commands/LoggerCommand.java
+++ b/cli/src/main/java/org/apache/syncope/cli/commands/LoggerCommand.java
@@ -25,7 +25,6 @@ import java.util.HashMap;
 import java.util.Map;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.cli.SyncopeServices;
-import org.apache.syncope.cli.validators.DebugLevelValidator;
 import org.apache.syncope.common.SyncopeClientException;
 import org.apache.syncope.common.services.LoggerService;
 import org.apache.syncope.common.to.LoggerTO;
@@ -60,19 +59,16 @@ public class LoggerCommand extends AbstractCommand {
             + "    -d, --delete \n"
             + "       Syntax: -d={LOG-NAME}";
 
-    @Parameter(names = {"-l", "--list"})
-    public boolean list = false;
-
     @Parameter(names = {"-r", "--read"})
     public String logNameToRead;
 
     @DynamicParameter(names = {"-u", "--update"})
     private final Map<String, String> updateLogs = new HashMap<String, String>();
 
-    @Parameter(names = {"-ua", "--update-all"}, validateWith = DebugLevelValidator.class)
+    @Parameter(names = {"-ua", "--update-all"})
     public String logLevel;
 
-    @DynamicParameter(names = {"-u", "--update"})
+    @DynamicParameter(names = {"-c", "--create"})
     private final Map<String, String> createLogs = new HashMap<String, String>();
 
     @Parameter(names = {"-d", "--delete"})
@@ -106,40 +102,57 @@ public class LoggerCommand extends AbstractCommand {
             }
         } else if (!updateLogs.isEmpty()) {
             LOG.debug("- logger update command with params {}", updateLogs);
-            try {
-                for (final Map.Entry<String, String> entrySet : updateLogs.entrySet())
{
-                    final LoggerTO loggerTO = loggerService.read(LoggerType.LOG, entrySet.getKey());
-                    loggerTO.setLevel(LoggerLevel.valueOf(entrySet.getValue()));
+
+            for (final Map.Entry<String, String> log : updateLogs.entrySet()) {
+                final LoggerTO loggerTO = loggerService.read(LoggerType.LOG, log.getKey());
+                try {
+                    loggerTO.setLevel(LoggerLevel.valueOf(log.getValue()));
                     loggerService.update(LoggerType.LOG, loggerTO.getName(), loggerTO);
                     System.out.println(" - Logger " + loggerTO.getName() + " new level ->
" + loggerTO.getLevel());
+                } catch (final SyncopeClientException ex) {
+                    System.out.println(" - Error: " + ex.getMessage());
+                } catch (final IllegalArgumentException ex) {
+                    System.out.println(" - Error: " + log.getValue() + " isn't a valid logger
level, try with:");
+                    for (final LoggerLevel level : LoggerLevel.values()) {
+                        System.out.println("  *** " + level.name());
+                    }
                 }
-            } catch (final SyncopeClientException ex) {
-                System.out.println(" - Error: " + ex.getMessage());
             }
         } else if (StringUtils.isNotBlank(logLevel)) {
             LOG.debug("- logger update all command with level {}", logLevel);
-            try {
-
-                for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) {
+            for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) {
+                try {
                     loggerTO.setLevel(LoggerLevel.valueOf(logLevel));
                     loggerService.update(LoggerType.LOG, loggerTO.getName(), loggerTO);
                     System.out.println(" - Logger " + loggerTO.getName() + " new level ->
" + loggerTO.getLevel());
+                } catch (final SyncopeClientException ex) {
+                    System.out.println(" - Error: " + ex.getMessage());
+                } catch (final IllegalArgumentException ex) {
+                    System.out.println(" - Error: " + loggerTO.getLevel() + " isn't a valid
logger level, try with:");
+                    for (final LoggerLevel level : LoggerLevel.values()) {
+                        System.out.println("  *** " + level.name());
+                    }
                 }
-            } catch (final SyncopeClientException ex) {
-                System.out.println(" - Error: " + ex.getMessage());
             }
         } else if (!createLogs.isEmpty()) {
             LOG.debug("- logger create command with params {}", createLogs);
-            try {
-                for (final Map.Entry<String, String> entrySet : createLogs.entrySet())
{
-                    final LoggerTO loggerTO = new LoggerTO();
+
+            for (final Map.Entry<String, String> entrySet : createLogs.entrySet())
{
+                final LoggerTO loggerTO = new LoggerTO();
+                try {
                     loggerTO.setName(entrySet.getKey());
                     loggerTO.setLevel(LoggerLevel.valueOf(entrySet.getValue()));
                     loggerService.update(LoggerType.LOG, loggerTO.getName(), loggerTO);
-                    System.out.println(" - Logger " + loggerTO.getName() + " created with
level -> " + loggerTO.getLevel());
+                    System.out.println(" - Logger " + loggerTO.getName() + " created with
level -> " + loggerTO.
+                            getLevel());
+                } catch (final SyncopeClientException ex) {
+                    System.out.println(" - Error: " + ex.getMessage());
+                } catch (final IllegalArgumentException ex) {
+                    System.out.println(" - Error: " + loggerTO.getLevel() + " isn't a valid
logger level, try with:");
+                    for (final LoggerLevel level : LoggerLevel.values()) {
+                        System.out.println("  *** " + level.name());
+                    }
                 }
-            } catch (final SyncopeClientException ex) {
-                System.out.println(" - Error: " + ex.getMessage());
             }
         } else if (StringUtils.isNotBlank(logNameToDelete)) {
             try {

http://git-wip-us.apache.org/repos/asf/syncope/blob/f32528c1/cli/src/main/java/org/apache/syncope/cli/commands/NotificationCommand.java
----------------------------------------------------------------------
diff --git a/cli/src/main/java/org/apache/syncope/cli/commands/NotificationCommand.java b/cli/src/main/java/org/apache/syncope/cli/commands/NotificationCommand.java
new file mode 100644
index 0000000..fdc0d37
--- /dev/null
+++ b/cli/src/main/java/org/apache/syncope/cli/commands/NotificationCommand.java
@@ -0,0 +1,95 @@
+/*
+ * 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.cli.commands;
+
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.Parameters;
+import org.apache.syncope.cli.SyncopeServices;
+import org.apache.syncope.common.SyncopeClientException;
+import org.apache.syncope.common.services.NotificationService;
+import org.apache.syncope.common.to.NotificationTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Parameters(
+        commandNames = "notification",
+        optionPrefixes = "-",
+        separators = "=",
+        commandDescription = "Apache Syncope notification service")
+public class NotificationCommand extends AbstractCommand {
+
+    private static final Logger LOG = LoggerFactory.getLogger(NotificationCommand.class);
+
+    private static final Class SYNCOPE_NOTIFICATION_CLASS = NotificationService.class;
+
+    private final String helpMessage = "Usage: notification [options]\n"
+            + "  Options:\n"
+            + "    -h, --help \n"
+            + "    -l, --list \n"
+            + "    -r, --read \n"
+            + "       Syntax: -r={NOTIFICATION-ID} \n"
+            + "    -d, --delete \n"
+            + "       Syntax: -d={NOTIFICATION-ID}";
+
+    @Parameter(names = {"-r", "--read"})
+    public Long notificationIdToRead = -1L;
+
+    @Parameter(names = {"-d", "--delete"})
+    public Long notificationIdToDelete = -1L;
+
+    @Override
+    public void execute() {
+        final NotificationService notificationService = ((NotificationService) SyncopeServices.get(
+                SYNCOPE_NOTIFICATION_CLASS));
+
+        LOG.debug("Notification service successfully created");
+
+        if (help) {
+            LOG.debug("- notification help command");
+            System.out.println(helpMessage);
+        } else if (list) {
+            LOG.debug("- notification list command");
+            try {
+                for (final NotificationTO notificationTO : notificationService.list()) {
+                    System.out.println(notificationTO);
+                }
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            }
+        } else if (notificationIdToRead > -1L) {
+            LOG.debug("- notification read {} command", notificationIdToRead);
+            try {
+                System.out.println(notificationService.read(notificationIdToRead));
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            }
+        } else if (notificationIdToDelete > -1L) {
+            try {
+                LOG.debug("- notification delete {} command", notificationIdToDelete);
+                notificationService.delete(notificationIdToDelete);
+                System.out.println(" - Notification " + notificationIdToDelete + " deleted!");
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            }
+        } else {
+            System.out.println(helpMessage);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/f32528c1/cli/src/main/java/org/apache/syncope/cli/commands/PolicyCommand.java
----------------------------------------------------------------------
diff --git a/cli/src/main/java/org/apache/syncope/cli/commands/PolicyCommand.java b/cli/src/main/java/org/apache/syncope/cli/commands/PolicyCommand.java
new file mode 100644
index 0000000..d1574eb
--- /dev/null
+++ b/cli/src/main/java/org/apache/syncope/cli/commands/PolicyCommand.java
@@ -0,0 +1,107 @@
+/*
+ * 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.cli.commands;
+
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.Parameters;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.cli.SyncopeServices;
+import org.apache.syncope.common.SyncopeClientException;
+import org.apache.syncope.common.services.PolicyService;
+import org.apache.syncope.common.to.AbstractPolicyTO;
+import org.apache.syncope.common.types.PolicyType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Parameters(
+        commandNames = "policy",
+        optionPrefixes = "-",
+        separators = "=",
+        commandDescription = "Apache Syncope policy service")
+public class PolicyCommand extends AbstractCommand {
+
+    private static final Logger LOG = LoggerFactory.getLogger(PolicyCommand.class);
+
+    private static final Class SYNCOPE_POLICY_CLASS = PolicyService.class;
+
+    private final String helpMessage = "Usage: policy [options]\n"
+            + "  Options:\n"
+            + "    -h, --help \n"
+            + "    -l, --list \n"
+            + "    -ll, --list-policy \n"
+            + "       Syntax: -ll={POLICY-TYPE} \n"
+            + "    -r, --read \n"
+            + "       Syntax: -r={POLICY-ID} \n"
+            + "    -d, --delete \n"
+            + "       Syntax: -d={POLICY-ID}";
+
+    @Parameter(names = {"-ll", "--list-policy"})
+    public String policyType;
+
+    @Parameter(names = {"-r", "--read"})
+    public Long policyIdToRead = -1L;
+
+    @Parameter(names = {"-d", "--delete"})
+    public Long policyIdToDelete = -1L;
+
+    @Override
+    public void execute() {
+        final PolicyService policyService = (PolicyService) SyncopeServices.get(SYNCOPE_POLICY_CLASS);
+        LOG.debug("Policy service successfully created");
+
+        if (help) {
+            LOG.debug("- policy help command");
+            System.out.println(helpMessage);
+        } else if (list) {
+
+        } else if (StringUtils.isNotBlank(policyType)) {
+            LOG.debug("- policy list command for type {}", policyType);
+            try {
+                for (final AbstractPolicyTO policyTO : policyService.list(PolicyType.valueOf(policyType)))
{
+                    System.out.println(policyTO);
+                }
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            } catch (final IllegalArgumentException ex) {
+                System.out.println(" - Error: " + policyType + " isn't a valid policy type,
try with:");
+                for (final PolicyType type : PolicyType.values()) {
+                    System.out.println("  *** " + type.name() + ": " + type.getDescription());
+                }
+            }
+        } else if (policyIdToRead > -1L) {
+            LOG.debug("- policy read {} command", policyIdToRead);
+            try {
+                System.out.println(policyService.read(policyIdToRead));
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            }
+        } else if (policyIdToDelete > -1L) {
+            try {
+                LOG.debug("- policy delete {} command", policyIdToDelete);
+                policyService.delete(policyIdToDelete);
+                System.out.println(" - Report " + policyIdToDelete + " deleted!");
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            }
+        } else {
+            System.out.println(helpMessage);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/f32528c1/cli/src/main/java/org/apache/syncope/cli/commands/ReportCommand.java
----------------------------------------------------------------------
diff --git a/cli/src/main/java/org/apache/syncope/cli/commands/ReportCommand.java b/cli/src/main/java/org/apache/syncope/cli/commands/ReportCommand.java
new file mode 100644
index 0000000..721503b
--- /dev/null
+++ b/cli/src/main/java/org/apache/syncope/cli/commands/ReportCommand.java
@@ -0,0 +1,195 @@
+/*
+ * 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.cli.commands;
+
+import com.beust.jcommander.Parameter;
+import com.beust.jcommander.Parameters;
+import java.io.IOException;
+import java.io.SequenceInputStream;
+import java.util.List;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import org.apache.syncope.cli.SyncopeServices;
+import org.apache.syncope.cli.util.XmlUtils;
+import org.apache.syncope.common.SyncopeClientException;
+import org.apache.syncope.common.services.ReportService;
+import org.apache.syncope.common.to.ReportExecTO;
+import org.apache.syncope.common.to.ReportTO;
+import org.apache.syncope.common.types.ReportExecExportFormat;
+import org.apache.syncope.common.wrap.ReportletConfClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXException;
+
+@Parameters(
+        commandNames = "report",
+        optionPrefixes = "-",
+        separators = "=",
+        commandDescription = "Apache Syncope report service")
+public class ReportCommand extends AbstractCommand {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ReportCommand.class);
+
+    private static final Class SYNCOPE_REPORT_CLASS = ReportService.class;
+
+    private final String helpMessage = "Usage: report [options]\n"
+            + "  Options:\n"
+            + "    -h, --help \n"
+            + "    -l, --list \n"
+            + "    -r, --read \n"
+            + "       Syntax: -r={POLICY-ID} \n"
+            + "    -d, --delete \n"
+            + "       Syntax: -d={POLICY-ID} \n"
+            + "    -e, --execute \n"
+            + "       Syntax: -e={POLICY-ID} \n"
+            + "    -re, --read-executecution \n"
+            + "       Syntax: -re={EXECUTION-ID} \n"
+            + "    -de, --delete-executecution \n"
+            + "       Syntax: -de={EXECUTION-ID} \n"
+            + "    -eer, --export-executecution-result \n"
+            + "       Syntax: -eer={EXECUTION-ID} \n"
+            + "    -rc, --reportlet-class";
+
+    @Parameter(names = {"-r", "--read"})
+    public Long reportIdToRead = -1L;
+
+    @Parameter(names = {"-d", "--delete"})
+    public Long reportIdToDelete = -1L;
+
+    @Parameter(names = {"-e", "--execute"})
+    public Long reportIdToExecute = -1L;
+
+    @Parameter(names = {"-re", "--read-execution"})
+    public Long executionIdToRead = -1L;
+
+    @Parameter(names = {"-de", "--delete-execution"})
+    public Long executionIdToDelete = -1L;
+
+    @Parameter(names = {"-eer", "--export-execution-result"})
+    public Long exportId = -1L;
+
+    @Parameter(names = {"-rc", "--reportlet-class"})
+    public boolean reportletClass = false;
+
+    @Override
+    public void execute() {
+        final ReportService reportService = (ReportService) SyncopeServices.get(SYNCOPE_REPORT_CLASS);
+        LOG.debug("Report service successfully created");
+
+        if (help) {
+            LOG.debug("- report help command");
+            System.out.println(helpMessage);
+        } else if (list) {
+            LOG.debug("- report list command");
+            try {
+                for (final ReportTO reportTO : reportService.list().getResult()) {
+                    System.out.println(reportTO);
+                }
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            }
+        } else if (reportIdToRead > -1L) {
+            LOG.debug("- report read {} command", reportIdToRead);
+            try {
+                System.out.println(reportService.read(reportIdToRead));
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            }
+        } else if (reportIdToDelete > -1L) {
+            try {
+                LOG.debug("- report delete {} command", reportIdToDelete);
+                reportService.delete(reportIdToDelete);
+                System.out.println(" - Report " + reportIdToDelete + " deleted!");
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            }
+        } else if (reportIdToExecute > -1L) {
+            try {
+                LOG.debug("- report execute {} command", reportIdToExecute);
+                reportService.execute(reportIdToExecute);
+                final List<ReportExecTO> executionList = reportService.read(reportIdToExecute).getExecutions();
+                final ReportExecTO lastExecution = executionList.get(executionList.size()
- 1);
+                System.out.println(" - Report execution id: " + lastExecution.getId());
+                System.out.println(" - Report execution status: " + lastExecution.getStatus());
+                System.out.println(" - Report execution start date: " + lastExecution.getStartDate());
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            }
+        } else if (executionIdToRead > -1L) {
+            try {
+                LOG.debug("- report execution read {} command", executionIdToRead);
+                ReportExecTO reportExecTO = reportService.readExecution(executionIdToRead);
+                System.out.println(" - Report execution id: " + reportExecTO.getId());
+                System.out.println(" - Report execution status: " + reportExecTO.getStatus());
+                System.out.println(" - Report execution start date: " + reportExecTO.getStartDate());
+                System.out.println(" - Report execution end date: " + reportExecTO.getEndDate());
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            }
+        } else if (executionIdToDelete > -1L) {
+            try {
+                LOG.debug("- report execution delete {} command", executionIdToDelete);
+                reportService.deleteExecution(executionIdToDelete);
+                System.out.println(" - Report execution " + executionIdToDelete + "successfyllt
deleted!");
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            }
+        } else if (exportId > -1L) {
+            LOG.debug("- report export command for report: {}", exportId);
+
+            try {
+                XmlUtils.createXMLFile((SequenceInputStream) reportService.exportExecutionResult(exportId,
+                        ReportExecExportFormat.XML).getEntity(), "export_" + exportId + ".xml");
+                System.out.println(" - " + "export_" + exportId + " successfully created");
+            } catch (final IOException ex) {
+                LOG.error("Error creating xml file", ex);
+                System.out.println(" - Error creating " + "export_" + exportId + " " + ex.getMessage());
+            } catch (final ParserConfigurationException ex) {
+                LOG.error("Error creating xml file", ex);
+                System.out.println(" - Error creating " + "export_" + exportId + " " + ex.getMessage());
+            } catch (final SAXException ex) {
+                LOG.error("Error creating xml file", ex);
+                System.out.println(" - Error creating " + "export_" + exportId + " " + ex.getMessage());
+            } catch (final TransformerConfigurationException ex) {
+                LOG.error("Error creating xml file", ex);
+                System.out.println(" - Error creating " + "export_" + exportId + " " + ex.getMessage());
+            } catch (final TransformerException ex) {
+                LOG.error("Error creating xml file", ex);
+                System.out.println(" - Error creating export_" + exportId + " " + ex.getMessage());
+            } catch (final SyncopeClientException ex) {
+                LOG.error("Error calling configuration service", ex);
+                System.out.println(" - Error calling configuration service " + ex.getMessage());
+            }
+        } else if (reportletClass) {
+            try {
+                LOG.debug("- reportlet configuration class list command");
+                System.out.println("Reportlet conf classes");
+                for (final ReportletConfClass reportletConfClass : reportService.getReportletConfClasses())
{
+                    System.out.println("  *** " + reportletConfClass.getElement());
+                }
+            } catch (final SyncopeClientException ex) {
+                System.out.println(" - Error: " + ex.getMessage());
+            }
+        } else {
+            System.out.println(helpMessage);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/f32528c1/cli/src/main/java/org/apache/syncope/cli/util/XmlUtils.java
----------------------------------------------------------------------
diff --git a/cli/src/main/java/org/apache/syncope/cli/util/XmlUtils.java b/cli/src/main/java/org/apache/syncope/cli/util/XmlUtils.java
new file mode 100644
index 0000000..8da1fba
--- /dev/null
+++ b/cli/src/main/java/org/apache/syncope/cli/util/XmlUtils.java
@@ -0,0 +1,28 @@
+package org.apache.syncope.cli.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.SequenceInputStream;
+import java.io.StringReader;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import org.apache.cxf.helpers.IOUtils;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class XmlUtils {
+
+    public static void createXMLFile(SequenceInputStream sis, String filePath)
+            throws TransformerConfigurationException, TransformerException, SAXException,
IOException,
+            ParserConfigurationException {
+        TransformerFactory.newInstance().newTransformer()
+                .transform(new DOMSource(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
+                                        new InputSource(new StringReader(IOUtils.toString(sis))))),
+                        new StreamResult(new File(filePath)));
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/f32528c1/cli/src/main/resources/syncope.properties
----------------------------------------------------------------------
diff --git a/cli/src/main/resources/syncope.properties b/cli/src/main/resources/syncope.properties
index e9fd513..9f84a72 100644
--- a/cli/src/main/resources/syncope.properties
+++ b/cli/src/main/resources/syncope.properties
@@ -14,6 +14,6 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-syncope.rest.services=http://localhost:8080/syncope/rest/
+syncope.rest.services=http://localhost:9080/syncope/rest/
 syncope.user=admin
-syncope.password=password
\ No newline at end of file
+syncope.password=password

http://git-wip-us.apache.org/repos/asf/syncope/blob/f32528c1/core/src/main/java/org/apache/syncope/core/services/ReportServiceImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/syncope/core/services/ReportServiceImpl.java b/core/src/main/java/org/apache/syncope/core/services/ReportServiceImpl.java
index 05ec25b..afe4d8d 100644
--- a/core/src/main/java/org/apache/syncope/core/services/ReportServiceImpl.java
+++ b/core/src/main/java/org/apache/syncope/core/services/ReportServiceImpl.java
@@ -50,7 +50,7 @@ public class ReportServiceImpl extends AbstractServiceImpl implements ReportServ
         ReportTO createdReportTO = controller.create(reportTO);
         URI location = uriInfo.getAbsolutePathBuilder().path(String.valueOf(createdReportTO.getId())).build();
         return Response.created(location).
-                header(RESTHeaders.RESOURCE_ID.toString(), createdReportTO.getId()).
+                header(RESTHeaders.RESOURCE_ID, createdReportTO.getId()).
                 build();
     }
 


Mime
View raw message