de.fh_mannheim.mm.dms.framework
Class UploadManager

java.lang.Object
  extended byde.fh_mannheim.mm.dms.framework.UploadManager
All Implemented Interfaces:
IElement, IProducer

public class UploadManager
extends java.lang.Object
implements IProducer

UploadManager loads files to the server and connects to the database.

Version:
$Revision: 1.40 $
Author:
Jan Löffler, mail@jlsoft.de

Constructor Summary
UploadManager(Config cfg)
          Constructor.
 
Method Summary
 boolean addHit(int nUploadID)
          Add hits of this file.
 boolean addUpload(Upload upload)
          Add new upload order.
 boolean addUpload(Upload upload, boolean bForceUpdate)
          Add new upload order.
 boolean addUpload(Upload upload, java.io.BufferedInputStream is, boolean bForceUpdate)
          Add new upload order and copy filestream to upload destination.
 boolean addUpload(Upload upload, java.lang.String strFilename, boolean bForceUpdate)
          Add new upload order and copy local file to upload destination.
 boolean checkInUpload(int nID)
          Move upload order to file database.
 boolean checkInUpload(Upload upload)
          Move upload order to file database.
 int deleteMissingFiles()
          Delete all records, where file is missing.
 boolean deleteUpload(int nID)
          Delete an upload order.
 boolean deleteUpload(int nID, boolean bDeleteFile)
          Delete an upload order.
 boolean existsFile(java.lang.String strFilename)
          Test if a file exists.
 boolean existsFile(Upload upload)
          Test if a file exists.
 boolean existsUpload(int nUploadID)
          Check if upload exists.
 boolean existsUpload(java.lang.String strFilename)
          Check if upload exists.
 boolean exportUploads(java.lang.String strFilename)
          Export uploads to xml file.
 java.lang.String getAbsoluteFilename(java.lang.String strFilename)
          Return filename with path on the server.
 java.util.ArrayList getAllFilenames()
          Get all files by filename.
 java.util.ArrayList getAllFilenames(boolean bScheduledUploadsToo)
          Get all files by filename.
 UploadList getAllFiles()
          Get all files but not the scheduled uploads.
 UploadList getAllFiles(boolean bScheduledUploadsToo)
          Get all files.
 UploadList getAllFilesByAuthor(int nAuthorID)
          Get all files but not the scheduled uploads.
 UploadList getAllFilesByAuthor(int nAuthorID, boolean bScheduledUploadsToo)
          Get all files of an author.
 UploadList getAllFilesByCategory(int nCategoryID)
          Get all files of a category.
 java.util.ArrayList getAllScheduledUploadFilenames()
          Get all scheduled upload orders by filename.
 UploadList getAllScheduledUploads()
          Get all scheduled upload orders.
 UploadList getAllScheduledUploadsByAuthor(int nAuthorID)
          Get all scheduled upload orders of an author.
 int getFileHits(int nUploadID)
          Count hits of this file.
 double getFileHitsPerMonth(int nUploadID)
          Count hitrate of this file.
 int getFileNum()
          Count all files.
 int getFileNum(int nAuthorID)
          Count all files of an author.
 FileSize getFileSize(java.lang.String strFilename)
          Get the size in bytes of a file.
 FormattedDate getLastHit(int nUserID, int nFileID)
          Get the last acces of a upload by a user.
 Upload getNextScheduledUpload()
          Get first upload order.
 Upload getNextScheduledUpload(int nID)
          Get next upload order.
 java.lang.String getRelativeFilename(java.lang.String strFilename, int nUserID, boolean bExtractFilename)
          Return filename with relative path on the server.
 java.lang.String getRelativeFilename(java.lang.String strFilename, java.lang.String strBasePath)
          Return filename with relative path on the server.
 java.lang.String getRelativeFilename(java.lang.String strFilename, java.lang.String strBasePath, int nUserID)
          Return filename with relative path on the server.
 int getScheduledUploadNum()
          Count all scheduled upload orders.
 int getScheduledUploadNum(int nAuthorID)
          Count all scheduled upload orders of an author.
 int getSystemFileNum()
          Count all files.
 FileSize getSystemSize()
          Get the size in bytes of all files.
 Upload getUpload(int nID)
          Get an upload order.
 Upload getUpload(java.lang.String strFilename)
          Get an upload order.
 int importFiles(java.lang.String strFilename)
          Import uploads from xml file..
 int importFiles(java.lang.String strPath, java.lang.String strExtension, int nUserID, boolean bSearchSubdirs, boolean bForceUpdate)
          Search all files and check them in.
 int importFiles(java.lang.String strPath, java.lang.String strBasePath, java.lang.String strExtension, int nUserID, boolean bSearchSubdirs, boolean bForceUpdate)
          Search all files and check them in.
 org.w3c.dom.Document produceReport()
          Generate xml document.
 boolean scheduleAllUploads()
          Move all uploads to upload database.
 boolean scheduleUpload(int nID)
          Move upload order to upload database.
 boolean scheduleUpload(Upload upload)
          Move upload order to upload database.
 int sendUpdateNotifierMails(Upload upload)
          Send informationmails to watching users of this file.
 org.w3c.dom.Element toElement(org.w3c.dom.Document doc)
          Write information of uploads in a xml element.
 org.w3c.dom.Element toElement(org.w3c.dom.Element element, org.w3c.dom.Document doc)
          Write information of uploads in a xml element.
 java.lang.String toString()
          Write information of files in a string.
 boolean updateUpload(Upload editedUpload)
          Update an existing upload.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UploadManager

public UploadManager(Config cfg)
Constructor.

Parameters:
cfg - Config
Method Detail

addHit

public boolean addHit(int nUploadID)
Add hits of this file.

Parameters:
nUploadID - ID of file
Returns:
true, if successful

addUpload

public boolean addUpload(Upload upload)
                  throws DuplicateUploadException
Add new upload order.

Parameters:
upload - Order, which should be prepared
Returns:
true, if successful
Throws:
DuplicateUploadException

addUpload

public boolean addUpload(Upload upload,
                         boolean bForceUpdate)
                  throws DuplicateUploadException
Add new upload order.

Parameters:
upload - Order, which should be prepared
bForceUpdate - Overwrite existing upload
Returns:
true, if successful
Throws:
DuplicateUploadException

addUpload

public boolean addUpload(Upload upload,
                         java.io.BufferedInputStream is,
                         boolean bForceUpdate)
                  throws DuplicateUploadException,
                         InvalidFileTypeException,
                         java.io.IOException
Add new upload order and copy filestream to upload destination.

Parameters:
upload - Order, which should be prepared
is - Filestream
bForceUpdate - Overwrite existing upload
Returns:
true, if successful
Throws:
DuplicateUploadException
java.io.IOException
InvalidFileTypeException

addUpload

public boolean addUpload(Upload upload,
                         java.lang.String strFilename,
                         boolean bForceUpdate)
                  throws DuplicateUploadException,
                         InvalidFileTypeException,
                         java.io.IOException
Add new upload order and copy local file to upload destination.

Parameters:
upload - Order, which should be prepared
strFilename - File, which should be copied
bForceUpdate - Overwrite existing upload
Returns:
true, if successful
Throws:
DuplicateUploadException
java.io.IOException
InvalidFileTypeException

checkInUpload

public boolean checkInUpload(int nID)
Move upload order to file database.

Parameters:
nID - ID of upload order
Returns:
true, if successful

checkInUpload

public boolean checkInUpload(Upload upload)
Move upload order to file database.

Parameters:
upload - Order, which should be prepared
Returns:
true, if successful

deleteMissingFiles

public int deleteMissingFiles()
Delete all records, where file is missing.

Returns:
number of deleted records

deleteUpload

public boolean deleteUpload(int nID)
Delete an upload order.

Parameters:
nID - ID of upload
Returns:
true, if successful

deleteUpload

public boolean deleteUpload(int nID,
                            boolean bDeleteFile)
Delete an upload order.

Parameters:
nID - ID of upload
bDeleteFile - Should file be deleted too
Returns:
true, if successful

existsFile

public boolean existsFile(java.lang.String strFilename)
Test if a file exists.

Parameters:
strFilename - Filename
Returns:
true, if file exists

existsFile

public boolean existsFile(Upload upload)
Test if a file exists.

Parameters:
upload - Upload, which should be checked
Returns:
true, if file exists

existsUpload

public boolean existsUpload(int nUploadID)
Check if upload exists.

Parameters:
nUploadID - ID of upload
Returns:
true, if successful

existsUpload

public boolean existsUpload(java.lang.String strFilename)
Check if upload exists.

Parameters:
strFilename - Filename of upload
Returns:
true, if successful

exportUploads

public boolean exportUploads(java.lang.String strFilename)
                      throws java.io.IOException
Export uploads to xml file.

Parameters:
strFilename - Filename of xml file
Returns:
true, if successful
Throws:
java.io.IOException - When file could not be saved

getAbsoluteFilename

public java.lang.String getAbsoluteFilename(java.lang.String strFilename)
Return filename with path on the server.

Parameters:
strFilename - Filename of upload
Returns:
absolut filepath

getAllFilenames

public java.util.ArrayList getAllFilenames()
Get all files by filename.

Returns:
List with all found records

getAllFilenames

public java.util.ArrayList getAllFilenames(boolean bScheduledUploadsToo)
Get all files by filename.

Parameters:
bScheduledUploadsToo - Should the scheduled uploads be added too
Returns:
List with all found records

getAllFiles

public UploadList getAllFiles()
Get all files but not the scheduled uploads.

Returns:
List with all found records

getAllFiles

public UploadList getAllFiles(boolean bScheduledUploadsToo)
Get all files.

Parameters:
bScheduledUploadsToo - Should the scheduled uploads be added too
Returns:
List with all found records

getAllFilesByAuthor

public UploadList getAllFilesByAuthor(int nAuthorID)
Get all files but not the scheduled uploads.

Returns:
List with all found records

getAllFilesByAuthor

public UploadList getAllFilesByAuthor(int nAuthorID,
                                      boolean bScheduledUploadsToo)
Get all files of an author.

Parameters:
nAuthorID - ID of author
bScheduledUploadsToo - Should the scheduled uploads be added too
Returns:
List with all found records

getAllFilesByCategory

public UploadList getAllFilesByCategory(int nCategoryID)
Get all files of a category.

Parameters:
nCategoryID - ID of category
Returns:
List with all found records

getAllScheduledUploadFilenames

public java.util.ArrayList getAllScheduledUploadFilenames()
Get all scheduled upload orders by filename.

Returns:
List with all found records

getAllScheduledUploads

public UploadList getAllScheduledUploads()
Get all scheduled upload orders.

Returns:
List with all found records

getAllScheduledUploadsByAuthor

public UploadList getAllScheduledUploadsByAuthor(int nAuthorID)
Get all scheduled upload orders of an author.

Parameters:
nAuthorID - ID of author
Returns:
List with all found records

getFileHits

public int getFileHits(int nUploadID)
Count hits of this file.

Parameters:
nUploadID - ID of file
Returns:
number of hits

getFileHitsPerMonth

public double getFileHitsPerMonth(int nUploadID)
Count hitrate of this file.

Parameters:
nUploadID - ID of file
Returns:
number of hits

getFileNum

public int getFileNum()
Count all files.

Returns:
number of found files

getFileNum

public int getFileNum(int nAuthorID)
Count all files of an author.

Parameters:
nAuthorID - ID of author
Returns:
number of found files of author

getFileSize

public FileSize getFileSize(java.lang.String strFilename)
Get the size in bytes of a file.

Parameters:
strFilename - Filename
Returns:
Filesize

getLastHit

public FormattedDate getLastHit(int nUserID,
                                int nFileID)
Get the last acces of a upload by a user.

Returns:
Date

getNextScheduledUpload

public Upload getNextScheduledUpload()
Get first upload order.

Returns:
first upload order

getNextScheduledUpload

public Upload getNextScheduledUpload(int nID)
Get next upload order.

Parameters:
nID - ID of current upload
Returns:
next upload order

getRelativeFilename

public java.lang.String getRelativeFilename(java.lang.String strFilename,
                                            int nUserID,
                                            boolean bExtractFilename)
Return filename with relative path on the server.

Example:


getRelativeFilename

public java.lang.String getRelativeFilename(java.lang.String strFilename,
                                            java.lang.String strBasePath)
Return filename with relative path on the server.

Example:


getRelativeFilename

public java.lang.String getRelativeFilename(java.lang.String strFilename,
                                            java.lang.String strBasePath,
                                            int nUserID)
Return filename with relative path on the server.

Example:


getScheduledUploadNum

public int getScheduledUploadNum()
Count all scheduled upload orders.

Returns:
number of found upload orders

getScheduledUploadNum

public int getScheduledUploadNum(int nAuthorID)
Count all scheduled upload orders of an author.

Parameters:
nAuthorID - ID of author
Returns:
number of found upload orders

getSystemFileNum

public int getSystemFileNum()
Count all files.

Returns:
number of found files

getSystemSize

public FileSize getSystemSize()
Get the size in bytes of all files.

Returns:
Filesize

getUpload

public Upload getUpload(int nID)
Get an upload order.

Parameters:
nID - ID of upload
Returns:
upload order

getUpload

public Upload getUpload(java.lang.String strFilename)
Get an upload order.

Parameters:
strFilename - Filename of upload
Returns:
upload order

importFiles

public int importFiles(java.lang.String strPath,
                       java.lang.String strExtension,
                       int nUserID,
                       boolean bSearchSubdirs,
                       boolean bForceUpdate)
Search all files and check them in.

Parameters:
strPath - Path to be searched
strExtension - Filetype which should be found
nUserID - ID of user
bSearchSubdirs - Should subdiretories be searched too
bForceUpdate - Overwrite existing upload

importFiles

public int importFiles(java.lang.String strPath,
                       java.lang.String strBasePath,
                       java.lang.String strExtension,
                       int nUserID,
                       boolean bSearchSubdirs,
                       boolean bForceUpdate)
Search all files and check them in.

Parameters:
strPath - Path to be searched
strBasePath - Rootpath to be searched
strExtension - Filetype which should be found
nUserID - ID of user
bSearchSubdirs - Should subdiretories be searched too
bForceUpdate - Overwrite existing upload

importFiles

public int importFiles(java.lang.String strFilename)
Import uploads from xml file..

Parameters:
strFilename - Filename of xmlfile
Returns:
Number of imported uploads

produceReport

public org.w3c.dom.Document produceReport()
Generate xml document.

Specified by:
produceReport in interface IProducer
Returns:
xml document

toElement

public org.w3c.dom.Element toElement(org.w3c.dom.Document doc)
Write information of uploads in a xml element.

Specified by:
toElement in interface IElement
Parameters:
doc - XML Document
Returns:
element

toElement

public org.w3c.dom.Element toElement(org.w3c.dom.Element element,
                                     org.w3c.dom.Document doc)
Write information of uploads in a xml element.

Specified by:
toElement in interface IElement
Parameters:
element - Root element
doc - XML Document
Returns:
element

scheduleAllUploads

public boolean scheduleAllUploads()
Move all uploads to upload database.

Returns:
true, if successful

scheduleUpload

public boolean scheduleUpload(int nID)
Move upload order to upload database.

Parameters:
nID - ID of upload order
Returns:
true, if successful

scheduleUpload

public boolean scheduleUpload(Upload upload)
Move upload order to upload database.

Parameters:
upload - Upload, which should be scheduled again
Returns:
true, if successful

sendUpdateNotifierMails

public int sendUpdateNotifierMails(Upload upload)
Send informationmails to watching users of this file.

Parameters:
upload - Upload
Returns:
number of mails

toString

public java.lang.String toString()
Write information of files in a string.

Specified by:
toString in interface IElement
Returns:
information

updateUpload

public boolean updateUpload(Upload editedUpload)
Update an existing upload.

Parameters:
editedUpload - Order, which should be updated
Returns:
true, if successful