syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmarte...@apache.org
Subject [41/50] [abbrv] syncope git commit: added details option, SYNCOPE-158
Date Fri, 30 Oct 2015 11:35:20 GMT
http://git-wip-us.apache.org/repos/asf/syncope/blob/d43268c1/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserCount.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserCount.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserCount.java
deleted file mode 100644
index 7316768..0000000
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserCount.java
+++ /dev/null
@@ -1,45 +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.user;
-
-import org.apache.syncope.client.cli.Input;
-import org.apache.syncope.common.lib.SyncopeClientException;
-
-public class UserCount extends AbstractUserCommand {
-
-    private static final String COUNT_HELP_MESSAGE = "user --count";
-
-    private final Input input;
-
-    public UserCount(final Input input) {
-        this.input = input;
-    }
-
-    public void count() {
-        if (input.parameterNumber() == 0) {
-            try {
-                userResultManager.genericMessage("Total users: " + userSyncopeOperations.count());
-            } catch (final SyncopeClientException ex) {
-                userResultManager.genericError(ex.getMessage());
-            }
-        } else {
-            userResultManager.unnecessaryParameters(input.listParameters(), COUNT_HELP_MESSAGE);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d43268c1/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserDetails.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserDetails.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserDetails.java
new file mode 100644
index 0000000..f09b4ad
--- /dev/null
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserDetails.java
@@ -0,0 +1,73 @@
+/*
+ * 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.List;
+import java.util.Map;
+import org.apache.commons.collections4.map.LinkedMap;
+import org.apache.syncope.client.cli.Input;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.UserTO;
+
+public class UserDetails extends AbstractUserCommand {
+
+    private static final String COUNT_HELP_MESSAGE = "user --details";
+
+    private final Input input;
+
+    public UserDetails(final Input input) {
+        this.input = input;
+    }
+
+    public void details() {
+        if (input.parameterNumber() == 0) {
+            try {
+                final Map<String, String> details = new LinkedMap<>();
+                final List<UserTO> usersTOs = userSyncopeOperations.list().getResult();
+                int withoutResource = 0;
+                int withoutRole = 0;
+                int activeStatus = 0;
+                int suspendedStatus = 0;
+                for (final UserTO userTO : usersTOs) {
+                    if (!userTO.getResources().isEmpty()) {
+                        withoutResource++;
+                    }
+                    if (!userTO.getRoles().isEmpty()) {
+                        withoutRole++;
+                    }
+                    if ("active".equalsIgnoreCase(userTO.getStatus())) {
+                        activeStatus++;
+                    } else if ("suspended".equalsIgnoreCase(userTO.getStatus())) {
+                        suspendedStatus++;
+                    }
+                }
+                details.put("Total number", String.valueOf(usersTOs.size()));
+                details.put("Active", String.valueOf(activeStatus));
+                details.put("Suspended", String.valueOf(suspendedStatus));
+                details.put("Without resources", String.valueOf(withoutResource));
+                details.put("Without roles", String.valueOf(withoutRole));
+                userResultManager.printDetails(details);
+            } catch (final SyncopeClientException ex) {
+                userResultManager.genericError(ex.getMessage());
+            }
+        } else {
+            userResultManager.unnecessaryParameters(input.listParameters(), COUNT_HELP_MESSAGE);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/syncope/blob/d43268c1/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserResultManager.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserResultManager.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserResultManager.java
index b175842..ccc8631 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserResultManager.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserResultManager.java
@@ -19,6 +19,7 @@
 package org.apache.syncope.client.cli.commands.user;
 
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import org.apache.syncope.client.cli.commands.CommonsResultManager;
 import org.apache.syncope.common.lib.to.AttrTO;
@@ -104,4 +105,8 @@ public class UserResultManager extends CommonsResultManager {
             System.out.println("       type: " + relationshipTO.getType());
         }
     }
+
+    public void printDetails(final Map<String, String> details) {
+        printDetails("users details", details);
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/d43268c1/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserSyncopeOperations.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserSyncopeOperations.java
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserSyncopeOperations.java
index 0496d97..8df901f 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserSyncopeOperations.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/user/UserSyncopeOperations.java
@@ -64,10 +64,6 @@ public class UserSyncopeOperations {
         userService.delete(Long.valueOf(userId));
     }
 
-    public int count() {
-        return list().getResult().size();
-    }
-
     public String getUsernameFromId(final String userId) {
         return userService.getUsername(Long.valueOf(userId)).getHeaderString(RESTHeaders.USERNAME);
     }

http://git-wip-us.apache.org/repos/asf/syncope/blob/d43268c1/client/cli/src/main/java/org/apache/syncope/client/cli/view/Table.java
----------------------------------------------------------------------
diff --git a/client/cli/src/main/java/org/apache/syncope/client/cli/view/Table.java b/client/cli/src/main/java/org/apache/syncope/client/cli/view/Table.java
index 5230f42..3c872fc 100644
--- a/client/cli/src/main/java/org/apache/syncope/client/cli/view/Table.java
+++ b/client/cli/src/main/java/org/apache/syncope/client/cli/view/Table.java
@@ -55,6 +55,7 @@ public final class Table {
     }
 
     public void print() {
+        System.out.println("");
         columnsNumber = headers.size();
         tmpValuesArray = new String[columnsNumber];
 
@@ -69,6 +70,7 @@ public final class Table {
         printBorder();
         printeContent();
         printBorder();
+        System.out.println("");
     }
 
     private void buildTableContentFormat() {


Mime
View raw message