Repository: syncope Updated Branches: refs/heads/2_0_X 9cbd0d0e8 -> 689e8bbb3
[SYNCOPE-620] cli Project: http://git-wip-us.apache.org/repos/asf/syncope/repo Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/689e8bbb Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/689e8bbb Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/689e8bbb Branch: refs/heads/2_0_X Commit: 689e8bbb3803132309411c99bf1d18371623a810 Parents: 9cbd0d0 Author: Francesco Chicchiriccò <[email protected]> Authored: Thu Feb 12 18:31:56 2015 +0100 Committer: Francesco Chicchiriccò <[email protected]> Committed: Thu Feb 12 18:31:56 2015 +0100 ---------------------------------------------------------------------- syncope620/client/cli/pom.xml | 178 ++++++++++++++++ .../apache/syncope/client/cli/SyncopeAdm.java | 123 +++++++++++ .../syncope/client/cli/SyncopeServices.java | 45 ++++ .../client/cli/commands/AbstractCommand.java | 32 +++ .../cli/commands/ConfigurationCommand.java | 209 +++++++++++++++++++ .../client/cli/commands/EntitlementCommand.java | 70 +++++++ .../client/cli/commands/LoggerCommand.java | 168 +++++++++++++++ .../cli/commands/NotificationCommand.java | 92 ++++++++ .../client/cli/commands/PolicyCommand.java | 105 ++++++++++ .../client/cli/commands/ReportCommand.java | 193 +++++++++++++++++ .../syncope/client/cli/util/XmlUtils.java | 47 +++++ .../cli/validators/DebugLevelValidator.java | 61 ++++++ .../client/cli/src/main/resources/log4j2.xml | 58 +++++ .../cli/src/main/resources/syncope.properties | 19 ++ syncope620/client/pom.xml | 1 + syncope620/pom.xml | 6 + 16 files changed, 1407 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/syncope/blob/689e8bbb/syncope620/client/cli/pom.xml ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/pom.xml b/syncope620/client/cli/pom.xml new file mode 100644 index 0000000..fa70a01 --- /dev/null +++ b/syncope620/client/cli/pom.xml @@ -0,0 +1,178 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.syncope</groupId> + <artifactId>syncope-client</artifactId> + <version>2.0.0-SNAPSHOT</version> + </parent> + + <name>Apache Syncope Client CLI</name> + <description>Apache Syncope Client CLI</description> + + <groupId>org.apache.syncope</groupId> + <artifactId>syncope-client-cli</artifactId> + <packaging>jar</packaging> + + <properties> + <log.directory>/tmp</log.directory> + </properties> + + <dependencies> + <dependency> + <groupId>com.beust</groupId> + <artifactId>jcommander</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.syncope.client</groupId> + <artifactId>syncope-client-lib</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + </dependency> + <dependency> + <groupId>com.lmax</groupId> + <artifactId>disruptor</artifactId> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + </dependency> + + </dependencies> + + <build> + + <defaultGoal>package</defaultGoal> + + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>2.3</version> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <createDependencyReducedPom>false</createDependencyReducedPom> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <manifestEntries> + <Main-Class>org.apache.syncope.cli.SyncopeAdm</Main-Class> + </manifestEntries> + </transformer> + <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> + <resource>messages.properties</resource> + <file>src/main/resources/messages.properties</file> + </transformer> + <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"> + <resource>messages_it_IT.properties</resource> + <file>src/main/resources/messages_it_IT.properties</file> + </transformer> + <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> + <resource>META-INF/spring.handlers</resource> + </transformer> + <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> + <resource>META-INF/spring.schemas</resource> + </transformer> + <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> + <resource>META-INF/cxf/bus-extensions.txt</resource> + </transformer> + <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer"> + <resource>META-INF/wsdl.plugin.xml</resource> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + <targetPath>${project.build.directory}/classes</targetPath> + <includes> + <include>log4j2.xml</include> + </includes> + </resource> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + <targetPath>${project.build.directory}/classes</targetPath> + <includes> + <include>syncope.properties</include> + </includes> + </resource> + <resource> + <directory>..</directory> + <targetPath>META-INF</targetPath> + <includes> + <include>LICENSE</include> + <include>NOTICE</include> + </includes> + </resource> + </resources> + + </build> + + <profiles> + <profile> + <id>apache-release</id> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> http://git-wip-us.apache.org/repos/asf/syncope/blob/689e8bbb/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java new file mode 100644 index 0000000..2bb802f --- /dev/null +++ b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli; + +import com.beust.jcommander.JCommander; +import com.beust.jcommander.ParameterException; +import org.apache.syncope.client.cli.commands.ConfigurationCommand; +import org.apache.syncope.client.cli.commands.EntitlementCommand; +import org.apache.syncope.client.cli.commands.LoggerCommand; +import org.apache.syncope.client.cli.commands.NotificationCommand; +import org.apache.syncope.client.cli.commands.PolicyCommand; +import org.apache.syncope.client.cli.commands.ReportCommand; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SyncopeAdm { + + private static final Logger LOG = LoggerFactory.getLogger(SyncopeAdm.class); + + private static final String helpMessage = "Usage: Main [options]\n" + + " Options:\n" + + " logger --help \n" + + " config --help \n" + + " notification --help \n" + + " report --help \n" + + " policy --help \n" + + " entitlement --help \n"; + + private static final JCommander jcommander = new JCommander(); + + private static LoggerCommand loggerCommand; + + private static ConfigurationCommand configurationCommand; + + private static NotificationCommand notificationCommand; + + private static ReportCommand reportCommand; + + private static PolicyCommand policyCommand; + + private static EntitlementCommand entitlementCommand; + + public static void main(final String[] args) { + LOG.debug("Starting with args \n"); + + for (final String arg : args) { + LOG.debug("Arg: {}", arg); + } + + instantiateCommands(); + + if (args.length == 0) { + System.out.println(helpMessage); + } else { + try { + jcommander.parse(args); + } catch (final ParameterException ioe) { + System.out.println(helpMessage); + LOG.error("Parameter exception", ioe); + } + executeCommand(); + } + + } + + private static void instantiateCommands() { + LOG.debug("Init JCommander"); + loggerCommand = new LoggerCommand(); + jcommander.addCommand(loggerCommand); + LOG.debug("Added LoggerCommand"); + 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"); + entitlementCommand = new EntitlementCommand(); + jcommander.addCommand(entitlementCommand); + LOG.debug("Added EntitlementCommand"); + } + + private static void executeCommand() { + final String command = jcommander.getParsedCommand(); + + LOG.debug("Called command {}", command); + + if ("logger".equalsIgnoreCase(command)) { + 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(); + } else if ("entitlement".equalsIgnoreCase(command)) { + entitlementCommand.execute(); + } + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/689e8bbb/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java new file mode 100644 index 0000000..26ce276 --- /dev/null +++ b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli; + +import java.util.ResourceBundle; +import org.apache.syncope.client.lib.SyncopeClient; +import org.apache.syncope.client.lib.SyncopeClientFactoryBean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class SyncopeServices { + + private static final Logger LOG = LoggerFactory.getLogger(SyncopeServices.class); + + private final static ResourceBundle SYNCOPE_PROPS = ResourceBundle.getBundle("syncope"); + + private static final SyncopeClient CLIENT = new SyncopeClientFactoryBean() + .setAddress(SYNCOPE_PROPS.getString("syncope.rest.services")) + .create(SYNCOPE_PROPS.getString("syncope.user"), SYNCOPE_PROPS.getString("syncope.password")); + + public static <T> T get(final Class<T> claz) { + LOG.debug("Creting service for {}", claz.getName()); + return CLIENT.getService(claz); + } + + private SyncopeServices() { + // private constructor for static utility class + } +} http://git-wip-us.apache.org/repos/asf/syncope/blob/689e8bbb/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/AbstractCommand.java ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/AbstractCommand.java b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/AbstractCommand.java new file mode 100644 index 0000000..a6753bf --- /dev/null +++ b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/AbstractCommand.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands; + +import com.beust.jcommander.Parameter; + +public abstract class AbstractCommand { + + @Parameter(names = {"-h", "--help"}) + protected boolean help = false; + + @Parameter(names = {"-l", "--list"}) + protected boolean list = false; + + protected abstract void execute(); +} http://git-wip-us.apache.org/repos/asf/syncope/blob/689e8bbb/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java new file mode 100644 index 0000000..4ca94d0 --- /dev/null +++ b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java @@ -0,0 +1,209 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands; + +import com.beust.jcommander.DynamicParameter; +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; +import java.io.IOException; +import java.io.SequenceInputStream; +import java.util.HashMap; +import java.util.Map; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.cli.SyncopeServices; +import org.apache.syncope.client.cli.util.XmlUtils; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AttrTO; +import org.apache.syncope.common.lib.to.ConfTO; +import org.apache.syncope.common.rest.api.service.ConfigurationService; +import org.apache.syncope.common.rest.api.service.SyncopeService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +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 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 = { "-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 SyncopeService syncopeService = SyncopeServices.get(SyncopeService.class); + final ConfigurationService configurationService = SyncopeServices.get(ConfigurationService.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 AttrTO attrTO : confTO.getPlainAttrMap().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 AttrTO 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 AttrTO 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 AttrTO attrTO = new AttrTO(); + 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 { + System.out.println("Conf validator class: "); + for (final String validator : syncopeService.info().getValidators()) { + System.out.println(" *** " + validator); + } + } 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 String mailTemplate : syncopeService.info().getMailTemplates()) { + System.out.println(" *** " + mailTemplate); + } + } 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 { + 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); + 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/689e8bbb/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/EntitlementCommand.java ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/EntitlementCommand.java b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/EntitlementCommand.java new file mode 100644 index 0000000..e0058ab --- /dev/null +++ b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/EntitlementCommand.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands; + +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; +import org.apache.syncope.client.cli.SyncopeServices; +import org.apache.syncope.common.lib.wrap.EntitlementTO; +import org.apache.syncope.common.rest.api.service.EntitlementService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Parameters( + commandNames = "entitlement", + optionPrefixes = "-", + separators = "=", + commandDescription = "Apache Syncope entitlement service") +public class EntitlementCommand extends AbstractCommand { + + private static final Logger LOG = LoggerFactory.getLogger(EntitlementCommand.class); + + private final String helpMessage = "Usage: entitlement [options]\n" + + " Options:\n" + + " -h, --help \n" + + " -l, --list \n" + + " -lo, --list-own \n"; + + @Parameter(names = { "-lo", "--list-own" }) + public boolean listOwn = false; + + @Override + public void execute() { + final EntitlementService entitlementService = SyncopeServices.get(EntitlementService.class); + LOG.debug("Entitlement service successfully created"); + + if (help) { + LOG.debug("- entitlement help command"); + System.out.println(helpMessage); + } else if (list) { + System.out.println("All entitlement:"); + for (final EntitlementTO entitlementTO : entitlementService.getAllEntitlements()) { + System.out.println(" *** " + entitlementTO.getElement()); + } + } else if (listOwn) { + System.out.println("All own entitlement:"); + for (final EntitlementTO entitlementTO : entitlementService.getOwnEntitlements()) { + System.out.println(" *** " + entitlementTO.getElement()); + } + } else { + System.out.println(helpMessage); + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/689e8bbb/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java new file mode 100644 index 0000000..e5115d9 --- /dev/null +++ b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/LoggerCommand.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands; + +import com.beust.jcommander.DynamicParameter; +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.cli.SyncopeServices; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.LoggerTO; +import org.apache.syncope.common.lib.types.LoggerLevel; +import org.apache.syncope.common.lib.types.LoggerType; +import org.apache.syncope.common.rest.api.service.LoggerService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Parameters( + commandNames = "logger", + optionPrefixes = "-", + separators = "=", + commandDescription = "Apache Syncope logger service") +public class LoggerCommand extends AbstractCommand { + + private static final Logger LOG = LoggerFactory.getLogger(LoggerCommand.class); + + private final String helpMessage = "Usage: logger [options]\n" + + " Options:\n" + + " -h, --help \n" + + " -l, --list \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={LOG-NAME}"; + + @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" }) + public String logLevel; + + @DynamicParameter(names = { "-c", "--create" }) + private final Map<String, String> createLogs = new HashMap<String, String>(); + + @Parameter(names = { "-d", "--delete" }) + public String logNameToDelete; + + @Override + public void execute() { + final LoggerService loggerService = SyncopeServices.get(LoggerService.class); + + LOG.debug("Logger service successfully created"); + + if (help) { + LOG.debug("- logger help command"); + System.out.println(helpMessage); + } else if (list) { + LOG.debug("- logger list command"); + try { + for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) { + System.out.println(" - " + loggerTO.getKey() + " -> " + 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.getKey() + " 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); + + 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.getKey(), loggerTO); + System.out.println(" - Logger " + loggerTO.getKey() + " 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()); + } + } + } + } else if (StringUtils.isNotBlank(logLevel)) { + LOG.debug("- logger update all command with level {}", logLevel); + for (final LoggerTO loggerTO : loggerService.list(LoggerType.LOG)) { + try { + loggerTO.setLevel(LoggerLevel.valueOf(logLevel)); + loggerService.update(LoggerType.LOG, loggerTO.getKey(), loggerTO); + System.out.println(" - Logger " + loggerTO.getKey() + " 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()); + } + } + } + } else if (!createLogs.isEmpty()) { + LOG.debug("- logger create command with params {}", createLogs); + + for (final Map.Entry<String, String> entrySet : createLogs.entrySet()) { + final LoggerTO loggerTO = new LoggerTO(); + try { + loggerTO.setKey(entrySet.getKey()); + loggerTO.setLevel(LoggerLevel.valueOf(entrySet.getValue())); + loggerService.update(LoggerType.LOG, loggerTO.getKey(), loggerTO); + System.out.println(" - Logger " + loggerTO.getKey() + " 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()); + } + } + } + } else if (StringUtils.isNotBlank(logNameToDelete)) { + 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); + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/689e8bbb/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java new file mode 100644 index 0000000..4e18996 --- /dev/null +++ b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/NotificationCommand.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands; + +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; +import org.apache.syncope.client.cli.SyncopeServices; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.NotificationTO; +import org.apache.syncope.common.rest.api.service.NotificationService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@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 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 = SyncopeServices.get(NotificationService.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/689e8bbb/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java new file mode 100644 index 0000000..c2bcb5f --- /dev/null +++ b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands; + +import com.beust.jcommander.Parameter; +import com.beust.jcommander.Parameters; +import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.client.cli.SyncopeServices; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.AbstractPolicyTO; +import org.apache.syncope.common.lib.types.PolicyType; +import org.apache.syncope.common.rest.api.service.PolicyService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@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 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 = SyncopeServices.get(PolicyService.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/689e8bbb/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java new file mode 100644 index 0000000..17f0e14 --- /dev/null +++ b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ReportCommand.java @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.commands; + +import 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.client.cli.SyncopeServices; +import org.apache.syncope.client.cli.util.XmlUtils; +import org.apache.syncope.common.lib.SyncopeClientException; +import org.apache.syncope.common.lib.to.ReportExecTO; +import org.apache.syncope.common.lib.to.ReportTO; +import org.apache.syncope.common.lib.types.ReportExecExportFormat; +import org.apache.syncope.common.lib.wrap.ReportletConfClass; +import org.apache.syncope.common.rest.api.service.ReportService; +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 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 = SyncopeServices.get(ReportService.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.getKey()); + 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.getKey()); + 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/689e8bbb/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/util/XmlUtils.java ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/util/XmlUtils.java b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/util/XmlUtils.java new file mode 100644 index 0000000..fa228d5 --- /dev/null +++ b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/util/XmlUtils.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.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(final SequenceInputStream sis, final 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/689e8bbb/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/validators/DebugLevelValidator.java ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/validators/DebugLevelValidator.java b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/validators/DebugLevelValidator.java new file mode 100644 index 0000000..58c12f3 --- /dev/null +++ b/syncope620/client/cli/src/main/java/org/apache/syncope/client/cli/validators/DebugLevelValidator.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.client.cli.validators; + +import com.beust.jcommander.IParameterValidator; +import com.beust.jcommander.ParameterException; + +public class DebugLevelValidator implements IParameterValidator { + + @Override + public void validate(final String name, final String value) throws ParameterException { + if (!Levels.contains(value)) { + final StringBuilder exceptionMessage = new StringBuilder(); + exceptionMessage.append("Parameter ") + .append(name) + .append(" should be :\n"); + for (final Levels l : Levels.values()) { + exceptionMessage.append(l).append("\n"); + } + System.out.println(">>>> " + exceptionMessage.toString()); + } + } + + private enum Levels { + + OFF, + FATAL, + ERROR, + WARN, + INFO, + DEBUG, + TRACE, + ALL; + + public static boolean contains(final String name) { + for (final Levels c : Levels.values()) { + if (c.name().equals(name)) { + return true; + } + } + return false; + } + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/689e8bbb/syncope620/client/cli/src/main/resources/log4j2.xml ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/resources/log4j2.xml b/syncope620/client/cli/src/main/resources/log4j2.xml new file mode 100644 index 0000000..0688f6b --- /dev/null +++ b/syncope620/client/cli/src/main/resources/log4j2.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<configuration status="WARN"> + + <appenders> + + <RollingRandomAccessFile name="main" fileName="${log.directory}/cli.log" + filePattern="${log.directory}/cli-%d{yyyy-MM-dd}.log.gz" + immediateFlush="false" append="true"> + <PatternLayout> + <pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern> + </PatternLayout> + <Policies> + <TimeBasedTriggeringPolicy/> + <SizeBasedTriggeringPolicy size="250 MB"/> + </Policies> + </RollingRandomAccessFile> + + </appenders> + + <loggers> + + <asyncLogger name="com.beust" additivity="false" level="DEBUG"> + <appender-ref ref="main"/> + </asyncLogger> + + <asyncLogger name="org.apache.syncope.cli" additivity="false" level="DEBUG"> + <appender-ref ref="main"/> + </asyncLogger> + + <asyncLogger name="org.apache.syncope.client" additivity="false" level="OFF"> + <appender-ref ref="main"/> + </asyncLogger> + + <root level="DEBUG"> + <appender-ref ref="main"/> + </root> + + </loggers> + +</configuration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/syncope/blob/689e8bbb/syncope620/client/cli/src/main/resources/syncope.properties ---------------------------------------------------------------------- diff --git a/syncope620/client/cli/src/main/resources/syncope.properties b/syncope620/client/cli/src/main/resources/syncope.properties new file mode 100644 index 0000000..9f84a72 --- /dev/null +++ b/syncope620/client/cli/src/main/resources/syncope.properties @@ -0,0 +1,19 @@ +# 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. +syncope.rest.services=http://localhost:9080/syncope/rest/ +syncope.user=admin +syncope.password=password http://git-wip-us.apache.org/repos/asf/syncope/blob/689e8bbb/syncope620/client/pom.xml ---------------------------------------------------------------------- diff --git a/syncope620/client/pom.xml b/syncope620/client/pom.xml index 0143d08..78bfcbd 100644 --- a/syncope620/client/pom.xml +++ b/syncope620/client/pom.xml @@ -36,6 +36,7 @@ under the License. <modules> <module>lib</module> <module>console</module> + <module>cli</module> </modules> </project> http://git-wip-us.apache.org/repos/asf/syncope/blob/689e8bbb/syncope620/pom.xml ---------------------------------------------------------------------- diff --git a/syncope620/pom.xml b/syncope620/pom.xml index 9ca00b9..37c783b 100644 --- a/syncope620/pom.xml +++ b/syncope620/pom.xml @@ -907,6 +907,12 @@ under the License. <version>${codemirror.version}</version> </dependency> + <dependency> + <groupId>com.beust</groupId> + <artifactId>jcommander</artifactId> + <version>1.47</version> + </dependency> + <!-- TEST --> <dependency> <groupId>net.tirasa.connid.bundles.soap</groupId>
