airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject airavata git commit: check entities exist before creating
Date Tue, 04 Oct 2016 21:03:47 GMT
Repository: airavata
Updated Branches:
  refs/heads/airavata-gov-registry 3c73df277 -> 81c812b9a


check entities exist before creating


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

Branch: refs/heads/airavata-gov-registry
Commit: 81c812b9a3eaf3c5e73585c22ae7ed7291d23d36
Parents: 3c73df2
Author: scnakandala <supun.nakandala@gmail.com>
Authored: Tue Oct 4 17:03:43 2016 -0400
Committer: scnakandala <supun.nakandala@gmail.com>
Committed: Tue Oct 4 17:03:43 2016 -0400

----------------------------------------------------------------------
 .../db/repositories/AbstractRepository.java        |  2 ++
 .../registry/server/GovRegistryServerHandler.java  | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/81c812b9/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java
----------------------------------------------------------------------
diff --git a/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java
b/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java
index 4a56cc1..1a95b97 100644
--- a/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java
+++ b/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java
@@ -84,6 +84,8 @@ public abstract class AbstractRepository<T, E, Id> {
         E entity = JPAUtils.execute(entityManager -> entityManager
                 .find(dbEntityGenericClass, id));
         Mapper mapper = ObjectMapperSingleton.getInstance();
+        if(entity == null)
+            return null;
         return mapper.map(entity, thriftGenericClass);
     }
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/81c812b9/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/GovRegistryServerHandler.java
----------------------------------------------------------------------
diff --git a/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/GovRegistryServerHandler.java
b/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/GovRegistryServerHandler.java
index eb04938..657a3ee 100644
--- a/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/GovRegistryServerHandler.java
+++ b/modules/airavata-sharing-registry/airavata-sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/GovRegistryServerHandler.java
@@ -64,6 +64,9 @@ public class GovRegistryServerHandler implements GovRegistryService.Iface{
      */
     @Override
     public String createDomain(Domain domain) throws GovRegistryException, TException {
+        if(domainRepository.get(domain.domainId) != null)
+            throw new GovRegistryException("There exist domain with given domain id");
+
         domain.setCreatedTime(System.currentTimeMillis());
         domain.setUpdatedTime(System.currentTimeMillis());
         domainRepository.create(domain);
@@ -113,6 +116,9 @@ public class GovRegistryServerHandler implements GovRegistryService.Iface{
      */
     @Override
     public String createUser(User user) throws GovRegistryException, TException {
+        if(userRepository.get(user.userId) != null)
+            throw new GovRegistryException("There exist user with given user id");
+
         user.setCreatedTime(System.currentTimeMillis());
         user.setUpdatedTime(System.currentTimeMillis());
         userRepository.create(user);
@@ -169,6 +175,9 @@ public class GovRegistryServerHandler implements GovRegistryService.Iface{
      */
     @Override
     public String createGroup(UserGroup group) throws GovRegistryException, TException {
+        if(userGroupRepository.get(group.groupId) != null)
+            throw new GovRegistryException("There exist group with given group id");
+
         group.setCreatedTime(System.currentTimeMillis());
         group.setUpdatedTime(System.currentTimeMillis());
         userGroupRepository.create(group);
@@ -266,6 +275,9 @@ public class GovRegistryServerHandler implements GovRegistryService.Iface{
      */
     @Override
     public String createEntityType(EntityType entityType) throws GovRegistryException, TException
{
+        if(entityTypeRepository.get(entityType.entityTypeId) != null)
+            throw new GovRegistryException("There exist EntityType with given EntityType
id");
+
         entityType.setCreatedTime(System.currentTimeMillis());
         entityType.setUpdatedTime(System.currentTimeMillis());
         entityTypeRepository.create(entityType);
@@ -306,6 +318,8 @@ public class GovRegistryServerHandler implements GovRegistryService.Iface{
      */
     @Override
     public String createPermissionType(PermissionType permissionType) throws GovRegistryException,
TException {
+        if(permissionTypeRepository.get(permissionType.permissionTypeId) != null)
+            throw new GovRegistryException("There exist PermissionType with given PermissionType
id");
         permissionType.setCreatedTime(System.currentTimeMillis());
         permissionType.setUpdatedTime(System.currentTimeMillis());
         permissionTypeRepository.create(permissionType);
@@ -345,6 +359,9 @@ public class GovRegistryServerHandler implements GovRegistryService.Iface{
      */
     @Override
     public String createEntity(Entity entity) throws GovRegistryException, TException {
+        if(entityRepository.get(entity.entityId) != null)
+            throw new GovRegistryException("There exist Entity with given Entity id");
+
         entity.setCreatedTime(System.currentTimeMillis());
         entity.setUpdatedTime(System.currentTimeMillis());
         entityRepository.create(entity);


Mime
View raw message