You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sc...@apache.org on 2016/10/18 19:16:29 UTC

[1/4] airavata git commit: updates for sharing catalog tests

Repository: airavata
Updated Branches:
  refs/heads/develop 273d074ac -> 2ac72d9e9


updates for sharing catalog tests


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

Branch: refs/heads/develop
Commit: 07097ce3919c82a8ef1b466c0581f58f73692094
Parents: 273d074
Author: scnakandala <su...@gmail.com>
Authored: Tue Oct 18 12:08:49 2016 -0400
Committer: scnakandala <su...@gmail.com>
Committed: Tue Oct 18 12:08:49 2016 -0400

----------------------------------------------------------------------
 .../migrator/airavata/AiravataDataMigrator.java |  6 +--
 .../registry/SharingRegistryServiceTest.java    | 50 +++++++++++++++----
 .../sharing-service-docs/index.html             | 51 +++++++++++++++++---
 3 files changed, 86 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/07097ce3/modules/sharing-registry/sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/AiravataDataMigrator.java
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/AiravataDataMigrator.java b/modules/sharing-registry/sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/AiravataDataMigrator.java
index a8ec19f..3de14d6 100644
--- a/modules/sharing-registry/sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/AiravataDataMigrator.java
+++ b/modules/sharing-registry/sharing-data-migrator/src/main/java/org/apache/airavata/sharing/registry/migrator/airavata/AiravataDataMigrator.java
@@ -49,11 +49,7 @@ public class AiravataDataMigrator {
         while (rs.next()) {
             //Creating domain entries
             Domain domain = new Domain();
-            domain.setDomainId(rs.getString("GATEWAY_ID"));
-            if(rs.getString("GATEWAY_NAME") != null)
-                domain.setName(rs.getString("GATEWAY_NAME"));
-            else
-                domain.setName(rs.getString("GATEWAY_ID"));
+            domain.setName(rs.getString("GATEWAY_ID"));
             domain.setDescription("Domain entry for " + domain.name);
 
             govRegistryServerHandler.createDomain(domain);

http://git-wip-us.apache.org/repos/asf/airavata/blob/07097ce3/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java b/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
index c05924a..2433da0 100644
--- a/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
+++ b/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
@@ -28,6 +28,7 @@ import org.apache.thrift.protocol.TBinaryProtocol;
 import org.apache.thrift.protocol.TProtocol;
 import org.apache.thrift.transport.TSocket;
 import org.apache.thrift.transport.TTransport;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -176,6 +177,13 @@ public class SharingRegistryServiceTest {
         permissionType2.setDescription("WRITE description");
         sharingServiceClient.createPermissionType(permissionType2);
 
+        PermissionType permissionType3 = new PermissionType();
+        permissionType3.setPermissionTypeId("CLONE");
+        permissionType3.setDomainId(domainId);
+        permissionType3.setName("CLONE");
+        permissionType3.setDescription("CLONE description");
+        sharingServiceClient.createPermissionType(permissionType3);
+
         EntityType entityType1 = new EntityType();
         //required
         entityType1.setEntityTypeId("PROJECT");
@@ -194,6 +202,13 @@ public class SharingRegistryServiceTest {
         entityType2.setDescription("EXPERIMENT entity type");
         sharingServiceClient.createEntityType(entityType2);
 
+        EntityType entityType3 = new EntityType();
+        entityType3.setEntityTypeId("FILE");
+        entityType3.setDomainId(domainId);
+        entityType3.setName("FILE");
+        entityType3.setDescription("FILE entity type");
+        sharingServiceClient.createEntityType(entityType3);
+
 
         //Creating entities
         Entity entity1 = new Entity();
@@ -237,27 +252,44 @@ public class SharingRegistryServiceTest {
         entity3.setFullText("test experiment 1 3-methyl 1-butanol");
         sharingServiceClient.createEntity(entity3);
 
+        Entity entity4 = new Entity();
+        entity4.setEntityId("test-file-1");
+        entity4.setDomainId(domainId);
+        entity4.setEntityTypeId("FILE");
+        entity4.setOwnerId("test-user-1");
+        entity4.setName("test-file-1");
+        entity4.setDescription("test file 1 description");
+        entity4.setParentEntityId("test-experiment-2");
+        entity4.setFullText("test input file 1 for experiment 2");
+        sharingServiceClient.createEntity(entity4);
+
         sharingServiceClient.shareEntityWithUsers(domainId, "test-project-1", Arrays.asList("test-user-2"), "WRITE", true);
         sharingServiceClient.shareEntityWithGroups(domainId, "test-experiment-2", Arrays.asList("test-group-2"), "READ", true);
+        sharingServiceClient.shareEntityWithGroups(domainId, "test-experiment-2", Arrays.asList("test-group-2"), "CLONE", false);
 
         //true
-        System.out.println(sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-project-1", "WRITE"));
+        Assert.assertTrue(sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-project-1", "WRITE"));
         //true
-        System.out.println(sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-experiment-1", "WRITE"));
+        Assert.assertTrue(sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-experiment-1", "WRITE"));
         //true
-        System.out.println(sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-experiment-2", "WRITE"));
+        Assert.assertTrue(sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-experiment-2", "WRITE"));
 
         //false
-        System.out.println(sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-experiment-1", "READ"));
+        Assert.assertFalse(sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-experiment-1", "READ"));
         //true
-        System.out.println(sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-experiment-2", "READ"));
+        Assert.assertTrue(sharingServiceClient.userHasAccess(domainId, "test-user-2", "test-experiment-2", "READ"));
 
         //false
-        System.out.println(sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-project-1", "READ"));
+        Assert.assertFalse(sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-project-1", "READ"));
+        //true
+        Assert.assertTrue(sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-experiment-2", "READ"));
+        //false
+        Assert.assertFalse(sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-experiment-2", "WRITE"));
+
         //true
-        System.out.println(sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-experiment-2", "READ"));
+        Assert.assertTrue((sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-experiment-2", "CLONE")));
         //false
-        System.out.println(sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-experiment-2", "WRITE"));
+        Assert.assertFalse((sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-file-1", "CLONE")));
 
         ArrayList<SearchCriteria> filters = new ArrayList<>();
         SearchCriteria searchCriteria = new SearchCriteria();
@@ -272,6 +304,6 @@ public class SharingRegistryServiceTest {
         searchCriteria.setSearchField(EntitySearchField.PERMISSION_TYPE_ID);
         filters.add(searchCriteria);
 
-        System.out.println(sharingServiceClient.searchEntities(domainId, "test-user-2", "EXPERIMENT", filters, 0, -1).size());
+        Assert.assertTrue(sharingServiceClient.searchEntities(domainId, "test-user-2", "EXPERIMENT", filters, 0, -1).size()==1);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/07097ce3/modules/sharing-registry/sharing-service-docs/index.html
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-service-docs/index.html b/modules/sharing-registry/sharing-service-docs/index.html
index 0364025..2f05d16 100644
--- a/modules/sharing-registry/sharing-service-docs/index.html
+++ b/modules/sharing-registry/sharing-service-docs/index.html
@@ -185,6 +185,13 @@
                 permissionType2.setName("WRITE");
                 permissionType2.setDescription("WRITE description");
                 sharingServiceClient.createPermissionType(permissionType2);
+
+                PermissionType permissionType3 = new PermissionType();
+                permissionType3.setPermissionTypeId("CLONE");
+                permissionType3.setDomainId(domainId);
+                permissionType3.setName("CLONE");
+                permissionType3.setDescription("CLONE description");
+                sharingServiceClient.createPermissionType(permissionType3);
             </pre>
         </div>
 
@@ -208,6 +215,13 @@
                 entityType2.setName("EXPERIMENT");
                 entityType2.setDescription("EXPERIMENT entity type");
                 sharingServiceClient.createEntityType(entityType2);
+
+                EntityType entityType3 = new EntityType();
+                entityType3.setEntityTypeId("FILE");
+                entityType3.setDomainId(domainId);
+                entityType3.setName("FILE");
+                entityType3.setDescription("FILE entity type");
+                sharingServiceClient.createEntityType(entityType3);
             </pre>
         </div>
 
@@ -253,21 +267,39 @@
                 entity3.setParentEntityId("test-project-1");
                 entity3.setFullText("test experiment 1 3-methyl 1-butanol");
                 sharingServiceClient.createEntity(entity3);
+
+                Entity entity4 = new Entity();
+                entity4.setEntityId("test-file-1");
+                entity4.setDomainId(domainId);
+                entity4.setEntityTypeId("FILE");
+                entity4.setOwnerId("test-user-1");
+                entity4.setName("test-file-1");
+                entity4.setDescription("test file 1 description");
+                entity4.setParentEntityId("test-experiment-2");
+                entity4.setFullText("test input file 1 for experiment 2");
+                sharingServiceClient.createEntity(entity4);
             </pre>
         </div>
 
         <div class="definition" id="sharing-entities">
         <h4>9. Share Entities with Users and Groups</h4>
             <pre>
+                //shared with cascading permissions
                 sharingServiceClient.shareEntityWithUsers(domainId, "test-project-1", Arrays.asList("test-user-2"), "WRITE", true);
                 sharingServiceClient.shareEntityWithGroups(domainId, "test-experiment-2", Arrays.asList("test-group-2"), "READ", true);
 
-                /**********************************************************************/
-                /*          test-project-1 (OWNER:test-user-1, WRITE:test-user-2)     */
-                /*             /                        \                             */
-                /*    test-experiment-1          test-experiment-2                    */
-                /*   (OWNER:test-user-1)     (OWNER:test-user-1, READ:test-group-2)   */
-                /**********************************************************************/
+                //shared with non cascading permissions
+                sharingServiceClient.shareEntityWithGroups(domainId, "test-experiment-2", Arrays.asList("test-group-2"), "CLONE", false);
+
+                /***********************************************************************/
+                /*          test-project-1 (OWNER:test-user-1, WRITE:test-user-2)      */
+                /*             /                        \                              */
+                /*    test-experiment-1           test-experiment-2                    */
+                /*   (OWNER:test-user-1)  (OWNER:test-user-1, READ/CLONE:test-group-2) */
+                /*                                          |                          */
+                /*                                     test-file-1                     */
+                /*                       (OWNER:test-user-1, READ:test-group-2)        */
+                /***********************************************************************/
             </pre>
         </div>
 
@@ -293,13 +325,18 @@
 
                 //test-user-3 does not have WRITE permission to test-experiment-2
                 System.out.println(sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-experiment-2", "WRITE"));
+
+                //test-user-3 has CLONE permission to test-experiment-2
+                System.out.println((sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-experiment-2", "CLONE")));
+                //test-user-3 does not have CLONE permission to test-file-1
+                System.out.println((sharingServiceClient.userHasAccess(domainId, "test-user-3", "test-file-1", "CLONE")));
             </pre>
         </div>
 
         <div class="definition" id="search-entities">
             <h4>10. Searching Entities</h4>
             <pre>
-                ArrayList<SearchCriteria> filters = new ArrayList<>();
+                ArrayList&lt;SearchCriteria&gt; filters = new ArrayList<>();
                 SearchCriteria searchCriteria = new SearchCriteria();
                 searchCriteria.setSearchCondition(SearchCondition.LIKE);
                 searchCriteria.setValue("experiment");


[4/4] airavata git commit: logging all errors at the server handler layer

Posted by sc...@apache.org.
logging all errors at the server handler layer


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

Branch: refs/heads/develop
Commit: 2ac72d9e95c0e8d6081b21252044e62c865736e2
Parents: a6860dc
Author: scnakandala <su...@gmail.com>
Authored: Tue Oct 18 15:16:21 2016 -0400
Committer: scnakandala <su...@gmail.com>
Committed: Tue Oct 18 15:16:21 2016 -0400

----------------------------------------------------------------------
 .../server/SharingRegistryServerHandler.java    | 990 ++++++++++++-------
 1 file changed, 608 insertions(+), 382 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/2ac72d9e/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java
index 4f88e16..97a7142 100644
--- a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java
+++ b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java
@@ -67,51 +67,76 @@ public class SharingRegistryServerHandler implements SharingRegistryService.Ifac
      */
     @Override
     public String createDomain(Domain domain) throws SharingRegistryException, TException {
-        domain.setDomainId(domain.name);
-        if(domainRepository.get(domain.domainId) != null)
-            throw new SharingRegistryException("There exist domain with given domain id");
-
-        domain.setCreatedTime(System.currentTimeMillis());
-        domain.setUpdatedTime(System.currentTimeMillis());
-        domainRepository.create(domain);
-
-        //create the global permission for the domain
-        PermissionType permissionType = new PermissionType();
-        permissionType.setPermissionTypeId(OWNER_PERMISSION_NAME);
-        permissionType.setDomainId(domain.domainId);
-        permissionType.setName(OWNER_PERMISSION_NAME);
-        permissionType.setDescription("GLOBAL permission to " + domain.domainId);
-        permissionType.setCreatedTime(System.currentTimeMillis());
-        permissionType.setUpdatedTime(System.currentTimeMillis());
-        permissionTypeRepository.create(permissionType);
-
-        return domain.domainId;
+        try{
+            domain.setDomainId(domain.name);
+            if(domainRepository.get(domain.domainId) != null)
+                throw new SharingRegistryException("There exist domain with given domain id");
+
+            domain.setCreatedTime(System.currentTimeMillis());
+            domain.setUpdatedTime(System.currentTimeMillis());
+            domainRepository.create(domain);
+
+            //create the global permission for the domain
+            PermissionType permissionType = new PermissionType();
+            permissionType.setPermissionTypeId(OWNER_PERMISSION_NAME);
+            permissionType.setDomainId(domain.domainId);
+            permissionType.setName(OWNER_PERMISSION_NAME);
+            permissionType.setDescription("GLOBAL permission to " + domain.domainId);
+            permissionType.setCreatedTime(System.currentTimeMillis());
+            permissionType.setUpdatedTime(System.currentTimeMillis());
+            permissionTypeRepository.create(permissionType);
+
+            return domain.domainId;
+        }catch (SharingRegistryException ex){
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean updateDomain(Domain domain) throws SharingRegistryException, TException {
-        Domain oldDomain = domainRepository.get(domain.domainId);
-        domain.setCreatedTime(oldDomain.createdTime);
-        domain.setUpdatedTime(System.currentTimeMillis());
-        domain = getUpdatedObject(oldDomain, domain);
-        domainRepository.update(domain);
-        return true;
+        try{
+            Domain oldDomain = domainRepository.get(domain.domainId);
+            domain.setCreatedTime(oldDomain.createdTime);
+            domain.setUpdatedTime(System.currentTimeMillis());
+            domain = getUpdatedObject(oldDomain, domain);
+            domainRepository.update(domain);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean deleteDomain(String domainId) throws SharingRegistryException, TException {
-        domainRepository.delete(domainId);
-        return true;
+        try{
+            domainRepository.delete(domainId);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public Domain getDomain(String domainId) throws SharingRegistryException, TException {
-        return domainRepository.get(domainId);
+        try{
+            return domainRepository.get(domainId);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public List<Domain> getDomains(int offset, int limit) throws TException {
-        return domainRepository.select(new HashMap<>(), offset, limit);
+        try{
+            return domainRepository.select(new HashMap<>(), offset, limit);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     /**
@@ -120,77 +145,102 @@ public class SharingRegistryServerHandler implements SharingRegistryService.Ifac
      */
     @Override
     public String createUser(User user) throws SharingRegistryException, TException {
-        UserPK userPK = new UserPK();
-        userPK.setUserId(user.getUserId());
-        userPK.setDomainId(user.domainId);
-        if(userRepository.get(userPK) != null)
-            throw new SharingRegistryException("There exist user with given user id");
-
-        user.setCreatedTime(System.currentTimeMillis());
-        user.setUpdatedTime(System.currentTimeMillis());
-        userRepository.create(user);
-
-        UserGroup userGroup = new UserGroup();
-        userGroup.setGroupId(user.userId);
-        userGroup.setDomainId(user.domainId);
-        userGroup.setName(user.userName);
-        userGroup.setDescription("user " + user.userName + " group");
-        userGroup.setOwnerId(user.userId);
-        userGroup.setGroupType(GroupType.USER_LEVEL_GROUP);
-        userGroup.setGroupCardinality(GroupCardinality.SINGLE_USER);
-        userGroupRepository.create(userGroup);
-
-        return user.userId;
+        try{
+            UserPK userPK = new UserPK();
+            userPK.setUserId(user.getUserId());
+            userPK.setDomainId(user.domainId);
+            if(userRepository.get(userPK) != null)
+                throw new SharingRegistryException("There exist user with given user id");
+
+            user.setCreatedTime(System.currentTimeMillis());
+            user.setUpdatedTime(System.currentTimeMillis());
+            userRepository.create(user);
+
+            UserGroup userGroup = new UserGroup();
+            userGroup.setGroupId(user.userId);
+            userGroup.setDomainId(user.domainId);
+            userGroup.setName(user.userName);
+            userGroup.setDescription("user " + user.userName + " group");
+            userGroup.setOwnerId(user.userId);
+            userGroup.setGroupType(GroupType.USER_LEVEL_GROUP);
+            userGroup.setGroupCardinality(GroupCardinality.SINGLE_USER);
+            userGroupRepository.create(userGroup);
+
+            return user.userId;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean updatedUser(User user) throws SharingRegistryException, TException {
-        UserPK userPK = new UserPK();
-        userPK.setUserId(user.userId);
-        userPK.setDomainId(user.domainId);
-        User oldUser = userRepository.get(userPK);
-        user.setCreatedTime(oldUser.createdTime);
-        user.setUpdatedTime(System.currentTimeMillis());
-        user = getUpdatedObject(oldUser, user);
-        userRepository.update(user);
-
-        UserGroupPK userGroupPK = new UserGroupPK();
-        userGroupPK.setGroupId(user.getUserId());
-        userGroupPK.setDomainId(user.domainId);
-        UserGroup userGroup = userGroupRepository.get(userGroupPK);
-        userGroup.setName(user.userName);
-        userGroup.setDescription("user " + user.userName + " group");
-        updateGroup(userGroup);
-        return true;
+        try{
+            UserPK userPK = new UserPK();
+            userPK.setUserId(user.userId);
+            userPK.setDomainId(user.domainId);
+            User oldUser = userRepository.get(userPK);
+            user.setCreatedTime(oldUser.createdTime);
+            user.setUpdatedTime(System.currentTimeMillis());
+            user = getUpdatedObject(oldUser, user);
+            userRepository.update(user);
+
+            UserGroupPK userGroupPK = new UserGroupPK();
+            userGroupPK.setGroupId(user.getUserId());
+            userGroupPK.setDomainId(user.domainId);
+            UserGroup userGroup = userGroupRepository.get(userGroupPK);
+            userGroup.setName(user.userName);
+            userGroup.setDescription("user " + user.userName + " group");
+            updateGroup(userGroup);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean deleteUser(String domainId, String userId) throws SharingRegistryException, TException {
-        UserPK userPK = new UserPK();
-        userPK.setUserId(userId);
-        userPK.setDomainId(domainId);
-        userRepository.delete(userPK);
-
-        UserGroupPK userGroupPK = new UserGroupPK();
-        userGroupPK.setGroupId(userId);
-        userGroupPK.setDomainId(domainId);
-        userGroupRepository.delete(userGroupPK);
-        return true;
+        try{
+            UserPK userPK = new UserPK();
+            userPK.setUserId(userId);
+            userPK.setDomainId(domainId);
+            userRepository.delete(userPK);
+
+            UserGroupPK userGroupPK = new UserGroupPK();
+            userGroupPK.setGroupId(userId);
+            userGroupPK.setDomainId(domainId);
+            userGroupRepository.delete(userGroupPK);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public User getUser(String domainId, String userId) throws SharingRegistryException, TException {
-        UserPK userPK = new UserPK();
-        userPK.setUserId(userId);
-        userPK.setDomainId(domainId);
-        return userRepository.get(userPK);
+        try{
+            UserPK userPK = new UserPK();
+            userPK.setUserId(userId);
+            userPK.setDomainId(domainId);
+            return userRepository.get(userPK);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public List<User> getUsers(String domain, int offset, int limit) throws SharingRegistryException, TException {
-        HashMap<String, String> filters = new HashMap<>();
-        filters.put(DBConstants.UserTable.DOMAIN_ID, domain);
-        return userRepository.select(filters, offset, limit);
+        try{
+            HashMap<String, String> filters = new HashMap<>();
+            filters.put(DBConstants.UserTable.DOMAIN_ID, domain);
+            return userRepository.select(filters, offset, limit);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     /**
@@ -199,129 +249,184 @@ public class SharingRegistryServerHandler implements SharingRegistryService.Ifac
      */
     @Override
     public String createGroup(UserGroup group) throws SharingRegistryException, TException {
-        UserGroupPK userGroupPK = new UserGroupPK();
-        userGroupPK.setGroupId(group.groupId);
-        userGroupPK.setDomainId(group.domainId);
-        if(userGroupRepository.get(userGroupPK) != null)
-            throw new SharingRegistryException("There exist group with given group id");
-        //Client created groups are always of type MULTI_USER
-        group.setGroupCardinality(GroupCardinality.MULTI_USER);
-        group.setCreatedTime(System.currentTimeMillis());
-        group.setUpdatedTime(System.currentTimeMillis());
-        userGroupRepository.create(group);
-
-        addUsersToGroup(group.domainId, Arrays.asList(group.ownerId), group.groupId);
-        return group.groupId;
+        try{
+            UserGroupPK userGroupPK = new UserGroupPK();
+            userGroupPK.setGroupId(group.groupId);
+            userGroupPK.setDomainId(group.domainId);
+            if(userGroupRepository.get(userGroupPK) != null)
+                throw new SharingRegistryException("There exist group with given group id");
+            //Client created groups are always of type MULTI_USER
+            group.setGroupCardinality(GroupCardinality.MULTI_USER);
+            group.setCreatedTime(System.currentTimeMillis());
+            group.setUpdatedTime(System.currentTimeMillis());
+            userGroupRepository.create(group);
+
+            addUsersToGroup(group.domainId, Arrays.asList(group.ownerId), group.groupId);
+            return group.groupId;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean updateGroup(UserGroup group) throws SharingRegistryException, TException {
-        group.setUpdatedTime(System.currentTimeMillis());
-        UserGroupPK userGroupPK = new UserGroupPK();
-        userGroupPK.setGroupId(group.groupId);
-        userGroupPK.setDomainId(group.domainId);
-        UserGroup oldGroup = userGroupRepository.get(userGroupPK);
-        //Client created groups are always of type MULTI_USER
-        group.setGroupCardinality(GroupCardinality.MULTI_USER);
-        group.setCreatedTime(oldGroup.createdTime);
-        group = getUpdatedObject(oldGroup, group);
-
-        if(!group.ownerId.equals(oldGroup.ownerId))
-            throw new SharingRegistryException("Group owner cannot be changed");
-
-        userGroupRepository.update(group);
-        return true;
+        try{
+            group.setUpdatedTime(System.currentTimeMillis());
+            UserGroupPK userGroupPK = new UserGroupPK();
+            userGroupPK.setGroupId(group.groupId);
+            userGroupPK.setDomainId(group.domainId);
+            UserGroup oldGroup = userGroupRepository.get(userGroupPK);
+            //Client created groups are always of type MULTI_USER
+            group.setGroupCardinality(GroupCardinality.MULTI_USER);
+            group.setCreatedTime(oldGroup.createdTime);
+            group = getUpdatedObject(oldGroup, group);
+
+            if(!group.ownerId.equals(oldGroup.ownerId))
+                throw new SharingRegistryException("Group owner cannot be changed");
+
+            userGroupRepository.update(group);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean deleteGroup(String domainId, String groupId) throws SharingRegistryException, TException {
-        UserGroupPK userGroupPK = new UserGroupPK();
-        userGroupPK.setGroupId(groupId);
-        userGroupPK.setDomainId(domainId);
-        userGroupRepository.delete(userGroupPK);
-        return true;
+        try{
+            UserGroupPK userGroupPK = new UserGroupPK();
+            userGroupPK.setGroupId(groupId);
+            userGroupPK.setDomainId(domainId);
+            userGroupRepository.delete(userGroupPK);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public UserGroup getGroup(String domainId, String groupId) throws SharingRegistryException, TException {
-        UserGroupPK userGroupPK = new UserGroupPK();
-        userGroupPK.setGroupId(groupId);
-        userGroupPK.setDomainId(domainId);
-        return userGroupRepository.get(userGroupPK);
+        try{
+            UserGroupPK userGroupPK = new UserGroupPK();
+            userGroupPK.setGroupId(groupId);
+            userGroupPK.setDomainId(domainId);
+            return userGroupRepository.get(userGroupPK);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public List<UserGroup> getGroups(String domain, int offset, int limit) throws TException {
-        HashMap<String, String> filters = new HashMap<>();
-        filters.put(DBConstants.UserTable.DOMAIN_ID, domain);
-        return userGroupRepository.select(filters, offset, limit);
+        try{
+            HashMap<String, String> filters = new HashMap<>();
+            filters.put(DBConstants.UserTable.DOMAIN_ID, domain);
+            return userGroupRepository.select(filters, offset, limit);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean addUsersToGroup(String domainId, List<String> userIds, String groupId) throws SharingRegistryException, TException {
-        for(int i=0; i < userIds.size(); i++){
-            GroupMembership groupMembership = new GroupMembership();
-            groupMembership.setParentId(groupId);
-            groupMembership.setChildId(userIds.get(i));
-            groupMembership.setChildType(GroupChildType.USER);
-            groupMembership.setDomainId(domainId);
-            groupMembership.setCreatedTime(System.currentTimeMillis());
-            groupMembership.setUpdatedTime(System.currentTimeMillis());
-            groupMembershipRepository.create(groupMembership);
+        try{
+            for(int i=0; i < userIds.size(); i++){
+                GroupMembership groupMembership = new GroupMembership();
+                groupMembership.setParentId(groupId);
+                groupMembership.setChildId(userIds.get(i));
+                groupMembership.setChildType(GroupChildType.USER);
+                groupMembership.setDomainId(domainId);
+                groupMembership.setCreatedTime(System.currentTimeMillis());
+                groupMembership.setUpdatedTime(System.currentTimeMillis());
+                groupMembershipRepository.create(groupMembership);
+            }
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
         }
-        return true;
     }
 
     @Override
     public boolean removeUsersFromGroup(String domainId, List<String> userIds, String groupId) throws SharingRegistryException, TException {
-        for(int i=0; i < userIds.size(); i++){
-            GroupMembershipPK groupMembershipPK = new GroupMembershipPK();
-            groupMembershipPK.setParentId(groupId);
-            groupMembershipPK.setChildId(userIds.get(i));
-            groupMembershipPK.setDomainId(domainId);
-            groupMembershipRepository.delete(groupMembershipPK);
+        try{
+            for(int i=0; i < userIds.size(); i++){
+                GroupMembershipPK groupMembershipPK = new GroupMembershipPK();
+                groupMembershipPK.setParentId(groupId);
+                groupMembershipPK.setChildId(userIds.get(i));
+                groupMembershipPK.setDomainId(domainId);
+                groupMembershipRepository.delete(groupMembershipPK);
+            }
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
         }
-        return true;
     }
 
     @Override
     public List<User> getGroupMembersOfTypeUser(String domainId, String groupId, int offset, int limit) throws SharingRegistryException, TException {
-        //TODO limit offset
-        List<User> groupMemberUsers = groupMembershipRepository.getAllChildUsers(domainId, groupId);
-        return groupMemberUsers;
+        try{
+            //TODO limit offset
+            List<User> groupMemberUsers = groupMembershipRepository.getAllChildUsers(domainId, groupId);
+            return groupMemberUsers;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public List<UserGroup> getGroupMembersOfTypeGroup(String domainId, String groupId, int offset, int limit) throws SharingRegistryException, TException {
-        //TODO limit offset
-        List<UserGroup> groupMemberGroups = groupMembershipRepository.getAllChildGroups(domainId, groupId);
-        return groupMemberGroups;
+        try{
+            //TODO limit offset
+            List<UserGroup> groupMemberGroups = groupMembershipRepository.getAllChildGroups(domainId, groupId);
+            return groupMemberGroups;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean addChildGroupsToParentGroup(String domainId, List<String> childIds, String groupId) throws SharingRegistryException, TException {
-        for(String childId : childIds) {
-            //Todo check for cyclic dependencies
-            GroupMembership groupMembership = new GroupMembership();
-            groupMembership.setParentId(groupId);
-            groupMembership.setChildId(childId);
-            groupMembership.setChildType(GroupChildType.GROUP);
-            groupMembership.setDomainId(domainId);
-            groupMembership.setCreatedTime(System.currentTimeMillis());
-            groupMembership.setUpdatedTime(System.currentTimeMillis());
-            groupMembershipRepository.create(groupMembership);
+        try{
+            for(String childId : childIds) {
+                //Todo check for cyclic dependencies
+                GroupMembership groupMembership = new GroupMembership();
+                groupMembership.setParentId(groupId);
+                groupMembership.setChildId(childId);
+                groupMembership.setChildType(GroupChildType.GROUP);
+                groupMembership.setDomainId(domainId);
+                groupMembership.setCreatedTime(System.currentTimeMillis());
+                groupMembership.setUpdatedTime(System.currentTimeMillis());
+                groupMembershipRepository.create(groupMembership);
+            }
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
         }
-        return true;
     }
 
     @Override
     public boolean removeChildGroupFromParentGroup(String domainId, String childId, String groupId) throws SharingRegistryException, TException {
-        GroupMembershipPK groupMembershipPK = new GroupMembershipPK();
-        groupMembershipPK.setParentId(groupId);
-        groupMembershipPK.setChildId(childId);
-        groupMembershipPK.setDomainId(domainId);
-        groupMembershipRepository.delete(groupMembershipPK);
-        return true;
+        try{
+            GroupMembershipPK groupMembershipPK = new GroupMembershipPK();
+            groupMembershipPK.setParentId(groupId);
+            groupMembershipPK.setChildId(childId);
+            groupMembershipPK.setDomainId(domainId);
+            groupMembershipRepository.delete(groupMembershipPK);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     /**
@@ -330,53 +435,78 @@ public class SharingRegistryServerHandler implements SharingRegistryService.Ifac
      */
     @Override
     public String createEntityType(EntityType entityType) throws SharingRegistryException, TException {
-        EntityTypePK entityTypePK = new EntityTypePK();
-        entityTypePK.setDomainId(entityType.domainId);
-        entityTypePK.setEntityTypeId(entityType.entityTypeId);
-        if(entityTypeRepository.get(entityTypePK) != null)
-            throw new SharingRegistryException("There exist EntityType with given EntityType id");
-
-        entityType.setCreatedTime(System.currentTimeMillis());
-        entityType.setUpdatedTime(System.currentTimeMillis());
-        entityTypeRepository.create(entityType);
-        return entityType.entityTypeId;
+        try{
+            EntityTypePK entityTypePK = new EntityTypePK();
+            entityTypePK.setDomainId(entityType.domainId);
+            entityTypePK.setEntityTypeId(entityType.entityTypeId);
+            if(entityTypeRepository.get(entityTypePK) != null)
+                throw new SharingRegistryException("There exist EntityType with given EntityType id");
+
+            entityType.setCreatedTime(System.currentTimeMillis());
+            entityType.setUpdatedTime(System.currentTimeMillis());
+            entityTypeRepository.create(entityType);
+            return entityType.entityTypeId;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean updateEntityType(EntityType entityType) throws SharingRegistryException, TException {
-        entityType.setUpdatedTime(System.currentTimeMillis());
-        EntityTypePK entityTypePK = new EntityTypePK();
-        entityTypePK.setDomainId(entityType.domainId);
-        entityTypePK.setEntityTypeId(entityType.entityTypeId);
-        EntityType oldEntityType = entityTypeRepository.get(entityTypePK);
-        entityType.setCreatedTime(oldEntityType.createdTime);
-        entityType = getUpdatedObject(oldEntityType, entityType);
-        entityTypeRepository.update(entityType);
-        return true;
+        try{
+            entityType.setUpdatedTime(System.currentTimeMillis());
+            EntityTypePK entityTypePK = new EntityTypePK();
+            entityTypePK.setDomainId(entityType.domainId);
+            entityTypePK.setEntityTypeId(entityType.entityTypeId);
+            EntityType oldEntityType = entityTypeRepository.get(entityTypePK);
+            entityType.setCreatedTime(oldEntityType.createdTime);
+            entityType = getUpdatedObject(oldEntityType, entityType);
+            entityTypeRepository.update(entityType);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean deleteEntityType(String domainId, String entityTypeId) throws SharingRegistryException, TException {
-        EntityTypePK entityTypePK = new EntityTypePK();
-        entityTypePK.setDomainId(domainId);
-        entityTypePK.setEntityTypeId(entityTypeId);
-        entityTypeRepository.delete(entityTypePK);
-        return true;
+        try{
+            EntityTypePK entityTypePK = new EntityTypePK();
+            entityTypePK.setDomainId(domainId);
+            entityTypePK.setEntityTypeId(entityTypeId);
+            entityTypeRepository.delete(entityTypePK);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public EntityType getEntityType(String domainId, String entityTypeId) throws SharingRegistryException, TException {
-        EntityTypePK entityTypePK = new EntityTypePK();
-        entityTypePK.setDomainId(domainId);
-        entityTypePK.setEntityTypeId(entityTypeId);
-        return entityTypeRepository.get(entityTypePK);
+        try{
+            EntityTypePK entityTypePK = new EntityTypePK();
+            entityTypePK.setDomainId(domainId);
+            entityTypePK.setEntityTypeId(entityTypeId);
+            return entityTypeRepository.get(entityTypePK);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public List<EntityType> getEntityTypes(String domain, int offset, int limit) throws TException {
-        HashMap<String, String> filters = new HashMap<>();
-        filters.put(DBConstants.EntityTypeTable.DOMAIN_ID, domain);
-        return entityTypeRepository.select(domain, offset, limit);
+        try{
+            HashMap<String, String> filters = new HashMap<>();
+            filters.put(DBConstants.EntityTypeTable.DOMAIN_ID, domain);
+            return entityTypeRepository.select(domain, offset, limit);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     /**
@@ -385,51 +515,76 @@ public class SharingRegistryServerHandler implements SharingRegistryService.Ifac
      */
     @Override
     public String createPermissionType(PermissionType permissionType) throws SharingRegistryException, TException {
-        PermissionTypePK permissionTypePK =  new PermissionTypePK();
-        permissionTypePK.setDomainId(permissionType.domainId);
-        permissionTypePK.setPermissionTypeId(permissionType.permissionTypeId);
-        if(permissionTypeRepository.get(permissionTypePK) != null)
-            throw new SharingRegistryException("There exist PermissionType with given PermissionType id");
-        permissionType.setCreatedTime(System.currentTimeMillis());
-        permissionType.setUpdatedTime(System.currentTimeMillis());
-        permissionTypeRepository.create(permissionType);
-        return permissionType.permissionTypeId;
+        try{
+            PermissionTypePK permissionTypePK =  new PermissionTypePK();
+            permissionTypePK.setDomainId(permissionType.domainId);
+            permissionTypePK.setPermissionTypeId(permissionType.permissionTypeId);
+            if(permissionTypeRepository.get(permissionTypePK) != null)
+                throw new SharingRegistryException("There exist PermissionType with given PermissionType id");
+            permissionType.setCreatedTime(System.currentTimeMillis());
+            permissionType.setUpdatedTime(System.currentTimeMillis());
+            permissionTypeRepository.create(permissionType);
+            return permissionType.permissionTypeId;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean updatePermissionType(PermissionType permissionType) throws SharingRegistryException, TException {
-        permissionType.setUpdatedTime(System.currentTimeMillis());
-        PermissionTypePK permissionTypePK =  new PermissionTypePK();
-        permissionTypePK.setDomainId(permissionType.domainId);
-        permissionTypePK.setPermissionTypeId(permissionType.permissionTypeId);
-        PermissionType oldPermissionType = permissionTypeRepository.get(permissionTypePK);
-        permissionType = getUpdatedObject(oldPermissionType, permissionType);
-        permissionTypeRepository.update(permissionType);
-        return true;
+        try{
+            permissionType.setUpdatedTime(System.currentTimeMillis());
+            PermissionTypePK permissionTypePK =  new PermissionTypePK();
+            permissionTypePK.setDomainId(permissionType.domainId);
+            permissionTypePK.setPermissionTypeId(permissionType.permissionTypeId);
+            PermissionType oldPermissionType = permissionTypeRepository.get(permissionTypePK);
+            permissionType = getUpdatedObject(oldPermissionType, permissionType);
+            permissionTypeRepository.update(permissionType);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean deletePermissionType(String domainId, String permissionTypeId) throws SharingRegistryException, TException {
-        PermissionTypePK permissionTypePK =  new PermissionTypePK();
-        permissionTypePK.setDomainId(domainId);
-        permissionTypePK.setPermissionTypeId(permissionTypeId);
-        permissionTypeRepository.delete(permissionTypePK);
-        return true;
+        try{
+            PermissionTypePK permissionTypePK =  new PermissionTypePK();
+            permissionTypePK.setDomainId(domainId);
+            permissionTypePK.setPermissionTypeId(permissionTypeId);
+            permissionTypeRepository.delete(permissionTypePK);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public PermissionType getPermissionType(String domainId, String permissionTypeId) throws SharingRegistryException, TException {
-        PermissionTypePK permissionTypePK =  new PermissionTypePK();
-        permissionTypePK.setDomainId(domainId);
-        permissionTypePK.setPermissionTypeId(permissionTypeId);
-        return permissionTypeRepository.get(permissionTypePK);
+        try{
+            PermissionTypePK permissionTypePK =  new PermissionTypePK();
+            permissionTypePK.setDomainId(domainId);
+            permissionTypePK.setPermissionTypeId(permissionTypeId);
+            return permissionTypeRepository.get(permissionTypePK);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public List<PermissionType> getPermissionTypes(String domain, int offset, int limit) throws SharingRegistryException, TException {
-        HashMap<String, String> filters = new HashMap<>();
-        filters.put(DBConstants.PermissionTypeTable.DOMAIN_ID, domain);
-        return permissionTypeRepository.select(filters, offset, limit);
+        try{
+            HashMap<String, String> filters = new HashMap<>();
+            filters.put(DBConstants.PermissionTypeTable.DOMAIN_ID, domain);
+            return permissionTypeRepository.select(filters, offset, limit);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     /**
@@ -438,115 +593,150 @@ public class SharingRegistryServerHandler implements SharingRegistryService.Ifac
      */
     @Override
     public String createEntity(Entity entity) throws SharingRegistryException, TException {
-        EntityPK entityPK = new EntityPK();
-        entityPK.setDomainId(entity.domainId);
-        entityPK.setEntityId(entity.entityId);
-        if(entityRepository.get(entityPK) != null)
-            throw new SharingRegistryException("There exist Entity with given Entity id");
-
-        UserPK userPK = new UserPK();
-        userPK.setDomainId(entity.domainId);
-        userPK.setUserId(entity.ownerId);
-        if(!userRepository.isExists(userPK)){
-            //Todo this is for Airavata easy integration. Proper thing is to throw an exception here
-            User user = new User();
-            user.setUserId(entity.getOwnerId());
-            user.setDomainId(entity.domainId);
-            user.setUserName(user.userId.split("@")[0]);
-
-            createUser(user);
-        }
-        entity.setCreatedTime(System.currentTimeMillis());
-        entity.setUpdatedTime(System.currentTimeMillis());
-
-        if(entity.originalEntityCreationTime==0){
-            entity.originalEntityCreationTime = entity.createdTime;
-        }
-        entityRepository.create(entity);
-
-        //Assigning global permission for the owner
-        Sharing newSharing = new Sharing();
-        newSharing.setPermissionTypeId(permissionTypeRepository.getGlobalPermissionTypeIdForDomain(entity.domainId));
-        newSharing.setEntityId(entity.entityId);
-        newSharing.setGroupId(entity.ownerId);
-        newSharing.setSharingType(SharingType.DIRECT_CASCADING);
-        newSharing.setInheritedParentId(entity.entityId);
-        newSharing.setDomainId(entity.domainId);
-        newSharing.setCreatedTime(System.currentTimeMillis());
-        newSharing.setUpdatedTime(System.currentTimeMillis());
-
-        sharingRepository.create(newSharing);
-
-        //creating records for inherited permissions
-        if(entity.getParentEntityId() != null && entity.getParentEntityId() != ""){
-            List<Sharing> sharings = sharingRepository.getCascadingPermissionsForEntity(entity.domainId, entity.parentEntityId);
-            for(Sharing sharing : sharings){
-                newSharing = new Sharing();
-                newSharing.setPermissionTypeId(sharing.permissionTypeId);
-                newSharing.setEntityId(entity.entityId);
-                newSharing.setGroupId(sharing.groupId);
-                newSharing.setInheritedParentId(sharing.inheritedParentId);
-                newSharing.setSharingType(SharingType.INDIRECT_CASCADING);
-                newSharing.setDomainId(entity.domainId);
-                newSharing.setCreatedTime(System.currentTimeMillis());
-                newSharing.setUpdatedTime(System.currentTimeMillis());
-
-                sharingRepository.create(newSharing);
+        try{
+            EntityPK entityPK = new EntityPK();
+            entityPK.setDomainId(entity.domainId);
+            entityPK.setEntityId(entity.entityId);
+            if(entityRepository.get(entityPK) != null)
+                throw new SharingRegistryException("There exist Entity with given Entity id");
+
+            UserPK userPK = new UserPK();
+            userPK.setDomainId(entity.domainId);
+            userPK.setUserId(entity.ownerId);
+            if(!userRepository.isExists(userPK)){
+                //Todo this is for Airavata easy integration. Proper thing is to throw an exception here
+                User user = new User();
+                user.setUserId(entity.getOwnerId());
+                user.setDomainId(entity.domainId);
+                user.setUserName(user.userId.split("@")[0]);
+
+                createUser(user);
             }
-        }
+            entity.setCreatedTime(System.currentTimeMillis());
+            entity.setUpdatedTime(System.currentTimeMillis());
 
-        return entity.entityId;
+            if(entity.originalEntityCreationTime==0){
+                entity.originalEntityCreationTime = entity.createdTime;
+            }
+            entityRepository.create(entity);
+
+            //Assigning global permission for the owner
+            Sharing newSharing = new Sharing();
+            newSharing.setPermissionTypeId(permissionTypeRepository.getGlobalPermissionTypeIdForDomain(entity.domainId));
+            newSharing.setEntityId(entity.entityId);
+            newSharing.setGroupId(entity.ownerId);
+            newSharing.setSharingType(SharingType.DIRECT_CASCADING);
+            newSharing.setInheritedParentId(entity.entityId);
+            newSharing.setDomainId(entity.domainId);
+            newSharing.setCreatedTime(System.currentTimeMillis());
+            newSharing.setUpdatedTime(System.currentTimeMillis());
+
+            sharingRepository.create(newSharing);
+
+            //creating records for inherited permissions
+            if(entity.getParentEntityId() != null && entity.getParentEntityId() != ""){
+                List<Sharing> sharings = sharingRepository.getCascadingPermissionsForEntity(entity.domainId, entity.parentEntityId);
+                for(Sharing sharing : sharings){
+                    newSharing = new Sharing();
+                    newSharing.setPermissionTypeId(sharing.permissionTypeId);
+                    newSharing.setEntityId(entity.entityId);
+                    newSharing.setGroupId(sharing.groupId);
+                    newSharing.setInheritedParentId(sharing.inheritedParentId);
+                    newSharing.setSharingType(SharingType.INDIRECT_CASCADING);
+                    newSharing.setDomainId(entity.domainId);
+                    newSharing.setCreatedTime(System.currentTimeMillis());
+                    newSharing.setUpdatedTime(System.currentTimeMillis());
+
+                    sharingRepository.create(newSharing);
+                }
+            }
+
+            return entity.entityId;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean updateEntity(Entity entity) throws SharingRegistryException, TException {
-        //TODO Check for permission changes
-        entity.setUpdatedTime(System.currentTimeMillis());
-        EntityPK entityPK = new EntityPK();
-        entityPK.setDomainId(entity.domainId);
-        entityPK.setEntityId(entity.entityId);
-        Entity oldEntity = entityRepository.get(entityPK);
-        entity.setCreatedTime(oldEntity.createdTime);
-        entity = getUpdatedObject(oldEntity, entity);
-        entityRepository.update(entity);
-        return true;
+        try{
+            //TODO Check for permission changes
+            entity.setUpdatedTime(System.currentTimeMillis());
+            EntityPK entityPK = new EntityPK();
+            entityPK.setDomainId(entity.domainId);
+            entityPK.setEntityId(entity.entityId);
+            Entity oldEntity = entityRepository.get(entityPK);
+            entity.setCreatedTime(oldEntity.createdTime);
+            entity = getUpdatedObject(oldEntity, entity);
+            entityRepository.update(entity);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean deleteEntity(String domainId, String entityId) throws SharingRegistryException, TException {
-        //TODO Check for permission changes
-        EntityPK entityPK = new EntityPK();
-        entityPK.setDomainId(domainId);
-        entityPK.setEntityId(entityId);
-        entityRepository.delete(entityPK);
-        return true;
+        try{
+            //TODO Check for permission changes
+            EntityPK entityPK = new EntityPK();
+            entityPK.setDomainId(domainId);
+            entityPK.setEntityId(entityId);
+            entityRepository.delete(entityPK);
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public Entity getEntity(String domainId, String entityId) throws SharingRegistryException, TException {
-        EntityPK entityPK = new EntityPK();
-        entityPK.setDomainId(domainId);
-        entityPK.setEntityId(entityId);
-        return entityRepository.get(entityPK);
+        try{
+            EntityPK entityPK = new EntityPK();
+            entityPK.setDomainId(domainId);
+            entityPK.setEntityId(entityId);
+            return entityRepository.get(entityPK);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public List<Entity> searchEntities(String domainId, String userId, String entityTypeId, List<SearchCriteria> filters,
                                        int offset, int limit) throws SharingRegistryException, TException {
-        List<String> groupIds = new ArrayList<>();
-        groupIds.add(userId);
-        groupMembershipRepository.getAllParentMembershipsForChild(domainId, userId).stream().forEach(gm->groupIds.add(gm.parentId));
-        return entityRepository.searchEntities(domainId, groupIds, entityTypeId, filters, offset, limit);
+        try{
+            List<String> groupIds = new ArrayList<>();
+            groupIds.add(userId);
+            groupMembershipRepository.getAllParentMembershipsForChild(domainId, userId).stream().forEach(gm -> groupIds.add(gm.parentId));
+            return entityRepository.searchEntities(domainId, groupIds, entityTypeId, filters, offset, limit);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public List<User> getListOfSharedUsers(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException, TException {
-        return userRepository.getAccessibleUsers(domainId, entityId, permissionTypeId);
+        try{
+            return userRepository.getAccessibleUsers(domainId, entityId, permissionTypeId);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public List<UserGroup> getListOfSharedGroups(String domainId, String entityId, String permissionTypeId) throws SharingRegistryException, TException {
-        return userGroupRepository.getAccessibleGroups(domainId, entityId, permissionTypeId);
+        try{
+            return userGroupRepository.getAccessibleGroups(domainId, entityId, permissionTypeId);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     /**
@@ -559,111 +749,126 @@ public class SharingRegistryServerHandler implements SharingRegistryService.Ifac
      */
     @Override
     public boolean shareEntityWithUsers(String domainId, String entityId, List<String> userList, String permissionTypeId, boolean cascadePermission) throws SharingRegistryException, TException {
-        return shareEntity(domainId, entityId, userList, permissionTypeId, cascadePermission);
+        try{
+            return shareEntity(domainId, entityId, userList, permissionTypeId, cascadePermission);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean shareEntityWithGroups(String domainId, String entityId, List<String> groupList, String permissionTypeId, boolean cascadePermission) throws SharingRegistryException, TException {
-        return shareEntity(domainId, entityId, groupList, permissionTypeId, cascadePermission);
+        try{
+            return shareEntity(domainId, entityId, groupList, permissionTypeId, cascadePermission);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     private boolean shareEntity(String domainId, String entityId, List<String> groupOrUserList, String permissionTypeId, boolean cascadePermission)  throws SharingRegistryException, TException {
-        if(permissionTypeId.equals(permissionTypeRepository.getGlobalPermissionTypeIdForDomain(domainId))){
-            throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned");
-        }
-
-        //Adding permission for the specified users/groups for the specified entity
-        LinkedList<Entity> temp = new LinkedList<>();
-        for(String userId : groupOrUserList){
-            Sharing sharing = new Sharing();
-            sharing.setPermissionTypeId(permissionTypeId);
-            sharing.setEntityId(entityId);
-            sharing.setGroupId(userId);
-            sharing.setInheritedParentId(entityId);
-            sharing.setDomainId(domainId);
-            if(cascadePermission) {
-                sharing.setSharingType(SharingType.DIRECT_CASCADING);
-            }else {
-                sharing.setSharingType(SharingType.DIRECT_NON_CASCADING);
+        try{
+            if(permissionTypeId.equals(permissionTypeRepository.getGlobalPermissionTypeIdForDomain(domainId))){
+                throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be assigned");
+            }
+
+            //Adding permission for the specified users/groups for the specified entity
+            LinkedList<Entity> temp = new LinkedList<>();
+            for(String userId : groupOrUserList){
+                Sharing sharing = new Sharing();
+                sharing.setPermissionTypeId(permissionTypeId);
+                sharing.setEntityId(entityId);
+                sharing.setGroupId(userId);
+                sharing.setInheritedParentId(entityId);
+                sharing.setDomainId(domainId);
+                if(cascadePermission) {
+                    sharing.setSharingType(SharingType.DIRECT_CASCADING);
+                }else {
+                    sharing.setSharingType(SharingType.DIRECT_NON_CASCADING);
+                }
+                sharing.setCreatedTime(System.currentTimeMillis());
+                sharing.setUpdatedTime(System.currentTimeMillis());
+
+                sharingRepository.create(sharing);
             }
-            sharing.setCreatedTime(System.currentTimeMillis());
-            sharing.setUpdatedTime(System.currentTimeMillis());
-
-            sharingRepository.create(sharing);
-        }
-
-        if(cascadePermission){
-            //Adding permission for the specified users/groups for all child entities
-            entityRepository.getChildEntities(entityId).stream().forEach(e-> temp.addLast(e));
-            while(temp.size() > 0){
-                Entity entity = temp.pop();
-                String childEntityId = entity.entityId;
-                for(String userId : groupOrUserList){
-                    Sharing sharing = new Sharing();
-                    sharing.setPermissionTypeId(permissionTypeId);
-                    sharing.setEntityId(childEntityId);
-                    sharing.setGroupId(userId);
-                    sharing.setInheritedParentId(entityId);
-                    sharing.setSharingType(SharingType.INDIRECT_CASCADING);
-                    sharing.setInheritedParentId(entityId);
-                    sharing.setDomainId(domainId);
-                    sharing.setCreatedTime(System.currentTimeMillis());
-                    sharing.setUpdatedTime(System.currentTimeMillis());
-                    sharingRepository.create(sharing);
-                    entityRepository.getChildEntities(childEntityId).stream().forEach(e-> temp.addLast(e));
+
+            if(cascadePermission){
+                //Adding permission for the specified users/groups for all child entities
+                entityRepository.getChildEntities(entityId).stream().forEach(e-> temp.addLast(e));
+                while(temp.size() > 0){
+                    Entity entity = temp.pop();
+                    String childEntityId = entity.entityId;
+                    for(String userId : groupOrUserList){
+                        Sharing sharing = new Sharing();
+                        sharing.setPermissionTypeId(permissionTypeId);
+                        sharing.setEntityId(childEntityId);
+                        sharing.setGroupId(userId);
+                        sharing.setInheritedParentId(entityId);
+                        sharing.setSharingType(SharingType.INDIRECT_CASCADING);
+                        sharing.setInheritedParentId(entityId);
+                        sharing.setDomainId(domainId);
+                        sharing.setCreatedTime(System.currentTimeMillis());
+                        sharing.setUpdatedTime(System.currentTimeMillis());
+                        sharingRepository.create(sharing);
+                        entityRepository.getChildEntities(childEntityId).stream().forEach(e-> temp.addLast(e));
+                    }
                 }
             }
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
         }
-        return true;
     }
 
     @Override
     public boolean revokeEntitySharingFromUsers(String domainId, String entityId, List<String> userList, String permissionTypeId) throws SharingRegistryException, TException {
-        return revokeEntitySharing(domainId, entityId, userList, permissionTypeId);
+        try{
+            return revokeEntitySharing(domainId, entityId, userList, permissionTypeId);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
 
     @Override
     public boolean revokeEntitySharingFromGroups(String domainId, String entityId, List<String> groupList, String permissionTypeId) throws SharingRegistryException, TException {
-        return revokeEntitySharing(domainId, entityId, groupList, permissionTypeId);
+        try{
+            return revokeEntitySharing(domainId, entityId, groupList, permissionTypeId);
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     @Override
     public boolean userHasAccess(String domainId, String userId, String entityId, String permissionTypeId) throws SharingRegistryException, TException {
-        //check whether the user has permission directly or indirectly
-        List<GroupMembership> parentMemberships = groupMembershipRepository.getAllParentMembershipsForChild(domainId, userId);
-        List<String> groupIds = new ArrayList<>();
-        parentMemberships.stream().forEach(pm->groupIds.add(pm.parentId));
-        groupIds.add(userId);
-        return sharingRepository.hasAccess(domainId, entityId, groupIds, Arrays.asList(permissionTypeId,
-                permissionTypeRepository.getGlobalPermissionTypeIdForDomain(domainId)));
+        try{
+            //check whether the user has permission directly or indirectly
+            List<GroupMembership> parentMemberships = groupMembershipRepository.getAllParentMembershipsForChild(domainId, userId);
+            List<String> groupIds = new ArrayList<>();
+            parentMemberships.stream().forEach(pm->groupIds.add(pm.parentId));
+            groupIds.add(userId);
+            return sharingRepository.hasAccess(domainId, entityId, groupIds, Arrays.asList(permissionTypeId,
+                    permissionTypeRepository.getGlobalPermissionTypeIdForDomain(domainId)));
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
+        }
     }
 
     public boolean revokeEntitySharing(String domainId, String entityId, List<String> groupOrUserList, String permissionTypeId) throws SharingRegistryException {
-        if(permissionTypeId.equals(permissionTypeRepository.getGlobalPermissionTypeIdForDomain(domainId))){
-            throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be removed");
-        }
-
-        //revoking permission for the entity
-        for(String groupId : groupOrUserList){
-            SharingPK sharingPK = new SharingPK();
-            sharingPK.setEntityId(entityId);
-            sharingPK.setGroupId(groupId);
-            sharingPK.setPermissionTypeId(permissionTypeId);
-            sharingPK.setInheritedParentId(entityId);
-            sharingPK.setDomainId(domainId);
-
-            sharingRepository.delete(sharingPK);
-        }
+        try{
+            if(permissionTypeId.equals(permissionTypeRepository.getGlobalPermissionTypeIdForDomain(domainId))){
+                throw new SharingRegistryException(OWNER_PERMISSION_NAME + " permission cannot be removed");
+            }
 
-        //revoking permission from inheritance
-        List<Sharing> temp = new ArrayList<>();
-        sharingRepository.getIndirectSharedChildren(domainId, entityId, permissionTypeId).stream().forEach(s->temp.add(s));
-        for(Sharing sharing : temp){
-            String childEntityId = sharing.entityId;
+            //revoking permission for the entity
             for(String groupId : groupOrUserList){
                 SharingPK sharingPK = new SharingPK();
-                sharingPK.setEntityId(childEntityId);
+                sharingPK.setEntityId(entityId);
                 sharingPK.setGroupId(groupId);
                 sharingPK.setPermissionTypeId(permissionTypeId);
                 sharingPK.setInheritedParentId(entityId);
@@ -671,8 +876,29 @@ public class SharingRegistryServerHandler implements SharingRegistryService.Ifac
 
                 sharingRepository.delete(sharingPK);
             }
+
+            //revoking permission from inheritance
+            List<Sharing> temp = new ArrayList<>();
+            sharingRepository.getIndirectSharedChildren(domainId, entityId, permissionTypeId).stream().forEach(s -> temp.add(s));
+            for(Sharing sharing : temp){
+                String childEntityId = sharing.entityId;
+                for(String groupId : groupOrUserList){
+                    SharingPK sharingPK = new SharingPK();
+                    sharingPK.setEntityId(childEntityId);
+                    sharingPK.setGroupId(groupId);
+                    sharingPK.setPermissionTypeId(permissionTypeId);
+                    sharingPK.setInheritedParentId(entityId);
+                    sharingPK.setDomainId(domainId);
+
+                    sharingRepository.delete(sharingPK);
+                }
+            }
+            return true;
+        }catch (SharingRegistryException ex) {
+            logger.error(ex.getMessage(), ex);
+            throw ex;
         }
-        return true;
+
     }
 
 


[2/4] airavata git commit: WIP

Posted by sc...@apache.org.
WIP


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

Branch: refs/heads/develop
Commit: 6be0702deae02cfa62d5349b911616a70786ceed
Parents: 07097ce
Author: scnakandala <su...@gmail.com>
Authored: Tue Oct 18 12:44:46 2016 -0400
Committer: scnakandala <su...@gmail.com>
Committed: Tue Oct 18 12:44:46 2016 -0400

----------------------------------------------------------------------
 .../sharing/registry/db/repositories/EntityRepository.java  | 9 ++++++++-
 .../sharing/registry/SharingRegistryServiceTest.java        | 4 ++--
 2 files changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/6be0702d/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java
index 6d60aa9..6064077 100644
--- a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java
+++ b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java
@@ -67,7 +67,14 @@ public class EntityRepository extends AbstractRepository<Entity, EntityEntity, E
             }else if(searchCriteria.getSearchField().equals(EntitySearchField.PERMISSION_TYPE_ID)){
                 query += "S." + DBConstants.SharingTable.PERMISSION_TYPE_ID + " = '" + searchCriteria.getValue() + "' AND ";
             }else if(searchCriteria.getSearchField().equals(EntitySearchField.FULL_TEXT)){
-                query += "E." + DBConstants.EntityTable.FULL_TEXT + " LIKE '%" + searchCriteria.getValue() + "%' AND ";
+                //FULL TEXT Search with Query Expansion
+                String queryTerms = "";
+                for(String word : searchCriteria.getValue().trim().replaceAll(" +", " ").split(" ")){
+                    queryTerms += queryTerms + " +" + word;
+                }
+                queryTerms = queryTerms.trim();
+                query += "MATCH(E." + DBConstants.EntityTable.FULL_TEXT + ") AGAINST ('" + queryTerms
+                        + "' IN BOOLEAN MODE WITH QUERY EXPANSION) AND ";
             }else if(searchCriteria.getSearchField().equals(EntitySearchField.PARRENT_ENTITY_ID)){
                 query += "E." + DBConstants.EntityTable.PARENT_ENTITY_ID + " = '" + searchCriteria.getValue() + "' AND ";
             }else if(searchCriteria.getSearchField().equals(EntitySearchField.CREATED_TIME)){

http://git-wip-us.apache.org/repos/asf/airavata/blob/6be0702d/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java b/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
index 2433da0..df9a556 100644
--- a/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
+++ b/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
@@ -293,9 +293,9 @@ public class SharingRegistryServiceTest {
 
         ArrayList<SearchCriteria> filters = new ArrayList<>();
         SearchCriteria searchCriteria = new SearchCriteria();
-        searchCriteria.setSearchCondition(SearchCondition.LIKE);
+        searchCriteria.setSearchCondition(SearchCondition.FULL_TEXT);
         searchCriteria.setValue("experiment");
-        searchCriteria.setSearchField(EntitySearchField.NAME);
+        searchCriteria.setSearchField(EntitySearchField.FULL_TEXT);
         filters.add(searchCriteria);
 
         searchCriteria = new SearchCriteria();


[3/4] airavata git commit: fixing full text search issue

Posted by sc...@apache.org.
fixing full text search issue


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

Branch: refs/heads/develop
Commit: a6860dc491d23f59bdd489026853147f55596ed2
Parents: 6be0702
Author: scnakandala <su...@gmail.com>
Authored: Tue Oct 18 14:59:28 2016 -0400
Committer: scnakandala <su...@gmail.com>
Committed: Tue Oct 18 14:59:28 2016 -0400

----------------------------------------------------------------------
 .../db/repositories/AbstractRepository.java     | 10 ++++
 .../db/repositories/EntityRepository.java       | 55 +++++++++++---------
 .../main/resources/sharing-registry-derby.sql   |  1 +
 .../main/resources/sharing-registry-mysql.sql   |  1 +
 .../registry/SharingRegistryServiceTest.java    |  4 +-
 5 files changed, 45 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/a6860dc4/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java
index 9f5a706..ed99f62 100644
--- a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java
+++ b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java
@@ -121,6 +121,16 @@ public abstract class AbstractRepository<T, E, Id> {
         return gatewayList;
     }
 
+    public List<T> selectFromNativeQuery(String queryString, int offset, int limit) throws SharingRegistryException {
+        int newLimit = limit < 0 ? DBConstants.SELECT_MAX_ROWS: limit;
+        List resultSet = JPAUtils.execute(entityManager -> entityManager.createNativeQuery(queryString).setFirstResult(offset)
+                .setMaxResults(newLimit).getResultList());
+        Mapper mapper = ObjectMapperSingleton.getInstance();
+        List<T> gatewayList = new ArrayList<>();
+        resultSet.stream().forEach(rs -> gatewayList.add(mapper.map(rs, thriftGenericClass)));
+        return gatewayList;
+    }
+
     public String getSelectQuery(Map<String, String> filters){
         String query = "SELECT DISTINCT p from " + dbEntityGenericClass.getSimpleName() + " as p";
         if(filters != null && filters.size() != 0){

http://git-wip-us.apache.org/repos/asf/airavata/blob/a6860dc4/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java
index 6064077..46a7cd0 100644
--- a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java
+++ b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/db/repositories/EntityRepository.java
@@ -20,10 +20,12 @@
 */
 package org.apache.airavata.sharing.registry.db.repositories;
 
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.ServerSettings;
 import org.apache.airavata.sharing.registry.db.entities.EntityEntity;
 import org.apache.airavata.sharing.registry.db.entities.EntityPK;
-import org.apache.airavata.sharing.registry.db.entities.SharingEntity;
 import org.apache.airavata.sharing.registry.db.utils.DBConstants;
+import org.apache.airavata.sharing.registry.db.utils.JPAUtils;
 import org.apache.airavata.sharing.registry.models.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,48 +54,53 @@ public class EntityRepository extends AbstractRepository<Entity, EntityEntity, E
             groupIdString += groupId + "','";
         groupIdString = groupIdString.substring(0, groupIdString.length()-2);
 
-        String query = "SELECT DISTINCT E FROM " + EntityEntity.class.getSimpleName() + " E, " + SharingEntity.class.getSimpleName() + " S WHERE " +
-                "E." + DBConstants.EntityTable.ENTITY_ID + " = S." + DBConstants.SharingTable.ENTITY_ID + " AND " +
-                "E." + DBConstants.EntityTable.DOMAIN_ID + " = S." + DBConstants.SharingTable.DOMAIN_ID + " AND " +
-                "E." + DBConstants.EntityTable.DOMAIN_ID + " = '" + domainId + "' AND " +
-                "S." + DBConstants.SharingTable.GROUP_ID + " IN(" + groupIdString + ") AND E." + DBConstants.EntityTable.ENTITY_TYPE_ID + "='" +
-                entityTypeId + "' AND ";
+        String query = "SELECT E.* FROM ENTITY AS E INNER JOIN SHARING AS S ON (E.ENTITY_ID=S.ENTITY_ID AND E.DOMAIN_ID=S.DOMAIN_ID) WHERE " +
+                    "E.DOMAIN_ID = '" + domainId + "' AND " + "S.GROUP_ID IN(" + groupIdString + ") AND E." +
+                    "ENTITY_TYPE_ID" + "='" + entityTypeId + "' AND ";
 
         for(SearchCriteria searchCriteria : filters){
             if(searchCriteria.getSearchField().equals(EntitySearchField.NAME)){
-                query += "E." + DBConstants.EntityTable.NAME + " LIKE '%" + searchCriteria.getValue() + "%' AND ";
+                query += "E.NAME LIKE '%" + searchCriteria.getValue() + "%' AND ";
             }else if(searchCriteria.getSearchField().equals(EntitySearchField.DESCRIPTION)){
-                query += "E." + DBConstants.EntityTable.DESCRIPTION + " LIKE '%" + searchCriteria.getValue() + "%' AND ";
+                query += "E.DESCRIPTION LIKE '%" + searchCriteria.getValue() + "%' AND ";
             }else if(searchCriteria.getSearchField().equals(EntitySearchField.PERMISSION_TYPE_ID)){
-                query += "S." + DBConstants.SharingTable.PERMISSION_TYPE_ID + " = '" + searchCriteria.getValue() + "' AND ";
+                query += "S.PERMISSION_TYPE_ID = '" + searchCriteria.getValue() + "' AND ";
             }else if(searchCriteria.getSearchField().equals(EntitySearchField.FULL_TEXT)){
-                //FULL TEXT Search with Query Expansion
-                String queryTerms = "";
-                for(String word : searchCriteria.getValue().trim().replaceAll(" +", " ").split(" ")){
-                    queryTerms += queryTerms + " +" + word;
+                try {
+                    if(ServerSettings.getSetting(JPAUtils.SHARING_REG_JDBC_DRIVER).contains("derby")){
+                        query += "E.FULL_TEXT LIKE '%" + searchCriteria.getValue() + "%' AND ";
+                    }else{
+                        //FULL TEXT Search with Query Expansion
+                        String queryTerms = "";
+                        for(String word : searchCriteria.getValue().trim().replaceAll(" +", " ").split(" ")){
+                            queryTerms += queryTerms + " +" + word;
+                        }
+                        queryTerms = queryTerms.trim();
+                        query += "MATCH(E.FULL_TEXT) AGAINST ('" + queryTerms
+                                + "' IN BOOLEAN MODE) AND ";
+                    }
+                } catch (ApplicationSettingsException e) {
+                    logger.error(e.getMessage(), e);
+                    throw new SharingRegistryException(e.getMessage());
                 }
-                queryTerms = queryTerms.trim();
-                query += "MATCH(E." + DBConstants.EntityTable.FULL_TEXT + ") AGAINST ('" + queryTerms
-                        + "' IN BOOLEAN MODE WITH QUERY EXPANSION) AND ";
             }else if(searchCriteria.getSearchField().equals(EntitySearchField.PARRENT_ENTITY_ID)){
-                query += "E." + DBConstants.EntityTable.PARENT_ENTITY_ID + " = '" + searchCriteria.getValue() + "' AND ";
+                query += "E.PARENT_ENTITY_ID = '" + searchCriteria.getValue() + "' AND ";
             }else if(searchCriteria.getSearchField().equals(EntitySearchField.CREATED_TIME)){
                 if(searchCriteria.getSearchCondition().equals(SearchCondition.GTE)){
-                    query += "E." + DBConstants.EntityTable.CREATED_TIME + " >= " + Integer.parseInt(searchCriteria.getValue().trim()) + " AND ";
+                    query += "E.CREATED_TIME >= " + Integer.parseInt(searchCriteria.getValue().trim()) + " AND ";
                 }else{
-                    query += "E." + DBConstants.EntityTable.CREATED_TIME + " <= " + Integer.parseInt(searchCriteria.getValue().trim()) + " AND ";
+                    query += "E.CREATED_TIME <= " + Integer.parseInt(searchCriteria.getValue().trim()) + " AND ";
                 }
             }else if(searchCriteria.getSearchField().equals(EntitySearchField.UPDATED_TIME)){
                 if(searchCriteria.getSearchCondition().equals(SearchCondition.GTE)){
-                    query += "E." + DBConstants.EntityTable.UPDATED_TIME + " >= " + Integer.parseInt(searchCriteria.getValue().trim()) + " AND ";
+                    query += "E.UPDATED_TIME >= " + Integer.parseInt(searchCriteria.getValue().trim()) + " AND ";
                 }else{
-                    query += "E." + DBConstants.EntityTable.UPDATED_TIME + " <= " + Integer.parseInt(searchCriteria.getValue().trim()) + " AND ";
+                    query += "E.UPDATED_TIME <= " + Integer.parseInt(searchCriteria.getValue().trim()) + " AND ";
                 }
             }
         }
-
         query = query.substring(0, query.length() - 5);
-        return select(query, offset, limit);
+        return selectFromNativeQuery(query, offset, limit);
     }
 
     public String getSelectQuery(Map<String, String> filters){

http://git-wip-us.apache.org/repos/asf/airavata/blob/a6860dc4/modules/sharing-registry/sharing-registry-server/src/main/resources/sharing-registry-derby.sql
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-registry-server/src/main/resources/sharing-registry-derby.sql b/modules/sharing-registry/sharing-registry-server/src/main/resources/sharing-registry-derby.sql
index 923894e..19389c9 100644
--- a/modules/sharing-registry/sharing-registry-server/src/main/resources/sharing-registry-derby.sql
+++ b/modules/sharing-registry/sharing-registry-server/src/main/resources/sharing-registry-derby.sql
@@ -123,6 +123,7 @@ CREATE TABLE SHARING (
   UPDATED_TIME BIGINT NOT NULL,
   PRIMARY KEY (PERMISSION_TYPE_ID, ENTITY_ID, GROUP_ID, DOMAIN_ID, INHERITED_PARENT_ID),
   FOREIGN KEY (PERMISSION_TYPE_ID, DOMAIN_ID) REFERENCES PERMISSION_TYPE(PERMISSION_TYPE_ID, DOMAIN_ID) ON DELETE CASCADE ON UPDATE NO ACTION,
+  FOREIGN KEY (ENTITY_ID, DOMAIN_ID) REFERENCES ENTITY(ENTITY_ID, DOMAIN_ID) ON DELETE CASCADE ON UPDATE NO ACTION,
   FOREIGN KEY (INHERITED_PARENT_ID, DOMAIN_ID) REFERENCES ENTITY(ENTITY_ID, DOMAIN_ID) ON DELETE CASCADE ON UPDATE NO ACTION,
   FOREIGN KEY (GROUP_ID, DOMAIN_ID) REFERENCES USER_GROUP(GROUP_ID, DOMAIN_ID) ON DELETE CASCADE ON UPDATE NO ACTION
 );

http://git-wip-us.apache.org/repos/asf/airavata/blob/a6860dc4/modules/sharing-registry/sharing-registry-server/src/main/resources/sharing-registry-mysql.sql
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-registry-server/src/main/resources/sharing-registry-mysql.sql b/modules/sharing-registry/sharing-registry-server/src/main/resources/sharing-registry-mysql.sql
index 9bfe64a..7697d52 100644
--- a/modules/sharing-registry/sharing-registry-server/src/main/resources/sharing-registry-mysql.sql
+++ b/modules/sharing-registry/sharing-registry-server/src/main/resources/sharing-registry-mysql.sql
@@ -123,6 +123,7 @@ CREATE TABLE SHARING (
   UPDATED_TIME BIGINT NOT NULL,
   PRIMARY KEY (PERMISSION_TYPE_ID, ENTITY_ID, GROUP_ID, DOMAIN_ID, INHERITED_PARENT_ID),
   FOREIGN KEY (PERMISSION_TYPE_ID, DOMAIN_ID) REFERENCES PERMISSION_TYPE(PERMISSION_TYPE_ID, DOMAIN_ID) ON DELETE CASCADE ON UPDATE NO ACTION,
+  FOREIGN KEY (ENTITY_ID, DOMAIN_ID) REFERENCES ENTITY(ENTITY_ID, DOMAIN_ID) ON DELETE CASCADE ON UPDATE NO ACTION,
   FOREIGN KEY (INHERITED_PARENT_ID, DOMAIN_ID) REFERENCES ENTITY(ENTITY_ID, DOMAIN_ID) ON DELETE CASCADE ON UPDATE NO ACTION,
   FOREIGN KEY (GROUP_ID, DOMAIN_ID) REFERENCES USER_GROUP(GROUP_ID, DOMAIN_ID) ON DELETE CASCADE ON UPDATE NO ACTION
 );

http://git-wip-us.apache.org/repos/asf/airavata/blob/a6860dc4/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
----------------------------------------------------------------------
diff --git a/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java b/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
index df9a556..9802113 100644
--- a/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
+++ b/modules/sharing-registry/sharing-registry-server/src/test/java/org/apache/airavata/sharing/registry/SharingRegistryServiceTest.java
@@ -49,7 +49,7 @@ public class SharingRegistryServiceTest {
 
 
     @Test
-    public void test() throws TException {
+    public void test() throws TException, InterruptedException {
         String serverHost = "localhost";
         int serverPort = 7878;
 
@@ -249,7 +249,7 @@ public class SharingRegistryServiceTest {
         entity3.setName("test-experiment-2");
         entity3.setDescription("test experiment 2 description");
         entity3.setParentEntityId("test-project-1");
-        entity3.setFullText("test experiment 1 3-methyl 1-butanol");
+        entity3.setFullText("test experiment 1 3-methyl 1-butanol stampede");
         sharingServiceClient.createEntity(entity3);
 
         Entity entity4 = new Entity();