added read by username option, SYNCOPE-158

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

Branch: refs/heads/master
Commit: a02adbd8771a80ec6e606d3adf0eeb8f2b7fb39d
Parents: 341c985
Author: massi <[email protected]>
Authored: Mon Nov 30 13:09:52 2015 +0100
Committer: massi <[email protected]>
Committed: Mon Nov 30 16:16:38 2015 +0100

----------------------------------------------------------------------
 .../client/cli/commands/user/UserCommand.java   | 10 ++-
 .../client/cli/commands/user/UserGetKey.java    |  2 +-
 .../cli/commands/user/UserReadByUserId.java     | 66 +++++++++++++++++++
 .../cli/commands/user/UserReadByUsername.java   | 67 ++++++++++++++++++++
 .../cli/src/main/resources/messages.properties  |  2 +-
 5 files changed, 142 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/a02adbd8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserCommand.java
----------------------------------------------------------------------
diff --git 
a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserCommand.java
 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserCommand.java
index 3832625..e74eb95 100644
--- 
a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserCommand.java
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserCommand.java
@@ -49,8 +49,11 @@ public class UserCommand extends AbstractCommand {
             case GET_BY_USERNAME:
                 new UserGetUsername(input).get();
                 break;
-            case READ:
-                new UserRead(input).read();
+            case READ_BY_ID:
+                new UserReadByUserId(input).read();
+                break;
+            case READ_BY_USERNAME:
+                new UserReadByUsername(input).read();
                 break;
             case SEARCH_BY_ATTRIBUTE:
                 new UserSearchByAttribute(input).search();
@@ -90,7 +93,8 @@ public class UserCommand extends AbstractCommand {
         LIST("--list"),
         GET_BY_KEY("--get-user-key"),
         GET_BY_USERNAME("--get-username"),
-        READ("--read"),
+        READ_BY_ID("--read-by-userid"),
+        READ_BY_USERNAME("--read-by-username"),
         SEARCH_BY_ATTRIBUTE("--search-by-attribute"),
         SEARCH_BY_ROLE("--search-by-role"),
         SEARCH_BY_RESOURCE("--search-by-resource"),

http://git-wip-us.apache.org/repos/asf/syncope/blob/a02adbd8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserGetKey.java
----------------------------------------------------------------------
diff --git 
a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserGetKey.java
 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserGetKey.java
index 5012ea9..2eb1e3d 100644
--- 
a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserGetKey.java
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserGetKey.java
@@ -39,7 +39,7 @@ public class UserGetKey extends AbstractUserCommand {
         if (input.getParameters().length == 1) {
             try {
                 final String userId = 
userSyncopeOperations.getIdFromUsername(input.firstParameter());
-                userResultManager.genericMessage(input.firstParameter() + " 
user ID is : " + userId);
+                userResultManager.genericMessage(input.firstParameter() + " 
user ID is " + userId);
             } catch (final SyncopeClientException ex) {
                 LOG.error("Error getting user", ex);
                 userResultManager.genericError(ex.getMessage());

http://git-wip-us.apache.org/repos/asf/syncope/blob/a02adbd8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserReadByUserId.java
----------------------------------------------------------------------
diff --git 
a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserReadByUserId.java
 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserReadByUserId.java
new file mode 100644
index 0000000..25ff680
--- /dev/null
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserReadByUserId.java
@@ -0,0 +1,66 @@
+/*
+ * 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.user;
+
+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.UserTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UserReadByUserId extends AbstractUserCommand {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(UserReadByUserId.class);
+
+    private static final String READ_HELP_MESSAGE = "user --read {USER-ID} 
{USER-ID} [...]";
+
+    private final Input input;
+
+    public UserReadByUserId(final Input input) {
+        this.input = input;
+    }
+
+    public void read() {
+        if (input.getParameters().length >= 1) {
+            final List<UserTO> userTOs = new ArrayList<>();
+            for (final String parameter : input.getParameters()) {
+                try {
+                    userTOs.add(userSyncopeOperations.read(parameter));
+                } catch (final SyncopeClientException | WebServiceException 
ex) {
+                    LOG.error("Error reading user", ex);
+                    if (ex.getMessage().startsWith("NotFound")) {
+                        userResultManager.notFoundError("User", parameter);
+                    } else {
+                        userResultManager.genericError(ex.getMessage());
+                    }
+                    break;
+                } catch (final NumberFormatException ex) {
+                    LOG.error("Error reading user", ex);
+                    userResultManager.numberFormatException("user", parameter);
+                }
+            }
+            userResultManager.printUsers(userTOs);
+        } else {
+            userResultManager.commandOptionError(READ_HELP_MESSAGE);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/a02adbd8/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserReadByUsername.java
----------------------------------------------------------------------
diff --git 
a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserReadByUsername.java
 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserReadByUsername.java
new file mode 100644
index 0000000..bc325bd
--- /dev/null
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserReadByUsername.java
@@ -0,0 +1,67 @@
+/*
+ * 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.user;
+
+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.UserTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UserReadByUsername extends AbstractUserCommand {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(UserReadByUsername.class);
+
+    private static final String READ_HELP_MESSAGE = "user --read {USERNAME} 
{USERNAME} [...]";
+
+    private final Input input;
+
+    public UserReadByUsername(final Input input) {
+        this.input = input;
+    }
+
+    public void read() {
+        if (input.getParameters().length >= 1) {
+            final List<UserTO> userTOs = new ArrayList<>();
+            for (final String parameter : input.getParameters()) {
+                try {
+                    final String userId = 
userSyncopeOperations.getIdFromUsername(parameter);
+                    userTOs.add(userSyncopeOperations.read(userId));
+                } catch (final SyncopeClientException | WebServiceException 
ex) {
+                    LOG.error("Error reading user", ex);
+                    if (ex.getMessage().startsWith("NotFound")) {
+                        userResultManager.notFoundError("User", parameter);
+                    } else {
+                        userResultManager.genericError(ex.getMessage());
+                    }
+                    break;
+                } catch (final NumberFormatException ex) {
+                    LOG.error("Error reading user", ex);
+                    userResultManager.numberFormatException("user", parameter);
+                }
+            }
+            userResultManager.printUsers(userTOs);
+        } else {
+            userResultManager.commandOptionError(READ_HELP_MESSAGE);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/a02adbd8/client/cli/src/main/resources/messages.properties
----------------------------------------------------------------------
diff --git a/client/cli/src/main/resources/messages.properties 
b/client/cli/src/main/resources/messages.properties
index a4fd5f4..d51a25e 100644
--- a/client/cli/src/main/resources/messages.properties
+++ b/client/cli/src/main/resources/messages.properties
@@ -30,5 +30,5 @@ resource.help.message=\nUsage: resource [options]\n  
Options:\n    --help \n
 role.help.message=\nUsage: role [options]\n  Options:\n    --help \n    
--details \n    --list \n    --read \n       Syntax: --read {ROLE-ID} {ROLE-ID} 
[...]\n    --delete \n       Syntax: --delete {ROLE-ID} {ROLE-ID} [...]\n
 schema.help.message=\nUsage: schema [options]\n  Options:\n    --help \n    
--details \n    --list-all\n    --list-plain\n    --list-derived\n    
--list-virtual\n    --read {SCHEMA-TYPE} {SCHEMA-KEY}\n        Schema type: 
PLAIN / DERIVED / VIRTUAL\n    --delete {SCHEMA-TYPE} {SCHEMA-KEY}\n        
Schema type: PLAIN / DERIVED / VIRTUAL\n
 task.help.message=\nUsage: task [options]\n  Options:\n    --help \n    
--details\n    --list\n       Syntax: --list {TASK-TYPE} \n          Task type: 
NOTIFICATION / PROPAGATION / PUSH / SCHEDULED / SYNCHRONIZATION\n    
--list-running-jobs \n    --list-scheduled-jobs \n    --read \n       Syntax: 
--read {TASK-ID} {TASK-ID} [...]\n    --read-execution \n       Syntax: 
--read-execution {TASK-EXEC-ID} {TASK-EXEC-ID} [...]\n    --delete \n       
Syntax: --delete {TASK-ID} {TASK-ID} [...]\n    --delete-execution \n       
Syntax: --delete-execution {TASK-EXEC-ID} {TASK-EXEC-ID} [...]\n    --execute 
\n       Syntax: --execute {TASK-ID} {DRY-RUN}\n          Dry run: true / 
false\n
-user.help.message=\nUsage: user [options]\n  Options:\n    --help \n    
--details \n    --list \n    --get-user-key\n       Syntax: --get-user-key 
{USERNAME}\n    --get-username\n       Syntax: --get-username {USER-ID}\n    
--read \n       Syntax: --read {USER-ID} {USER-ID} [...]\n    
--search-by-attribute \n       Syntax: --search-by-attribute {REALM} 
{ATTR-NAME}={ATTR-VALUE}\n    --search-by-role \n       Syntax: 
--search-by-role {REALM} {ROLE-ID}\n    --search-by-resource \n       Syntax: 
--search-by-resource {REALM} {RESOURCE-NAME}\n    --delete \n       Syntax: 
--delete {USER-ID} {USER-ID} [...]\n    --delete-all \n       Syntax: 
--delete-all {REALM}\n    --delete-by-attribute \n       Syntax: 
--delete-by-attribute {REALM} {ATTR-NAME}={ATTR-VALUE}\n
+user.help.message=\nUsage: user [options]\n  Options:\n    --help \n    
--details \n    --list \n    --get-user-key\n       Syntax: --get-user-key 
{USERNAME}\n    --get-username\n       Syntax: --get-username {USER-ID}\n    
--read-by-userid \n       Syntax: --read-by-userid {USER-ID} {USER-ID} [...]\n  
  --read-by-username\n       Syntax: --read-by-username {USERNAME} {USERNAME} 
[...]\n    --search-by-attribute \n       Syntax: --search-by-attribute {REALM} 
{ATTR-NAME}={ATTR-VALUE}\n    --search-by-role \n       Syntax: 
--search-by-role {REALM} {ROLE-ID}\n    --search-by-resource \n       Syntax: 
--search-by-resource {REALM} {RESOURCE-NAME}\n    --delete \n       Syntax: 
--delete {USER-ID} {USER-ID} [...]\n    --delete-all \n       Syntax: 
--delete-all {REALM}\n    --delete-by-attribute \n       Syntax: 
--delete-by-attribute {REALM} {ATTR-NAME}={ATTR-VALUE}\n
 workflow.help.message=\nUsage: workflow [options]\n  Options:\n    --help \n   
 --export-diagram {ANY-TYPE-KIND}\n        Any type kind: ANY_OBJECT / USER / 
GROUP\n    --export-definition {ANY-TYPE-KIND}\n        Any type kind: 
ANY_OBJECT / USER / GROUP\n

Reply via email to