airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scnakand...@apache.org
Subject [11/14] airavata git commit: Use abstractrepository to implement tenantprofile business logic
Date Wed, 08 Mar 2017 23:45:52 GMT
Use abstractrepository to implement tenantprofile business logic


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

Branch: refs/heads/user-profile
Commit: 8e83408a9d35d018b7047be55619630d1858d821
Parents: 2eb3ee7
Author: Gourav Shenoy <shenoy.200@gmail.com>
Authored: Wed Mar 8 18:00:49 2017 -0500
Committer: Gourav Shenoy <shenoy.200@gmail.com>
Committed: Wed Mar 8 18:00:49 2017 -0500

----------------------------------------------------------------------
 .../repositories/AbstractRepository.java        |   22 +-
 .../commons/tenant/entities/GatewayEntity.java  |    7 +-
 .../profile/commons/utils/QueryConstants.java   |   21 +-
 .../src/main/resources/META-INF/persistence.xml |    2 +-
 .../handlers/TenantProfileServiceHandler.java   |   79 +-
 .../profile/server/ProfileServiceServer.java    |    8 +-
 .../gateway/cpi/GatewayProfileService.java      | 6865 ------------------
 .../GatewayProfileServiceException.java         |  407 --
 .../cpi/profile_gateway_cpiConstants.java       |   59 -
 .../tenant/core/impl/GatewayRegistry.java       |    8 +-
 .../repositories/TenantProfileRepository.java   |   51 +
 .../profile/tenant/core/util/GatewayUtils.java  |    8 +-
 .../tenant/core/util/QueryConstants.java        |    6 +-
 .../repositories/WorkspaceRepositoryTest.java   |   10 +-
 14 files changed, 153 insertions(+), 7400 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/8e83408a/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/repositories/AbstractRepository.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/repositories/AbstractRepository.java
b/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/repositories/AbstractRepository.java
index a38ca02..7f80a96 100644
--- a/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/repositories/AbstractRepository.java
+++ b/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/repositories/AbstractRepository.java
@@ -69,13 +69,21 @@ public abstract class AbstractRepository<T, E, Id> {
         return mapper.map(entity, thriftGenericClass);
     }
 
+    public List<T> select(String query) {
+        List resultSet = (List) JPAUtils.execute(entityManager -> entityManager.createQuery(query).getResultList());
+        Mapper mapper = ObjectMapperSingleton.getInstance();
+        List<T> resultList = new ArrayList<>();
+        resultSet.stream().forEach(rs -> resultList.add(mapper.map(rs, thriftGenericClass)));
+        return resultList;
+    }
+
     public List<T> select(String query, int limit, int offset) {
         List resultSet = (List) JPAUtils.execute(entityManager -> entityManager.createQuery(query).setFirstResult(offset)
-                .setMaxResults(offset).getResultList());
+                .setMaxResults(limit).getResultList());
         Mapper mapper = ObjectMapperSingleton.getInstance();
-        List<T> gatewayList = new ArrayList<>();
-        resultSet.stream().forEach(rs -> gatewayList.add(mapper.map(rs, thriftGenericClass)));
-        return gatewayList;
+        List<T> resultList = new ArrayList<>();
+        resultSet.stream().forEach(rs -> resultList.add(mapper.map(rs, thriftGenericClass)));
+        return resultList;
     }
 
     public List<T> select(String query, int limit, int offset, Map<String, Object>
queryParams) {
@@ -91,8 +99,8 @@ public abstract class AbstractRepository<T, E, Id> {
 
         });
         Mapper mapper = ObjectMapperSingleton.getInstance();
-        List<T> gatewayList = new ArrayList<>();
-        resultSet.stream().forEach(rs -> gatewayList.add(mapper.map(rs, thriftGenericClass)));
-        return gatewayList;
+        List<T> resultList = new ArrayList<>();
+        resultSet.stream().forEach(rs -> resultList.add(mapper.map(rs, thriftGenericClass)));
+        return resultList;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/8e83408a/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/tenant/entities/GatewayEntity.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/tenant/entities/GatewayEntity.java
b/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/tenant/entities/GatewayEntity.java
index 0a67383..3b1e370 100644
--- a/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/tenant/entities/GatewayEntity.java
+++ b/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/tenant/entities/GatewayEntity.java
@@ -24,13 +24,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.persistence.*;
-import java.sql.Timestamp;
 import java.util.Date;
 
 @Entity
 @Table(name = "GATEWAY")
-public class Gateway {
-    private final static Logger logger = LoggerFactory.getLogger(Gateway.class);
+public class GatewayEntity {
+    private final static Logger logger = LoggerFactory.getLogger(GatewayEntity.class);
     private String gatewayId;
     private String gatewayName;
     private String domain;
@@ -230,7 +229,7 @@ public class Gateway {
 
     @Override
     public String toString() {
-        return "Gateway{" +
+        return "GatewayEntity{" +
                 "gatewayId='" + gatewayId + '\'' +
                 ", gatewayName='" + gatewayName + '\'' +
                 ", domain='" + domain + '\'' +

http://git-wip-us.apache.org/repos/asf/airavata/blob/8e83408a/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/utils/QueryConstants.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/utils/QueryConstants.java
b/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/utils/QueryConstants.java
index 5edf72e..696d9d1 100644
--- a/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/utils/QueryConstants.java
+++ b/airavata-services/profile-service/profile-service-commons/src/main/java/org/apache/airavata/service/profile/commons/utils/QueryConstants.java
@@ -1,22 +1,27 @@
 package org.apache.airavata.service.profile.commons.utils;
 
 import org.apache.airavata.model.user.UserProfile;
+import org.apache.airavata.model.workspace.Gateway;
 
 /**
  * Created by goshenoy on 03/08/2017.
  */
-public interface QueryConstants {
+public class QueryConstants {
 
 
-
-    String FIND_USER_PROFILE_BY_USER_ID = "SELECT u FROM UserProfileEntity u " +
+    public static final String FIND_USER_PROFILE_BY_USER_ID = "SELECT u FROM UserProfileEntity
u " +
             "where u.userId LIKE :" + UserProfile._Fields.USER_ID.getFieldName() + " " +
-            "AND u.gatewayId LIKE :"+ UserProfile._Fields.GATEWAY_ID.getFieldName() + "";
+            "AND u.gatewayId LIKE :" + UserProfile._Fields.GATEWAY_ID.getFieldName() + "";
 
-    String FIND_ALL_USER_PROFILES_BY_GATEWAY_ID = "SELECT u FROM UserProfileEntity u " +
-            "where u.gatewayId LIKE :"+ UserProfile._Fields.GATEWAY_ID.getFieldName() + "";
+    public static final String FIND_ALL_USER_PROFILES_BY_GATEWAY_ID = "SELECT u FROM UserProfileEntity
u " +
+            "where u.gatewayId LIKE :" + UserProfile._Fields.GATEWAY_ID.getFieldName() +
"";
 
-    String FIND_USER_PROFILE_BY_USER_NAME = "SELECT u FROM UserProfileEntity u " +
+    public static final String FIND_USER_PROFILE_BY_USER_NAME = "SELECT u FROM UserProfileEntity
u " +
             "where u.userId LIKE :" + UserProfile._Fields.USER_NAME.getFieldName() + " "
+
-            "AND u.gatewayId LIKE :"+ UserProfile._Fields.GATEWAY_ID.getFieldName() + "";
+            "AND u.gatewayId LIKE :" + UserProfile._Fields.GATEWAY_ID.getFieldName() + "";
+
+    public static final String FIND_GATEWAY_BY_ID = "SELECT g FROM GatewayEntity g " +
+            "where g.gatewayId LIKE :" + Gateway._Fields.GATEWAY_ID.getFieldName() + "";
+
+    public static final String GET_ALL_GATEWAYS = "SELECT g FROM GatewayEntity g";
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/8e83408a/airavata-services/profile-service/profile-service-commons/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-service-commons/src/main/resources/META-INF/persistence.xml
b/airavata-services/profile-service/profile-service-commons/src/main/resources/META-INF/persistence.xml
index 34c0efa..2a0adc6 100644
--- a/airavata-services/profile-service/profile-service-commons/src/main/resources/META-INF/persistence.xml
+++ b/airavata-services/profile-service/profile-service-commons/src/main/resources/META-INF/persistence.xml
@@ -24,7 +24,7 @@
         <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
         <class>org.apache.airavata.service.profile.commons.user.entities.UserProfileEntity</class>
         <class>org.apache.airavata.service.profile.commons.user.entities.NSFDemographicsEntity</class>
-        <class>org.apache.airavata.service.profile.commons.tenant.entities.Gateway</class>
+        <class>org.apache.airavata.service.profile.commons.tenant.entities.GatewayEntity</class>
         <exclude-unlisted-classes>true</exclude-unlisted-classes>
 
         <properties>

http://git-wip-us.apache.org/repos/asf/airavata/blob/8e83408a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java
b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java
index 16a5666..ebda0dd 100644
--- a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java
+++ b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/TenantProfileServiceHandler.java
@@ -21,10 +21,12 @@
 package org.apache.airavata.service.profile.handlers;
 
 import org.apache.airavata.model.workspace.Gateway;
+import org.apache.airavata.service.profile.commons.tenant.entities.GatewayEntity;
 import org.apache.airavata.service.profile.tenant.core.impl.GatewayRegistry;
-import org.apache.airavata.service.profile.gateway.cpi.GatewayProfileService;
-import org.apache.airavata.service.profile.gateway.cpi.exception.GatewayProfileServiceException;
-import org.apache.airavata.service.profile.gateway.cpi.profile_gateway_cpiConstants;
+import org.apache.airavata.service.profile.tenant.core.repositories.TenantProfileRepository;
+import org.apache.airavata.service.profile.tenant.cpi.TenantProfileService;
+import org.apache.airavata.service.profile.tenant.cpi.exception.TenantProfileServiceException;
+import org.apache.airavata.service.profile.tenant.cpi.profile_tenant_cpiConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -33,96 +35,115 @@ import java.util.List;
 /**
  * Created by goshenoy on 3/6/17.
  */
-public class TenantProfileServiceHandler implements GatewayProfileService.Iface {
+public class TenantProfileServiceHandler implements TenantProfileService.Iface {
 
     private final static Logger logger = LoggerFactory.getLogger(TenantProfileServiceHandler.class);
 
     private final GatewayRegistry gatewayRegistry = new GatewayRegistry();
 
+    private TenantProfileRepository tenantProfileRepository;
+
+    public TenantProfileServiceHandler() {
+        logger.debug("Initializing TenantProfileServiceHandler");
+        this.tenantProfileRepository = new TenantProfileRepository(Gateway.class, GatewayEntity.class);
+    }
+
     @Override
-    public String getAPIVersion() throws GatewayProfileServiceException {
+    public String getAPIVersion() throws TenantProfileServiceException {
         try {
-            return profile_gateway_cpiConstants.GATEWAY_PROFILE_CPI_VERSION;
+            return profile_tenant_cpiConstants.TENANT_PROFILE_CPI_VERSION;
         } catch (Exception ex) {
             logger.error("Error getting API version, reason: " + ex.getMessage(), ex);
-            GatewayProfileServiceException exception = new GatewayProfileServiceException();
+            TenantProfileServiceException exception = new TenantProfileServiceException();
             exception.setMessage("Error getting API version, reason: " + ex.getMessage());
             throw exception;
         }
     }
 
     @Override
-    public String addGateway(Gateway gateway) throws GatewayProfileServiceException {
+    public String addGateway(Gateway gateway) throws TenantProfileServiceException {
         try {
-            String gatewayId = gatewayRegistry.addGateway(gateway);
-            logger.debug("Airavata added gateway-profile with ID: " + gatewayId);
-            return gatewayId;
+            tenantProfileRepository.create(gateway);
+            if (gateway != null) {
+                logger.debug("Added Airavata Gateway with Id: " + gateway.getGatewayId());
+                return gateway.getGatewayId();
+            } else {
+                throw new Exception("Gateway object is null.");
+            }
         } catch (Exception ex) {
             logger.error("Error adding gateway-profile, reason: " + ex.getMessage(), ex);
-            GatewayProfileServiceException exception = new GatewayProfileServiceException();
+            TenantProfileServiceException exception = new TenantProfileServiceException();
             exception.setMessage("Error adding gateway-profile, reason: " + ex.getMessage());
             throw exception;
         }
     }
 
     @Override
-    public boolean updateGateway(String gatewayId, Gateway updatedGateway) throws GatewayProfileServiceException
{
+    public boolean updateGateway(Gateway updatedGateway) throws TenantProfileServiceException
{
         try {
-            logger.debug("Updating gateway-profile with ID: " + gatewayId);
-            gatewayRegistry.updateGateway(gatewayId, updatedGateway);
-            return true;
+            if (tenantProfileRepository.update(updatedGateway) != null) {
+                logger.debug("Updated gateway-profile with ID: " + updatedGateway.getGatewayId());
+                return true;
+            } else {
+                return false;
+            }
         } catch (Exception ex) {
             logger.error("Error updating gateway-profile, reason: " + ex.getMessage(), ex);
-            GatewayProfileServiceException exception = new GatewayProfileServiceException();
+            TenantProfileServiceException exception = new TenantProfileServiceException();
             exception.setMessage("Error updating gateway-profile, reason: " + ex.getMessage());
             return false;
         }
     }
 
     @Override
-    public Gateway getGateway(String gatewayId) throws GatewayProfileServiceException {
+    public Gateway getGateway(String gatewayId) throws TenantProfileServiceException {
         try {
-            return gatewayRegistry.getGateway(gatewayId);
+            Gateway gateway = tenantProfileRepository.getGateway(gatewayId);
+            if (gateway == null) {
+                throw new Exception("Could not find Gateway with ID: " + gatewayId);
+            }
+            return gateway;
         } catch (Exception ex) {
             logger.error("Error getting gateway-profile, reason: " + ex.getMessage(), ex);
-            GatewayProfileServiceException exception = new GatewayProfileServiceException();
+            TenantProfileServiceException exception = new TenantProfileServiceException();
             exception.setMessage("Error getting gateway-profile, reason: " + ex.getMessage());
             throw exception;
         }
     }
 
     @Override
-    public boolean deleteGateway(String gatewayId) throws GatewayProfileServiceException
{
+    public boolean deleteGateway(String gatewayId) throws TenantProfileServiceException {
         try {
             logger.debug("Deleting Airavata gateway-profile with ID: " + gatewayId);
-            return gatewayRegistry.removeGateway(gatewayId);
+            return tenantProfileRepository.delete(gatewayId);
         } catch (Exception ex) {
             logger.error("Error deleting gateway-profile, reason: " + ex.getMessage(), ex);
-            GatewayProfileServiceException exception = new GatewayProfileServiceException();
+            TenantProfileServiceException exception = new TenantProfileServiceException();
             exception.setMessage("Error deleting gateway-profile, reason: " + ex.getMessage());
             throw exception;
         }
     }
 
     @Override
-    public List<Gateway> getAllGateways() throws GatewayProfileServiceException {
+    public List<Gateway> getAllGateways() throws TenantProfileServiceException {
         try {
-            return gatewayRegistry.getAllGateways();
+            return tenantProfileRepository.getAllGateways();
         } catch (Exception ex) {
             logger.error("Error getting all gateway-profiles, reason: " + ex.getMessage(),
ex);
-            GatewayProfileServiceException exception = new GatewayProfileServiceException();
+            TenantProfileServiceException exception = new TenantProfileServiceException();
             exception.setMessage("Error getting all gateway-profiles, reason: " + ex.getMessage());
             throw exception;
         }
     }
 
     @Override
-    public boolean isGatewayExist(String gatewayId) throws GatewayProfileServiceException
{
+    public boolean isGatewayExist(String gatewayId) throws TenantProfileServiceException
{
         try {
-            return gatewayRegistry.isGatewayExist(gatewayId);
+            Gateway gateway = tenantProfileRepository.getGateway(gatewayId);
+            return gateway != null;
         } catch (Exception ex) {
             logger.error("Error checking if gateway-profile exists, reason: " + ex.getMessage(),
ex);
-            GatewayProfileServiceException exception = new GatewayProfileServiceException();
+            TenantProfileServiceException exception = new TenantProfileServiceException();
             exception.setMessage("Error checking if gateway-profile exists, reason: " + ex.getMessage());
             throw exception;
         }

http://git-wip-us.apache.org/repos/asf/airavata/blob/8e83408a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
index c998b11..e2c3fd0 100644
--- a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
+++ b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/server/ProfileServiceServer.java
@@ -23,10 +23,10 @@ package org.apache.airavata.service.profile.server;
 
 import org.apache.airavata.common.utils.IServer;
 import org.apache.airavata.common.utils.ServerSettings;
-import org.apache.airavata.service.profile.gateway.cpi.GatewayProfileService;
-import org.apache.airavata.service.profile.gateway.cpi.profile_gateway_cpiConstants;
+import org.apache.airavata.service.profile.tenant.cpi.profile_tenant_cpiConstants;
 import org.apache.airavata.service.profile.handlers.TenantProfileServiceHandler;
 import org.apache.airavata.service.profile.handlers.UserProfileServiceHandler;
+import org.apache.airavata.service.profile.tenant.cpi.TenantProfileService;
 import org.apache.airavata.service.profile.user.cpi.UserProfileService;
 import org.apache.airavata.service.profile.user.cpi.profile_user_cpiConstants;
 import org.apache.thrift.TMultiplexedProcessor;
@@ -80,12 +80,12 @@ public class ProfileServiceServer implements IServer {
 
             // create multiple processors for each profile-service
             UserProfileService.Processor userProfileProcessor = new UserProfileService.Processor(new
UserProfileServiceHandler());
-            GatewayProfileService.Processor gatewayProfileProcessor = new GatewayProfileService.Processor(new
TenantProfileServiceHandler());
+            TenantProfileService.Processor teneantProfileProcessor = new TenantProfileService.Processor(new
TenantProfileServiceHandler());
 
             // create a multiplexed processor
             TMultiplexedProcessor profileServiceProcessor = new TMultiplexedProcessor();
             profileServiceProcessor.registerProcessor(profile_user_cpiConstants.USER_PROFILE_CPI_NAME,
userProfileProcessor);
-            profileServiceProcessor.registerProcessor(profile_gateway_cpiConstants.GATEWAY_PROFILE_CPI_NAME,
gatewayProfileProcessor);
+            profileServiceProcessor.registerProcessor(profile_tenant_cpiConstants.TENANT_PROFILE_CPI_NAME,
teneantProfileProcessor);
 
             TServerTransport serverTransport;
 


Mime
View raw message