org.molgenis.omx.services
Class FileUploadUtils

java.lang.Object
  extended by org.molgenis.omx.services.FileUploadUtils

public class FileUploadUtils
extends Object


Constructor Summary
FileUploadUtils()
           
 
Method Summary
static void copyHelper(File content, File dest, boolean skipWhenDestExists)
           
static void doUpload(Database db, boolean useTx, String name, String type, File content, HashMap<String,String> extraFields, boolean skipWhenDestExists)
          Generic file upload.
static void doUpload(Database db, MolgenisFile mf, File content, boolean skipWhenDestExists)
          Generic file upload.
static void fileNameChecks(String name)
           
static ArrayList<String> getNeededExtraFields(String type, Database db)
          Reusable function that will return a list of fieldnames that are needed for this subclass of 'MolgenisFile'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUploadUtils

public FileUploadUtils()
Method Detail

doUpload

public static void doUpload(Database db,
                            MolgenisFile mf,
                            File content,
                            boolean skipWhenDestExists)
                     throws Exception
Generic file upload. This function assumes the MolgenisFile is already in the database, and only a file source corresponding to this MolgenisFile is added.

Parameters:
db -
mf -
content -
Throws:
Exception
XGAPStorageException

doUpload

public static void doUpload(Database db,
                            boolean useTx,
                            String name,
                            String type,
                            File content,
                            HashMap<String,String> extraFields,
                            boolean skipWhenDestExists)
                     throws Exception
Generic file upload. This function will create a new MolgenisFile object in the database, as well as put the referenced file source for this MolgenisFile in the correct place. The 'type' must correspond to the name of a subclass of MolgenisFile. Fields and types are dynamically checked and casted.

Parameters:
db - The database to use.
name - Full name of the original file (eg. 'mypicture.png')
type - Type of the file. Must correspond to a MolgenisFile subclass. (eg. 'Image' or 'BinaryDataMatrix') Used as part of the storage location. (eg. {storagedir}/{deployname}/image)
content - Any existing file of which only the content is submitted to the upload.
extraFields - A hashmap containing values of the additional fields that are used by this subclass of MolgenisFile. For example, 'investigation_name' for Image.
Throws:
Exception

fileNameChecks

public static void fileNameChecks(String name)
                           throws Exception
Throws:
Exception

getNeededExtraFields

public static ArrayList<String> getNeededExtraFields(String type,
                                                     Database db)
                                              throws Exception
Reusable function that will return a list of fieldnames that are needed for this subclass of 'MolgenisFile'.

Parameters:
type -
db -
Returns:
Throws:
Exception

copyHelper

public static void copyHelper(File content,
                              File dest,
                              boolean skipWhenDestExists)
                       throws IOException
Throws:
IOException


Copyright © 2013. All Rights Reserved.