You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by ma...@apache.org on 2015/01/26 15:41:43 UTC
[1/5] syncope git commit: Fixed #SYNCOPE-581
Repository: syncope
Updated Branches:
refs/heads/master 9df1e03de -> f32528c1f
Fixed #SYNCOPE-581
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/c6006673
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/c6006673
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/c6006673
Branch: refs/heads/master
Commit: c60066731b034948b0ea96fb50458cc90d41c2fd
Parents: e36a4a2
Author: massi <ma...@tirasa.net>
Authored: Fri Jan 23 16:37:13 2015 +0100
Committer: massi <ma...@tirasa.net>
Committed: Fri Jan 23 16:37:13 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/syncope/cli/SyncopeAdm.java | 19 +-
.../syncope/cli/commands/AbstractCommand.java | 11 +
.../cli/commands/ConfigurationCommand.java | 225 +++++++++++++++++++
.../syncope/cli/commands/LoggerCommand.java | 108 ++++++---
4 files changed, 324 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/c6006673/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 4e8966e..296614f 100644
--- a/cli/src/main/java/org/apache/syncope/cli/SyncopeAdm.java
+++ b/cli/src/main/java/org/apache/syncope/cli/SyncopeAdm.java
@@ -20,6 +20,7 @@ package org.apache.syncope.cli;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,11 +31,14 @@ public class SyncopeAdm {
private static final String helpMessage = "Usage: Main [options]\n"
+ " Options:\n"
- + " logger --help \n";
+ + " logger --help \n"
+ + " config --help \n";
+
+ private static final JCommander jcommander = new JCommander();
private static LoggerCommand loggerCommand;
- private static final JCommander jc = new JCommander();
+ private static ConfigurationCommand configurationCommand;
public static void main(final String[] args) {
LOG.debug("Starting with args \n");
@@ -49,7 +53,7 @@ public class SyncopeAdm {
System.out.println(helpMessage);
} else {
try {
- jc.parse(args);
+ jcommander.parse(args);
} catch (final ParameterException ioe) {
System.out.println(helpMessage);
LOG.error("Parameter exception", ioe);
@@ -62,17 +66,22 @@ public class SyncopeAdm {
private static void instantiateCommands() {
LOG.debug("Init JCommander");
loggerCommand = new LoggerCommand();
- jc.addCommand(loggerCommand);
+ jcommander.addCommand(loggerCommand);
LOG.debug("Added LoggerCommand");
+ configurationCommand = new ConfigurationCommand();
+ jcommander.addCommand(configurationCommand);
+ LOG.debug("Added ConfigurationCommand");
}
private static void executeCommand() {
- final String command = jc.getParsedCommand();
+ final String command = jcommander.getParsedCommand();
LOG.debug("Called command {}", command);
if ("logger".equalsIgnoreCase(command)) {
loggerCommand.execute();
+ } else if ("config".equalsIgnoreCase(command)) {
+ configurationCommand.execute();
}
}
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/c6006673/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
new file mode 100644
index 0000000..5dd3d38
--- /dev/null
+++ b/cli/src/main/java/org/apache/syncope/cli/commands/AbstractCommand.java
@@ -0,0 +1,11 @@
+package org.apache.syncope.cli.commands;
+
+import com.beust.jcommander.Parameter;
+
+public abstract class AbstractCommand {
+
+ @Parameter(names = {"-h", "--help"})
+ protected boolean help = false;
+
+ public abstract void execute();
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/c6006673/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
new file mode 100644
index 0000000..f0f54ee
--- /dev/null
+++ b/cli/src/main/java/org/apache/syncope/cli/commands/ConfigurationCommand.java
@@ -0,0 +1,225 @@
+/*
+ * 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.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.common.SyncopeClientException;
+import org.apache.syncope.common.services.ConfigurationService;
+import org.apache.syncope.common.to.AttributeTO;
+import org.apache.syncope.common.to.ConfTO;
+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(
+ commandNames = "config",
+ optionPrefixes = "-",
+ separators = "=",
+ commandDescription = "Apache Syncope configuration service")
+public class ConfigurationCommand extends AbstractCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ConfigurationCommand.class);
+
+ private static final Class SYNCOPE_CONFIGURATION_CLASS = ConfigurationService.class;
+
+ private static final String EXPORT_FILE_NAME = "/content.xml";
+
+ private final String helpMessage = "Usage: config [options]\n"
+ + " Options:\n"
+ + " -h, --help \n"
+ + " -l, --list \n"
+ + " -r, --read \n"
+ + " Syntax: -r={CONF-NAME} \n"
+ + " -u, --update \n"
+ + " Syntax: {CONF-NAME}={CONF-VALUE} \n"
+ + " -c, --create \n"
+ + " Syntax: {CONF-NAME}={CONF-VALUE} \n"
+ + " -d, --delete \n"
+ + " Syntax: -d={CONF-NAME}"
+ + " -v, --validators \n"
+ + " -mt, --mail-templates \n"
+ + " -e, --export \n"
+ + " Syntax: -e={WHERE-DIR} \n";
+
+ @Parameter(names = {"-l", "--list"})
+ public boolean list = false;
+
+ @Parameter(names = {"-r", "--read"})
+ public String confNameToRead;
+
+ @DynamicParameter(names = {"-u", "--update"})
+ private final Map<String, String> updateConf = new HashMap<String, String>();
+
+ @DynamicParameter(names = {"-c", "--create"})
+ private final Map<String, String> createConf = new HashMap<String, String>();
+
+ @Parameter(names = {"-d", "--delete"})
+ public String confNameToDelete;
+
+ @Parameter(names = {"-v", "--validators"})
+ public boolean validators = false;
+
+ @Parameter(names = {"-mt", "--mail-templates"})
+ public boolean mailTemplates = false;
+
+ @Parameter(names = {"-e", "--export"})
+ public String export;
+
+ @Override
+ public void execute() {
+ final ConfigurationService configurationService = ((ConfigurationService) SyncopeServices.
+ get(SYNCOPE_CONFIGURATION_CLASS));
+
+ LOG.debug("Logger service successfully created");
+
+ if (help) {
+ LOG.debug("- configuration help command");
+ System.out.println(helpMessage);
+ } else if (list) {
+ LOG.debug("- configuration list command");
+ try {
+ final ConfTO confTO = configurationService.list();
+ for (final AttributeTO attrTO : confTO.getAttrMap().values()) {
+ System.out.println(" - Conf " + attrTO.getSchema() + " has value(s) " + attrTO.getValues()
+ + " - readonly: " + attrTO.isReadonly());
+ }
+ } catch (final SyncopeClientException ex) {
+ System.out.println(" - Error: " + ex.getMessage());
+ }
+ } else if (StringUtils.isNotBlank(confNameToRead)) {
+ LOG.debug("- configuration read {} command", confNameToRead);
+ try {
+ final AttributeTO attrTO = configurationService.read(confNameToRead);
+ System.out.println(" - Conf " + attrTO.getSchema() + " has value(s) " + attrTO.getValues()
+ + " - readonly: " + attrTO.isReadonly());
+ } catch (final SyncopeClientException ex) {
+ System.out.println(" - Error: " + ex.getMessage());
+ }
+ } else if (!updateConf.isEmpty()) {
+ LOG.debug("- configuration update command with params {}", updateConf);
+ try {
+ for (final Map.Entry<String, String> entrySet : updateConf.entrySet()) {
+ final AttributeTO attrTO = configurationService.read(entrySet.getKey());
+ attrTO.getValues().clear();
+ attrTO.getValues().add(entrySet.getValue());
+ configurationService.set(entrySet.getKey(), attrTO);
+ System.out.println(" - Conf " + attrTO.getSchema() + " has value(s) " + attrTO.getValues()
+ + " - readonly: " + attrTO.isReadonly());
+ }
+ } catch (final SyncopeClientException ex) {
+ System.out.println(" - Error: " + ex.getMessage());
+ }
+ } else if (!createConf.isEmpty()) {
+ LOG.debug("- configuration create command with params {}", createConf);
+ try {
+ for (final Map.Entry<String, String> entrySet : createConf.entrySet()) {
+ final AttributeTO attrTO = new AttributeTO();
+ attrTO.setSchema(entrySet.getKey());
+ attrTO.getValues().add(entrySet.getValue());
+ configurationService.set(entrySet.getKey(), attrTO);
+ System.out.println(" - Conf " + attrTO.getSchema() + " created with value(s) " + attrTO.getValues()
+ + " - readonly: " + attrTO.isReadonly());
+ }
+ } catch (final SyncopeClientException ex) {
+ System.out.println(" - Error: " + ex.getMessage());
+ }
+ } else if (StringUtils.isNotBlank(confNameToDelete)) {
+ try {
+ LOG.debug("- configuration delete {} command", confNameToDelete);
+ configurationService.delete(confNameToDelete);
+ System.out.println(" - Conf " + confNameToDelete + " deleted!");
+ } catch (final SyncopeClientException ex) {
+ System.out.println(" - Error: " + ex.getMessage());
+ }
+ } else if (validators) {
+ LOG.debug("- configuration validators command");
+ try {
+ for (final Validator validator : configurationService.getValidators()) {
+ System.out.println(" - Conf validator class: " + validator.getElement());
+ }
+ } catch (final SyncopeClientException ex) {
+ System.out.println(" - Error: " + ex.getMessage());
+ }
+ } else if (mailTemplates) {
+ LOG.debug("- configuration mailTemplates command");
+ try {
+ System.out.println(" - Conf mail template for:");
+ for (final MailTemplate mailTemplate : configurationService.getMailTemplates()) {
+ System.out.println(" *** " + mailTemplate.getElement());
+ }
+ } catch (final SyncopeClientException ex) {
+ System.out.println(" - Error: " + ex.getMessage());
+ }
+ } else if (StringUtils.isNotBlank(export)) {
+ 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)));
+ System.out.println(" - " + export + EXPORT_FILE_NAME + " successfully created");
+ } catch (final IOException ex) {
+ LOG.error("Error creating content.xml file in {} directory", export, ex);
+ System.out.println(" - Error creating " + export + EXPORT_FILE_NAME + " " + ex.getMessage());
+ } catch (final ParserConfigurationException ex) {
+ LOG.error("Error creating content.xml file in {} directory", export, ex);
+ System.out.println(" - Error creating " + export + EXPORT_FILE_NAME + " " + ex.getMessage());
+ } catch (final SAXException ex) {
+ LOG.error("Error creating content.xml file in {} directory", export, ex);
+ System.out.println(" - Error creating " + export + EXPORT_FILE_NAME + " " + ex.getMessage());
+ } catch (final TransformerConfigurationException ex) {
+ LOG.error("Error creating content.xml file in {} directory", export, ex);
+ System.out.println(" - Error creating " + export + EXPORT_FILE_NAME + " " + ex.getMessage());
+ } catch (final TransformerException ex) {
+ LOG.error("Error creating content.xml file in {} directory", export, ex);
+ System.out.println(" - Error creating " + export + EXPORT_FILE_NAME + " " + ex.getMessage());
+ } catch (final SyncopeClientException ex) {
+ LOG.error("Error calling configuration service", ex);
+ System.out.println(" - Error calling configuration service " + ex.getMessage());
+ }
+ } else {
+ System.out.println(helpMessage);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/c6006673/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 3c2a415..e4d3a1c 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
@@ -26,6 +26,7 @@ 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;
import org.apache.syncope.common.types.LoggerLevel;
@@ -38,43 +39,48 @@ import org.slf4j.LoggerFactory;
optionPrefixes = "-",
separators = "=",
commandDescription = "Apache Syncope logger service")
-public class LoggerCommand {
+public class LoggerCommand extends AbstractCommand {
private static final Logger LOG = LoggerFactory.getLogger(LoggerCommand.class);
- private static final Class syncopeLoggerClass = LoggerService.class;
+ private static final Class SYNCOPE_LOGGER_CLASS = LoggerService.class;
private final String helpMessage = "Usage: logger [options]\n"
+ " Options:\n"
+ " -h, --help \n"
+ " -l, --list \n"
- + " -ua, --update-all \n"
- + " Syntax: -ua={LOGGER-LEVEL} \n"
+ + " -r, --read \n"
+ + " Syntax: -r={LOG-NAME} \n"
+ " -u, --update \n"
+ " Syntax: {LOG-NAME}={LOG-LEVEL} \n"
+ + " -ua, --update-all \n"
+ + " Syntax: -ua={LOG-LEVEL} \n"
+ + " -c, --create \n"
+ + " Syntax: {LOG-NAME}={LOG-LEVEL} \n"
+ " -d, --delete \n"
- + " Syntax: -d={LOGGER-NAME}";
-
- @Parameter(names = {"-h", "--help"})
- public boolean help = false;
+ + " 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)
public String logLevel;
- @Parameter(names = {"-r", "--read"})
- public String logNameToRead;
+ @DynamicParameter(names = {"-u", "--update"})
+ private final Map<String, String> createLogs = new HashMap<String, String>();
@Parameter(names = {"-d", "--delete"})
public String logNameToDelete;
- @DynamicParameter(names = {"-u", "--update"})
- private final Map<String, String> params = new HashMap<String, String>();
-
+ @Override
public void execute() {
- final LoggerService loggerService = ((LoggerService) SyncopeServices.get(syncopeLoggerClass));
+ final LoggerService loggerService = ((LoggerService) SyncopeServices.get(SYNCOPE_LOGGER_CLASS));
LOG.debug("Logger service successfully created");
@@ -83,32 +89,66 @@ public class LoggerCommand {
System.out.println(helpMessage);
} else if (list) {
LOG.debug("- logger list command");
- for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) {
- System.out.println(" - " + loggerTO.getName() + " -> " + loggerTO.getLevel());
+ try {
+ for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) {
+ System.out.println(" - " + loggerTO.getName() + " -> " + loggerTO.getLevel());
+ }
+ } catch (final SyncopeClientException ex) {
+ System.out.println(" - Error: " + ex.getMessage());
+ }
+ } else if (StringUtils.isNotBlank(logNameToRead)) {
+ LOG.debug("- logger read {} command", logNameToRead);
+ try {
+ final LoggerTO loggerTO = loggerService.read(LoggerType.LOG, logNameToRead);
+ System.out.println(" - Logger " + loggerTO.getName() + " with level -> " + loggerTO.getLevel());
+ } catch (final SyncopeClientException ex) {
+ System.out.println(" - Error: " + ex.getMessage());
+ }
+ } 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()));
+ 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());
}
} else if (StringUtils.isNotBlank(logLevel)) {
LOG.debug("- logger update all command with level {}", logLevel);
- for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) {
- loggerTO.setLevel(LoggerLevel.valueOf(logLevel));
- loggerService.update(LoggerType.LOG, loggerTO.getName(), loggerTO);
- System.out.println(" - Logger " + loggerTO.getName() + " new value -> " + loggerTO.getLevel());
+ try {
+
+ for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) {
+ 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());
}
- } else if (!params.isEmpty()) {
- LOG.debug("- logger update command with params {}", params);
- for (final Map.Entry<String, String> entrySet : params.entrySet()) {
- final LoggerTO loggerTO = loggerService.read(LoggerType.LOG, entrySet.getKey());
- loggerTO.setLevel(LoggerLevel.valueOf(entrySet.getValue()));
- loggerService.update(LoggerType.LOG, loggerTO.getName(), loggerTO);
- System.out.println(" - Logger " + loggerTO.getName() + " new value -> " + loggerTO.getLevel());
+ } 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();
+ 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());
+ }
+ } catch (final SyncopeClientException ex) {
+ System.out.println(" - Error: " + ex.getMessage());
}
- } else if (StringUtils.isNotBlank(logNameToRead)) {
- LOG.debug("- logger read {} command", logNameToRead);
- final LoggerTO loggerTO = loggerService.read(LoggerType.LOG, logNameToRead);
- System.out.println(" - Logger " + loggerTO.getName() + " with level -> " + loggerTO.getLevel());
} else if (StringUtils.isNotBlank(logNameToDelete)) {
- LOG.debug("- logger delete {} command", logNameToDelete);
- loggerService.delete(LoggerType.LOG, logNameToDelete);
- System.out.println(" - Logger " + logNameToDelete + " deleted!");
+ try {
+ LOG.debug("- logger delete {} command", logNameToDelete);
+ loggerService.delete(LoggerType.LOG, logNameToDelete);
+ System.out.println(" - Logger " + logNameToDelete + " deleted!");
+ } catch (final SyncopeClientException ex) {
+ System.out.println(" - Error: " + ex.getMessage());
+ }
} else {
System.out.println(helpMessage);
}
[4/5] syncope git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/syncope
Posted by ma...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/syncope
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/344a9400
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/344a9400
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/344a9400
Branch: refs/heads/master
Commit: 344a9400853a25fa324d0ca56c835b827952f99b
Parents: ed3993b 9df1e03
Author: massi <ma...@tirasa.net>
Authored: Mon Jan 26 10:08:00 2015 +0100
Committer: massi <ma...@tirasa.net>
Committed: Mon Jan 26 10:08:00 2015 +0100
----------------------------------------------------------------------
.../core/rest/ConfigurationTestITCase.java | 79 +++++++++++---------
1 file changed, 42 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
[5/5] syncope git commit: Fixed #SYNCOPE-587
Posted by ma...@apache.org.
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/master
Commit: f32528c1fb798ec51a6da7a43abaa1f52b1efe28
Parents: 344a940
Author: massi <ma...@tirasa.net>
Authored: Mon Jan 26 15:41:01 2015 +0100
Committer: massi <ma...@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();
}
[2/5] syncope git commit: Fixed #SYNCOPE-581
Posted by ma...@apache.org.
Fixed #SYNCOPE-581
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/172908de
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/172908de
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/172908de
Branch: refs/heads/master
Commit: 172908de1fcd055be242be2f932e080dc5b21b66
Parents: c600667
Author: massi <ma...@tirasa.net>
Authored: Fri Jan 23 16:38:48 2015 +0100
Committer: massi <ma...@tirasa.net>
Committed: Fri Jan 23 16:38:48 2015 +0100
----------------------------------------------------------------------
.../syncope/cli/commands/AbstractCommand.java | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/172908de/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 5dd3d38..290f974 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
@@ -1,3 +1,21 @@
+/*
+ * 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;
[3/5] syncope git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/syncope
Posted by ma...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/syncope
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/ed3993b6
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/ed3993b6
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/ed3993b6
Branch: refs/heads/master
Commit: ed3993b6dfb7223c24e79e30898fe4bdd5654d2b
Parents: 172908d b2cac79
Author: massi <ma...@tirasa.net>
Authored: Fri Jan 23 16:39:20 2015 +0100
Committer: massi <ma...@tirasa.net>
Committed: Fri Jan 23 16:39:20 2015 +0100
----------------------------------------------------------------------
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------