Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 603B6200B8B for ; Tue, 4 Oct 2016 23:03:50 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5E8D7160ACC; Tue, 4 Oct 2016 21:03:50 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 746D7160AC7 for ; Tue, 4 Oct 2016 23:03:49 +0200 (CEST) Received: (qmail 44648 invoked by uid 500); 4 Oct 2016 21:03:48 -0000 Mailing-List: contact commits-help@airavata.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airavata.apache.org Delivered-To: mailing list commits@airavata.apache.org Received: (qmail 44639 invoked by uid 99); 4 Oct 2016 21:03:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Oct 2016 21:03:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 19227DFC55; Tue, 4 Oct 2016 21:03:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: scnakandala@apache.org To: commits@airavata.apache.org Message-Id: <50fe4057900349488117df09d1220651@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: airavata git commit: check entities exist before creating Date: Tue, 4 Oct 2016 21:03:47 +0000 (UTC) archived-at: Tue, 04 Oct 2016 21:03:50 -0000 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 Authored: Tue Oct 4 17:03:43 2016 -0400 Committer: scnakandala 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 { 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);