diff options
author | Björn Hagemeister | 2014-10-07 16:39:06 +0200 |
---|---|---|
committer | Björn Hagemeister | 2014-10-07 16:39:06 +0200 |
commit | cfa03468e10e28867904a58f86222862859e165c (patch) | |
tree | 32b281ff8f0de1cf720137411f660449488ac051 | |
parent | Added createTime and changeTime to DbImage. (diff) | |
download | satellite-daemon-cfa03468e10e28867904a58f86222862859e165c.tar.gz satellite-daemon-cfa03468e10e28867904a58f86222862859e165c.tar.xz satellite-daemon-cfa03468e10e28867904a58f86222862859e165c.zip |
Adapted FielUploadWorker and ThriftConnection for using publishUser(..).
But publishUser ist not implemented yet. Plus added class DbUser for reading from
user database.
3 files changed, 53 insertions, 2 deletions
diff --git a/src/main/java/org/openslx/satellitedaemon/db/DbUser.java b/src/main/java/org/openslx/satellitedaemon/db/DbUser.java new file mode 100644 index 0000000..133adf4 --- /dev/null +++ b/src/main/java/org/openslx/satellitedaemon/db/DbUser.java @@ -0,0 +1,29 @@ +package org.openslx.satellitedaemon.db; + +public class DbUser +{ + + public final String userId; + public final String firstName; + public final String lastName; + public final String email; + + public DbUser(String userId, String firstName, String lastName, String email) { + this.userId = userId; + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + } + + /** + * Returns DbUser with given userId. + * @param userId + * @return DbUser with userId. + */ + public static DbUser getUserById(String userId) { + return MySQL.findUniqueOrNull( DbUser.class, "SELECT user.userID, user.Vorname AS firstName, " + + "user.Nachname AS lastName, user.mail AS email" + + "FROM m_user user" + + "WHERE userID = ?", userId ); + } +} diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java index 8ace390..6947b5a 100644 --- a/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java +++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/FileUploadWorker.java @@ -2,15 +2,16 @@ package org.openslx.satellitedaemon.filetransfer; import java.io.IOException; import java.util.List; -import java.util.UUID; import org.apache.log4j.Logger; import org.openslx.filetransfer.Uploader; import org.openslx.imagemaster.thrift.iface.ImageData; import org.openslx.imagemaster.thrift.iface.UploadData; +import org.openslx.imagemaster.thrift.iface.UserInfo; import org.openslx.satellitedaemon.Globals; import org.openslx.satellitedaemon.db.DbImage; import org.openslx.satellitedaemon.db.DbImage.Status; +import org.openslx.satellitedaemon.db.DbUser; public class FileUploadWorker implements Runnable { @@ -35,7 +36,10 @@ public class FileUploadWorker implements Runnable String path = Globals.getImageFolder() + "/" + image.path; // ThriftConnection.getUploadInfos returns uploadInfo and handles ThriftAuthentication - UploadData upInfos = ThriftConnection.getUploadInfos( imDat, path ); + DbUser dbUser = DbUser.getUserById(imDat.ownerLogin); + UserInfo userInfo = new UserInfo(dbUser.userId, dbUser.firstName, dbUser.lastName, dbUser.email, null); + ThriftConnection.publishUser(userInfo); + UploadData upInfos = ThriftConnection.getUploadInfos( imDat, path); if ( upInfos == null ) { log.error( "The UploadInfos returned by ThriftConnection Class are null" ); continue; diff --git a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java index 18462be..5cae49b 100644 --- a/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java +++ b/src/main/java/org/openslx/satellitedaemon/filetransfer/ThriftConnection.java @@ -27,6 +27,7 @@ import org.openslx.imagemaster.thrift.iface.ServerSessionData; import org.openslx.imagemaster.thrift.iface.UploadData; import org.openslx.imagemaster.thrift.iface.UploadError; import org.openslx.imagemaster.thrift.iface.UploadException; +import org.openslx.imagemaster.thrift.iface.UserInfo; import org.openslx.satellitedaemon.Globals; import org.openslx.satellitedaemon.db.DbImage; import org.openslx.satellitedaemon.db.DbImage.Status; @@ -252,4 +253,21 @@ public class ThriftConnection client.set( newClient ); return newClient; } + + public static boolean publishUser(UserInfo userInfo) { + ImageServer.Client theClient = null; + theClient = getConnection(); + if ( theClient == null ) { + log.error( "Client was null!" ); + return false; + } + try { + return theClient.publishUser( sSD.sessionId, userInfo ); + } catch ( AuthorizationException e ) { + log.error( "AutorizationException", e ); + } catch ( TException e ) { + log.error( "TException", e ); + } + return false; + } } |