airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From goshe...@apache.org
Subject [1/5] airavata git commit: Checking for duplicate gateway request
Date Mon, 12 Jun 2017 18:52:24 GMT
Repository: airavata
Updated Branches:
  refs/heads/develop 7f3a93928 -> b45fac7a9


Checking for duplicate gateway request


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

Branch: refs/heads/develop
Commit: 98ec4bfa32e51af7b50b6252b8f7b5001f94d03b
Parents: 59ca27b
Author: Sneha Tilak <tilaks@149-160-244-249.dhcp-bl.indiana.edu>
Authored: Tue Jun 6 16:05:54 2017 -0400
Committer: Sneha Tilak <tilaks@149-160-244-249.dhcp-bl.indiana.edu>
Committed: Tue Jun 6 16:05:54 2017 -0400

----------------------------------------------------------------------
 .../handlers/TenantProfileServiceHandler.java   | 23 ++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/98ec4bfa/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 04870d9..51fc841 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
@@ -72,7 +72,9 @@ public class TenantProfileServiceHandler implements TenantProfileService.Iface
{
     @SecurityCheck
     public String addGateway(AuthzToken authzToken, Gateway gateway) throws TenantProfileServiceException,
AuthorizationException, TException {
         try {
-            gateway = tenantProfileRepository.create(gateway);
+            if (!checkDuplicate(gateway)) {
+                gateway = tenantProfileRepository.create(gateway);
+            }
             if (gateway != null) {
                 logger.info("Added Airavata Gateway with Id: " + gateway.getGatewayId());
                 // replicate tenant at end-places only if status is APPROVED
@@ -146,8 +148,8 @@ public class TenantProfileServiceHandler implements TenantProfileService.Iface
{
                 // delete tenant at end-places
                 ProfileServiceUtils.getDbEventPublisher().publish(
                         ProfileServiceUtils.getDBEventMessageContext(EntityType.TENANT, CrudType.DELETE,
-                                // pass along gateway datamodel, with correct gatewayId;
-                                // approvalstatus is not used for delete, hence set dummy
value
+                                 // pass along gateway datamodel, with correct gatewayId;
+                                 // approvalstatus is not used for delete, hence set dummy
value
                                 new Gateway(
                                         gatewayId,
                                         GatewayApprovalStatus.DEACTIVATED
@@ -183,7 +185,8 @@ public class TenantProfileServiceHandler implements TenantProfileService.Iface
{
     public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) throws TenantProfileServiceException,
AuthorizationException, TException {
         try {
             Gateway gateway = tenantProfileRepository.getGateway(gatewayId);
-            return gateway != null;
+            boolean checkStatus = gateway.getGatewayApprovalStatus().equals(GatewayApprovalStatus.APPROVED);
+            return (gateway != null && checkStatus);
         } catch (Exception ex) {
             logger.error("Error checking if gateway-profile exists, reason: " + ex.getMessage(),
ex);
             TenantProfileServiceException exception = new TenantProfileServiceException();
@@ -191,4 +194,16 @@ public class TenantProfileServiceHandler implements TenantProfileService.Iface
{
             throw exception;
         }
     }
+
+    private boolean checkDuplicate(Gateway gateway) throws TenantProfileServiceException
{
+        try {
+            Gateway duplicateGateway = tenantProfileRepository.getGateway(gateway.getGatewayId());
+            return ((duplicateGateway.getGatewayId() == gateway.getGatewayId()) &&
(duplicateGateway.getGatewayName() == gateway.getGatewayName()) && (duplicateGateway.getGatewayURL()
== gateway.getGatewayURL()) && (duplicateGateway.getGatewayApprovalStatus().equals(GatewayApprovalStatus.APPROVED)));
+        } catch (Exception ex) {
+            logger.error("Error checking if duplicate gateway-profile exists, reason: " +
ex.getMessage(), ex);
+            TenantProfileServiceException exception = new TenantProfileServiceException();
+            exception.setMessage("Error checking if duplicate gateway-profiles exists, reason:
" + ex.getMessage());
+            throw exception;
+        }
+    }
 }


Mime
View raw message