airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject [1/2] airavata git commit: WIP
Date Sun, 09 Oct 2016 04:57:45 GMT
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 <supun.nakandala@gmail.com>
Authored: Sat Oct 8 12:20:13 2016 -0400
Committer: scnakandala <supun.nakandala@gmail.com>
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<T, E, Id> {
         return mapper.map(entity, thriftGenericClass);
     }
 
+    public boolean isExists(Id id) throws SharingRegistryException {
+        return get(id) != null;
+    }
+
     public List<T> get(List<Id> idList) throws SharingRegistryException {
         List<T> 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<String, String> properties = new HashMap<String, String>();
             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);


Mime
View raw message