summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/imagemaster/db/mappers/DbImage.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/db/mappers/DbImage.java')
-rw-r--r--src/main/java/org/openslx/imagemaster/db/mappers/DbImage.java223
1 files changed, 4 insertions, 219 deletions
diff --git a/src/main/java/org/openslx/imagemaster/db/mappers/DbImage.java b/src/main/java/org/openslx/imagemaster/db/mappers/DbImage.java
index 027ddf6..2f5394c 100644
--- a/src/main/java/org/openslx/imagemaster/db/mappers/DbImage.java
+++ b/src/main/java/org/openslx/imagemaster/db/mappers/DbImage.java
@@ -1,11 +1,7 @@
package org.openslx.imagemaster.db.mappers;
-import java.util.List;
-
import org.openslx.bwlp.thrift.iface.ImagePublishData;
-import org.openslx.imagemaster.Globals;
-import org.openslx.imagemaster.serverconnection.UploadingImage;
-import org.openslx.imagemaster.util.Util;
+
/**
* Representing an image in the database.
@@ -14,221 +10,10 @@ import org.openslx.imagemaster.util.Util;
public class DbImage
{
- public final String uuid;
- public final int revision;
- public final String title;
- /**
- * Relative path of image file (relative to Globals.getImageDir())
- */
- public final String relativePath;
- public final long createTime;
- public final long updateTime;
- public final int ownerId;
- public final String ownerLogin;
- public final int operatingSystem;
- public final boolean isValid;
- public final boolean isDeleted;
- public final String longDescription;
- public final long fileSize;
- public final int[] blockStatus;
-
- public DbImage( String uuid )
- {
- this.uuid = uuid;
- this.revision = 0;
- this.title = null;
- this.relativePath = null;
- this.createTime = 0;
- this.updateTime = 0;
- this.ownerId = 0;
- this.ownerLogin = null;
- this.operatingSystem = 0;
- this.isValid = false;
- this.isDeleted = false;
- this.longDescription = null;
- this.fileSize = 0;
- this.blockStatus = null;
- }
-
- public DbImage( String uuid, int imageVersion, String imageName, String imagePath,
- long imageCreateTime, long imageUpdateTime, int imageOwnerId, String imageOwnerLogin, int contentOperatingSystem,
- boolean isValid, boolean isDeleted, String longDescription,
- long fileSize, String missingBlocksList )
- {
- this.uuid = uuid;
- this.revision = imageVersion;
- this.title = imageName;
- this.relativePath = imagePath;
- this.createTime = imageCreateTime;
- this.updateTime = imageUpdateTime;
- this.ownerId = imageOwnerId;
- this.ownerLogin = imageOwnerLogin;
- this.operatingSystem = contentOperatingSystem;
- this.isValid = isValid;
- this.isDeleted = isDeleted;
- this.longDescription = longDescription;
- this.fileSize = fileSize;
-
- String[] parts = missingBlocksList.split( ";" );
- blockStatus = new int[ Util.getNumberOfBlocks( fileSize, Globals.blockSize ) ]; // initialize array to ones
- for ( int i = 0; i < blockStatus.length; ++i ) {
- blockStatus[i] = UploadingImage.VALID;
- }
- for ( String block : parts ) { // Now mark missing blocks (if any)
- int i = Util.tryToParseInt( block, -1 );
- if ( i >= 0 && i < blockStatus.length )
- blockStatus[i] = UploadingImage.MISSING;
- }
- }
-
- /**
- * Check if image with imageData already exists. (Only checks the UUID.)
- *
- * @param imageData
- * @return
- */
- public static boolean exists( String uuid )
- {
- return getImageByUuid( uuid ) != null;
- }
-
- /**
- * Insert a new image into database
- *
- * @param imageData
- * The metadata of the image
- * @param filepath
- * Local storage path of image
- * @return Affected rows
- */
- public static int insert( ImagePublishData imageData, String filepath )
- {
- int numBlocks = Util.getNumberOfBlocks( imageData.fileSize, Globals.blockSize );
- String missingBlocksList = "";
- for ( int i = 0; i < numBlocks; i++ ) {
- missingBlocksList = missingBlocksList + String.valueOf( i ) + ";";
- }
- DbUser user = DbUser.forLogin( imageData.ownerLogin );
- int owner = 0;
- if ( user != null )
- owner = user.userId;
-
- return MySQL
- .update(
- "INSERT IGNORE INTO image (uuid, revision, title, path, createtime, updatetime, ownerid, operatingsystem, isvalid, isdeleted, description, filesize, missingblocks) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
- imageData.uuid, imageData.revision, imageData.title, filepath,
- imageData.createTime, imageData.updateTime, owner,
- imageData.operatingSystem, imageData.isValid,
- imageData.isDeleted, imageData.description, imageData.fileSize,
- missingBlocksList );
- }
-
- /**
- * Updates the missing blocks of an uploading image.
- *
- * @param missingBlocks
- * @return
- */
- public int updateMissingBlocks( List<Integer> missingBlocks )
- {
- String missingBlocksList = "";
- if ( missingBlocks != null ) {
- for ( Integer block : missingBlocks ) {
- missingBlocksList = missingBlocksList + String.valueOf( block ) + ";";
- }
- }
- return MySQL.update( "UPDATE image SET image.missingblocks = ? WHERE image.uuid = ?", missingBlocksList, uuid );
- }
-
- /**
- * Marks an image as _deleted_ in the database.
- *
- * @return
- */
- public int delete()
- {
- return MySQL.update( "UPDATE image SET image.isdeleted = 1 WHERE image.uuid = ?", this.uuid );
- }
-
- /**
- * Returns all images from database where blocks are still missing.
- *
- * @return
- */
- public static List<DbImage> getUploadingImages()
- {
- return MySQL
- .findAll(
- DbImage.class,
- "SELECT image.uuid, image.revision, image.title, image.path, image.createtime, image.updatetime, image.ownerid, user.login, image.operatingsystem, image.isvalid, image.isdeleted, image.description, image.filesize, image.missingblocks"
- + " FROM image"
- + " INNER JOIN user ON (image.ownerid = user.userid)"
- + " WHERE missingBlocks != ''" );
- }
-
- /**
- * Returns the image that is corrsponding to a specified uuid.
- *
- * @param uuid
- * @return
- */
- public static DbImage getImageByUuid( String uuid )
- {
- return MySQL
- .findUniqueOrNull(
- DbImage.class,
- "SELECT image.uuid, image.revision, image.title, image.path, image.createtime, image.updatetime, image.ownerid, user.login, image.operatingsystem, image.isvalid, image.isdeleted, image.description, image.filesize, image.missingblocks"
- + " FROM image"
- + " INNER JOIN user ON (image.ownerid = user.userid)"
- + " WHERE uuid = ?",
- uuid );
- }
-
- /**
- * Return all public images as ImageData list, which can be directly
- * used by the thrift API.
- *
- * @param start
- * @param limit
- * @return
- */
- public static List<ImageData> asImageDataList( int start, int limit )
- {
- return MySQL
- .findAll(
- ImageData.class,
- "SELECT image.uuid, image.revision, image.title, image.createtime, image.updatetime, user.login, image.operatingsystem, image.isvalid, image.isdeleted, image.description, image.filesize"
- + " FROM image"
- + " INNER JOIN user ON (image.ownerid = user.userid)"
- + " ORDER BY uuid, revision"
- + " LIMIT " + start + ", " + limit );
- }
-
- /**
- * Creates an instance of the thrift ImageData class of this DbImage object.
- *
- * @return The corresponding image data
- */
- public ImageData getImageData()
- {
- String owner = "unknown";
- DbUser user = DbUser.forLogin( this.ownerId );
- if ( user != null )
- owner = user.getLogin();
- return new ImageData(
- this.uuid, this.revision, this.title, this.createTime,
- this.updateTime, owner, this.operatingSystem, this.isValid,
- this.isDeleted, this.longDescription, this.fileSize );
- }
-
- /**
- * Get absolute path of this image
- *
- * @return absolute path
- */
- public String getAbsolutePath()
+ public static ImagePublishData getImageVersion( String imageVersionId )
{
- return Globals.getImageDir() + "/" + this.relativePath;
+ // TODO Auto-generated method stub
+ return null;
}
}