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/10/21 10:55:09 UTC
syncope git commit: refactoring for configuration stack, SYNCOPE-158
Repository: syncope
Updated Branches:
refs/heads/master 462289dce -> 6b9cd592b
refactoring for configuration stack, SYNCOPE-158
Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/6b9cd592
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/6b9cd592
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/6b9cd592
Branch: refs/heads/master
Commit: 6b9cd592b21440d54fabd6012616c4f6a18a81f3
Parents: 462289d
Author: massi <ma...@tirasa.net>
Authored: Wed Oct 21 10:54:47 2015 +0200
Committer: massi <ma...@tirasa.net>
Committed: Wed Oct 21 10:54:47 2015 +0200
----------------------------------------------------------------------
.../apache/syncope/client/cli/SyncopeAdm.java | 8 +-
.../cli/commands/CommonsResultManager.java | 50 ++++
.../cli/commands/ConfigurationCommand.java | 297 -------------------
.../AbstractConfigurationCommand.java | 30 ++
.../configuration/ConfigurationCommand.java | 124 ++++++++
.../configuration/ConfigurationDelete.java | 57 ++++
.../configuration/ConfigurationExport.java | 71 +++++
.../configuration/ConfigurationGet.java | 36 +++
.../configuration/ConfigurationRead.java | 62 ++++
.../ConfigurationResultManager.java | 53 ++++
.../configuration/ConfigurationUpdate.java | 76 +++++
.../commands/logger/AbstractLoggerCommand.java | 2 +-
.../cli/commands/logger/LoggerCommand.java | 3 +-
.../cli/commands/logger/LoggerCreate.java | 6 +-
.../cli/commands/logger/LoggerDelete.java | 15 +-
.../client/cli/commands/logger/LoggerList.java | 4 +-
.../client/cli/commands/logger/LoggerRead.java | 8 +-
.../commands/logger/LoggerResultManager.java | 61 ++++
.../cli/commands/logger/LoggerUpdate.java | 12 +-
.../cli/commands/logger/LoggerUpdateAll.java | 8 +-
.../cli/commands/logger/ResultManager.java | 79 -----
21 files changed, 649 insertions(+), 413 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java b/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java
index 78e2f54..b5a1365 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeAdm.java
@@ -20,7 +20,7 @@ package org.apache.syncope.client.cli;
import javax.ws.rs.ProcessingException;
import org.apache.syncope.client.cli.commands.AbstractCommand;
-import org.apache.syncope.client.cli.commands.logger.ResultManager;
+import org.apache.syncope.client.cli.commands.logger.LoggerResultManager;
import org.apache.syncope.client.cli.util.CommandUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -49,12 +49,12 @@ public final class SyncopeAdm {
System.out.println(helpMessage());
} catch (final IllegalArgumentException ex) {
LOG.error("Error in main", ex);
- new ResultManager().genericError(ex.getMessage());
+ new LoggerResultManager().genericError(ex.getMessage());
if (!ex.getMessage().startsWith("It seems you")) {
System.out.println(helpMessage());
}
} catch (final ProcessingException e) {
- new ResultManager().genericError("Syncope server offline", e.getCause().getMessage());
+ new LoggerResultManager().genericError("Syncope server offline", e.getCause().getMessage());
}
}
@@ -72,7 +72,7 @@ public final class SyncopeAdm {
helpMessageBuilder.append("\n");
}
} catch (final IllegalAccessException | IllegalArgumentException | InstantiationException ex) {
- new ResultManager().genericError(ex.getMessage());
+ new LoggerResultManager().genericError(ex.getMessage());
}
return helpMessageBuilder.toString();
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java
new file mode 100644
index 0000000..9bfde8d
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/CommonsResultManager.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.syncope.client.cli.messages.Messages;
+import org.apache.syncope.client.cli.util.CommandUtils;
+import org.apache.syncope.common.lib.types.LoggerLevel;
+
+public abstract class CommonsResultManager {
+
+ public void deletedMessage(final String what, final String key) {
+ Messages.printDeletedMessage(what, key);
+ }
+
+ public void notFoundError(final String what, final String parameter) {
+ Messages.printNofFoundMessage(what, parameter);
+ }
+
+ public void typeNotValidError(final String parameter) {
+ Messages.printTypeNotValidMessage("logger level", parameter, CommandUtils.fromEnumToArray(LoggerLevel.class));
+ }
+
+ public void commandOptionError(final String message) {
+ Messages.printCommandOptionMessage(message);
+ }
+
+ public void defaultError(final String option, final String helpMessage) {
+ Messages.printDefaultMessage(option, helpMessage);
+ }
+
+ public void genericError(final String... messages) {
+ Messages.printMessage(messages);
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java
deleted file mode 100644
index e7d8938..0000000
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/ConfigurationCommand.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.client.cli.commands;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.SequenceInputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.ws.WebServiceException;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.syncope.client.cli.Command;
-import org.apache.syncope.client.cli.Input;
-import org.apache.syncope.client.cli.SyncopeServices;
-import org.apache.syncope.client.cli.messages.Messages;
-import org.apache.syncope.client.cli.messages.TwoColumnTable;
-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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.xml.sax.SAXException;
-
-@Command(name = "configuration")
-public class ConfigurationCommand extends AbstractCommand {
-
- private static final Logger LOG = LoggerFactory.getLogger(ConfigurationCommand.class);
-
- private static final String EXPORT_FILE_NAME = "/content.xml";
-
- private static final String HELP_MESSAGE = "Usage: configuration [options]\n"
- + " Options:\n"
- + " --help \n"
- + " --get \n"
- + " --read \n"
- + " Syntax: --read {CONF-NAME} {CONF-NAME} [...] \n"
- + " --update \n"
- + " Syntax: --update {CONF-NAME}={CONF-VALUE} {CONF-NAME}={CONF-VALUE} [...]\n"
- + " --delete \n"
- + " Syntax: --delete {CONF-NAME} {CONF-NAME} [...]\n"
- + " --export \n"
- + " Syntax: --export {WHERE-DIR}";
-
- @Override
- public void execute(final Input input) {
- LOG.debug("Logger service successfully created");
- LOG.debug("Option: {}", input.getOption());
- LOG.debug("Parameters:");
- for (final String parameter : input.getParameters()) {
- LOG.debug(" > " + parameter);
- }
-
- final String[] parameters = input.getParameters();
-
- if (StringUtils.isBlank(input.getOption())) {
- input.setOption(Options.HELP.getOptionName());
- }
-
- final ConfigurationService configurationService = SyncopeServices.get(ConfigurationService.class);
- switch (Options.fromName(input.getOption())) {
- case GET:
- try {
- final ConfTO confTO = configurationService.list();
- toTable("Syncope configuration", "attribute", "value", confTO.getPlainAttrs());
- } catch (final Exception ex) {
- Messages.printMessage(ex.getMessage());
- break;
- }
- break;
- case READ:
- final String readErrorMessage = "configuration --read {CONF-NAME} {CONF-NAME} [...]";
- if (parameters.length >= 1) {
- final Set<AttrTO> attrList = new HashSet<>();
- boolean failed = false;
- for (final String parameter : parameters) {
- try {
- attrList.add(configurationService.get(parameter));
- } catch (final SyncopeClientException | WebServiceException ex) {
- if (ex.getMessage().startsWith("NotFound")) {
- Messages.printNofFoundMessage("Logger", parameter);
- } else {
- Messages.printMessage(ex.getMessage());
- }
- failed = true;
- break;
- }
- }
- if (!failed) {
- toTable("Read result", "attribute", "value", attrList);
- }
- } else {
- Messages.printCommandOptionMessage(readErrorMessage);
- }
- break;
- case UPDATE:
- final String updateErrorMessage
- = "configuration --update {CONF-NAME}={CONF-VALUE} {CONF-NAME}={CONF-VALUE} [...]";
- if (parameters.length >= 1) {
- Input.PairParameter pairParameter = null;
- AttrTO attrTO;
- final Set<AttrTO> attrList = new HashSet<>();
- boolean failed = false;
- for (final String parameter : parameters) {
- try {
- pairParameter = input.toPairParameter(parameter);
- attrTO = configurationService.get(pairParameter.getKey());
- attrTO.getValues().clear();
- attrTO.getValues().add(pairParameter.getValue());
- configurationService.set(attrTO);
- attrList.add(attrTO);
- } catch (final IllegalArgumentException ex) {
- Messages.printMessage(ex.getMessage(), updateErrorMessage);
- failed = true;
- break;
- } catch (final SyncopeClientException | WebServiceException ex) {
- if (ex.getMessage().startsWith("NotFound")) {
- Messages.printNofFoundMessage("Configuration", pairParameter.getKey());
- } else if (ex.getMessage().startsWith("InvalidValues")) {
- Messages.printMessage(
- pairParameter.getValue() + " is not a valid value for "
- + pairParameter.getKey());
- } else {
- Messages.printMessage(ex.getMessage());
- }
- failed = true;
- break;
- }
- }
- if (!failed) {
- toTable("updated attribute", "attribute", "new value", attrList);
- }
- } else {
- Messages.printCommandOptionMessage(updateErrorMessage);
- }
- break;
- case DELETE:
- final String deleteErrorMessage = "configuration --delete {CONF-NAME} {CONF-NAME} [...]";
- if (parameters.length >= 1) {
- for (final String parameter : parameters) {
- try {
- configurationService.delete(parameter);
- Messages.printDeletedMessage("Configuration", parameter);
- } catch (final SyncopeClientException | WebServiceException ex) {
- if (ex.getMessage().startsWith("NotFound")) {
- Messages.printNofFoundMessage("Configuration", parameter);
- } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
- Messages.printMessage("You cannot delete configuration", parameter);
- } else {
- Messages.printMessage(ex.getMessage());
- }
- break;
- }
- }
- } else {
- Messages.printCommandOptionMessage(deleteErrorMessage);
- }
- break;
- case EXPORT:
- final String exportErrorMessage = "configuration --export {WHERE-DIR}";
- if (parameters.length == 1) {
- try {
- XMLUtils.createXMLFile((SequenceInputStream) configurationService.export().getEntity(),
- parameters[0] + EXPORT_FILE_NAME);
- System.out.println(" - " + parameters[0] + EXPORT_FILE_NAME + " successfully created");
- } catch (final IOException ex) {
- Messages.printMessage(ex.getMessage());
- } catch (ParserConfigurationException | SAXException | TransformerConfigurationException ex) {
- LOG.error("Error creating content.xml file in {} directory", parameters[0], ex);
- Messages.printMessage(
- "Error creating " + parameters[0] + EXPORT_FILE_NAME + " " + ex.getMessage());
- break;
- } catch (final TransformerException ex) {
- LOG.error("Error creating content.xml file in {} directory", parameters[0], ex);
- if (ex.getCause() instanceof FileNotFoundException) {
- Messages.printMessage("Permission denied on " + parameters[0]);
- } else {
- Messages.printMessage(
- "Error creating " + parameters[0] + EXPORT_FILE_NAME + " " + ex.getMessage());
- }
- break;
- } catch (final SyncopeClientException ex) {
- LOG.error("Error calling configuration service", ex);
- Messages.printMessage("Error calling configuration service " + ex.getMessage());
- break;
- }
- } else {
- Messages.printCommandOptionMessage(exportErrorMessage);
- }
- break;
- case HELP:
- System.out.println(HELP_MESSAGE);
- break;
- default:
- Messages.printDefaultMessage(input.getOption(), HELP_MESSAGE);
- break;
- }
- }
-
- private void toTable(final String tableTitle,
- final String firstHeader,
- final String seconHeader,
- final Set<AttrTO> attrList) {
- int maxFirstColumnLenght = 0;
- int maxSecondColumnLenght = 0;
- final Map<String, String> attributes = new HashMap<>();
- for (final AttrTO attrTO : attrList) {
- String value = attrTO.getValues().toString();
- value = value.substring(0, value.length() - 1);
- value = value.substring(1, value.length());
- attributes.put(attrTO.getSchema(), value);
- if (attrTO.getSchema().length() > maxFirstColumnLenght) {
- maxFirstColumnLenght = attrTO.getSchema().length();
- }
-
- if (value.length() > maxSecondColumnLenght) {
- maxSecondColumnLenght = attrTO.getSchema().length();
- }
- }
- final TwoColumnTable loggerTableResult = new TwoColumnTable(
- tableTitle,
- firstHeader, maxFirstColumnLenght,
- seconHeader, maxSecondColumnLenght);
- loggerTableResult.printTable(attributes);
- }
-
- @Override
- public String getHelpMessage() {
- return HELP_MESSAGE;
- }
-
- private enum Options {
-
- HELP("--help"),
- GET("--get"),
- READ("--read"),
- UPDATE("--update"),
- DELETE("--delete"),
- EXPORT("--export");
-
- private final String optionName;
-
- Options(final String optionName) {
- this.optionName = optionName;
- }
-
- public String getOptionName() {
- return optionName;
- }
-
- public boolean equalsOptionName(final String otherName) {
- return (otherName == null) ? false : optionName.equals(otherName);
- }
-
- public static Options fromName(final String name) {
- Options optionToReturn = HELP;
- for (final Options option : Options.values()) {
- if (option.equalsOptionName(name)) {
- optionToReturn = option;
- }
- }
- return optionToReturn;
- }
-
- public static List<String> toList() {
- final List<String> options = new ArrayList<>();
- for (final Options value : values()) {
- options.add(value.getOptionName());
- }
- return options;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/AbstractConfigurationCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/AbstractConfigurationCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/AbstractConfigurationCommand.java
new file mode 100644
index 0000000..59fc423
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/AbstractConfigurationCommand.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.client.cli.commands.configuration;
+
+import org.apache.syncope.client.cli.SyncopeServices;
+import org.apache.syncope.common.rest.api.service.ConfigurationService;
+
+public class AbstractConfigurationCommand {
+
+ protected final ConfigurationService configurationService = SyncopeServices.get(ConfigurationService.class);
+
+ protected final ConfigurationResultManager configurationResultManager = new ConfigurationResultManager();
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationCommand.java
new file mode 100644
index 0000000..d74ea78
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationCommand.java
@@ -0,0 +1,124 @@
+/*
+ * 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.configuration;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.client.cli.Command;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.client.cli.commands.AbstractCommand;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Command(name = "configuration")
+public class ConfigurationCommand extends AbstractCommand {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ConfigurationCommand.class);
+
+ private static final String HELP_MESSAGE = "Usage: configuration [options]\n"
+ + " Options:\n"
+ + " --help \n"
+ + " --get \n"
+ + " --read \n"
+ + " Syntax: --read {CONF-NAME} {CONF-NAME} [...] \n"
+ + " --update \n"
+ + " Syntax: --update {CONF-NAME}={CONF-VALUE} {CONF-NAME}={CONF-VALUE} [...]\n"
+ + " --delete \n"
+ + " Syntax: --delete {CONF-NAME} {CONF-NAME} [...]\n"
+ + " --export \n"
+ + " Syntax: --export {WHERE-DIR}";
+
+ @Override
+ public void execute(final Input input) {
+ if (StringUtils.isBlank(input.getOption())) {
+ input.setOption(Options.HELP.getOptionName());
+ }
+
+ switch (Options.fromName(input.getOption())) {
+ case GET:
+ new ConfigurationGet().get();
+ break;
+ case READ:
+ new ConfigurationRead(input).read();
+ break;
+ case UPDATE:
+ new ConfigurationUpdate(input).update();
+ break;
+ case DELETE:
+ new ConfigurationDelete(input).delete();
+ break;
+ case EXPORT:
+ break;
+ case HELP:
+ System.out.println(HELP_MESSAGE);
+ break;
+ default:
+ new ConfigurationResultManager().defaultError(input.getOption(), HELP_MESSAGE);
+ break;
+ }
+ }
+
+ @Override
+ public String getHelpMessage() {
+ return HELP_MESSAGE;
+ }
+
+ private enum Options {
+
+ HELP("--help"),
+ GET("--get"),
+ READ("--read"),
+ UPDATE("--update"),
+ DELETE("--delete"),
+ EXPORT("--export");
+
+ private final String optionName;
+
+ Options(final String optionName) {
+ this.optionName = optionName;
+ }
+
+ public String getOptionName() {
+ return optionName;
+ }
+
+ public boolean equalsOptionName(final String otherName) {
+ return (otherName == null) ? false : optionName.equals(otherName);
+ }
+
+ public static Options fromName(final String name) {
+ Options optionToReturn = HELP;
+ for (final Options option : Options.values()) {
+ if (option.equalsOptionName(name)) {
+ optionToReturn = option;
+ }
+ }
+ return optionToReturn;
+ }
+
+ public static List<String> toList() {
+ final List<String> options = new ArrayList<>();
+ for (final Options value : values()) {
+ options.add(value.getOptionName());
+ }
+ return options;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationDelete.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationDelete.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationDelete.java
new file mode 100644
index 0000000..4f8c227
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationDelete.java
@@ -0,0 +1,57 @@
+/*
+ * 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.configuration;
+
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+
+public class ConfigurationDelete extends AbstractConfigurationCommand {
+
+ private static final String DELETE_HELP_MESSAGE = "configuration --delete {CONF-NAME} {CONF-NAME} [...]";
+
+ private final Input input;
+
+ public ConfigurationDelete(final Input input) {
+ this.input = input;
+ }
+
+ public void delete() {
+ if (input.parameterNumber() >= 1) {
+ for (final String parameter : input.getParameters()) {
+ try {
+ configurationService.delete(parameter);
+ configurationResultManager.deletedMessage("Configuration", parameter);
+ } catch (final SyncopeClientException | WebServiceException ex) {
+ if (ex.getMessage().startsWith("NotFound")) {
+ configurationResultManager.notFoundError("Configuration", parameter);
+ } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
+ configurationResultManager.genericError("You cannot delete configuration", parameter);
+ } else {
+ configurationResultManager.genericError(ex.getMessage());
+ }
+ break;
+ }
+ }
+ } else {
+ configurationResultManager.commandOptionError(DELETE_HELP_MESSAGE);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationExport.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationExport.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationExport.java
new file mode 100644
index 0000000..0bc274f
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationExport.java
@@ -0,0 +1,71 @@
+/*
+ * 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.configuration;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.SequenceInputStream;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.client.cli.util.XMLUtils;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.xml.sax.SAXException;
+
+public class ConfigurationExport extends AbstractConfigurationCommand {
+
+ private static final String EXPORT_HELP_MESSAGE = "configuration --export {WHERE-DIR}";
+
+ private static final String EXPORT_FILE_NAME = "/content.xml";
+
+ private final Input input;
+
+ public ConfigurationExport(final Input input) {
+ this.input = input;
+ }
+
+ public void export() {
+ if (input.parameterNumber() == 1) {
+ try {
+ XMLUtils.createXMLFile(
+ (SequenceInputStream) configurationService.export().getEntity(),
+ input.firstParameter() + EXPORT_FILE_NAME);
+ configurationResultManager.genericError(
+ input.firstParameter() + EXPORT_FILE_NAME + " successfully created");
+ } catch (final IOException ex) {
+ configurationResultManager.genericError(ex.getMessage());
+ } catch (ParserConfigurationException | SAXException | TransformerConfigurationException ex) {
+ configurationResultManager.genericError(
+ "Error creating " + input.firstParameter() + EXPORT_FILE_NAME + " " + ex.getMessage());
+ } catch (final TransformerException ex) {
+ if (ex.getCause() instanceof FileNotFoundException) {
+ configurationResultManager.genericError("Permission denied on " + input.firstParameter());
+ } else {
+ configurationResultManager.genericError(
+ "Error creating " + input.firstParameter() + EXPORT_FILE_NAME + " " + ex.getMessage());
+ }
+ } catch (final SyncopeClientException ex) {
+ configurationResultManager.genericError("Error calling configuration service " + ex.getMessage());
+ }
+ } else {
+ configurationResultManager.commandOptionError(EXPORT_HELP_MESSAGE);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationGet.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationGet.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationGet.java
new file mode 100644
index 0000000..91f3dce
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationGet.java
@@ -0,0 +1,36 @@
+/*
+ * 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.configuration;
+
+import java.util.LinkedList;
+
+public class ConfigurationGet extends AbstractConfigurationCommand {
+
+ public ConfigurationGet() {
+ }
+
+ public void get() {
+ try {
+ configurationResultManager.fromGet(new LinkedList<>(configurationService.list().getPlainAttrs()));
+ } catch (final Exception ex) {
+ configurationResultManager.genericError(ex.getMessage());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationRead.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationRead.java
new file mode 100644
index 0000000..801f01d
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationRead.java
@@ -0,0 +1,62 @@
+/*
+ * 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.configuration;
+
+import java.util.LinkedList;
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.AttrTO;
+
+public class ConfigurationRead extends AbstractConfigurationCommand {
+
+ private static final String READ_HELP_MESSAGE = "configuration --read {CONF-NAME} {CONF-NAME} [...]";
+
+ private final Input input;
+
+ public ConfigurationRead(final Input input) {
+ this.input = input;
+ }
+
+ public void read() {
+ if (input.parameterNumber() >= 1) {
+ final LinkedList<AttrTO> attrList = new LinkedList<>();
+ boolean failed = false;
+ for (final String parameter : input.getParameters()) {
+ try {
+ attrList.add(configurationService.get(parameter));
+ } catch (final SyncopeClientException | WebServiceException ex) {
+ if (ex.getMessage().startsWith("NotFound")) {
+ configurationResultManager.notFoundError("Configuration", parameter);
+ } else {
+ configurationResultManager.genericError(ex.getMessage());
+ }
+ failed = true;
+ break;
+ }
+ }
+ if (!failed) {
+ configurationResultManager.fromGet(attrList);
+ }
+ } else {
+ configurationResultManager.commandOptionError(READ_HELP_MESSAGE);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationResultManager.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationResultManager.java
new file mode 100644
index 0000000..446d08a
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationResultManager.java
@@ -0,0 +1,53 @@
+/*
+ * 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.configuration;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import org.apache.syncope.client.cli.commands.CommonsResultManager;
+import org.apache.syncope.client.cli.messages.Table;
+import org.apache.syncope.common.lib.to.AttrTO;
+
+public class ConfigurationResultManager extends CommonsResultManager {
+
+ public void fromGet(final LinkedList<AttrTO> attrTOs) {
+ fromCommandToView("syncope configuration", attrTOs);
+ }
+
+ public void fromRead(final LinkedList<AttrTO> attrTOs) {
+ fromCommandToView("selected configuration attributes", attrTOs);
+ }
+
+ public void fromUpdate(final LinkedList<AttrTO> attrTOs) {
+ fromCommandToView("updated configuration attributes", attrTOs);
+ }
+
+ private void fromCommandToView(final String title, final LinkedList<AttrTO> attrTOs) {
+ final Table.TableBuilder tableBuilder
+ = new Table.TableBuilder(title).header("attribute").header("value");
+ for (final AttrTO attrTO : attrTOs) {
+ String attrValue = attrTO.getValues().toString();
+ attrValue = attrValue.substring(0, attrValue.length() - 1);
+ attrValue = attrValue.substring(1, attrValue.length());
+ tableBuilder.rowValues(
+ new LinkedList(Arrays.asList(attrTO.getSchema(), attrValue)));
+ }
+ tableBuilder.build().print();
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationUpdate.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationUpdate.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationUpdate.java
new file mode 100644
index 0000000..9be74e2
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/configuration/ConfigurationUpdate.java
@@ -0,0 +1,76 @@
+/*
+ * 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.configuration;
+
+import java.util.LinkedList;
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.AttrTO;
+
+public class ConfigurationUpdate extends AbstractConfigurationCommand {
+
+ private static final String UPDATE_HELP_MESSAGE
+ = "configuration --update {CONF-NAME}={CONF-VALUE} {CONF-NAME}={CONF-VALUE} [...]";
+
+ private final Input input;
+
+ public ConfigurationUpdate(final Input input) {
+ this.input = input;
+ }
+
+ public void update() {
+ if (input.parameterNumber() >= 1) {
+ Input.PairParameter pairParameter = null;
+ AttrTO attrTO;
+ final LinkedList<AttrTO> attrList = new LinkedList<>();
+ boolean failed = false;
+ for (final String parameter : input.getParameters()) {
+ try {
+ pairParameter = input.toPairParameter(parameter);
+ attrTO = configurationService.get(pairParameter.getKey());
+ attrTO.getValues().clear();
+ attrTO.getValues().add(pairParameter.getValue());
+ configurationService.set(attrTO);
+ attrList.add(attrTO);
+ } catch (final IllegalArgumentException ex) {
+ configurationResultManager.genericError(ex.getMessage(), UPDATE_HELP_MESSAGE);
+ failed = true;
+ break;
+ } catch (final SyncopeClientException | WebServiceException ex) {
+ if (ex.getMessage().startsWith("NotFound")) {
+ configurationResultManager.notFoundError("Configuration", pairParameter.getKey());
+ } else if (ex.getMessage().startsWith("InvalidValues")) {
+ configurationResultManager.genericError(
+ pairParameter.getValue() + " is not a valid value for " + pairParameter.getKey());
+ } else {
+ configurationResultManager.genericError(ex.getMessage());
+ }
+ failed = true;
+ break;
+ }
+ }
+ if (!failed) {
+ configurationResultManager.fromUpdate(attrList);
+ }
+ } else {
+ configurationResultManager.commandOptionError(UPDATE_HELP_MESSAGE);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/AbstractLoggerCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/AbstractLoggerCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/AbstractLoggerCommand.java
index 4654cb6..3782eac 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/AbstractLoggerCommand.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/AbstractLoggerCommand.java
@@ -25,6 +25,6 @@ public class AbstractLoggerCommand {
protected final LoggerService loggerService = SyncopeServices.get(LoggerService.class);
- protected final ResultManager resultManager = new ResultManager();
+ protected final LoggerResultManager loggerResultManager = new LoggerResultManager();
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCommand.java
index 34acc25..134c294 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCommand.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCommand.java
@@ -24,7 +24,6 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.client.cli.Command;
import org.apache.syncope.client.cli.Input;
import org.apache.syncope.client.cli.commands.AbstractCommand;
-import org.apache.syncope.client.cli.messages.Messages;
@Command(name = "logger")
public class LoggerCommand extends AbstractCommand {
@@ -73,7 +72,7 @@ public class LoggerCommand extends AbstractCommand {
System.out.println(HELP_MESSAGE);
break;
default:
- Messages.printDefaultMessage(input.getOption(), HELP_MESSAGE);
+ new LoggerResultManager().defaultError(input.getOption(), HELP_MESSAGE);
}
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCreate.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCreate.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCreate.java
index d70aad1..29d60ad 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCreate.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerCreate.java
@@ -52,16 +52,16 @@ public class LoggerCreate extends AbstractLoggerCommand {
loggerService.update(LoggerType.LOG, loggerTO);
loggerTOs.add(loggerTO);
} catch (final WebServiceException | SyncopeClientException | IllegalArgumentException ex) {
- resultManager.typeNotValidError(input.firstParameter());
+ loggerResultManager.typeNotValidError(input.firstParameter());
failed = true;
break;
}
}
if (!failed) {
- resultManager.fromUpdate(loggerTOs);
+ loggerResultManager.fromUpdate(loggerTOs);
}
} else {
- resultManager.commandOptionError(CREATE_HELP_MESSAGE);
+ loggerResultManager.commandOptionError(CREATE_HELP_MESSAGE);
}
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerDelete.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerDelete.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerDelete.java
index 44f39ee..6614f07 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerDelete.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerDelete.java
@@ -18,11 +18,9 @@
*/
package org.apache.syncope.client.cli.commands.logger;
-import java.util.LinkedList;
import javax.xml.ws.WebServiceException;
import org.apache.syncope.client.cli.Input;
import org.apache.syncope.common.lib.SyncopeClientException;
-import org.apache.syncope.common.lib.to.LoggerTO;
import org.apache.syncope.common.lib.types.LoggerType;
public class LoggerDelete extends AbstractLoggerCommand {
@@ -37,25 +35,20 @@ public class LoggerDelete extends AbstractLoggerCommand {
public void delete() {
if (input.parameterNumber() >= 1) {
- final LinkedList<LoggerTO> loggerTOs = new LinkedList<>();
- boolean failed = false;
for (final String parameter : input.getParameters()) {
try {
loggerService.delete(LoggerType.LOG, parameter);
+ loggerResultManager.deletedMessage("Logger", parameter);
} catch (final WebServiceException | SyncopeClientException ex) {
if (ex.getMessage().startsWith("NotFound")) {
- resultManager.notFoundError(parameter);
+ loggerResultManager.notFoundError("Logger", parameter);
} else {
- resultManager.genericError(ex.getMessage());
+ loggerResultManager.genericError(ex.getMessage());
}
- failed = true;
}
}
- if (!failed) {
- resultManager.fromDelete(loggerTOs);
- }
} else {
- resultManager.commandOptionError(DELETE_HELP_MESSAGE);
+ loggerResultManager.commandOptionError(DELETE_HELP_MESSAGE);
}
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerList.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerList.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerList.java
index bee7e7c..f65da34 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerList.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerList.java
@@ -29,9 +29,9 @@ public class LoggerList extends AbstractLoggerCommand {
public void list() {
try {
- resultManager.fromList(new LinkedList<>(loggerService.list(LoggerType.LOG)));
+ loggerResultManager.fromList(new LinkedList<>(loggerService.list(LoggerType.LOG)));
} catch (final SyncopeClientException ex) {
- resultManager.genericError("Error: " + ex.getMessage());
+ loggerResultManager.genericError("Error: " + ex.getMessage());
}
}
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerRead.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerRead.java
index 3cbca46..c796c47 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerRead.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerRead.java
@@ -44,19 +44,19 @@ public class LoggerRead extends AbstractLoggerCommand {
loggerTOs.add(loggerService.read(LoggerType.LOG, parameter));
} catch (final SyncopeClientException | WebServiceException ex) {
if (ex.getMessage().startsWith("NotFound")) {
- resultManager.notFoundError(parameter);
+ loggerResultManager.notFoundError("Logger", parameter);
} else {
- resultManager.genericError("Error: " + ex.getMessage());
+ loggerResultManager.genericError("Error: " + ex.getMessage());
}
failed = true;
break;
}
}
if (!failed) {
- resultManager.fromRead(loggerTOs);
+ loggerResultManager.fromRead(loggerTOs);
}
} else {
- resultManager.commandOptionError(READ_HELP_MESSAGE);
+ loggerResultManager.commandOptionError(READ_HELP_MESSAGE);
}
}
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerResultManager.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerResultManager.java
new file mode 100644
index 0000000..1a686cd
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerResultManager.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.commands.logger;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import org.apache.syncope.client.cli.commands.CommonsResultManager;
+import org.apache.syncope.client.cli.messages.Table;
+import org.apache.syncope.common.lib.to.LoggerTO;
+
+public class LoggerResultManager extends CommonsResultManager {
+
+ public void fromList(final LinkedList<LoggerTO> loggerTOs) {
+ fromCommandToView("list loggers", "level", loggerTOs);
+ }
+
+ public void fromRead(final LinkedList<LoggerTO> loggerTOs) {
+ fromCommandToView("read loggers", "level", loggerTOs);
+ }
+
+ public void fromCreate(final LinkedList<LoggerTO> loggerTOs) {
+ fromCommandToView("created loggers", "level", loggerTOs);
+ }
+
+ public void fromUpdate(final LinkedList<LoggerTO> loggerTOs) {
+ fromCommandToView("updated loggers", "new level", loggerTOs);
+ }
+
+ public void fromDelete(final LinkedList<LoggerTO> loggerTOs) {
+ fromCommandToView("deleted loggers", "new level", loggerTOs);
+ }
+
+ private void fromCommandToView(final String title,
+ final String secondHeader,
+ final LinkedList<LoggerTO> loggerTOs) {
+ final Table.TableBuilder tableBuilder
+ = new Table.TableBuilder(title).header("logger").header(secondHeader);
+ for (final LoggerTO loggerTO : loggerTOs) {
+ tableBuilder.rowValues(
+ new LinkedList(Arrays.asList(loggerTO.getKey(), loggerTO.getLevel().getLevel().name())));
+ }
+ tableBuilder.build().print();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdate.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdate.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdate.java
index d309c4c..cbfc196 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdate.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdate.java
@@ -52,23 +52,23 @@ public class LoggerUpdate extends AbstractLoggerCommand {
loggerTOs.add(loggerTO);
} catch (final WebServiceException | SyncopeClientException | IllegalArgumentException ex) {
if (ex.getMessage().startsWith("No enum constant org.apache.syncope.common.lib.types.")) {
- resultManager.typeNotValidError(input.firstParameter());
+ loggerResultManager.typeNotValidError(input.firstParameter());
} else if ("Parameter syntax error!".equalsIgnoreCase(ex.getMessage())) {
- resultManager.genericError(ex.getMessage(), UPDATE_HELP_MESSAGE);
+ loggerResultManager.genericError(ex.getMessage(), UPDATE_HELP_MESSAGE);
} else if (ex.getMessage().startsWith("NotFound")) {
- resultManager.notFoundError(parameter);
+ loggerResultManager.notFoundError("Logger", parameter);
} else {
- resultManager.genericError(ex.getMessage(), UPDATE_HELP_MESSAGE);
+ loggerResultManager.genericError(ex.getMessage(), UPDATE_HELP_MESSAGE);
}
failed = true;
break;
}
}
if (!failed) {
- resultManager.fromUpdate(loggerTOs);
+ loggerResultManager.fromUpdate(loggerTOs);
}
} else {
- resultManager.commandOptionError(UPDATE_HELP_MESSAGE);
+ loggerResultManager.commandOptionError(UPDATE_HELP_MESSAGE);
}
}
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdateAll.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdateAll.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdateAll.java
index 3393ae4..305fa30 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdateAll.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/LoggerUpdateAll.java
@@ -47,19 +47,19 @@ public class LoggerUpdateAll extends AbstractLoggerCommand {
loggerTOs.add(loggerTO);
} catch (final WebServiceException | SyncopeClientException | IllegalArgumentException ex) {
if (ex.getMessage().startsWith("No enum constant org.apache.syncope.common.lib.types.")) {
- resultManager.typeNotValidError(input.firstParameter());
+ loggerResultManager.typeNotValidError(input.firstParameter());
} else {
- resultManager.genericError(ex.getMessage(), UPDATE_ALL_HELP_MESSAGE);
+ loggerResultManager.genericError(ex.getMessage(), UPDATE_ALL_HELP_MESSAGE);
}
failed = true;
break;
}
}
if (!failed) {
- resultManager.fromUpdate(loggerTOs);
+ loggerResultManager.fromUpdate(loggerTOs);
}
} else {
- resultManager.commandOptionError(UPDATE_ALL_HELP_MESSAGE);
+ loggerResultManager.commandOptionError(UPDATE_ALL_HELP_MESSAGE);
}
}
}
http://git-wip-us.apache.org/repos/asf/syncope/blob/6b9cd592/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/ResultManager.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/ResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/ResultManager.java
deleted file mode 100644
index e993eb7..0000000
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/logger/ResultManager.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.client.cli.commands.logger;
-
-import java.util.Arrays;
-import java.util.LinkedList;
-import org.apache.syncope.client.cli.messages.Messages;
-import org.apache.syncope.client.cli.messages.Table;
-import org.apache.syncope.client.cli.util.CommandUtils;
-import org.apache.syncope.common.lib.to.LoggerTO;
-import org.apache.syncope.common.lib.types.LoggerLevel;
-
-public class ResultManager {
-
- public void notFoundError(final String parameter) {
- Messages.printNofFoundMessage("Logger", parameter);
- }
-
- public void typeNotValidError(final String parameter) {
- Messages.printTypeNotValidMessage("logger level", parameter, CommandUtils.fromEnumToArray(LoggerLevel.class));
- }
-
- public void commandOptionError(final String message) {
- Messages.printCommandOptionMessage(message);
- }
-
- public void genericError(final String... messages) {
- Messages.printMessage(messages);
- }
-
- public void fromList(final LinkedList<LoggerTO> loggerTOs) {
- fromCommandToView("list loggers", "level", loggerTOs);
- }
-
- public void fromRead(final LinkedList<LoggerTO> loggerTOs) {
- fromCommandToView("read loggers", "level", loggerTOs);
- }
-
- public void fromCreate(final LinkedList<LoggerTO> loggerTOs) {
- fromCommandToView("created loggers", "level", loggerTOs);
- }
-
- public void fromUpdate(final LinkedList<LoggerTO> loggerTOs) {
- fromCommandToView("updated loggers", "new level", loggerTOs);
- }
-
- public void fromDelete(final LinkedList<LoggerTO> loggerTOs) {
- fromCommandToView("deleted loggers", "new level", loggerTOs);
- }
-
- private void fromCommandToView(final String title,
- final String secondHeader,
- final LinkedList<LoggerTO> loggerTOs) {
- final Table.TableBuilder tableBuilder
- = new Table.TableBuilder(title).header("logger").header(secondHeader);
- for (final LoggerTO loggerTO : loggerTOs) {
- tableBuilder.rowValues(
- new LinkedList(Arrays.asList(loggerTO.getKey(), loggerTO.getLevel().getLevel().name())));
- }
- tableBuilder.build().print();
- }
-
-}