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 D73B2200BA9 for ; Sun, 9 Oct 2016 06:57:47 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D5B6A160AF3; Sun, 9 Oct 2016 04:57:47 +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 BCFB0160ADF for ; Sun, 9 Oct 2016 06:57:46 +0200 (CEST) Received: (qmail 9830 invoked by uid 500); 9 Oct 2016 04:57:45 -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 9812 invoked by uid 99); 9 Oct 2016 04:57:45 -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; Sun, 09 Oct 2016 04:57:45 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7BE98E00A4; Sun, 9 Oct 2016 04:57:45 +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 Date: Sun, 09 Oct 2016 04:57:45 -0000 Message-Id: <3a9da3c0493947bb8dbdd5b56d339f71@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] airavata git commit: WIP archived-at: Sun, 09 Oct 2016 04:57:48 -0000 Repository: airavata Updated Branches: refs/heads/airavata-gov-registry 4712ec33e -> 146ccc774 WIP Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/ff3fda15 Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/ff3fda15 Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/ff3fda15 Branch: refs/heads/airavata-gov-registry Commit: ff3fda151e438f6df853985822f19e7d3fabda75 Parents: 4712ec3 Author: scnakandala Authored: Sat Oct 8 12:20:13 2016 -0400 Committer: scnakandala Committed: Sat Oct 8 12:20:13 2016 -0400 ---------------------------------------------------------------------- .../db/repositories/AbstractRepository.java | 4 + .../sharing/registry/db/utils/JPAUtils.java | 22 ++-- .../server/SharingRegistryServerHandler.java | 113 ++++++++++--------- 3 files changed, 74 insertions(+), 65 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/ff3fda15/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java ---------------------------------------------------------------------- diff --git a/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java b/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java index 6e13c8d..a53a6a2 100644 --- a/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java +++ b/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/repositories/AbstractRepository.java @@ -89,6 +89,10 @@ public abstract class AbstractRepository { return mapper.map(entity, thriftGenericClass); } + public boolean isExists(Id id) throws SharingRegistryException { + return get(id) != null; + } + public List get(List idList) throws SharingRegistryException { List returnList = new ArrayList<>(); for(Id id : idList) http://git-wip-us.apache.org/repos/asf/airavata/blob/ff3fda15/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java ---------------------------------------------------------------------- diff --git a/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java b/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java index 0780bd3..ed147e2 100644 --- a/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java +++ b/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/db/utils/JPAUtils.java @@ -64,20 +64,20 @@ public class JPAUtils { @PersistenceContext(unitName = PERSISTENCE_UNIT_NAME) private static EntityManager entityManager; - public static EntityManager getEntityManager() { + public static EntityManager getEntityManager() throws SharingRegistryException { if (factory == null) { -// String connectionProperties = "DriverClassName=" + readServerProperties(SHARING_REG_JDBC_DRIVER) + "," + -// "Url=" + readServerProperties(SHARING_REG_JDBC_URL) + "?autoReconnect=true," + -// "Username=" + readServerProperties(SHARING_REG_JDBC_USER) + "," + -// "Password=" + readServerProperties(SHARING_REG_JDBC_PWD) + -// ",validationQuery=" + readServerProperties(SHARING_REG_VALIDATION_QUERY); + String connectionProperties = "DriverClassName=" + readServerProperties(SHARING_REG_JDBC_DRIVER) + "," + + "Url=" + readServerProperties(SHARING_REG_JDBC_URL) + "?autoReconnect=true," + + "Username=" + readServerProperties(SHARING_REG_JDBC_USER) + "," + + "Password=" + readServerProperties(SHARING_REG_JDBC_PWD) + + ",validationQuery=" + readServerProperties(SHARING_REG_VALIDATION_QUERY); // - String connectionProperties = "DriverClassName=com.mysql.jdbc.Driver," + - "Url=jdbc:mysql://localhost:3306/airavata_sharing_catalog?autoReconnect=true," + - "Username=root," + - "Password=," + - ",validationQuery=SELECT 1 FROM CONFIGURATION"; +// String connectionProperties = "DriverClassName=com.mysql.jdbc.Driver," + +// "Url=jdbc:mysql://localhost:3306/airavata_sharing_catalog?autoReconnect=true," + +// "Username=root," + +// "Password=," + +// ",validationQuery=SELECT 1 FROM CONFIGURATION"; Map properties = new HashMap(); properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource"); http://git-wip-us.apache.org/repos/asf/airavata/blob/ff3fda15/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java ---------------------------------------------------------------------- diff --git a/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java b/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java index e86de65..a5a32d2 100644 --- a/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java +++ b/modules/sharing-registry/sharing-registry-core/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServerHandler.java @@ -59,60 +59,56 @@ public class SharingRegistryServerHandler implements GovRegistryService.Iface{ this.entityRepository = new EntityRepository(); this.sharingRepository = new SharingRepository(); - Domain domain = null; - try{ - domain = getDomain(ServerSettings.getDefaultUserGateway()); - } finally { - if(domain == null){ - domain = new Domain(); - domain.setDomainId(ServerSettings.getDefaultUserGateway()); - domain.setName(ServerSettings.getDefaultUserGateway()); - domain.setDescription("Domain entry for " + domain.name); - createDomain(domain); - - User user = new User(); - user.setDomainId(domain.domainId); - user.setUserId(ServerSettings.getDefaultUser()+"@"+ServerSettings.getDefaultUserGateway()); - user.setUserName(ServerSettings.getDefaultUser()); - createUser(user); - - //Creating Entity Types for each domain - EntityType entityType = new EntityType(); - entityType.setEntityTypeId(domain.domainId+":PROJECT"); - entityType.setDomainId(domain.domainId); - entityType.setName("PROJECT"); - entityType.setDescription("Project entity type"); - createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.domainId+":EXPERIMENT"); - entityType.setDomainId(domain.domainId); - entityType.setName("EXPERIMENT"); - entityType.setDescription("Experiment entity type"); - createEntityType(entityType); - - entityType = new EntityType(); - entityType.setEntityTypeId(domain.domainId+":FILE"); - entityType.setDomainId(domain.domainId); - entityType.setName("FILE"); - entityType.setDescription("File entity type"); - createEntityType(entityType); - - //Creating Permission Types for each domain - PermissionType permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.domainId+":READ"); - permissionType.setDomainId(domain.domainId); - permissionType.setName("READ"); - permissionType.setDescription("Read permission type"); - createPermissionType(permissionType); - - permissionType = new PermissionType(); - permissionType.setPermissionTypeId(domain.domainId+":WRITE"); - permissionType.setDomainId(domain.domainId); - permissionType.setName("WRITE"); - permissionType.setDescription("Write permission type"); - createPermissionType(permissionType); - } + if(!domainRepository.isExists(ServerSettings.getDefaultUserGateway())){ + Domain domain = new Domain(); + domain.setDomainId(ServerSettings.getDefaultUserGateway()); + domain.setName(ServerSettings.getDefaultUserGateway()); + domain.setDescription("Domain entry for " + domain.name); + createDomain(domain); + + User user = new User(); + user.setDomainId(domain.domainId); + user.setUserId(ServerSettings.getDefaultUser()+"@"+ServerSettings.getDefaultUserGateway()); + user.setUserName(ServerSettings.getDefaultUser()); + createUser(user); + + //Creating Entity Types for each domain + EntityType entityType = new EntityType(); + entityType.setEntityTypeId(domain.domainId+":PROJECT"); + entityType.setDomainId(domain.domainId); + entityType.setName("PROJECT"); + entityType.setDescription("Project entity type"); + createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.domainId+":EXPERIMENT"); + entityType.setDomainId(domain.domainId); + entityType.setName("EXPERIMENT"); + entityType.setDescription("Experiment entity type"); + createEntityType(entityType); + + entityType = new EntityType(); + entityType.setEntityTypeId(domain.domainId+":FILE"); + entityType.setDomainId(domain.domainId); + entityType.setName("FILE"); + entityType.setDescription("File entity type"); + createEntityType(entityType); + + //Creating Permission Types for each domain + PermissionType permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.domainId+":READ"); + permissionType.setDomainId(domain.domainId); + permissionType.setName("READ"); + permissionType.setDescription("Read permission type"); + createPermissionType(permissionType); + + permissionType = new PermissionType(); + permissionType.setPermissionTypeId(domain.domainId+":WRITE"); + permissionType.setDomainId(domain.domainId); + permissionType.setName("WRITE"); + permissionType.setDescription("Write permission type"); + createPermissionType(permissionType); + } } @@ -420,6 +416,15 @@ public class SharingRegistryServerHandler implements GovRegistryService.Iface{ if(entityRepository.get(entity.entityId) != null) throw new SharingRegistryException("There exist Entity with given Entity id"); + if(!userRepository.isExists(entity.getOwnerId())){ + User user = new User(); + user.setUserId(entity.getOwnerId()); + user.setDomainId(entity.domainId); + user.setUserName(user.userId.split("@")[0]); + + userRepository.create(user); + } + entity.setCreatedTime(System.currentTimeMillis()); entity.setUpdatedTime(System.currentTimeMillis()); entityRepository.create(entity);