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/22 15:48:09 UTC
[1/2] syncope git commit: refactoring of the policy stack ,
SYNCOPE-158
Repository: syncope
Updated Branches:
refs/heads/master 15f6d19dc -> 493133037
refactoring of the policy 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/79d03167
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/79d03167
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/79d03167
Branch: refs/heads/master
Commit: 79d0316744dd868f3b9a489a4ead6885a8a8d65a
Parents: 15f6d19
Author: massi <ma...@tirasa.net>
Authored: Thu Oct 22 15:44:59 2015 +0200
Committer: massi <ma...@tirasa.net>
Committed: Thu Oct 22 15:45:08 2015 +0200
----------------------------------------------------------------------
.../client/cli/commands/PolicyCommand.java | 187 -------------------
.../cli/commands/policy/PolicyCommand.java | 111 +++++++++++
2 files changed, 111 insertions(+), 187 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/79d03167/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java
deleted file mode 100644
index fc3a8c0..0000000
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/PolicyCommand.java
+++ /dev/null
@@ -1,187 +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.util.ArrayList;
-import java.util.List;
-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.util.CommandUtils;
-import org.apache.syncope.common.lib.SyncopeClientException;
-import org.apache.syncope.common.lib.policy.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;
-
-@Command(name = "policy")
-public class PolicyCommand extends AbstractCommand {
-
- private static final Logger LOG = LoggerFactory.getLogger(PolicyCommand.class);
-
- private static final String HELP_MESSAGE = "Usage: policy [options]\n"
- + " Options:\n"
- + " --help \n"
- + " --list-policy \n"
- + " Syntax: --list-policy {POLICY-TYPE} \n"
- + " Policy type: ACCOUNT / PASSWORD / SYNC / PUSH\n"
- + " --read \n"
- + " Syntax: --read {POLICY-ID} {POLICY-ID} [...]\n"
- + " --delete \n"
- + " Syntax: --delete {POLICY-ID} {POLICY-ID} [...]";
-
- @Override
- public void execute(final Input input) {
- LOG.debug("Option: {}", input.getOption());
- LOG.debug("Parameters:");
- for (final String parameter : input.getParameters()) {
- LOG.debug(" > " + parameter);
- }
-
- final String[] parameters = input.getParameters();
-
- if (StringUtils.isBlank(input.getOption())) {
- input.setOption(Options.HELP.getOptionName());
- }
-
- final PolicyService policyService = SyncopeServices.get(PolicyService.class);
- switch (Options.fromName(input.getOption())) {
- case LIST_POLICY:
- final String listPolicyErrorMessage = "policy --list-policy {POLICY-TYPE}\n"
- + " Policy type: ACCOUNT / PASSWORD / SYNC / PUSH";
-
- if (parameters.length == 1) {
- try {
- for (final AbstractPolicyTO policyTO : policyService.list(PolicyType.valueOf(parameters[0]))) {
- System.out.println(policyTO);
- }
- } catch (final SyncopeClientException ex) {
- Messages.printMessage(ex.getMessage());
- } catch (final IllegalArgumentException ex) {
- Messages.printTypeNotValidMessage(
- "policy", input.firstParameter(), CommandUtils.fromEnumToArray(PolicyType.class));
- }
- } else {
- Messages.printCommandOptionMessage(listPolicyErrorMessage);
- }
- break;
- case READ:
- final String readErrorMessage = "policy --read {POLICY-ID} {POLICY-ID} [...]";
-
- if (parameters.length >= 1) {
- for (final String parameter : parameters) {
- try {
- System.out.println(policyService.read(Long.valueOf(parameter)));
- } catch (final NumberFormatException ex) {
- Messages.printIdNotNumberDeletedMessage("policy", parameter);
- } catch (final WebServiceException | SyncopeClientException ex) {
- if (ex.getMessage().startsWith("NotFound")) {
- Messages.printNofFoundMessage("Policy", parameter);
- } else {
- Messages.printMessage(ex.getMessage());
- }
- }
- }
- } else {
- Messages.printCommandOptionMessage(readErrorMessage);
- }
- break;
- case DELETE:
- final String deleteErrorMessage = "policy --delete {POLICY-ID} {POLICY-ID} [...]";
-
- if (parameters.length >= 1) {
- for (final String parameter : parameters) {
- try {
- policyService.delete(Long.valueOf(parameter));
- Messages.printDeletedMessage("Policy", parameter);
- } catch (final WebServiceException | SyncopeClientException ex) {
- System.out.println("Error:");
- if (ex.getMessage().startsWith("NotFound")) {
- Messages.printNofFoundMessage("Policy", parameter);
- } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
- Messages.printMessage("You cannot delete policy " + parameter);
- } else {
- Messages.printMessage(ex.getMessage());
- }
- } catch (final NumberFormatException ex) {
- Messages.printIdNotNumberDeletedMessage("policy", parameter);
- }
- }
- } else {
- Messages.printCommandOptionMessage(deleteErrorMessage);
- }
- break;
- case HELP:
- System.out.println(HELP_MESSAGE);
- break;
- default:
- Messages.printDefaultMessage(input.getOption(), HELP_MESSAGE);
- }
- }
-
- @Override
- public String getHelpMessage() {
- return HELP_MESSAGE;
- }
-
- private enum Options {
-
- HELP("--help"),
- LIST_POLICY("--list-policy"),
- READ("--read"),
- DELETE("--delete");
-
- 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/79d03167/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyCommand.java
new file mode 100644
index 0000000..7c92d9d
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyCommand.java
@@ -0,0 +1,111 @@
+/*
+ * 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.policy;
+
+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;
+
+@Command(name = "policy")
+public class PolicyCommand extends AbstractCommand {
+
+ private static final String HELP_MESSAGE = "Usage: policy [options]\n"
+ + " Options:\n"
+ + " --help \n"
+ + " --list-policy \n"
+ + " Syntax: --list-policy {POLICY-TYPE} \n"
+ + " Policy type: ACCOUNT / PASSWORD / SYNC / PUSH\n"
+ + " --read \n"
+ + " Syntax: --read {POLICY-ID} {POLICY-ID} [...]\n"
+ + " --delete \n"
+ + " Syntax: --delete {POLICY-ID} {POLICY-ID} [...]";
+
+ @Override
+ public void execute(final Input input) {
+ if (StringUtils.isBlank(input.getOption())) {
+ input.setOption(Options.HELP.getOptionName());
+ }
+
+ switch (Options.fromName(input.getOption())) {
+ case LIST_POLICY:
+ new PolicyList(input).list();
+ break;
+ case READ:
+ new PolicyRead(input).read();
+ break;
+ case DELETE:
+ new PolicyDelete(input).delete();
+ break;
+ case HELP:
+ System.out.println(HELP_MESSAGE);
+ break;
+ default:
+ new PolicyResultManager().defaultError(input.getOption(), HELP_MESSAGE);
+ }
+ }
+
+ @Override
+ public String getHelpMessage() {
+ return HELP_MESSAGE;
+ }
+
+ private enum Options {
+
+ HELP("--help"),
+ LIST_POLICY("--list-policy"),
+ READ("--read"),
+ DELETE("--delete");
+
+ 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;
+ }
+ }
+
+}
[2/2] syncope git commit: refactoring of the policy stack ,
SYNCOPE-158
Posted by ma...@apache.org.
refactoring of the policy 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/49313303
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/49313303
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/49313303
Branch: refs/heads/master
Commit: 493133037c867b335f1e5f046bba8fa78ad40f55
Parents: 79d0316
Author: massi <ma...@tirasa.net>
Authored: Thu Oct 22 15:45:18 2015 +0200
Committer: massi <ma...@tirasa.net>
Committed: Thu Oct 22 15:45:18 2015 +0200
----------------------------------------------------------------------
.../commands/policy/AbstractPolicyCommand.java | 30 +++++
.../cli/commands/policy/PolicyDelete.java | 59 +++++++++
.../client/cli/commands/policy/PolicyList.java | 59 +++++++++
.../client/cli/commands/policy/PolicyRead.java | 58 +++++++++
.../commands/policy/PolicyResultManager.java | 120 +++++++++++++++++++
5 files changed, 326 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/syncope/blob/49313303/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/AbstractPolicyCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/AbstractPolicyCommand.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/AbstractPolicyCommand.java
new file mode 100644
index 0000000..0bab4e5
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/AbstractPolicyCommand.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.policy;
+
+import org.apache.syncope.client.cli.SyncopeServices;
+import org.apache.syncope.common.rest.api.service.PolicyService;
+
+public abstract class AbstractPolicyCommand {
+
+ protected final PolicyService policyService = SyncopeServices.get(PolicyService.class);
+
+ protected final PolicyResultManager policyResultManager = new PolicyResultManager();
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/49313303/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyDelete.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyDelete.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyDelete.java
new file mode 100644
index 0000000..15ffa8d
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyDelete.java
@@ -0,0 +1,59 @@
+/*
+ * 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.policy;
+
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+
+public class PolicyDelete extends AbstractPolicyCommand {
+
+ private static final String DELETE_HELP_MESSAGE = "policy --delete {POLICY-ID} {POLICY-ID} [...]";
+
+ private final Input input;
+
+ public PolicyDelete(final Input input) {
+ this.input = input;
+ }
+
+ public void delete() {
+ if (input.parameterNumber() >= 1) {
+ for (final String parameter : input.getParameters()) {
+ try {
+ policyService.delete(Long.valueOf(parameter));
+ policyResultManager.deletedMessage("Policy", parameter);
+ } catch (final WebServiceException | SyncopeClientException ex) {
+ System.out.println("Error:");
+ if (ex.getMessage().startsWith("NotFound")) {
+ policyResultManager.notFoundError("Policy", parameter);
+ } else if (ex.getMessage().startsWith("DataIntegrityViolation")) {
+ policyResultManager.generic("You cannot delete policy " + parameter);
+ } else {
+ policyResultManager.generic(ex.getMessage());
+ }
+ } catch (final NumberFormatException ex) {
+ policyResultManager.notBooleanDeletedError("policy", parameter);
+ }
+ }
+ } else {
+ policyResultManager.commandOptionError(DELETE_HELP_MESSAGE);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/49313303/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyList.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyList.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyList.java
new file mode 100644
index 0000000..c05acf7
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyList.java
@@ -0,0 +1,59 @@
+/*
+ * 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.policy;
+
+import java.util.LinkedList;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.client.cli.util.CommandUtils;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.policy.AbstractPolicyTO;
+import org.apache.syncope.common.lib.types.PolicyType;
+
+public class PolicyList extends AbstractPolicyCommand {
+
+ private static final String LIST_HELP_MESSAGE = "policy --list-policy {POLICY-TYPE}\n"
+ + " Policy type: ACCOUNT / PASSWORD / SYNC / PUSH";
+
+ private final Input input;
+
+ public PolicyList(final Input input) {
+ this.input = input;
+ }
+
+ public void list() {
+
+ if (input.parameterNumber() == 1) {
+ try {
+ final PolicyType policyType = PolicyType.valueOf(input.firstParameter());
+ final LinkedList<AbstractPolicyTO> policyTOs = new LinkedList<>();
+ for (final AbstractPolicyTO policyTO : policyService.list(policyType)) {
+ policyTOs.add(policyTO);
+ }
+ policyResultManager.fromList(policyType, policyTOs);
+ } catch (final SyncopeClientException ex) {
+ policyResultManager.generic(ex.getMessage());
+ } catch (final IllegalArgumentException ex) {
+ policyResultManager.typeNotValidError(
+ "policy", input.firstParameter(), CommandUtils.fromEnumToArray(PolicyType.class));
+ }
+ } else {
+ policyResultManager.commandOptionError(LIST_HELP_MESSAGE);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/49313303/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyRead.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyRead.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyRead.java
new file mode 100644
index 0000000..f20d41e
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyRead.java
@@ -0,0 +1,58 @@
+/*
+ * 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.policy;
+
+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.policy.AbstractPolicyTO;
+
+public class PolicyRead extends AbstractPolicyCommand {
+
+ private static final String READ_HELP_MESSAGE = "policy --read {POLICY-ID} {POLICY-ID} [...]";
+
+ private final Input input;
+
+ public PolicyRead(final Input input) {
+ this.input = input;
+ }
+
+ public void read() {
+ if (input.parameterNumber() >= 1) {
+ final LinkedList<AbstractPolicyTO> policyTOs = new LinkedList<>();
+ for (final String parameter : input.getParameters()) {
+ try {
+ policyTOs.add(policyService.read(Long.valueOf(parameter)));
+ policyResultManager.fromRead(policyTOs);
+ } catch (final NumberFormatException ex) {
+ policyResultManager.notBooleanDeletedError("policy", parameter);
+ } catch (final WebServiceException | SyncopeClientException ex) {
+ if (ex.getMessage().startsWith("NotFound")) {
+ policyResultManager.notFoundError("Policy", parameter);
+ } else {
+ policyResultManager.generic(ex.getMessage());
+ }
+ }
+ }
+ } else {
+ policyResultManager.commandOptionError(READ_HELP_MESSAGE);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/syncope/blob/49313303/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyResultManager.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyResultManager.java b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyResultManager.java
new file mode 100644
index 0000000..88e40a0
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/policy/PolicyResultManager.java
@@ -0,0 +1,120 @@
+/*
+ * 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.policy;
+
+import java.util.LinkedList;
+import org.apache.syncope.client.cli.commands.CommonsResultManager;
+import org.apache.syncope.common.lib.policy.AbstractPolicyTO;
+import org.apache.syncope.common.lib.policy.AccountPolicyTO;
+import org.apache.syncope.common.lib.policy.PasswordPolicyTO;
+import org.apache.syncope.common.lib.policy.SyncPolicyTO;
+import org.apache.syncope.common.lib.types.PolicyType;
+
+public class PolicyResultManager extends CommonsResultManager {
+
+ public void fromRead(final LinkedList<AbstractPolicyTO> policyTOs) {
+ for (AbstractPolicyTO policyTO : policyTOs) {
+ if (!policyTOs.isEmpty()) {
+ final PolicyType policyType = policyTO.getType();
+ switch (policyType) {
+ case ACCOUNT:
+ printAccountPolicy((AccountPolicyTO) policyTO);
+ break;
+ case PASSWORD:
+ printPasswordPolicy((PasswordPolicyTO) policyTO);
+ break;
+ case PUSH:
+ System.out.println(policyTO);
+ break;
+ case SYNC:
+ printSyncPolicy((SyncPolicyTO) policyTO);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ }
+
+ public void fromList(final PolicyType policyType, final LinkedList<AbstractPolicyTO> policyTOs) {
+ switch (policyType) {
+ case ACCOUNT:
+ for (final AbstractPolicyTO policyTO : policyTOs) {
+ printAccountPolicy((AccountPolicyTO) policyTO);
+ }
+ break;
+ case PASSWORD:
+ for (final AbstractPolicyTO policyTO : policyTOs) {
+ printPasswordPolicy((PasswordPolicyTO) policyTO);
+ }
+ break;
+ case PUSH:
+ for (final AbstractPolicyTO policyTO : policyTOs) {
+ System.out.println(policyTO);
+ }
+ break;
+ case SYNC:
+ for (final AbstractPolicyTO policyTO : policyTOs) {
+ printSyncPolicy((SyncPolicyTO) policyTO);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ public void printAccountPolicy(final AccountPolicyTO policyTO) {
+ System.out.println(" > KEY: " + String.valueOf(policyTO.getKey()));
+ System.out.println(" type: " + policyTO.getType().name());
+ System.out.println(" description: " + policyTO.getDescription());
+ System.out.println(" resources : " + policyTO.getUsedByResources().toString());
+ System.out.println(" realms : " + policyTO.getUsedByRealms().toString());
+ System.out.println(" max authentication attempts : " + policyTO.getMaxAuthenticationAttempts());
+ System.out.println(" propagation suspension : " + policyTO.isPropagateSuspension());
+ System.out.println(" RULES : ");
+ System.out.println(" > class : " + policyTO.getRuleConfs());
+ }
+
+ public void printPasswordPolicy(final PasswordPolicyTO policyTO) {
+ System.out.println(" > KEY: " + String.valueOf(policyTO.getKey()));
+ System.out.println(" type: " + policyTO.getType().name());
+ System.out.println(" description: " + policyTO.getDescription());
+ System.out.println(" resources : " + policyTO.getUsedByResources().toString());
+ System.out.println(" realms : " + policyTO.getUsedByRealms().toString());
+ System.out.println(" history lenght : " + policyTO.getHistoryLength());
+ System.out.println(" allow null password : " + policyTO.isAllowNullPassword());
+ System.out.println(" RULES : ");
+ System.out.println(" > class : " + ((PasswordPolicyTO) policyTO).getRuleConfs());
+ }
+
+ public void printSyncPolicy(final SyncPolicyTO policyTO) {
+ System.out.println(" > KEY: " + String.valueOf(policyTO.getKey()));
+ System.out.println(" type: " + policyTO.getType().name());
+ System.out.println(" description: " + policyTO.getDescription());
+ System.out.println(" resources : " + policyTO.getUsedByResources().toString());
+ System.out.println(" realms : " + policyTO.getUsedByRealms().toString());
+ if (policyTO.getSpecification() != null) {
+ System.out.println(" conflict resolution action: "
+ + policyTO.getSpecification().getConflictResolutionAction().name());
+ System.out.println(" correlation rule : "
+ + policyTO.getSpecification().getCorrelationRules().toString());
+ }
+ }
+}