implementing DAO and db utils

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

Branch: refs/heads/develop
Commit: 6632b1a8f70b15d6278c27fb0124d5c267af1fb4
Parents: c4fb532
Author: Anuj Bhandar <bhandar.a...@gmail.com>
Authored: Mon Oct 10 18:30:04 2016 -0400
Committer: Anuj Bhandar <bhandar.a...@gmail.com>
Committed: Wed Oct 12 11:30:42 2016 -0400

----------------------------------------------------------------------
 .../credential/store/credential/Credential.java      | 11 +++++++++++
 .../store/store/impl/db/CredentialsDAO.java          | 15 +++++++++++----
 .../store/store/impl/db/SSHCredentialTest.java       |  2 +-
 3 files changed, 23 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/6632b1a8/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/credential/Credential.java
----------------------------------------------------------------------
diff --git 
a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/credential/Credential.java
 
b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/credential/Credential.java
index 0e9ee82..4715337 100644
--- 
a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/credential/Credential.java
+++ 
b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/credential/Credential.java
@@ -34,6 +34,17 @@ public abstract class Credential implements Serializable {
     private Date persistedTime;
     private String token;
 
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    private String description;
+
+
     public String getToken() {
         return token;
     }

http://git-wip-us.apache.org/repos/asf/airavata/blob/6632b1a8/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java
----------------------------------------------------------------------
diff --git 
a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java
 
b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java
index e73ea04..90e58af 100644
--- 
a/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java
+++ 
b/modules/credential-store/credential-store-service/src/main/java/org/apache/airavata/credential/store/store/impl/db/CredentialsDAO.java
@@ -86,7 +86,7 @@ public class CredentialsDAO extends ParentDAO {
     public void addCredentials(String gatewayId, Credential credential, 
Connection connection)
             throws CredentialStoreException {
 
-        String sql = "INSERT INTO CREDENTIALS VALUES (?, ?, ?, ?, ?)";
+        String sql = "INSERT INTO CREDENTIALS VALUES (?, ?, ?, ?, ?, ?)";
 
         PreparedStatement preparedStatement = null;
 
@@ -106,6 +106,8 @@ public class CredentialsDAO extends ParentDAO {
 
             preparedStatement.setTimestamp(5, timestamp);
 
+            preparedStatement.setString(6,credential.getDescription());
+
             preparedStatement.executeUpdate();
 
         } catch (SQLException e) {
@@ -161,7 +163,7 @@ public class CredentialsDAO extends ParentDAO {
     public void updateCredentials(String gatewayId, Credential credential, 
Connection connection)
             throws CredentialStoreException {
 
-        String sql = "UPDATE CREDENTIALS set CREDENTIAL = ?, PORTAL_USER_ID = 
?, TIME_PERSISTED = ? where GATEWAY_ID = ? and TOKEN_ID = ?";
+        String sql = "UPDATE CREDENTIALS set CREDENTIAL = ?, PORTAL_USER_ID = 
?, TIME_PERSISTED = ?, DESCRIPTION = ? where GATEWAY_ID = ? and TOKEN_ID = ?";
 
         PreparedStatement preparedStatement = null;
 
@@ -174,8 +176,10 @@ public class CredentialsDAO extends ParentDAO {
             preparedStatement.setString(2, credential.getPortalUserName());
 
             preparedStatement.setTimestamp(3, new Timestamp(new 
java.util.Date().getTime()));
-            preparedStatement.setString(4, gatewayId);
-            preparedStatement.setString(5, credential.getToken());
+            preparedStatement.setString(4, credential.getDescription());
+            preparedStatement.setString(5, gatewayId);
+            preparedStatement.setString(6, credential.getToken());
+
 
             preparedStatement.executeUpdate();
 
@@ -227,6 +231,7 @@ public class CredentialsDAO extends ParentDAO {
 
                 
certificateCredential.setPortalUserName(resultSet.getString("PORTAL_USER_ID"));
                 
certificateCredential.setCertificateRequestedTime(resultSet.getTimestamp("TIME_PERSISTED"));
+                
certificateCredential.setDescription(resultSet.getString("DESCRIPTION"));
 
                 return certificateCredential;
             }
@@ -314,6 +319,7 @@ public class CredentialsDAO extends ParentDAO {
 
                 
certificateCredential.setPortalUserName(resultSet.getString("PORTAL_USER_ID"));
                 
certificateCredential.setCertificateRequestedTime(resultSet.getTimestamp("TIME_PERSISTED"));
+                
certificateCredential.setDescription(resultSet.getString("DESCRIPTION"));
 
                 credentialList.add(certificateCredential);
             }
@@ -363,6 +369,7 @@ public class CredentialsDAO extends ParentDAO {
 
                 
certificateCredential.setPortalUserName(resultSet.getString("PORTAL_USER_ID"));
                 
certificateCredential.setCertificateRequestedTime(resultSet.getTimestamp("TIME_PERSISTED"));
+                
certificateCredential.setDescription(resultSet.getString("DESCRIPTION"));
 
                 credentialList.add(certificateCredential);
             }

http://git-wip-us.apache.org/repos/asf/airavata/blob/6632b1a8/modules/credential-store/credential-store-service/src/test/java/org/apache/airavata/credential/store/store/impl/db/SSHCredentialTest.java
----------------------------------------------------------------------
diff --git 
a/modules/credential-store/credential-store-service/src/test/java/org/apache/airavata/credential/store/store/impl/db/SSHCredentialTest.java
 
b/modules/credential-store/credential-store-service/src/test/java/org/apache/airavata/credential/store/store/impl/db/SSHCredentialTest.java
index 703ee7d..e160910 100644
--- 
a/modules/credential-store/credential-store-service/src/test/java/org/apache/airavata/credential/store/store/impl/db/SSHCredentialTest.java
+++ 
b/modules/credential-store/credential-store-service/src/test/java/org/apache/airavata/credential/store/store/impl/db/SSHCredentialTest.java
@@ -23,7 +23,6 @@ package org.apache.airavata.credential.store.store.impl.db;
 
 
 import org.apache.airavata.common.exception.ApplicationSettingsException;
-import org.apache.airavata.common.utils.AiravataUtils;
 import org.apache.airavata.common.utils.DBUtil;
 import org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential;
 import org.apache.airavata.credential.store.store.CredentialStoreException;
@@ -54,6 +53,7 @@ public class SSHCredentialTest {
             String token = TokenGenerator.generateToken(gatewayId, null);
             sshCredential.setToken(token);
             sshCredential.setPortalUserName("phasta");
+            sshCredential.setDescription("dummy creds for testing");
             FileInputStream privateKeyStream = new 
FileInputStream(privateKeyPath);
             File filePri = new File(privateKeyPath);
             byte[] bFilePri = new byte[(int) filePri.length()];

Reply via email to