summaryrefslogblamecommitdiffstats
path: root/src/main/java/org/openslx/satellitedaemon/db/DbImage.java
blob: c35fd5d8070022d793191c420de884010f9ebf60 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                                       


                      
                                                               



                      
 
                                 
                                 


                                    
                                   

                                     
                                                

                                       





                                                                                                                                                          

                                                                                           
                                                                                                        
                                                           
         



                                             










                                                   
                                 
                                 


                                       
                                         

                                             
                                                                     

                                       
         







                                                                              
                                                           
         
                                                                                                                                           
                                                                                                                                                                  
                                                                                                                


                                                                                                                           
                                                                              
         
 







                                                                                  


                                                                                                                                           
                                                                                                                                                                  
                                                                                                                


                                                                                                                           
                                                                                  

         





                                                                                                        
                                                 
         
                                                                                                                                   

         




                                                              
                                                   
         
                                                                                                                           
         

 
package org.openslx.satellitedaemon.db;

import java.util.List;

/**
 * Represents an image in the satellite's database (mostly from
 * m_VLData_imageInfo)
 */
public class DbImage
{

	public final String guid;
	public final String name;
	public final int rid;
	public final String path;
	public final String creator;
	public final long fileSize;
	public final long changeTime;
	public final long createTime;
	public final int contentOperatingSystem;
	public final boolean isValid;
	public final boolean isDeleted;

	public enum Status
	{
		only_local, to_be_published, being_published, successfully_published, to_be_decentralized, being_decentralized, successfully_decentralized
	}

	public DbImage(
			String guid, String name, Integer rid, String path, String creator,
			Long fileSize, Long createTime, Long changeTime, Integer contentOperatingSystem,
			Boolean isValid, Boolean isDeleted)
	{
		if ( rid == null )
			rid = -1;
		if ( fileSize == null )
			fileSize = (long) -1;
		if (createTime == null)
			createTime = (long) 0;
		if (changeTime == null)
			changeTime = (long) 0;
		if (contentOperatingSystem == null)
			contentOperatingSystem = 0;
		if (isValid == null) 
			isValid = true;
		if (isDeleted == null)
			isDeleted = false;

		this.guid = guid;
		this.name = name;
		this.rid = rid;
		this.path = path;
		this.creator = creator;
		this.fileSize = fileSize;
		this.createTime = createTime;
		this.changeTime = changeTime;
		this.contentOperatingSystem = contentOperatingSystem;
		this.isValid = true;
		this.isDeleted = false;
	}

	/**
	 * Returns a list of all images on this satellite that should be
	 * uploaded to the central server.
	 * 
	 * @return list of images that are marked for upload, where the upload
	 *         was either not started yet, or is incomplete
	 */
	public static List<DbImage> getAllMarkedForUpload()
	{
		return MySQL.findAll( DbImage.class, "SELECT image.GUID_imageID, image.image_name, image.imageVersion, image.image_path," +
				" user.loginName AS userID, image.image_filesize, UNIX_TIMESTAMP(image.rec_create_time), UNIX_TIMESTAMP(image.rec_change_time)," +
				" image.content_operatingSystem, image.status_isValid, image.status_isDeleted" +
				" FROM m_VLData_imageInfo image" +
				" INNER JOIN m_user user ON (image.image_owner = user.userID)" +
				" INNER JOIN m_institution institution ON (institution.institutionID = user.institution)" +
				" WHERE image_syncMode = 'to_be_published'" );
	}

	/**
	 * Returns a list of all images on this satellite that should be
	 * downloaded from the central server.
	 * 
	 * @return list of images that are marked for download, where the download
	 *         was either not started yet, or is incomplete
	 */
	
	public static List<DbImage> getAllMarkedForDownload()
	{
		return MySQL.findAll( DbImage.class, "SELECT image.GUID_imageID, image.image_name, image.imageVersion, image.image_path," +
				" user.loginName AS userID, image.image_filesize, UNIX_TIMESTAMP(image.rec_create_time), UNIX_TIMESTAMP(image.rec_change_time)," +
				" image.content_operatingSystem, image.status_isValid, image.status_isDeleted" +
				" FROM m_VLData_imageInfo image" +
				" INNER JOIN m_user user ON (image.image_owner = user.userID)" +
				" INNER JOIN m_institution institution ON (institution.institutionID = user.institution)" +
				" WHERE image_syncMode = 'to_be_decentralized'" );
	}

	/**
	 * Method for updating the status of an Image in the db. For example after a succesfull upload.
	 * 
	 * @param status : possible statuses are : "only_local, to_be_published, being_published, 
	 * successfully_published, to_be_decentralized, being_decentralized, successfully_decentralized"
	 */
	public void updateStatus( Status status )
	{
		MySQL.update( "UPDATE m_VLData_imageInfo SET image_syncMode=? WHERE GUID_imageID=?", status.toString(), this.guid);
	}

	/**
	 * Method for updating the size of an Image in the db.
	 * 
	 * @param filesize is the size of the file
	 */
	public void updateFilesize( long filesize )
	{
		MySQL.update( "UPDATE m_VLData_imageInfo SET image_filesize=? WHERE GUID_imageID=?", filesize, this.guid );
	}

}