Repository: opencb/opencga
Issue: Error calling opencga/rest/users/demo/info with lastActivity query parameter

When calling this ws with lastActivity parameter an error is returned:

"User { id: \\"demo\\" } not found."

``` json

{"warning":"","error":"","queryOptions":{"metadata":true,"exclude":["password","sessions"]},"response":[{"id":"","time":0,"dbTime":-1,"numResults":-1,"numTotalResults":-1,"warningMsg":"","errorMsg":"User { id: \\"demo\\" } not found.","resultType":"","result":[]}]}

```

And a CatalogDBException is printed in the server log:

org.opencb.opencga.catalog.db.CatalogDBException: User { id: "demo" } not found.


Changed files:
opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/CatalogMongoDBAdaptor.java
opencga-catalog/src/test/java/org/opencb/opencga/catalog/CatalogManagerTest.java

diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/CatalogMongoDBAdaptor.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/CatalogMongoDBAdaptor.java
index fa29164b67..cb73744769 100644
--- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/CatalogMongoDBAdaptor.java
+++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/CatalogMongoDBAdaptor.java
@@ -347,17 +347,17 @@ public class CatalogMongoDBAdaptor extends CatalogDBAdaptor {
     @Override
     public QueryResult<User> getUser(String userId, QueryOptions options, String lastActivity) throws CatalogDBException {
         long startTime = startQuery();
+        if (!userExists(userId)) {
+            throw CatalogDBException.idNotFound("User", userId);
+        }
         DBObject query = new BasicDBObject("id", userId);
         query.put("lastActivity", new BasicDBObject("$ne", lastActivity));
         QueryResult<DBObject> result = userCollection.find(query, options);
         User user = parseUser(result);
-        if(user == null){
-            throw CatalogDBException.idNotFound("User", userId);
-        }
-        joinFields(user, options);
-        if(user.getLastActivity() != null && user.getLastActivity().equals(lastActivity)) { // TODO explain
-            return endQuery("Get user", startTime);
+        if(user == null) {
+            return endQuery("Get user", startTime); // user exists but no different lastActivity was found: return empty result
         } else {
+            joinFields(user, options);
             return endQuery("Get user", startTime, Arrays.asList(user));
         }
     }
diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/CatalogManagerTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/CatalogManagerTest.java
index c42d620c58..7619c8511a 100644
--- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/CatalogManagerTest.java
+++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/CatalogManagerTest.java
@@ -139,7 +139,7 @@ public class CatalogManagerTest extends GenericTest {
         try {
             catalogManager.getUser("user", null, sessionIdUser2);
             fail();
-        } catch (CatalogDBException e) {
+        } catch (CatalogException e) {
             System.out.println(e);
         }
     }
@@ -193,7 +193,7 @@ public class CatalogManagerTest extends GenericTest {
         try {
             catalogManager.modifyUser("user", params, sessionIdUser2);
             fail("Expected exception");
-        } catch (CatalogDBException e){
+        } catch (CatalogException e){
             System.out.println(e);
         }