Add implementation for gatewayresource instead of gatewayresourceprofile'

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

Branch: refs/heads/develop
Commit: f9e4b0dfda8da03356d295661fc30d6b2732170d
Parents: bf2d92d
Author: Gourav Shenoy <[email protected]>
Authored: Tue Mar 7 16:51:25 2017 -0500
Committer: Gourav Shenoy <[email protected]>
Committed: Tue Mar 7 16:51:25 2017 -0500

----------------------------------------------------------------------
 .../gateway/core/GwyResourceProfile.java        |  78 -----
 .../gateway/core/impl/GatewayRegistry.java      | 137 ++++++++
 .../core/impl/GwyResourceProfileImpl.java       | 148 --------
 .../core/resources/GatewayProfileResource.java  | 342 -------------------
 .../gateway/core/resources/GatewayResource.java |  73 ++++
 .../profile/gateway/core/util/GatewayUtils.java | 182 ++++++++--
 .../profile/gateway/core/util/JPAUtils.java     |  17 -
 .../gateway/core/util/QueryConstants.java       |   4 +-
 .../handlers/GatewayProfileServiceHandler.java  |  43 ++-
 9 files changed, 405 insertions(+), 619 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/f9e4b0df/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/GwyResourceProfile.java
----------------------------------------------------------------------
diff --git 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/GwyResourceProfile.java
 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/GwyResourceProfile.java
deleted file mode 100644
index 6c3b961..0000000
--- 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/GwyResourceProfile.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.airavata.service.profile.gateway.core;
-
-import 
org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference;
-import 
org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
-import org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference;
-
-import java.util.List;
-
-public interface GwyResourceProfile {
-    /**
-     * This method will add a gateway profile
-     * @param gatewayProfile gateway profile
-     * @return gateway id
-     */
-    String addGatewayResourceProfile(GatewayResourceProfile gatewayProfile) 
throws Exception;
-
-    /**
-     * This method will update a gateway profile
-     * @param gatewayId unique gateway id
-     * @param updatedProfile updated profile
-     */
-    void updateGatewayResourceProfile(String gatewayId, GatewayResourceProfile 
updatedProfile) throws Exception;
-
-    /**
-     *
-     * @param gatewayId
-     * @return
-     */
-   GatewayResourceProfile getGatewayProfile(String gatewayId) throws Exception;
-
-    /**
-     * This method will remove a gateway profile
-     * @param gatewayId unique gateway id
-     * @return true or false
-     */
-    boolean removeGatewayResourceProfile(String gatewayId) throws Exception;
-
-    /**
-     * This method will check whether gateway profile exists
-     * @param gatewayId unique gateway id
-     * @return true or false
-     */
-    boolean isGatewayResourceProfileExists(String gatewayId) throws Exception;
-
-    /**
-     * This method will get gateway profile ids
-     * @param gatewayName
-     * @return
-     * @throws Exception
-     */
-    List<String> getGatewayProfileIds(String gatewayName) throws Exception;
-
-    /**
-     * This method will return all gateway profiles
-     * @return
-     * @throws Exception
-     */
-    List<GatewayResourceProfile> getAllGatewayProfiles() throws Exception;
-}

http://git-wip-us.apache.org/repos/asf/airavata/blob/f9e4b0df/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/impl/GatewayRegistry.java
----------------------------------------------------------------------
diff --git 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/impl/GatewayRegistry.java
 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/impl/GatewayRegistry.java
new file mode 100644
index 0000000..4e6b3c2
--- /dev/null
+++ 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/impl/GatewayRegistry.java
@@ -0,0 +1,137 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.service.profile.gateway.core.impl;
+
+import org.apache.airavata.model.workspace.Gateway;
+import 
org.apache.airavata.service.profile.gateway.core.resources.GatewayResource;
+import org.apache.airavata.service.profile.gateway.core.util.GatewayUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+
+public class GatewayRegistry {
+
+    private final static Logger logger = 
LoggerFactory.getLogger(GatewayRegistry.class);
+
+    public GatewayResource getExistingGateway (String gatewayName) throws 
Exception {
+        return GatewayUtils.getGateway(gatewayName);
+    }
+
+    public String addGateway (Gateway gateway) throws Exception {
+        try {
+            GatewayResource resource = 
GatewayUtils.createGateway(gateway.getGatewayId());
+            
resource.setGatewayApprovalStatus(gateway.getGatewayApprovalStatus().toString());
+            resource.setGatewayName(gateway.getGatewayName());
+            resource.setEmailAddress(gateway.getEmailAddress());
+            resource.setDomain(gateway.getDomain());
+            resource.setGatewayAcronym(gateway.getGatewayAcronym());
+            resource.setGatewayUrl(gateway.getGatewayURL());
+            
resource.setGatewayPublicAbstract(gateway.getGatewayPublicAbstract());
+            
resource.setReviewProposalDescription(gateway.getReviewProposalDescription());
+            
resource.setGatewayAdminFirstName(gateway.getGatewayAdminFirstName());
+            
resource.setGetGatewayAdminLastName(gateway.getGatewayAdminLastName());
+            resource.setGatewayAdminEmail(gateway.getGatewayAdminEmail());
+            
resource.setIdentityServerUserName(gateway.getIdentityServerUserName());
+            
resource.setIdentityServerPasswordToken(gateway.getIdentityServerPasswordToken());
+            resource.setDeclinedReason(gateway.getDeclinedReason());
+            resource.setOauthClientId(gateway.getOauthClientId());
+            resource.setOauthClientSecret(gateway.getOauthClientSecret());
+            resource.setRequestCreationTime(new 
Timestamp(System.currentTimeMillis()));
+            resource.setRequesterUsername(gateway.getRequesterUsername());
+            resource.save();
+            return gateway.getGatewayId();
+        } catch (Exception e){
+            logger.error("Error while saving gateway to registry, reason: " + 
e.getMessage(), e);
+            throw e;
+        }
+    }
+
+    public void updateGateway (String gatewayId, Gateway updatedGateway) 
throws Exception {
+        try {
+            GatewayResource existingGateway = 
GatewayUtils.getGateway(gatewayId);
+            
existingGateway.setGatewayApprovalStatus(updatedGateway.getGatewayApprovalStatus().toString());
+            existingGateway.setGatewayName(updatedGateway.getGatewayName());
+            existingGateway.setEmailAddress(updatedGateway.getEmailAddress());
+            existingGateway.setDomain(updatedGateway.getDomain());
+            
existingGateway.setGatewayAcronym(updatedGateway.getGatewayAcronym());
+            existingGateway.setGatewayUrl(updatedGateway.getGatewayURL());
+            
existingGateway.setGatewayPublicAbstract(updatedGateway.getGatewayPublicAbstract());
+            
existingGateway.setReviewProposalDescription(updatedGateway.getReviewProposalDescription());
+            
existingGateway.setGatewayAdminFirstName(updatedGateway.getGatewayAdminFirstName());
+            
existingGateway.setGetGatewayAdminLastName(updatedGateway.getGatewayAdminLastName());
+            
existingGateway.setGatewayAdminEmail(updatedGateway.getGatewayAdminEmail());
+            
existingGateway.setIdentityServerUserName(updatedGateway.getIdentityServerUserName());
+            
existingGateway.setIdentityServerPasswordToken(updatedGateway.getIdentityServerPasswordToken());
+            
existingGateway.setDeclinedReason(updatedGateway.getDeclinedReason());
+            
existingGateway.setOauthClientId(updatedGateway.getOauthClientId());
+            
existingGateway.setOauthClientSecret(updatedGateway.getOauthClientSecret());
+            
existingGateway.setRequesterUsername(updatedGateway.getRequesterUsername());
+            existingGateway.save();
+        } catch (Exception e){
+            logger.error("Error while updating gateway to registry, reason: " 
+ e.getMessage(), e);
+            throw e;
+        }
+    }
+
+    public Gateway getGateway (String gatewayId) throws Exception {
+        try {
+            GatewayResource resource = GatewayUtils.getGateway(gatewayId);
+            return GatewayUtils.toGateway(resource);
+        } catch (Exception e){
+            logger.error("Error while getting gateway, reason: " + 
e.getMessage(), e);
+            throw e;
+        }
+    }
+
+    public boolean isGatewayExist (String gatewayId) throws Exception {
+        try {
+            return GatewayUtils.isGatewayExist(gatewayId);
+        } catch (Exception e){
+            logger.error("Error while checking gateway exists, reason: " + 
e.getMessage(), e);
+            throw e;
+        }
+    }
+
+    public boolean removeGateway (String gatewayId) throws Exception {
+        try {
+            return GatewayUtils.removeGateway(gatewayId);
+        } catch (Exception e){
+            logger.error("Error while removing the gateway, reason: " + 
e.getMessage(), e);
+            throw new Exception(e);
+        }
+    }
+
+    public List<Gateway> getAllGateways () throws Exception {
+        List<Gateway> gatewayList = new ArrayList<Gateway>();
+        try {
+            List<GatewayResource> allGateways = GatewayUtils.getAllGateways();
+            return GatewayUtils.getAllGateways(allGateways);
+        } catch (Exception e){
+            logger.error("Error while getting all the gateways, reason: ", e);
+            throw e;
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/f9e4b0df/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/impl/GwyResourceProfileImpl.java
----------------------------------------------------------------------
diff --git 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/impl/GwyResourceProfileImpl.java
 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/impl/GwyResourceProfileImpl.java
deleted file mode 100644
index 9430779..0000000
--- 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/impl/GwyResourceProfileImpl.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.airavata.service.profile.gateway.core.impl;
-
-import 
org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
-import org.apache.airavata.service.profile.gateway.core.GwyResourceProfile;
-import 
org.apache.airavata.service.profile.gateway.core.resources.GatewayProfileResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class GwyResourceProfileImpl implements GwyResourceProfile {
-
-    private final static Logger logger = 
LoggerFactory.getLogger(GwyResourceProfileImpl.class);
-
-    @Override
-    public String addGatewayResourceProfile(GatewayResourceProfile 
gatewayProfile) throws Exception {
-        try {
-            GatewayProfileResource profileResource = new 
GatewayProfileResource();
-            if (!gatewayProfile.getGatewayID().equals("")){
-                profileResource.setGatewayID(gatewayProfile.getGatewayID());
-            }
-            if (gatewayProfile.getCredentialStoreToken()!= null){
-                
profileResource.setCredentialStoreToken(gatewayProfile.getCredentialStoreToken());
-            }
-            if (gatewayProfile.getIdentityServerTenant() != null){
-                
profileResource.setIdentityServerTenant(gatewayProfile.getIdentityServerTenant());
-            }
-            if (gatewayProfile.getIdentityServerPwdCredToken() != null){
-                
profileResource.setIdentityServerPwdCredToken(gatewayProfile.getIdentityServerPwdCredToken());
-            }
-            profileResource.setGatewayID(gatewayProfile.getGatewayID());
-            profileResource.save();
-            return profileResource.getGatewayID();
-        } catch (Exception e) {
-            logger.error("Error while saving gateway profile, exception: " + 
e, e);
-            throw e;
-        }
-    }
-
-    @Override
-    public void updateGatewayResourceProfile(String gatewayId, 
GatewayResourceProfile updatedProfile) throws Exception {
-        try {
-            GatewayProfileResource existingGP = new 
GatewayProfileResource().getByID(gatewayId);
-            
existingGP.setCredentialStoreToken(updatedProfile.getCredentialStoreToken());
-            
existingGP.setIdentityServerTenant(updatedProfile.getIdentityServerTenant());
-            
existingGP.setIdentityServerPwdCredToken(updatedProfile.getIdentityServerPwdCredToken());
-            existingGP.save();
-        } catch (Exception e) {
-            logger.error("Error while updating gateway profile, exception: " + 
e, e);
-            throw e;
-        }
-    }
-
-    @Override
-    public GatewayResourceProfile getGatewayProfile(String gatewayId) throws 
Exception {
-        try {
-            GatewayProfileResource gw = new 
GatewayProfileResource().getByID(gatewayId);
-            GatewayResourceProfile gatewayProfile = new 
GatewayResourceProfile();
-            gatewayProfile.setGatewayID(gw.getGatewayID());
-            
gatewayProfile.setCredentialStoreToken(gw.getCredentialStoreToken());
-            
gatewayProfile.setIdentityServerTenant(gw.getIdentityServerTenant());
-            
gatewayProfile.setIdentityServerPwdCredToken(gw.getIdentityServerPwdCredToken());
-            return gatewayProfile;
-        } catch (Exception e) {
-            logger.error("Error while retrieving gateway profile, exception: " 
+ e, e);
-            throw e;
-        }
-    }
-
-    @Override
-    public boolean removeGatewayResourceProfile(String gatewayId) throws 
Exception {
-       try {
-           GatewayProfileResource resource = new GatewayProfileResource();
-           resource.remove(gatewayId);
-           return true;
-       } catch (Exception e) {
-           logger.error("Error while deleting gateway profile, exception: " + 
e, e);
-           throw e;
-       }
-    }
-
-    @Override
-    public boolean isGatewayResourceProfileExists(String gatewayId) throws 
Exception {
-        try {
-            GatewayProfileResource resource = new GatewayProfileResource();
-            return resource.isExists(gatewayId);
-        } catch (Exception e) {
-            logger.error("Error while retrieving gateway profile, exception: " 
+ e, e);
-            throw e;
-        }
-    }
-
-    @Override
-    public List<String> getGatewayProfileIds(String gatewayName) throws 
Exception {
-        try {
-            GatewayProfileResource profileResource = new 
GatewayProfileResource();
-            List<String> gatewayIds = 
profileResource.getGatewayProfileIds(gatewayName);
-            return gatewayIds;
-        } catch (Exception e) {
-            logger.error("Error while retrieving gateway ids, exception: " + 
e, e);
-            throw e;
-        }
-    }
-
-    @Override
-    public List<GatewayResourceProfile> getAllGatewayProfiles() throws 
Exception {
-        try {
-            List<GatewayResourceProfile> gatewayResourceProfileList = new 
ArrayList<>();
-            List<GatewayProfileResource> resourceList = new 
GatewayProfileResource().getAll();
-            if (resourceList != null && !resourceList.isEmpty()){
-                for (GatewayProfileResource gw : resourceList) {
-                    GatewayResourceProfile gatewayProfile = new 
GatewayResourceProfile();
-                    gatewayProfile.setGatewayID(gw.getGatewayID());
-                    
gatewayProfile.setCredentialStoreToken(gw.getCredentialStoreToken());
-                    
gatewayProfile.setIdentityServerTenant(gw.getIdentityServerTenant());
-                    
gatewayProfile.setIdentityServerPwdCredToken(gw.getIdentityServerPwdCredToken());
-                    gatewayResourceProfileList.add(gatewayProfile);
-                }
-            }
-            return gatewayResourceProfileList;
-        } catch (Exception e) {
-            logger.error("Error while retrieving gateway ids, exception: " + 
e, e);
-            throw e;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/airavata/blob/f9e4b0df/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayProfileResource.java
----------------------------------------------------------------------
diff --git 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayProfileResource.java
 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayProfileResource.java
deleted file mode 100644
index ec78d1b..0000000
--- 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayProfileResource.java
+++ /dev/null
@@ -1,342 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.airavata.service.profile.gateway.core.resources;
-
-import org.apache.airavata.common.utils.AiravataUtils;
-import 
org.apache.airavata.service.profile.gateway.core.entities.GatewayProfile;
-import org.apache.airavata.service.profile.gateway.core.util.JPAUtils;
-import org.apache.airavata.service.profile.gateway.core.util.QueryConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-import java.sql.Timestamp;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.List;
-
-public class GatewayProfileResource {
-    private final static Logger logger = 
LoggerFactory.getLogger(GatewayProfileResource.class);
-
-    private String gatewayID;
-    private Timestamp createdTime;
-    private Timestamp updatedTime;
-    private String credentialStoreToken;
-    private String identityServerTenant;
-    private String identityServerPwdCredToken;
-
-    public Timestamp getCreatedTime() {
-        return createdTime;
-    }
-
-    public void setCreatedTime(Timestamp createdTime) {
-        this.createdTime = createdTime;
-    }
-
-    public Timestamp getUpdatedTime() {
-        return updatedTime;
-    }
-
-    public void setUpdatedTime(Timestamp updatedTime) {
-        this.updatedTime = updatedTime;
-    }
-
-    public String getCredentialStoreToken() {
-        return credentialStoreToken;
-    }
-
-    public void setCredentialStoreToken(String credentialStoreToken) {
-        this.credentialStoreToken = credentialStoreToken;
-    }
-
-    public String getIdentityServerTenant() {
-        return identityServerTenant;
-    }
-
-    public void setIdentityServerTenant(String identityServerTenant) {
-        this.identityServerTenant = identityServerTenant;
-    }
-
-    public String getIdentityServerPwdCredToken() {
-        return identityServerPwdCredToken;
-    }
-
-    public void setIdentityServerPwdCredToken(String 
identityServerPwdCredToken) {
-        this.identityServerPwdCredToken = identityServerPwdCredToken;
-    }
-
-    public void remove(String gatewayID) throws Exception {
-        EntityManager em = null;
-        try {
-            em = JPAUtils.getEntityManager();
-            em.getTransaction().begin();
-            GatewayProfile gp = em.find(GatewayProfile.class, gatewayID);
-            em.remove(gp);
-            em.getTransaction().commit();
-            if (em.isOpen()) {
-                if (em.getTransaction().isActive()){
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-        } catch (Exception e) {
-            logger.error(e.getMessage(), e);
-            throw e;
-        } finally {
-            if (em != null && em.isOpen()) {
-                if (em.getTransaction().isActive()) {
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-        }
-    }
-
-    public GatewayProfileResource getByID(String gatewayID) throws Exception {
-        EntityManager em = null;
-        try {
-            em = JPAUtils.getEntityManager();
-            em.getTransaction().begin();
-            GatewayProfile gatewayProfile = em.find(GatewayProfile.class, 
gatewayID);
-            GatewayProfileResource gatewayProfileResource = 
JPAUtils.createGatewayProfile(gatewayProfile);
-            em.getTransaction().commit();
-            if (em.isOpen()) {
-                if (em.getTransaction().isActive()){
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-            return gatewayProfileResource;
-        } catch (Exception e) {
-            logger.error(e.getMessage(), e);
-            throw e;
-        } finally {
-            if (em != null && em.isOpen()) {
-                if (em.getTransaction().isActive()) {
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    public List<GatewayProfileResource> getListByID(String gatewayID) throws 
Exception {
-        List<GatewayProfileResource> gatewayProfileResources = new 
ArrayList<GatewayProfileResource>();
-        EntityManager em = null;
-        try {
-            em = JPAUtils.getEntityManager();
-            em.getTransaction().begin();
-            Query q = 
em.createQuery(MessageFormat.format(QueryConstants.FIND_GATEWAY_PROFILE_BY_ID, 
gatewayID));
-            List<GatewayProfile> results = q.getResultList();
-            if (results.size() != 0) {
-                for (GatewayProfile gatewayProfile : results) {
-                    GatewayProfileResource gatewayProfileResource = 
JPAUtils.createGatewayProfile(gatewayProfile);
-                    gatewayProfileResources.add(gatewayProfileResource);
-                }
-            }
-            em.getTransaction().commit();
-            if (em.isOpen()) {
-                if (em.getTransaction().isActive()){
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-        } catch (Exception e) {
-            logger.error(e.getMessage(), e);
-            throw e;
-        } finally {
-            if (em != null && em.isOpen()) {
-                if (em.getTransaction().isActive()) {
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-        }
-        return gatewayProfileResources;
-    }
-
-    @SuppressWarnings("unchecked")
-    public List<GatewayProfileResource> getAll() throws Exception {
-        List<GatewayProfileResource> resourceList = new 
ArrayList<GatewayProfileResource>();
-        EntityManager em = null;
-        try {
-            em = JPAUtils.getEntityManager();
-            em.getTransaction().begin();
-            Query q = em.createQuery(QueryConstants.GET_ALL_GATEWAY_PROFILES);
-            List<GatewayProfile> results = q.getResultList();
-            if (results.size() != 0) {
-                for (GatewayProfile gatewayProfile : results) {
-                    GatewayProfileResource gatewayProfileResource = 
JPAUtils.createGatewayProfile(gatewayProfile);
-                    resourceList.add(gatewayProfileResource);
-                }
-            }
-            em.getTransaction().commit();
-            if (em.isOpen()) {
-                if (em.getTransaction().isActive()){
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-        } catch (Exception e) {
-            logger.error(e.getMessage(), e);
-            throw e;
-        } finally {
-            if (em != null && em.isOpen()) {
-                if (em.getTransaction().isActive()) {
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-        }
-        return resourceList;
-    }
-
-    @SuppressWarnings("unchecked")
-    public List<String> getGatewayProfileIds(String gatewayID) throws 
Exception {
-        List<String> gatewayProfileResourceIDs = new ArrayList<String>();
-        EntityManager em = null;
-        try {
-            em = JPAUtils.getEntityManager();
-            em.getTransaction().begin();
-            Query q = 
em.createQuery(MessageFormat.format(QueryConstants.FIND_GATEWAY_PROFILE_BY_ID, 
gatewayID));
-            List<GatewayProfile> results = q.getResultList();
-            if (results.size() != 0) {
-                for (Object result : results) {
-                    GatewayProfile gatewayProfile = (GatewayProfile) result;
-                    
gatewayProfileResourceIDs.add(gatewayProfile.getGatewayID());
-                }
-            }
-            em.getTransaction().commit();
-            if (em.isOpen()) {
-                if (em.getTransaction().isActive()){
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-        } catch (Exception e) {
-            logger.error(e.getMessage(), e);
-            throw e;
-        } finally {
-            if (em != null && em.isOpen()) {
-                if (em.getTransaction().isActive()) {
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-        }
-        return gatewayProfileResourceIDs;
-    }
-
-    public void save() throws Exception {
-        EntityManager em = null;
-        try {
-            em = JPAUtils.getEntityManager();
-            GatewayProfile existingGatewayProfile = 
em.find(GatewayProfile.class, gatewayID);
-            if (em.isOpen()) {
-                if (em.getTransaction().isActive()){
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-
-            em = JPAUtils.getEntityManager();
-            em.getTransaction().begin();
-            if (existingGatewayProfile != null) {
-                
existingGatewayProfile.setUpdateTime(AiravataUtils.getCurrentTimestamp());
-                if (credentialStoreToken != null){
-                    
existingGatewayProfile.setCredentialStoreToken(credentialStoreToken);
-                }
-                if (identityServerTenant != null){
-                    
existingGatewayProfile.setIdentityServerTenant(identityServerTenant);
-                }
-                if (identityServerPwdCredToken != null){
-                    
existingGatewayProfile.setIdentityServerPwdCredToken(identityServerPwdCredToken);
-                }
-                em.merge(existingGatewayProfile);
-            } else {
-                GatewayProfile gatewayProfile = new GatewayProfile();
-                gatewayProfile.setGatewayID(gatewayID);
-                
gatewayProfile.setCreationTime(AiravataUtils.getCurrentTimestamp());
-                if (credentialStoreToken != null){
-                    
gatewayProfile.setCredentialStoreToken(credentialStoreToken);
-                }
-                if (identityServerTenant != null){
-                    
gatewayProfile.setIdentityServerTenant(identityServerTenant);
-                }
-                if (identityServerPwdCredToken != null){
-                    
gatewayProfile.setIdentityServerPwdCredToken(identityServerPwdCredToken);
-                }
-                em.persist(gatewayProfile);
-            }
-            em.getTransaction().commit();
-            if (em.isOpen()) {
-                if (em.getTransaction().isActive()){
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-        } catch (Exception e) {
-            logger.error(e.getMessage(), e);
-            throw e;
-        } finally {
-            if (em != null && em.isOpen()) {
-                if (em.getTransaction().isActive()) {
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-        }
-    }
-
-    public boolean isExists(Object identifier) throws Exception {
-        EntityManager em = null;
-        try {
-            em = JPAUtils.getEntityManager();
-            GatewayProfile gatewayProfile = em.find(GatewayProfile.class, 
identifier);
-            if (em.isOpen()) {
-                if (em.getTransaction().isActive()){
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-            return gatewayProfile != null;
-        } catch (Exception e) {
-            logger.error(e.getMessage(), e);
-            throw e;
-        } finally {
-            if (em != null && em.isOpen()) {
-                if (em.getTransaction().isActive()) {
-                    em.getTransaction().rollback();
-                }
-                em.close();
-            }
-        }
-    }
-
-    public String getGatewayID() {
-        return gatewayID;
-    }
-
-    public void setGatewayID(String gatewayID) {
-        this.gatewayID = gatewayID;
-    }
-}

http://git-wip-us.apache.org/repos/asf/airavata/blob/f9e4b0df/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayResource.java
----------------------------------------------------------------------
diff --git 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayResource.java
 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayResource.java
index 48ad796..f6e4efd 100644
--- 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayResource.java
+++ 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayResource.java
@@ -20,9 +20,13 @@
  */
 package org.apache.airavata.service.profile.gateway.core.resources;
 
+import org.apache.airavata.service.profile.gateway.core.entities.Gateway;
+import org.apache.airavata.service.profile.gateway.core.util.GatewayUtils;
+import org.apache.airavata.service.profile.gateway.core.util.JPAUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.persistence.EntityManager;
 import java.sql.Timestamp;
 
 /**
@@ -203,4 +207,73 @@ public class GatewayResource {
     public void setRequesterUsername(String requesterUsername) {
         this.requesterUsername = requesterUsername;
     }
+
+    public void save() throws Exception {
+        EntityManager em = null;
+        try {
+            em = JPAUtils.getEntityManager();
+            Gateway existingGateway = em.find(Gateway.class, gatewayId);
+            em.close();
+
+            em = JPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            Gateway gateway = new Gateway();
+            gateway.setGatewayName(gatewayName);
+            gateway.setGatewayId(gatewayId);
+            gateway.setGatewayApprovalStatus(gatewayApprovalStatus);
+            gateway.setDomain(domain);
+            gateway.setEmailAddress(emailAddress);
+            gateway.setGatewayAcronym(gatewayAcronym);
+            gateway.setGatewayUrl(gatewayUrl);
+            gateway.setGatewayPublicAbstract(gatewayPublicAbstract);
+            gateway.setReviewProposalDescription(reviewProposalDescription);
+            gateway.setGatewayAdminFirstName(gatewayAdminFirstName);
+            gateway.setGetGatewayAdminLastName(getGatewayAdminLastName);
+            gateway.setGatewayAdminEmail(gatewayAdminEmail);
+            gateway.setIdentityServerUserName(identityServerUserName);
+            
gateway.setIdentityServerPasswordToken(identityServerPasswordToken);
+            gateway.setDeclinedReason(declinedReason);
+            gateway.setOauthClientId(oauthClientId);
+            gateway.setGetOauthClientSecret(oauthClientSecret);
+            gateway.setRequestCreationTime(requestCreationTime);
+            gateway.setRequesterUsername(requesterUsername);
+            if (existingGateway != null) {
+                existingGateway.setDomain(domain);
+                
existingGateway.setGatewayApprovalStatus(gatewayApprovalStatus);
+                existingGateway.setGatewayName(gatewayName);
+                gateway.setGatewayApprovalStatus(gatewayApprovalStatus);
+                existingGateway.setEmailAddress(emailAddress);
+                existingGateway.setGatewayAcronym(gatewayAcronym);
+                existingGateway.setGatewayUrl(gatewayUrl);
+                
existingGateway.setGatewayPublicAbstract(gatewayPublicAbstract);
+                
existingGateway.setReviewProposalDescription(reviewProposalDescription);
+                
existingGateway.setGatewayAdminFirstName(gatewayAdminFirstName);
+                
existingGateway.setGetGatewayAdminLastName(getGatewayAdminLastName);
+                existingGateway.setGatewayAdminEmail(gatewayAdminEmail);
+                
existingGateway.setIdentityServerUserName(identityServerUserName);
+                
existingGateway.setIdentityServerPasswordToken(identityServerPasswordToken);
+                existingGateway.setDeclinedReason(declinedReason);
+                existingGateway.setOauthClientId(oauthClientId);
+                existingGateway.setGetOauthClientSecret(oauthClientSecret);
+                existingGateway.setRequestCreationTime(requestCreationTime);
+                existingGateway.setRequesterUsername(requesterUsername);
+                em.merge(existingGateway);
+            } else {
+                em.persist(gateway);
+            }
+            em.getTransaction().commit();
+            em.close();
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            throw e;
+        } finally {
+            if (em != null && em.isOpen()) {
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/f9e4b0df/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/GatewayUtils.java
----------------------------------------------------------------------
diff --git 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/GatewayUtils.java
 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/GatewayUtils.java
index 27c2abc..03d275e 100644
--- 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/GatewayUtils.java
+++ 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/GatewayUtils.java
@@ -20,13 +20,16 @@
  */
 package org.apache.airavata.service.profile.gateway.core.util;
 
+import org.apache.airavata.model.workspace.GatewayApprovalStatus;
 import org.apache.airavata.service.profile.gateway.core.entities.Gateway;
 import 
org.apache.airavata.service.profile.gateway.core.resources.GatewayResource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import sun.reflect.annotation.ExceptionProxy;
 
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
+import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -42,32 +45,105 @@ public class GatewayUtils {
      * @param gateway
      * @return
      */
-    public static GatewayResource createGateway(Gateway gateway) {
+    public static GatewayResource toGatewayResource(Gateway gateway) throws 
Exception {
         GatewayResource gatewayResource = new GatewayResource();
-        gatewayResource.setGatewayName(gateway.getGatewayName());
-        gatewayResource.setGatewayId(gateway.getGatewayId());
-        gatewayResource.setDomain(gateway.getDomain());
-        gatewayResource.setEmailAddress(gateway.getEmailAddress());
-        
gatewayResource.setGatewayApprovalStatus(gateway.getGatewayApprovalStatus());
-        gatewayResource.setGatewayAcronym(gateway.getGatewayAcronym());
-        gatewayResource.setGatewayUrl(gateway.getGatewayUrl());
-        
gatewayResource.setGatewayPublicAbstract(gateway.getGatewayPublicAbstract());
-        
gatewayResource.setReviewProposalDescription(gateway.getReviewProposalDescription());
-        
gatewayResource.setGatewayAdminFirstName(gateway.getGatewayAdminFirstName());
-        
gatewayResource.setGetGatewayAdminLastName(gateway.getGetGatewayAdminLastName());
-        gatewayResource.setGatewayAdminEmail(gateway.getGatewayAdminEmail());
-        
gatewayResource.setIdentityServerUserName(gateway.getIdentityServerUserName());
-        
gatewayResource.setIdentityServerPasswordToken(gateway.getIdentityServerPasswordToken());
-        gatewayResource.setDeclinedReason(gateway.getDeclinedReason());
-        gatewayResource.setOauthClientId(gateway.getOauthClientId());
-        
gatewayResource.setRequestCreationTime(gateway.getRequestCreationTime());
-        gatewayResource.setRequesterUsername(gateway.getRequesterUsername());
-        
gatewayResource.setOauthClientSecret(gateway.getGetOauthClientSecret());
+        return toGatewayResource(gatewayResource, gateway);
+    }
 
+    /**
+     * This method converts Gateway object to GatewayResource
+     * @param gatewayResource
+     * @param gateway
+     * @return
+     */
+    public static GatewayResource toGatewayResource(GatewayResource 
gatewayResource, Gateway gateway) throws Exception {
+        if (gatewayResource != null) {
+            gatewayResource.setGatewayName(gateway.getGatewayName());
+            gatewayResource.setGatewayId(gateway.getGatewayId());
+            gatewayResource.setDomain(gateway.getDomain());
+            gatewayResource.setEmailAddress(gateway.getEmailAddress());
+            
gatewayResource.setGatewayApprovalStatus(gateway.getGatewayApprovalStatus());
+            gatewayResource.setGatewayAcronym(gateway.getGatewayAcronym());
+            gatewayResource.setGatewayUrl(gateway.getGatewayUrl());
+            
gatewayResource.setGatewayPublicAbstract(gateway.getGatewayPublicAbstract());
+            
gatewayResource.setReviewProposalDescription(gateway.getReviewProposalDescription());
+            
gatewayResource.setGatewayAdminFirstName(gateway.getGatewayAdminFirstName());
+            
gatewayResource.setGetGatewayAdminLastName(gateway.getGetGatewayAdminLastName());
+            
gatewayResource.setGatewayAdminEmail(gateway.getGatewayAdminEmail());
+            
gatewayResource.setIdentityServerUserName(gateway.getIdentityServerUserName());
+            
gatewayResource.setIdentityServerPasswordToken(gateway.getIdentityServerPasswordToken());
+            gatewayResource.setDeclinedReason(gateway.getDeclinedReason());
+            gatewayResource.setOauthClientId(gateway.getOauthClientId());
+            
gatewayResource.setRequestCreationTime(gateway.getRequestCreationTime());
+            
gatewayResource.setRequesterUsername(gateway.getRequesterUsername());
+            
gatewayResource.setOauthClientSecret(gateway.getGetOauthClientSecret());
+        } else {
+            throw new Exception("Could not get GatewayResource object because 
Gateway object is null");
+        }
         return gatewayResource;
     }
 
     /**
+     * This method converts GatewayResource to Gateway
+     * @param resource
+     * @return
+     */
+    public static org.apache.airavata.model.workspace.Gateway toGateway 
(GatewayResource resource){
+        org.apache.airavata.model.workspace.Gateway gateway = new 
org.apache.airavata.model.workspace.Gateway();
+        gateway.setGatewayId(resource.getGatewayId());
+        
gateway.setGatewayApprovalStatus(GatewayApprovalStatus.valueOf(resource.getGatewayApprovalStatus()));
+        gateway.setGatewayName(resource.getGatewayName());
+        gateway.setDomain(resource.getDomain());
+        gateway.setEmailAddress(resource.getEmailAddress());
+        gateway.setGatewayAcronym(resource.getGatewayAcronym());
+        gateway.setGatewayURL(resource.getGatewayUrl());
+        gateway.setGatewayPublicAbstract(resource.getGatewayPublicAbstract());
+        
gateway.setReviewProposalDescription(resource.getReviewProposalDescription());
+        gateway.setDeclinedReason(resource.getDeclinedReason());
+        gateway.setGatewayAdminFirstName(resource.getGatewayAdminFirstName());
+        gateway.setGatewayAdminLastName(resource.getGetGatewayAdminLastName());
+        gateway.setGatewayAdminEmail(resource.getGatewayAdminEmail());
+        
gateway.setIdentityServerUserName(resource.getIdentityServerUserName());
+        
gateway.setIdentityServerPasswordToken(resource.getIdentityServerPasswordToken());
+        gateway.setOauthClientId(resource.getOauthClientId());
+        gateway.setOauthClientSecret(resource.getOauthClientSecret());
+        if (resource.getRequestCreationTime() != null) {
+            
gateway.setRequestCreationTime(resource.getRequestCreationTime().getTime());
+        }
+        gateway.setRequesterUsername(resource.getRequesterUsername());
+        return gateway;
+    }
+
+    /**
+     * This method gets all gateways
+     * @param gatewayList
+     * @return
+     */
+    public static List<org.apache.airavata.model.workspace.Gateway> 
getAllGateways (List<GatewayResource> gatewayList){
+        List<org.apache.airavata.model.workspace.Gateway> gateways = new 
ArrayList<org.apache.airavata.model.workspace.Gateway>();
+        for (GatewayResource resource : gatewayList){
+            gateways.add(toGateway(resource));
+        }
+        return gateways;
+    }
+
+    /**
+     * This method creates new or returns existing gateway
+     * @param gatewayId
+     * @return
+     * @throws Exception
+     */
+    public static GatewayResource createGateway(String gatewayId) throws 
Exception {
+        if (!isGatewayExist(gatewayId)) {
+            GatewayResource gatewayResource = new GatewayResource();
+            gatewayResource.setGatewayId(gatewayId);
+            return gatewayResource;
+        } else {
+            return getGateway(gatewayId);
+        }
+    }
+
+    /**
      *  This method checks if a gateway exists
      * @param gatewayId
      * @return
@@ -92,6 +168,42 @@ public class GatewayUtils {
         }
     }
 
+
+    /**
+     * This method finds a gateway by id
+     * @param gatewayId
+     * @return
+     * @throws Exception
+     */
+    public static GatewayResource getGateway(String gatewayId) throws 
Exception {
+        EntityManager em = null;
+        try {
+            if (isGatewayExist(gatewayId)) {
+                em = JPAUtils.getEntityManager();
+                Gateway gateway = em.find(Gateway.class, gatewayId);
+                GatewayResource gatewayResource = toGatewayResource(gateway);
+                em.close();
+                return gatewayResource;
+            }
+        } catch (Exception e){
+            logger.error("Error finding gateway, reason: " + e.getMessage(), 
e);
+            throw e;
+        } finally {
+            if (em != null && em.isOpen()){
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * This method returns all gateways
+     * @return
+     * @throws Exception
+     */
     public static List<GatewayResource> getAllGateways() throws Exception {
         List<GatewayResource> resourceList = new ArrayList<GatewayResource>();
         EntityManager em = null;
@@ -104,7 +216,7 @@ public class GatewayUtils {
             if (!results.isEmpty()) {
                 for (Object result : results) {
                     Gateway gateway = (Gateway) result;
-                    GatewayResource gatewayResource = createGateway(gateway);
+                    GatewayResource gatewayResource = 
toGatewayResource(gateway);
                     resourceList.add(gatewayResource);
                 }
             }
@@ -123,4 +235,32 @@ public class GatewayUtils {
         }
         return resourceList;
     }
+
+    /**
+     * This method deletes a gateway
+     * @param gatewayId
+     * @return
+     */
+    public static boolean removeGateway(String gatewayId) {
+        EntityManager em = null;
+        try {
+            em = JPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            Query query = 
em.createQuery(MessageFormat.format(QueryConstants.DELETE_GATEWAY_BY_ID, 
gatewayId));
+            query.executeUpdate();
+            em.getTransaction().commit();
+            em.close();
+            return true;
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            return false;
+        }finally {
+            if (em != null && em.isOpen()){
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/f9e4b0df/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAUtils.java
----------------------------------------------------------------------
diff --git 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAUtils.java
 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAUtils.java
index ba5dda4..aea36b3 100644
--- 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAUtils.java
+++ 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/JPAUtils.java
@@ -1,8 +1,6 @@
 
 package org.apache.airavata.service.profile.gateway.core.util;
 
-import 
org.apache.airavata.service.profile.gateway.core.entities.GatewayProfile;
-import 
org.apache.airavata.service.profile.gateway.core.resources.GatewayProfileResource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,19 +47,4 @@ public class JPAUtils {
         entityManager = factory.createEntityManager();
         return entityManager;
     }
-
-    public static GatewayProfileResource createGatewayProfile(GatewayProfile 
gatewayProfile) {
-        GatewayProfileResource resource = new GatewayProfileResource();
-        if (gatewayProfile != null) {
-            resource.setGatewayID(gatewayProfile.getGatewayID());
-            resource.setCreatedTime(gatewayProfile.getCreationTime());
-            
resource.setCredentialStoreToken(gatewayProfile.getCredentialStoreToken());
-            
resource.setIdentityServerTenant(gatewayProfile.getIdentityServerTenant());
-            
resource.setIdentityServerPwdCredToken(gatewayProfile.getIdentityServerPwdCredToken());
-            if (gatewayProfile.getUpdateTime() != null) {
-                resource.setUpdatedTime(gatewayProfile.getUpdateTime());
-            }
-        }
-        return resource;
-    }
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/f9e4b0df/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/QueryConstants.java
----------------------------------------------------------------------
diff --git 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/QueryConstants.java
 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/QueryConstants.java
index 83b3845..d41f66e 100644
--- 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/QueryConstants.java
+++ 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/QueryConstants.java
@@ -7,7 +7,9 @@ import org.apache.airavata.model.user.UserProfile;
  */
 public class QueryConstants {
 
-    public static final String FIND_GATEWAY_BY_ID = "SELECT g FROM Gateway g 
where g.gatewayId='{}'";
+    public static final String FIND_GATEWAY_BY_ID = "SELECT g FROM Gateway g 
where g.gatewayId='{0}'";
 
     public static final String GET_ALL_GATEWAYS = "SELECT g FROM Gateway g";
+
+    public static final String DELETE_GATEWAY_BY_ID = "DELETE FROM Gateway g 
where g.gatewayId='{0}'";
 }

http://git-wip-us.apache.org/repos/asf/airavata/blob/f9e4b0df/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GatewayProfileServiceHandler.java
----------------------------------------------------------------------
diff --git 
a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GatewayProfileServiceHandler.java
 
b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GatewayProfileServiceHandler.java
index 89aa978..d36af84 100644
--- 
a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GatewayProfileServiceHandler.java
+++ 
b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/GatewayProfileServiceHandler.java
@@ -20,10 +20,8 @@
 */
 package org.apache.airavata.service.profile.handlers;
 
-import 
org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
 import org.apache.airavata.model.workspace.Gateway;
-import org.apache.airavata.service.profile.gateway.core.GwyResourceProfile;
-import 
org.apache.airavata.service.profile.gateway.core.impl.GwyResourceProfileImpl;
+import org.apache.airavata.service.profile.gateway.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;
@@ -39,7 +37,7 @@ public class GatewayProfileServiceHandler implements 
GatewayProfileService.Iface
 
     private final static Logger logger = 
LoggerFactory.getLogger(GatewayProfileServiceHandler.class);
 
-    private final GwyResourceProfile gatewayProfile = new 
GwyResourceProfileImpl();
+    private final GatewayRegistry gatewayRegistry = new GatewayRegistry();
 
     @Override
     public String getAPIVersion() throws GatewayProfileServiceException {
@@ -56,9 +54,7 @@ public class GatewayProfileServiceHandler implements 
GatewayProfileService.Iface
     @Override
     public String addGateway(Gateway gateway) throws 
GatewayProfileServiceException {
         try {
-            GatewayResourceProfile gatewayResourceProfile = new 
GatewayResourceProfile();
-            gatewayResourceProfile.setGatewayID(gateway.getGatewayId());
-            String gatewayId = 
gatewayProfile.addGatewayResourceProfile(gatewayResourceProfile);
+            String gatewayId = gatewayRegistry.addGateway(gateway);
             logger.debug("Airavata added gateway-profile with ID: " + 
gatewayId);
             return gatewayId;
         } catch (Exception ex) {
@@ -71,19 +67,35 @@ public class GatewayProfileServiceHandler implements 
GatewayProfileService.Iface
 
     @Override
     public boolean updateGateway(String gatewayId, Gateway updatedGateway) 
throws GatewayProfileServiceException {
-        return false;
+        try {
+            logger.debug("Updating gateway-profile with ID: " + gatewayId);
+            gatewayRegistry.updateGateway(gatewayId, updatedGateway);
+            return true;
+        } catch (Exception ex) {
+            logger.error("Error updating gateway-profile, reason: " + 
ex.getMessage(), ex);
+            GatewayProfileServiceException exception = new 
GatewayProfileServiceException();
+            exception.setMessage("Error updating gateway-profile, reason: " + 
ex.getMessage());
+            return false;
+        }
     }
 
     @Override
     public Gateway getGateway(String gatewayId) throws 
GatewayProfileServiceException {
-        return null;
+        try {
+            return gatewayRegistry.getGateway(gatewayId);
+        } catch (Exception ex) {
+            logger.error("Error getting gateway-profile, reason: " + 
ex.getMessage(), ex);
+            GatewayProfileServiceException exception = new 
GatewayProfileServiceException();
+            exception.setMessage("Error getting gateway-profile, reason: " + 
ex.getMessage());
+            throw exception;
+        }
     }
 
     @Override
     public boolean deleteGateway(String gatewayId) throws 
GatewayProfileServiceException {
         try {
             logger.debug("Deleting Airavata gateway-profile with ID: " + 
gatewayId);
-            return gatewayProfile.removeGatewayResourceProfile(gatewayId);
+            return gatewayRegistry.removeGateway(gatewayId);
         } catch (Exception ex) {
             logger.error("Error deleting gateway-profile, reason: " + 
ex.getMessage(), ex);
             GatewayProfileServiceException exception = new 
GatewayProfileServiceException();
@@ -94,13 +106,20 @@ public class GatewayProfileServiceHandler implements 
GatewayProfileService.Iface
 
     @Override
     public List<Gateway> getAllGateways() throws 
GatewayProfileServiceException {
-        return null;
+        try {
+            return gatewayRegistry.getAllGateways();
+        } catch (Exception ex) {
+            logger.error("Error getting all gateway-profiles, reason: " + 
ex.getMessage(), ex);
+            GatewayProfileServiceException exception = new 
GatewayProfileServiceException();
+            exception.setMessage("Error getting all gateway-profiles, reason: 
" + ex.getMessage());
+            throw exception;
+        }
     }
 
     @Override
     public boolean isGatewayExist(String gatewayId) throws 
GatewayProfileServiceException {
         try {
-            return gatewayProfile.isGatewayResourceProfileExists(gatewayId);
+            return gatewayRegistry.isGatewayExist(gatewayId);
         } catch (Exception ex) {
             logger.error("Error checking if gateway-profile exists, reason: " 
+ ex.getMessage(), ex);
             GatewayProfileServiceException exception = new 
GatewayProfileServiceException();

Reply via email to