syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [1/3] syncope git commit: Fixed SYNCOPE-591
Date Wed, 28 Oct 2015 16:21:46 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 74e867e8c -> 3c36fe10e


Fixed SYNCOPE-591


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

Branch: refs/heads/master
Commit: 435e59db756bbfcd836f651010cc9e4a61ba2957
Parents: 74e867e
Author: massi <massimiliano.perrone@tirasa.net>
Authored: Wed Oct 28 12:11:19 2015 +0100
Committer: massi <massimiliano.perrone@tirasa.net>
Committed: Wed Oct 28 12:11:19 2015 +0100

----------------------------------------------------------------------
 .../question/AbstractQuestionCommand.java       |  27 +++++
 .../cli/commands/question/QuestionCommand.java  | 114 +++++++++++++++++++
 .../cli/commands/question/QuestionDelete.java   |  57 ++++++++++
 .../cli/commands/question/QuestionList.java     |  32 ++++++
 .../cli/commands/question/QuestionRead.java     |  61 ++++++++++
 .../commands/question/QuestionReadByUser.java   |  53 +++++++++
 .../question/QuestionResultManager.java         |  38 +++++++
 .../question/QuestionSyncopeOperations.java     |  46 ++++++++
 .../cli/commands/role/AbstractRoleCommand.java  |   6 +-
 .../client/cli/commands/role/RoleDelete.java    |   2 +-
 10 files changed, 432 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/435e59db/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/AbstractQuestionCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/AbstractQuestionCommand.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/AbstractQuestionCommand.java
new file mode 100644
index 0000000..0a3846a
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/AbstractQuestionCommand.java
@@ -0,0 +1,27 @@
+/*
+ * 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.question;
+
+public abstract class AbstractQuestionCommand {
+
+    protected final QuestionSyncopeOperations questionSyncopeOperations = new QuestionSyncopeOperations();
+
+    protected final QuestionResultManager questionResultManager = new QuestionResultManager();
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/435e59db/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionCommand.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionCommand.java
new file mode 100644
index 0000000..2427203
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionCommand.java
@@ -0,0 +1,114 @@
+/*
+ * 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.question;
+
+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 = "question")
+public class QuestionCommand extends AbstractCommand {
+
+    private static final String HELP_MESSAGE = "Usage: question [options]\n"
+            + "  Options:\n"
+            + "    --help \n"
+            + "    --list \n"
+            + "    --read \n"
+            + "       Syntax: --read {QUESTION-ID} {QUESTION-ID} [...]\n"
+            + "    --read-by-user \n"
+            + "       Syntax: --read-by-user {USERNAME}\n"
+            + "    --delete \n"
+            + "       Syntax: --delete {QUESTION-ID} {QUESTION-ID} [...]";
+
+    @Override
+    public void execute(final Input input) {
+        if (StringUtils.isBlank(input.getOption())) {
+            input.setOption(QuestionOptions.HELP.getOptionName());
+        }
+
+        switch (QuestionOptions.fromName(input.getOption())) {
+            case LIST:
+                new QuestionList().list();
+                break;
+            case READ:
+                new QuestionRead(input).read();
+                break;
+            case READ_BY_USER:
+                new QuestionReadByUser(input).read();
+                break;
+            case DELETE:
+                break;
+            case HELP:
+                System.out.println(HELP_MESSAGE);
+                break;
+            default:
+                new QuestionResultManager().defaultError(input.getOption(), HELP_MESSAGE);
+        }
+    }
+
+    @Override
+    public String getHelpMessage() {
+        return HELP_MESSAGE;
+    }
+
+    private enum QuestionOptions {
+
+        HELP("--help"),
+        LIST("--list"),
+        READ("--read"),
+        READ_BY_USER("--read-by-user"),
+        DELETE("--delete");
+
+        private final String optionName;
+
+        QuestionOptions(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 QuestionOptions fromName(final String name) {
+            QuestionOptions optionToReturn = HELP;
+            for (final QuestionOptions option : QuestionOptions.values()) {
+                if (option.equalsOptionName(name)) {
+                    optionToReturn = option;
+                }
+            }
+            return optionToReturn;
+        }
+
+        public static List<String> toList() {
+            final List<String> options = new ArrayList<>();
+            for (final QuestionOptions value : values()) {
+                options.add(value.getOptionName());
+            }
+            return options;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/435e59db/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionDelete.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionDelete.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionDelete.java
new file mode 100644
index 0000000..d57ae5c
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionDelete.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.question;
+
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+
+public class QuestionDelete extends AbstractQuestionCommand {
+
+    private static final String DELETE_HELP_MESSAGE = "question --delete {QUESTION-ID} {QUESTION-ID}
[...]";
+
+    private final Input input;
+
+    public QuestionDelete(final Input input) {
+        this.input = input;
+    }
+
+    public void delete() {
+        if (input.getParameters().length >= 1) {
+            for (final String parameter : input.getParameters()) {
+                try {
+                    questionSyncopeOperations.delete(parameter);
+                    questionResultManager.deletedMessage("security question", parameter);
+                } catch (final SyncopeClientException | WebServiceException ex) {
+                    if (ex.getMessage().startsWith("NotFound")) {
+                        questionResultManager.notFoundError("Security question", parameter);
+                    } else {
+                        questionResultManager.generic("Error: " + ex.getMessage());
+                    }
+                    break;
+                } catch (final NumberFormatException ex) {
+                    questionResultManager.numberFormatException("security question", parameter);
+                }
+            }
+        } else {
+            questionResultManager.commandOptionError(DELETE_HELP_MESSAGE);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/435e59db/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionList.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionList.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionList.java
new file mode 100644
index 0000000..836554a
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionList.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.question;
+
+import org.apache.syncope.common.lib.SyncopeClientException;
+
+public class QuestionList extends AbstractQuestionCommand {
+
+    public void list() {
+        try {
+            questionResultManager.toView(questionSyncopeOperations.list());
+        } catch (final SyncopeClientException ex) {
+            questionResultManager.generic(ex.getMessage());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/435e59db/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionRead.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionRead.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionRead.java
new file mode 100644
index 0000000..5f96cd5
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionRead.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.question;
+
+import java.util.ArrayList;
+import java.util.List;
+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.SecurityQuestionTO;
+
+public class QuestionRead extends AbstractQuestionCommand {
+
+    private static final String READ_HELP_MESSAGE = "question --read {QUESTION-ID} {QUESTION-ID}
[...]";
+
+    private final Input input;
+
+    public QuestionRead(final Input input) {
+        this.input = input;
+    }
+
+    public void read() {
+        if (input.getParameters().length >= 1) {
+            final List<SecurityQuestionTO> questionTOs = new ArrayList<>();
+            for (final String parameter : input.getParameters()) {
+                try {
+                    questionTOs.add(questionSyncopeOperations.read(parameter));
+                } catch (final SyncopeClientException | WebServiceException ex) {
+                    if (ex.getMessage().startsWith("NotFound")) {
+                        questionResultManager.notFoundError("Security question", parameter);
+                    } else {
+                        questionResultManager.generic("Error: " + ex.getMessage());
+                    }
+                    break;
+                } catch (final NumberFormatException ex) {
+                    questionResultManager.numberFormatException("security question", parameter);
+                }
+            }
+            questionResultManager.toView(questionTOs);
+        } else {
+            questionResultManager.commandOptionError(READ_HELP_MESSAGE);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/435e59db/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionReadByUser.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionReadByUser.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionReadByUser.java
new file mode 100644
index 0000000..fa7b23d
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionReadByUser.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.question;
+
+import javax.xml.ws.WebServiceException;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+
+public class QuestionReadByUser extends AbstractQuestionCommand {
+
+    private static final String READ_HELP_MESSAGE = "question --read-by-user {USERNAME}";
+
+    private final Input input;
+
+    public QuestionReadByUser(final Input input) {
+        this.input = input;
+    }
+
+    public void read() {
+        if (input.getParameters().length == 1) {
+            try {
+                questionResultManager.printQuestion(questionSyncopeOperations.readByUser(input.firstParameter()));
+            } catch (final SyncopeClientException | WebServiceException ex) {
+                if (ex.getMessage().startsWith("NotFound")) {
+                    questionResultManager.notFoundError("Security question", input.firstParameter());
+                } else {
+                    questionResultManager.generic("Error: " + ex.getMessage());
+                }
+            } catch (final NumberFormatException ex) {
+                questionResultManager.numberFormatException("security question", input.firstParameter());
+            }
+        } else {
+            questionResultManager.commandOptionError(READ_HELP_MESSAGE);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/435e59db/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionResultManager.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionResultManager.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionResultManager.java
new file mode 100644
index 0000000..761b56b
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionResultManager.java
@@ -0,0 +1,38 @@
+/*
+ * 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.question;
+
+import java.util.List;
+import org.apache.syncope.client.cli.commands.CommonsResultManager;
+import org.apache.syncope.common.lib.to.SecurityQuestionTO;
+
+public class QuestionResultManager extends CommonsResultManager {
+
+    public void toView(final List<SecurityQuestionTO> questionTOs) {
+        for (final SecurityQuestionTO questionTO : questionTOs) {
+            printQuestion(questionTO);
+        }
+    }
+
+    public void printQuestion(final SecurityQuestionTO securityQuestionTO) {
+        System.out.println(" > SECURITY QUESTION ID: " + securityQuestionTO.getKey());
+        System.out.println("    content: " + securityQuestionTO.getContent());
+        System.out.println("");
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/435e59db/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionSyncopeOperations.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionSyncopeOperations.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionSyncopeOperations.java
new file mode 100644
index 0000000..238a576
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/question/QuestionSyncopeOperations.java
@@ -0,0 +1,46 @@
+/*
+ * 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.question;
+
+import java.util.List;
+import org.apache.syncope.client.cli.SyncopeServices;
+import org.apache.syncope.common.lib.to.SecurityQuestionTO;
+import org.apache.syncope.common.rest.api.service.SecurityQuestionService;
+
+public class QuestionSyncopeOperations {
+
+    private final SecurityQuestionService securityQuestionService = SyncopeServices.get(SecurityQuestionService.class);
+
+    public List<SecurityQuestionTO> list() {
+        return securityQuestionService.list();
+    }
+
+    public void delete(final String questionId) {
+        securityQuestionService.delete(Long.valueOf(questionId));
+    }
+
+    public SecurityQuestionTO read(final String questionId) {
+        return securityQuestionService.read(Long.valueOf(questionId));
+    }
+    
+    public SecurityQuestionTO readByUser(final String username) {
+        return securityQuestionService.readByUser(username);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/435e59db/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/AbstractRoleCommand.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/AbstractRoleCommand.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/AbstractRoleCommand.java
index b4709a0..de4aac6 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/AbstractRoleCommand.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/AbstractRoleCommand.java
@@ -18,10 +18,10 @@
  */
 package org.apache.syncope.client.cli.commands.role;
 
-public class AbstractRoleCommand {
+public abstract class AbstractRoleCommand {
 
-    protected RoleSyncopeOperations roleSyncopeOperations = new RoleSyncopeOperations();
+    protected final RoleSyncopeOperations roleSyncopeOperations = new RoleSyncopeOperations();
 
-    protected RoleResultManager roleResultManager = new RoleResultManager();
+    protected final RoleResultManager roleResultManager = new RoleResultManager();
 
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/435e59db/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleDelete.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleDelete.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleDelete.java
index 50ac248..e47a40e 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleDelete.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/role/RoleDelete.java
@@ -46,7 +46,7 @@ public class RoleDelete extends AbstractRoleCommand {
                     }
                     break;
                 } catch (final NumberFormatException ex) {
-                    roleResultManager.numberFormatException("user", parameter);
+                    roleResultManager.numberFormatException("role", parameter);
                 }
             }
         } else {


Mime
View raw message