diff options
| author | Nils Schwabe | 2014-06-30 17:11:03 +0200 |
|---|---|---|
| committer | Nils Schwabe | 2014-06-30 17:11:03 +0200 |
| commit | 1a3dbab6ca7118f4ca9f61043f416f074ede13bc (patch) | |
| tree | fad14555be544c3ba2afdf31b8f315364a67e7a6 /src/main/java/org/openslx/imagemaster/db | |
| parent | [Webinterface] Add "images" tab (diff) | |
| download | masterserver-1a3dbab6ca7118f4ca9f61043f416f074ede13bc.tar.gz masterserver-1a3dbab6ca7118f4ca9f61043f416f074ede13bc.tar.xz masterserver-1a3dbab6ca7118f4ca9f61043f416f074ede13bc.zip | |
Add implementation for the new up- and download protocoll
Remove some old stuff that is not needed anymore
Fix some small bugs
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/db')
| -rw-r--r-- | src/main/java/org/openslx/imagemaster/db/DbImage.java | 73 | ||||
| -rw-r--r-- | src/main/java/org/openslx/imagemaster/db/LdapUser.java | 19 |
2 files changed, 67 insertions, 25 deletions
diff --git a/src/main/java/org/openslx/imagemaster/db/DbImage.java b/src/main/java/org/openslx/imagemaster/db/DbImage.java index 5d22e33..e3a8888 100644 --- a/src/main/java/org/openslx/imagemaster/db/DbImage.java +++ b/src/main/java/org/openslx/imagemaster/db/DbImage.java @@ -3,6 +3,7 @@ package org.openslx.imagemaster.db; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.LinkedList; import java.util.List; import org.openslx.imagemaster.thrift.iface.ImageData; @@ -23,8 +24,10 @@ public class DbImage public final String shortDescription; public final String longDescription; public final Timestamp timestamp; - public final String ftpUser; public final long fileSize; + public final String token; + public final List<Integer> missingBlocks; + public final String serverSessionId; public DbImage(String UUID) @@ -42,14 +45,16 @@ public class DbImage this.shortDescription = null; this.longDescription = null; this.timestamp = new Timestamp( 0 ); - this.ftpUser = null; this.fileSize = 0; + this.token = null; + this.missingBlocks = null; + this.serverSessionId = null; } public DbImage(String UUID, int imageVersion, String imageName, String imagePath, Timestamp imageCreateTime, Timestamp imageUpdateTime, String imageOwner, String contentOperatingSystem, boolean isValid, boolean isDeleted, String shortDescription, String longDescription, - Timestamp timestamp, String ftpUser, long fileSize) + Timestamp timestamp, long fileSize, String token, String missingBlocksList, String serverSessionId) { this.UUID = UUID; this.imageVersion = imageVersion; @@ -64,8 +69,16 @@ public class DbImage this.shortDescription = shortDescription; this.longDescription = longDescription; this.timestamp = timestamp; - this.ftpUser = ftpUser; this.fileSize = fileSize; + this.token = token; + + String[] parts = missingBlocksList.split( ";" ); + this.missingBlocks = new LinkedList<>(); + for (int i = 0; i < parts.length - 1; i++) { // do not copy the last empty string (1;2;3;) -> "1","2","3","" + this.missingBlocks.add( Integer.valueOf( parts[i] ) ); + } + + this.serverSessionId = serverSessionId; } /** @@ -74,9 +87,9 @@ public class DbImage * @param imageData * @return */ - public static boolean exists( ImageData imageData ) + public static boolean exists( String uuid ) { - if ( MySQL.findUniqueOrNull( DbImage.class, "SELECT images.UUID FROM images WHERE images.UUID = ?", imageData.uuid ) == null ) { + if ( MySQL.findUniqueOrNull( DbImage.class, "SELECT images.UUID FROM images WHERE images.UUID = ?", uuid ) == null ) { return false; } else { return true; @@ -87,23 +100,34 @@ public class DbImage * Insert a new image into database * @param imageData The metadata of the image * @param ts The timestamp of inserting + * @param token The token that is able to upload this image + * @param missingBlocks The blocks that are missing for this image + * @param serverSessionId The server that is uploading this image * @return Affected rows */ - public static int insert( ImageData imageData, long ts, String ftpUser, String ftpPassword ) + public static int insert( ImageData imageData, long ts, String token, List<Integer> missingBlocks, String serverSessionId) { Date createTime = new Date( imageData.imageCreateTime ); Date updateTime = new Date( imageData.imageUpdateTime ); Date timestamp = new Date( ts ); SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); - + + String missingBlocksList = ""; + if (missingBlocks != null) { + for (Integer block : missingBlocks) { + missingBlocksList = missingBlocksList + String.valueOf( block ) + ";"; + } + } + return MySQL .update( - "INSERT INTO images (UUID, image_version, image_name, image_path, image_createTime, image_updateTime, image_owner, content_operatingSystem, status_isValid, status_isDeleted, image_shortDescription, image_longDescription, timestamp, ftpUser, fileSize) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + "INSERT INTO images (UUID, image_version, image_name, image_path, image_createTime, image_updateTime, image_owner, content_operatingSystem, status_isValid, status_isDeleted, image_shortDescription, image_longDescription, timestamp, fileSize, token, missingBlocks, serverSessionId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", imageData.uuid, imageData.imageVersion, imageData.imageName, "!uploading!", sdf.format( createTime ), sdf.format( updateTime ), imageData.imageOwner, imageData.conentOperatingSystem, imageData.statusIsValid, imageData.statusIsDeleted, imageData.imageShortDescription, - imageData.imageLongDescription, sdf.format( timestamp ), ftpUser, imageData.fileSize ); + imageData.imageLongDescription, sdf.format( timestamp ), imageData.fileSize, + token, missingBlocksList, serverSessionId); } public String getUUID() @@ -111,9 +135,20 @@ public class DbImage return this.UUID; } - public static int update( ImageData imageData, String location ) + public static int update( String uuid, String location ) { - return MySQL.update( "UPDATE images SET images.image_path = ? WHERE images.UUID = ?", location, imageData.uuid ); + return MySQL.update( "UPDATE images SET images.image_path = ? WHERE images.UUID = ?", location, uuid ); + } + + public static int updateMissingBlocks( String UUID, List<Integer> missingBlocks) + { + String missingBlocksList = ""; + if (missingBlocks != null) { + for (Integer block : missingBlocks) { + missingBlocksList = missingBlocksList + String.valueOf( block ) + ";"; + } + } + return MySQL.update( "UPDATE images SET images.missingBlocks = ? WHERE images.UUID = ?", missingBlocksList, UUID ); } public static int delete( String UUID ) @@ -123,10 +158,20 @@ public class DbImage public static List<DbImage> getUploadingImages() { - return MySQL.findAll( DbImage.class, "SELECT images.UUID, images.image_version, images.image_name, images.image_path, images.image_createTime, images.image_updateTime, images.image_owner, images.content_operatingSystem, images.status_isValid, images.status_isDeleted, images.image_shortDescription, images.image_longDescription, images.timestamp, images.ftpUser, images.fileSize FROM images WHERE image_path = ?", "!uploading!" ); + return MySQL.findAll( DbImage.class, "SELECT images.UUID, images.image_version, images.image_name, images.image_path, images.image_createTime, images.image_updateTime, images.image_owner, images.content_operatingSystem, images.status_isValid, images.status_isDeleted, images.image_shortDescription, images.image_longDescription, images.timestamp, images.fileSize, images.token, images.missingBlocks, images.serverSessionId FROM images WHERE missingBlocks != ?", "" ); } public static DbImage getImageByUUID(String uuid) { - return MySQL.findUniqueOrNull( DbImage.class, "SELECT images.UUID, images.image_version, images.image_name, images.image_path, images.image_createTime, images.image_updateTime, images.image_owner, images.content_operatingSystem, images.status_isValid, images.status_isDeleted, images.image_shortDescription, images.image_longDescription, images.timestamp, images.ftpUser, images.fileSize FROM images WHERE uuid = ?", uuid ); + return MySQL.findUniqueOrNull( DbImage.class, "SELECT images.UUID, images.image_version, images.image_name, images.image_path, images.image_createTime, images.image_updateTime, images.image_owner, images.content_operatingSystem, images.status_isValid, images.status_isDeleted, images.image_shortDescription, images.image_longDescription, images.timestamp, images.fileSize, images.token, images.missingBlocks, images.serverSessionId FROM images WHERE uuid = ?", uuid ); + } + + /** + * Creates a package of image data of this DbImage object. + * @return The corresponding image data + */ + public ImageData getImageData() { + return new ImageData(this.UUID, this.imageVersion, this.imageName, this.imageCreateTime.getTime(), + this.imageUpdateTime.getTime(), this.imageOwner, this.contentOperatingSystem, this.isValid, + this.isDeleted, this.shortDescription, this.longDescription, this.fileSize); } } diff --git a/src/main/java/org/openslx/imagemaster/db/LdapUser.java b/src/main/java/org/openslx/imagemaster/db/LdapUser.java index 0299829..39bbb69 100644 --- a/src/main/java/org/openslx/imagemaster/db/LdapUser.java +++ b/src/main/java/org/openslx/imagemaster/db/LdapUser.java @@ -20,9 +20,6 @@ import org.apache.directory.ldap.client.api.LdapNetworkConnection; import org.apache.log4j.Logger; import org.apache.mina.filter.ssl.KeyStoreFactory; import org.openslx.imagemaster.Globals; -import org.openslx.imagemaster.Globals.PropBool; -import org.openslx.imagemaster.Globals.PropInt; -import org.openslx.imagemaster.Globals.PropString; import org.openslx.imagemaster.session.User; import org.openslx.imagemaster.thrift.iface.AuthenticationError; import org.openslx.imagemaster.thrift.iface.AuthenticationException; @@ -62,22 +59,22 @@ public class LdapUser extends User try { LdapConnectionConfig config = new LdapConnectionConfig(); - String ldapHost = Globals.getPropertyString( PropString.LDAPHOST ); + String ldapHost = Globals.getLdapHost(); log.debug( "Setting host... " + ldapHost ); config.setLdapHost( ldapHost ); - boolean useSsl = Globals.getPropertyBool( PropBool.LDAPSSL ); + boolean useSsl = Globals.getLdapSsl(); log.debug( "Setting use ssl... " + useSsl); config.setUseSsl( useSsl ); - int ldapPort = Globals.getPropertyInt( PropInt.LDAPPORT ); + int ldapPort = Globals.getLdapPort(); log.debug( "Setting port... " + ldapPort ); config.setLdapPort( ldapPort ); // load keystore ... KeyStoreFactory ksf = new KeyStoreFactory(); - ksf.setDataFile( new File(Globals.getPropertyString( PropString.LDAPKEYSTOREPATH )) ); - ksf.setPassword( Globals.getPropertyString( PropString.LDAPKEYSTOREPASSWORD ) ); + ksf.setDataFile( new File(Globals.getLdapKeystorePath()) ); + ksf.setPassword( Globals.getLdapKeystorePassword()); ksf.setType( "jks" ); // ... and set TrustManager @@ -89,15 +86,15 @@ public class LdapUser extends User connection = new LdapNetworkConnection( config ); log.debug( "Trying to bind..." ); - String bind = Globals.getPropertyString( PropString.LDAPBINDQUERY ).replace( "%", login ); + String bind = Globals.getLdapBindQuery().replace( "%", login ); connection.bind( bind, password ); //connection.bind(); log.debug( "Bind successful" ); // make search query - EntryCursor cursor = connection.search( Globals.getPropertyString( Globals.PropString.LDAPSEARCHBASEDN ), - Globals.getPropertyString( Globals.PropString.LDAPSEARCHFILTER ).replace( "%", login ), SearchScope.SUBTREE ); + EntryCursor cursor = connection.search( Globals.getLdapSearchBaseDn(), + Globals.getLdapSearchFilter().replace( "%", login ), SearchScope.SUBTREE ); // only use the first result cursor.next(); Entry entry = cursor.get(); |
