org.bibalex.daf.entities.job
Class DownloadingState

java.lang.Object
  extended by org.bibalex.daf.entities.job.JobState
      extended by org.bibalex.daf.entities.job.DownloadingState

public class DownloadingState
extends JobState

This class contains the logic necessary to download the job. Calling makeTransition method will cause the job to be downloaded.

Author:
Shehab.Kamal

Field Summary
private  java.lang.String destination
           
private  boolean downloadWholeFolder
           
private  java.lang.String errorMessage
           
private  FileHandler ftpHandler
           
private  TransitionInfo info
           
private  Job job
           
private  int noOfFiles
           
private  Phase phase
           
private  java.lang.String source
           
private  User user
           
private  WorkStation workstation
           
 
Constructor Summary
DownloadingState(Job job, User user, WorkStation workstation, boolean downloadWholeFolder)
          Creates a new instance of DownloadingState.
 
Method Summary
private  PhaseDef getDownloadPhaseDef()
          Gets the phase definition used to download the job.
 java.lang.String getErrorMessage()
          This method gets the mesage that is to be displaed to the user
 java.lang.String getName()
          Gets the name of the state.
 int getNoOfFiles()
          Gets the number of files required to be transferred in order to download the job.
 boolean makeTransition()
          Downloads the job from the user's workstation to the server.
Note: Downloading the job is recorded in the database.
private  int similarFolderIndex(FolderElement[] folders, FolderElement folder)
          Determines whether the given folder matches a folder in the given array or not.
A folder is said to be similar to another folder if the "Name" and "NewName" attributes are the same.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

job

private Job job

user

private User user

workstation

private WorkStation workstation

info

private TransitionInfo info

phase

private Phase phase

ftpHandler

private FileHandler ftpHandler

source

private java.lang.String source

destination

private java.lang.String destination

noOfFiles

private int noOfFiles

downloadWholeFolder

private boolean downloadWholeFolder

errorMessage

private java.lang.String errorMessage
Constructor Detail

DownloadingState

public DownloadingState(Job job,
                        User user,
                        WorkStation workstation,
                        boolean downloadWholeFolder)
                 throws java.lang.Exception
Creates a new instance of DownloadingState.

Parameters:
job - The job to download.
user - The user who is downloading the job.
workstation - The workstation to which the job will downloaded.
downloadWholeFolder - True to download the whole folder. False to download the folders matching the phase definition.
Throws:
java.lang.Exception - If the information necessary to download the job cannot be obtained.
Method Detail

getName

public java.lang.String getName()
Gets the name of the state.

Specified by:
getName in class JobState
Returns:
The name of the state.

getNoOfFiles

public int getNoOfFiles()
Gets the number of files required to be transferred in order to download the job.

Specified by:
getNoOfFiles in class JobState
Returns:
The number of files to download the job.

makeTransition

public boolean makeTransition()
Downloads the job from the user's workstation to the server.
Note: Downloading the job is recorded in the database.

Specified by:
makeTransition in class JobState
Returns:
True if the job has been downloaded successfully, otherwise false.

getDownloadPhaseDef

private PhaseDef getDownloadPhaseDef()
Gets the phase definition used to download the job.

Problem:
In a certain phase, the pre-phase downloads the OTIFF and PTIFF folders to the user and the post-phase uploads the PTIFF and TXT folders from the user.
In order to download the job, we apply the pre-phase actions followed by the post-phase which results in the PTIFF folder downloaded twice.

Resolution:
We need to mix the pre-phase defintion and the post-phase defintion and remove any duplicate nodes.

Note:
Since each folder has a "Name" and a "NewName" attribute, folders in the post-phase need to have their "Name" and "NewName" swapped.
For instance if we are uploading a folder named "Client_PTIFF" to a folder named "Server_PTIFF", then when downloading we need to download the folder "Server_PTIFF" to "Client_PTIFF".

Returns:
The PhaseDef used to download the job or null if the phase couldn't be obtained.

The returned PhaseDef, if any, will have the following characteristics:
1) The pre-phase physical section doesn't have any repeated nodes, thus no folder is allowed twice.
2) It pre-phase doesn't contain any reflection or database sections.
3) The post-phase defintion will have the "Name" and "NewName" values swapped.


similarFolderIndex

private int similarFolderIndex(FolderElement[] folders,
                               FolderElement folder)
Determines whether the given folder matches a folder in the given array or not.
A folder is said to be similar to another folder if the "Name" and "NewName" attributes are the same.

Parameters:
folders - The folders to search in.
folder - The folder to search for.
Returns:
The index of the array element that matches the given folder, or -1 if no match is found.

getErrorMessage

public java.lang.String getErrorMessage()
Description copied from class: JobState
This method gets the mesage that is to be displaed to the user

Specified by:
getErrorMessage in class JobState
Returns:
The error message to be dispalayed to the user