You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sc...@apache.org on 2017/03/07 22:17:44 UTC
[09/11] airavata git commit: Refactor profile-gateway-core to
profile-tenant-core
http://git-wip-us.apache.org/repos/asf/airavata/blob/1a619c98/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/entities/GatewayProfile.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/entities/GatewayProfile.java b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/entities/GatewayProfile.java
new file mode 100644
index 0000000..6204182
--- /dev/null
+++ b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/entities/GatewayProfile.java
@@ -0,0 +1,100 @@
+/*
+ *
+ * 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.tenant.core.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+@Entity
+@Table(name = "GATEWAY_PROFILE")
+public class GatewayProfile implements Serializable {
+ @Id
+ @Column(name = "GATEWAY_ID")
+ private String gatewayID;
+ @Column(name = "CREATION_TIME")
+ private Timestamp creationTime;
+
+ @Column(name = "UPDATE_TIME")
+ private Timestamp updateTime;
+
+ @Column(name = "CS_TOKEN")
+ private String credentialStoreToken;
+
+ @Column(name = "IDENTITY_SERVER_TENANT")
+ private String identityServerTenant;
+
+ @Column(name = "IDENTITY_SERVER_PWD_CRED_TOKEN")
+ private String identityServerPwdCredToken;
+
+ public Timestamp getCreationTime() {
+ return creationTime;
+ }
+
+ public void setCreationTime(Timestamp creationTime) {
+ this.creationTime = creationTime;
+ }
+
+ public Timestamp getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(Timestamp updateTime) {
+ this.updateTime = updateTime;
+ }
+
+
+ public String getGatewayID() {
+ return gatewayID;
+ }
+
+ public void setGatewayID(String gatewayID) {
+ this.gatewayID = gatewayID;
+ }
+
+ 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;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/1a619c98/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/impl/GatewayRegistry.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/impl/GatewayRegistry.java b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/impl/GatewayRegistry.java
new file mode 100644
index 0000000..3140e5c
--- /dev/null
+++ b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/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.tenant.core.impl;
+
+import org.apache.airavata.model.workspace.Gateway;
+import org.apache.airavata.service.profile.tenant.core.resources.GatewayResource;
+import org.apache.airavata.service.profile.tenant.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/1a619c98/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/resources/GatewayResource.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/resources/GatewayResource.java b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/resources/GatewayResource.java
new file mode 100644
index 0000000..8ddc2d5
--- /dev/null
+++ b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/resources/GatewayResource.java
@@ -0,0 +1,278 @@
+/*
+ *
+ * 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.tenant.core.resources;
+
+import org.apache.airavata.service.profile.tenant.core.entities.Gateway;
+import org.apache.airavata.service.profile.tenant.core.util.JPAUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+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;
+ }
+
+ 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/1a619c98/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/GatewayUtils.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/GatewayUtils.java b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/GatewayUtils.java
new file mode 100644
index 0000000..a097685
--- /dev/null
+++ b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/GatewayUtils.java
@@ -0,0 +1,265 @@
+/*
+ *
+ * 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.tenant.core.util;
+
+import org.apache.airavata.model.workspace.GatewayApprovalStatus;
+import org.apache.airavata.service.profile.tenant.core.entities.Gateway;
+import org.apache.airavata.service.profile.tenant.core.resources.GatewayResource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import java.text.MessageFormat;
+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 toGatewayResource(Gateway gateway) throws Exception {
+ GatewayResource gatewayResource = new GatewayResource();
+ 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
+ */
+ 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();
+ }
+ }
+ }
+
+
+ /**
+ * 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;
+ 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 = toGatewayResource(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;
+ }
+
+ /**
+ * 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/1a619c98/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/JPAConstants.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/JPAConstants.java b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/JPAConstants.java
new file mode 100644
index 0000000..763c9ec
--- /dev/null
+++ b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/JPAConstants.java
@@ -0,0 +1,33 @@
+/*
+ *
+ * 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.tenant.core.util;
+public class JPAConstants {
+ public static final String KEY_JDBC_URL = "gateway.profile.catalog.registry.jdbc.url";
+ public static final String KEY_JDBC_USER = "gateway.profile.catalog.registry.jdbc.user";
+ public static final String KEY_JDBC_PASSWORD = "gateway.profile.catalog.registry.jdbc.password";
+ public static final String KEY_JDBC_DRIVER = "gateway.profile.catalog.registry.jdbc.driver";
+ // TODO: is this needed?
+ public static final String KEY_DERBY_START_ENABLE = "gateway.profile.catalog.start.derby.server.mode";
+ public static final String VALIDATION_QUERY = "gateway.profile.catalog.validationQuery";
+ public static final String JPA_CACHE_SIZE = "gateway.profile.catalog.jpa.cache.size";
+ public static final String ENABLE_CACHING = "gateway.profile.catalog.cache.enable";
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/1a619c98/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/JPAUtils.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/JPAUtils.java b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/JPAUtils.java
new file mode 100644
index 0000000..08b3394
--- /dev/null
+++ b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/JPAUtils.java
@@ -0,0 +1,50 @@
+
+package org.apache.airavata.service.profile.tenant.core.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.persistence.*;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by goshenoy on 3/6/17.
+ */
+public class JPAUtils {
+
+ private final static Logger logger = LoggerFactory.getLogger(JPAUtils.class);
+
+ private static final String PERSISTENCE_UNIT_NAME = "gateway_profile_catalog";
+
+ @PersistenceUnit(unitName = PERSISTENCE_UNIT_NAME)
+ private static EntityManagerFactory factory;
+
+ @PersistenceContext(unitName = PERSISTENCE_UNIT_NAME)
+ private static EntityManager entityManager;
+
+ public static EntityManager getEntityManager() {
+ if (factory == null) {
+ String connectionProperties = "DriverClassName=" + Utils.getJDBCDriver() + "," + "Url=" +
+ Utils.getJDBCURL() + "?autoReconnect=true," +
+ "Username=" + Utils.getJDBCUser() + "," + "Password=" + Utils.getJDBCPassword() +
+ ",validationQuery=" + Utils.getValidationQuery();
+ logger.info(connectionProperties);
+ Map<String, String> properties = new HashMap<String, String>();
+ properties.put("openjpa.ConnectionDriverName", "org.apache.commons.dbcp.BasicDataSource");
+ properties.put("openjpa.ConnectionProperties", connectionProperties);
+ properties.put("openjpa.DynamicEnhancementAgent", "true");
+ properties.put("openjpa.RuntimeUnenhancedClasses", "warn");
+ properties.put("openjpa.RemoteCommitProvider", "sjvm");
+ properties.put("openjpa.Log", "DefaultLevel=INFO, Runtime=INFO, Tool=INFO, SQL=INFO");
+ properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
+ properties.put("openjpa.jdbc.QuerySQLCache", "false");
+ properties.put("openjpa.ConnectionFactoryProperties", "PrettyPrint=true, PrettyPrintLineLength=72," +
+ " PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=31536000, autoReconnect=true");
+ factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, properties);
+ }
+
+ entityManager = factory.createEntityManager();
+ return entityManager;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/1a619c98/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/QueryConstants.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/QueryConstants.java b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/QueryConstants.java
new file mode 100644
index 0000000..44f6ee8
--- /dev/null
+++ b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/QueryConstants.java
@@ -0,0 +1,15 @@
+package org.apache.airavata.service.profile.tenant.core.util;
+
+import org.apache.airavata.model.user.UserProfile;
+
+/**
+ * Created by goshenoy on 11/11/2016.
+ */
+public class QueryConstants {
+
+ 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/1a619c98/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/Utils.java
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/Utils.java b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/Utils.java
new file mode 100644
index 0000000..e3be890
--- /dev/null
+++ b/airavata-services/profile-service/profile-tenant-core/src/main/java/org/apache/airavata/service/profile/tenant/core/util/Utils.java
@@ -0,0 +1,155 @@
+/*
+ *
+ * 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.tenant.core.util;
+
+import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.ServerSettings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.URI;
+
+
+public class Utils {
+ private final static Logger logger = LoggerFactory.getLogger(Utils.class);
+
+ public static String getJDBCFullURL(){
+ String jdbcUrl = getJDBCURL();
+ String jdbcUser = getJDBCUser();
+ String jdbcPassword = getJDBCPassword();
+ jdbcUrl = jdbcUrl + "?" + "user=" + jdbcUser + "&" + "password=" + jdbcPassword;
+ return jdbcUrl;
+ }
+
+ public static String getJDBCURL(){
+ try {
+ return ServerSettings.getSetting(JPAConstants.KEY_JDBC_URL);
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ return null;
+ }
+ }
+
+ public static String getHost(){
+ try{
+ String jdbcURL = getJDBCURL();
+ String cleanURI = jdbcURL.substring(5);
+ URI uri = URI.create(cleanURI);
+ return uri.getHost();
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ return null;
+ }
+ }
+
+ public static int getPort(){
+ try{
+ String jdbcURL = getJDBCURL();
+ String cleanURI = jdbcURL.substring(5);
+ URI uri = URI.create(cleanURI);
+ return uri.getPort();
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ return -1;
+ }
+ }
+
+ public static int getJPACacheSize (){
+ try {
+ String cache = ServerSettings.getSetting(JPAConstants.JPA_CACHE_SIZE, "5000");
+ return Integer.parseInt(cache);
+ }catch (Exception e){
+ logger.error(e.getMessage(), e);
+ return -1;
+ }
+ }
+
+ public static String isCachingEnabled (){
+ try {
+ return ServerSettings.getSetting(JPAConstants.ENABLE_CACHING, "true");
+ }catch (Exception e){
+ logger.error(e.getMessage(), e);
+ return "true";
+ }
+ }
+
+ public static String getDBType(){
+ try{
+ String jdbcURL = getJDBCURL();
+ String cleanURI = jdbcURL.substring(5);
+ URI uri = URI.create(cleanURI);
+ return uri.getScheme();
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ return null;
+ }
+ }
+
+ public static boolean isDerbyStartEnabled(){
+ try {
+ String s = ServerSettings.getSetting(JPAConstants.KEY_DERBY_START_ENABLE);
+ if("true".equals(s)){
+ return true;
+ }
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ return false;
+ }
+ return false;
+ }
+
+ public static String getJDBCUser(){
+ try {
+ return ServerSettings.getSetting(JPAConstants.KEY_JDBC_USER);
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ return null;
+ }
+ }
+
+ public static String getValidationQuery(){
+ try {
+ return ServerSettings.getSetting(JPAConstants.VALIDATION_QUERY);
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ return null;
+ }
+ }
+
+ public static String getJDBCPassword(){
+ try {
+ return ServerSettings.getSetting(JPAConstants.KEY_JDBC_PASSWORD);
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ return null;
+ }
+
+ }
+
+ public static String getJDBCDriver(){
+ try {
+ return ServerSettings.getSetting(JPAConstants.KEY_JDBC_DRIVER);
+ } catch (ApplicationSettingsException e) {
+ logger.error(e.getMessage(), e);
+ return null;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/airavata/blob/1a619c98/airavata-services/profile-service/profile-tenant-core/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/airavata-services/profile-service/profile-tenant-core/src/main/resources/META-INF/persistence.xml b/airavata-services/profile-service/profile-tenant-core/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 0000000..2482da5
--- /dev/null
+++ b/airavata-services/profile-service/profile-tenant-core/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,32 @@
+<?xml version="1.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.
+ *
+* -->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
+ <persistence-unit name="gateway_profile_catalog">
+ <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+
+ <exclude-unlisted-classes>true</exclude-unlisted-classes>
+ <properties>
+ <property name="openjpa.jdbc.MappingDefaults"
+ value="ForeignKeyDeleteAction=cascade, JoinForeignKeyDeleteAction=cascade" />
+ </properties>
+ </persistence-unit>
+</persistence>