Add GatewayUtils and Gateway entity

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

Branch: refs/heads/develop
Commit: bf2d92d986abe9237bf7e19916910391360357dd
Parents: 732abde
Author: Gourav Shenoy <[email protected]>
Authored: Tue Mar 7 15:27:41 2017 -0500
Committer: Gourav Shenoy <[email protected]>
Committed: Tue Mar 7 15:27:41 2017 -0500

----------------------------------------------------------------------
 .../profile/gateway/core/entities/Gateway.java  | 225 +++++++++++++++++++
 .../gateway/core/resources/GatewayResource.java | 206 +++++++++++++++++
 .../profile/gateway/core/util/GatewayUtils.java | 126 +++++++++++
 .../gateway/core/util/QueryConstants.java       |   9 +-
 4 files changed, 560 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/bf2d92d9/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/entities/Gateway.java
----------------------------------------------------------------------
diff --git 
a/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/entities/Gateway.java
 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/entities/Gateway.java
new file mode 100644
index 0000000..728c206
--- /dev/null
+++ 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/entities/Gateway.java
@@ -0,0 +1,225 @@
+/*
+ *
+ * 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.entities;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.*;
+import java.sql.Timestamp;
+import java.util.Collection;
+
+@Entity
+@Table(name = "GATEWAY")
+public class Gateway {
+    private final static Logger logger = 
LoggerFactory.getLogger(Gateway.class);
+    private String gatewayId;
+    private String gatewayName;
+    private String domain;
+    private String emailAddress;
+    private String gatewayApprovalStatus;
+    private String gatewayAcronym;
+    private String gatewayUrl;
+    private String gatewayPublicAbstract;
+    private String reviewProposalDescription;
+    private String gatewayAdminFirstName;
+    private String getGatewayAdminLastName;
+    private String gatewayAdminEmail;
+    private String identityServerUserName;
+    private String identityServerPasswordToken;
+    private String declinedReason;
+    private String oauthClientId;
+    private String getOauthClientSecret;
+    private Timestamp requestCreationTime;
+    private String requesterUsername;
+
+    @Id
+    @Column(name = "GATEWAY_ID")
+    public String getGatewayId() {
+        return gatewayId;
+    }
+
+    public void setGatewayId(String gatewayId) {
+        this.gatewayId = gatewayId;
+    }
+
+    @Column(name = "GATEWAY_NAME")
+    public String getGatewayName() {
+        return gatewayName;
+    }
+
+    public void setGatewayName(String gatewayName) {
+        this.gatewayName = gatewayName;
+    }
+
+    @Column(name = "GATEWAY_DOMAIN")
+    public String getDomain() {
+        return domain;
+    }
+
+    public void setDomain(String domain) {
+        this.domain = domain;
+    }
+
+    @Column(name = "EMAIL_ADDRESS")
+    public String getEmailAddress() {
+        return emailAddress;
+    }
+
+    public void setEmailAddress(String emailAddress) {
+        this.emailAddress = emailAddress;
+    }
+
+    @Column(name = "GATEWAY_APPROVAL_STATUS")
+    public String getGatewayApprovalStatus() {
+        return gatewayApprovalStatus;
+    }
+
+    public void setGatewayApprovalStatus(String gatewayApprovalStatus) {
+        this.gatewayApprovalStatus = gatewayApprovalStatus;
+    }
+
+    @Column(name = "GATEWAY_ACRONYM")
+    public String getGatewayAcronym() {
+        return gatewayAcronym;
+    }
+
+    public void setGatewayAcronym(String gatewayAcronym) {
+        this.gatewayAcronym = gatewayAcronym;
+    }
+
+    @Column(name = "GATEWAY_URL")
+    public String getGatewayUrl() {
+        return gatewayUrl;
+    }
+
+    public void setGatewayUrl(String gatewayUrl) {
+        this.gatewayUrl = gatewayUrl;
+    }
+
+    @Column(name = "GATEWAY_PUBLIC_ABSTRACT")
+    public String getGatewayPublicAbstract() {
+        return gatewayPublicAbstract;
+    }
+
+    public void setGatewayPublicAbstract(String gatewayPublicAbstract) {
+        this.gatewayPublicAbstract = gatewayPublicAbstract;
+    }
+
+    @Column(name = "GATEWAY_REVIEW_PROPOSAL_DESCRIPTION")
+    public String getReviewProposalDescription() {
+        return reviewProposalDescription;
+    }
+
+    public void setReviewProposalDescription(String reviewProposalDescription) 
{
+        this.reviewProposalDescription = reviewProposalDescription;
+    }
+
+    @Column(name = "GATEWAY_ADMIN_FIRST_NAME")
+    public String getGatewayAdminFirstName() {
+        return gatewayAdminFirstName;
+    }
+
+    public void setGatewayAdminFirstName(String gatewayAdminFirstName) {
+        this.gatewayAdminFirstName = gatewayAdminFirstName;
+    }
+
+    @Column(name = "GATEWAY_ADMIN_LAST_NAME")
+    public String getGetGatewayAdminLastName() {
+        return getGatewayAdminLastName;
+    }
+
+    public void setGetGatewayAdminLastName(String getGatewayAdminLastName) {
+        this.getGatewayAdminLastName = getGatewayAdminLastName;
+    }
+
+    @Column(name = "GATEWAY_ADMIN_EMAIL")
+    public String getGatewayAdminEmail() {
+        return gatewayAdminEmail;
+    }
+
+    public void setGatewayAdminEmail(String gatewayAdminEmail) {
+        this.gatewayAdminEmail = gatewayAdminEmail;
+    }
+
+    @Column(name = "IDENTITY_SERVER_USERNAME")
+    public String getIdentityServerUserName() {
+        return identityServerUserName;
+    }
+
+    public void setIdentityServerUserName(String identityServerUserName) {
+        this.identityServerUserName = identityServerUserName;
+    }
+
+    @Column(name = "IDENTITY_SERVER_PASSWORD_TOKEN")
+    public String getIdentityServerPasswordToken() {
+        return identityServerPasswordToken;
+    }
+
+    public void setIdentityServerPasswordToken(String 
identityServerPasswordToken) {
+        this.identityServerPasswordToken = identityServerPasswordToken;
+    }
+
+    @Column(name = "REQUESTER_USERNAME")
+    public String getRequesterUsername() {
+        return requesterUsername;
+    }
+
+    public void setRequesterUsername(String requesterUsername) {
+        this.requesterUsername = requesterUsername;
+    }
+
+    @Column(name = "DECLINED_REASON")
+    public String getDeclinedReason() {
+        return declinedReason;
+    }
+
+    public void setDeclinedReason(String declinedReason) {
+        this.declinedReason = declinedReason;
+    }
+
+    @Column(name = "OAUTH_CLIENT_ID")
+    public String getOauthClientId() {
+        return oauthClientId;
+    }
+
+    public void setOauthClientId(String oauthClientId) {
+        this.oauthClientId = oauthClientId;
+    }
+
+    @Column(name = "REQUEST_CREATION_TIME")
+    public Timestamp getRequestCreationTime() {
+        return requestCreationTime;
+    }
+
+    public void setRequestCreationTime(Timestamp requestCreationTime) {
+        this.requestCreationTime = requestCreationTime;
+    }
+
+    @Column(name = "OAUTH_CLIENT_SECRET")
+    public String getGetOauthClientSecret() {
+        return getOauthClientSecret;
+    }
+
+    public void setGetOauthClientSecret(String oauthClientSecret) {
+        this.getOauthClientSecret = oauthClientSecret;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf2d92d9/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
new file mode 100644
index 0000000..48ad796
--- /dev/null
+++ 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/resources/GatewayResource.java
@@ -0,0 +1,206 @@
+/*
+ *
+ * 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.sql.Timestamp;
+
+/**
+ * Created by goshenoy on 3/7/17.
+ */
+public class GatewayResource {
+
+    private final static Logger logger = 
LoggerFactory.getLogger(GatewayResource.class);
+
+    private String gatewayId;
+    private String gatewayName;
+    private String domain;
+    private String emailAddress;
+    private String gatewayApprovalStatus;
+    private String gatewayAcronym;
+    private String gatewayUrl;
+    private String gatewayPublicAbstract;
+    private String reviewProposalDescription;
+    private String gatewayAdminFirstName;
+    private String getGatewayAdminLastName;
+    private String gatewayAdminEmail;
+    private String identityServerUserName;
+    private String identityServerPasswordToken;
+    private String declinedReason;
+    private String oauthClientId;
+    private String oauthClientSecret;
+    private Timestamp requestCreationTime;
+    private String requesterUsername;
+
+    public String getGatewayId() {
+        return gatewayId;
+    }
+
+    public void setGatewayId(String gatewayId) {
+        this.gatewayId = gatewayId;
+    }
+
+    public String getGatewayName() {
+        return gatewayName;
+    }
+
+    public void setGatewayName(String gatewayName) {
+        this.gatewayName = gatewayName;
+    }
+
+    public String getDomain() {
+        return domain;
+    }
+
+    public void setDomain(String domain) {
+        this.domain = domain;
+    }
+
+    public String getEmailAddress() {
+        return emailAddress;
+    }
+
+    public void setEmailAddress(String emailAddress) {
+        this.emailAddress = emailAddress;
+    }
+
+    public String getGatewayApprovalStatus() {
+        return gatewayApprovalStatus;
+    }
+
+    public void setGatewayApprovalStatus(String gatewayApprovalStatus) {
+        this.gatewayApprovalStatus = gatewayApprovalStatus;
+    }
+
+    public String getGatewayAcronym() {
+        return gatewayAcronym;
+    }
+
+    public void setGatewayAcronym(String gatewayAcronym) {
+        this.gatewayAcronym = gatewayAcronym;
+    }
+
+    public String getGatewayUrl() {
+        return gatewayUrl;
+    }
+
+    public void setGatewayUrl(String gatewayUrl) {
+        this.gatewayUrl = gatewayUrl;
+    }
+
+    public String getGatewayPublicAbstract() {
+        return gatewayPublicAbstract;
+    }
+
+    public void setGatewayPublicAbstract(String gatewayPublicAbstract) {
+        this.gatewayPublicAbstract = gatewayPublicAbstract;
+    }
+
+    public String getReviewProposalDescription() {
+        return reviewProposalDescription;
+    }
+
+    public void setReviewProposalDescription(String reviewProposalDescription) 
{
+        this.reviewProposalDescription = reviewProposalDescription;
+    }
+
+    public String getGatewayAdminFirstName() {
+        return gatewayAdminFirstName;
+    }
+
+    public void setGatewayAdminFirstName(String gatewayAdminFirstName) {
+        this.gatewayAdminFirstName = gatewayAdminFirstName;
+    }
+
+    public String getGetGatewayAdminLastName() {
+        return getGatewayAdminLastName;
+    }
+
+    public void setGetGatewayAdminLastName(String getGatewayAdminLastName) {
+        this.getGatewayAdminLastName = getGatewayAdminLastName;
+    }
+
+    public String getGatewayAdminEmail() {
+        return gatewayAdminEmail;
+    }
+
+    public void setGatewayAdminEmail(String gatewayAdminEmail) {
+        this.gatewayAdminEmail = gatewayAdminEmail;
+    }
+
+    public String getIdentityServerUserName() {
+        return identityServerUserName;
+    }
+
+    public void setIdentityServerUserName(String identityServerUserName) {
+        this.identityServerUserName = identityServerUserName;
+    }
+
+    public String getIdentityServerPasswordToken() {
+        return identityServerPasswordToken;
+    }
+
+    public void setIdentityServerPasswordToken(String 
identityServerPasswordToken) {
+        this.identityServerPasswordToken = identityServerPasswordToken;
+    }
+
+    public String getDeclinedReason() {
+        return declinedReason;
+    }
+
+    public void setDeclinedReason(String declinedReason) {
+        this.declinedReason = declinedReason;
+    }
+
+    public String getOauthClientId() {
+        return oauthClientId;
+    }
+
+    public void setOauthClientId(String oauthClientId) {
+        this.oauthClientId = oauthClientId;
+    }
+
+    public String getOauthClientSecret() {
+        return oauthClientSecret;
+    }
+
+    public void setOauthClientSecret(String oauthClientSecret) {
+        this.oauthClientSecret = oauthClientSecret;
+    }
+
+    public Timestamp getRequestCreationTime() {
+        return requestCreationTime;
+    }
+
+    public void setRequestCreationTime(Timestamp requestCreationTime) {
+        this.requestCreationTime = requestCreationTime;
+    }
+
+    public String getRequesterUsername() {
+        return requesterUsername;
+    }
+
+    public void setRequesterUsername(String requesterUsername) {
+        this.requesterUsername = requesterUsername;
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf2d92d9/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
new file mode 100644
index 0000000..27c2abc
--- /dev/null
+++ 
b/airavata-services/profile-service/profile-gateway-core/src/main/java/org/apache/airavata/service/profile/gateway/core/util/GatewayUtils.java
@@ -0,0 +1,126 @@
+/*
+ *
+ * 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.util;
+
+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 javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by goshenoy on 3/7/17.
+ */
+public class GatewayUtils {
+
+    private final static Logger logger = 
LoggerFactory.getLogger(GatewayUtils.class);
+
+    /**
+     * This method converts Gateway object to GatewayResource
+     * @param gateway
+     * @return
+     */
+    public static GatewayResource createGateway(Gateway gateway) {
+        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 gatewayResource;
+    }
+
+    /**
+     *  This method checks if a gateway exists
+     * @param gatewayId
+     * @return
+     */
+    public static boolean isGatewayExist(String gatewayId) throws Exception {
+        EntityManager em = null;
+        try {
+            em = JPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            Gateway gateway = em.find(Gateway.class, gatewayId);
+            return gateway != null;
+        } catch (Exception e){
+            logger.error("Error checking if gateway exists, reason: " + 
e.getMessage(), e);
+            throw e;
+        } finally {
+            if (em != null && em.isOpen()){
+                if (em.getTransaction().isActive()){
+                    em.getTransaction().rollback();
+                }
+                em.close();
+            }
+        }
+    }
+
+    public static List<GatewayResource> getAllGateways() throws Exception {
+        List<GatewayResource> resourceList = new ArrayList<GatewayResource>();
+        EntityManager em = null;
+        try {
+            em = JPAUtils.getEntityManager();
+            em.getTransaction().begin();
+            Query query = em.createQuery(QueryConstants.GET_ALL_GATEWAYS);
+            List results = query.getResultList();
+
+            if (!results.isEmpty()) {
+                for (Object result : results) {
+                    Gateway gateway = (Gateway) result;
+                    GatewayResource gatewayResource = createGateway(gateway);
+                    resourceList.add(gatewayResource);
+                }
+            }
+            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();
+            }
+        }
+        return resourceList;
+    }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/bf2d92d9/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 f56ba6d..83b3845 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
@@ -5,12 +5,9 @@ import org.apache.airavata.model.user.UserProfile;
 /**
  * Created by goshenoy on 11/11/2016.
  */
-public interface QueryConstants {
+public class QueryConstants {
 
+    public static final String FIND_GATEWAY_BY_ID = "SELECT g FROM Gateway g 
where g.gatewayId='{}'";
 
-
-    String FIND_GATEWAY_PROFILE_BY_ID = "SELECT gp FROM GatewayProfile gp " +
-            "where gp.gatewayID='{}'";
-
-    String GET_ALL_GATEWAY_PROFILES = "SELECT gp FROM GatewayProfile gp";
+    public static final String GET_ALL_GATEWAYS = "SELECT g FROM Gateway g";
 }

Reply via email to