org.bibalex.daf.entities.phase
Class PhysicalAction

java.lang.Object
  extended by org.bibalex.daf.entities.phase.PhaseAction
      extended by org.bibalex.daf.entities.phase.PhysicalAction

public class PhysicalAction
extends PhaseAction

Responsible for applying the physical actions associted with a phase.

Author:
Shehab.Kamal

Field Summary
private  ActionContext context
          The context of the action, i.e.
private  PhysicalDef definition
          Holds the PhysicalDef that will be used when applying the action.
private  java.lang.String destinationParent
          The destination of the job folder excluding the folder name.
private  FileHandler handler
          The FileHandler used to create and copy files and folders.
private  java.lang.String jobFolder
          Holds the name of the job folder.
private  int noOfFiles
          Holds the number of files affected by the action.
private  java.lang.String sourceParent
          The source of the job folder excluding the folder name.
private  java.util.Date startDate
          The date at which the job started with the user.
 
Constructor Summary
PhysicalAction(PhysicalDef definition, FileHandler handler, java.lang.String source, java.lang.String jobFolder, java.lang.String destination, ActionContext context, java.util.Date startDate)
          Create a new instance of PhysicalAction.
 
Method Summary
 void applyAction()
          Applies the action.
private  boolean copyFiles(java.lang.String source, FileElement file, java.lang.String destination)
          Copies the files from source to destination.
Note: The context determines whether the files will be uploaded or downloaded.
private  boolean copyFolder(java.lang.String source, FolderElement folder, java.lang.String destination)
          Creates the folder then uploads or downloads it.
private  boolean createFolder(java.lang.String parentFolder, java.lang.String folderName, FileHandler handler)
          Creates the folder at the given parent folder.
 int getNoOfFiles()
          Gets the number of files affected by the action.
private  void manageFolder(FolderElement folder, java.lang.String source, java.lang.String destination)
          Applies the action to the given folder.
private  void manageRoot(FolderElement root, java.lang.String source, java.lang.String destination)
          Manages the root separately because it is a special case.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

definition

private PhysicalDef definition
Holds the PhysicalDef that will be used when applying the action.


handler

private FileHandler handler
The FileHandler used to create and copy files and folders.


sourceParent

private java.lang.String sourceParent
The source of the job folder excluding the folder name.


destinationParent

private java.lang.String destinationParent
The destination of the job folder excluding the folder name.


jobFolder

private java.lang.String jobFolder
Holds the name of the job folder.


context

private ActionContext context
The context of the action, i.e. whether this action is executed as part of the pre-phase or post-phase actions.


noOfFiles

private int noOfFiles
Holds the number of files affected by the action.


startDate

private java.util.Date startDate
The date at which the job started with the user. We count the files modified after this date.

Constructor Detail

PhysicalAction

public PhysicalAction(PhysicalDef definition,
                      FileHandler handler,
                      java.lang.String source,
                      java.lang.String jobFolder,
                      java.lang.String destination,
                      ActionContext context,
                      java.util.Date startDate)
Create a new instance of PhysicalAction.

Parameters:
definition - The PhysicalDef to be applied.
handler - The FileHandler used to create and copy files and folders. It should be an FTP implementation since files and folders are copied between the server and the local workstation.
source - The source of the job folder excluding the name of the folder. It can be a local or FTP path.
destination - The destination of the job folder excluding the name of the folder. It can be a local or FTP path.
jobFolder - The name of the job folder.
context - The context of the action.
startDate - The start date.
Method Detail

applyAction

public void applyAction()
                 throws PhaseActionException
Applies the action.

Specified by:
applyAction in class PhaseAction
Throws:
PhaseActionException - If the action fails.

manageRoot

private void manageRoot(FolderElement root,
                        java.lang.String source,
                        java.lang.String destination)
                 throws PhaseActionException
Manages the root separately because it is a special case.

Parameters:
root - A FolderElement representing the root which this the job folder.
source - The physical folder that represents the source folder containing the job folder.
destination - The physical folder that represents the destination folder that will contain the job folder.
Throws:
PhaseActionException - If a folder couldn't be managed.

manageFolder

private void manageFolder(FolderElement folder,
                          java.lang.String source,
                          java.lang.String destination)
                   throws PhaseActionException
Applies the action to the given folder. It includes the following:
1) Determine whether the subfiles will be copied or not.
2) Determine whether the subfolders will be copied or created.
Notes:
1) The decision of creating a folder is taken in its parent.
2) Use Filehandler.pathSeparator to concatenate 2 paths together.

Parameters:
folder - The FolderElement whose subfolders and subfiles are being examined.
source - The source of the parent of the given folder. Concatenate the 'folder.name' to get the full path.
destination - The destination of the parent of the given folder. Concatenate the 'folder.newName' to get the full path.
Throws:
PhaseActionException - If a folder couldn't be managed.

copyFiles

private boolean copyFiles(java.lang.String source,
                          FileElement file,
                          java.lang.String destination)
Copies the files from source to destination.
Note: The context determines whether the files will be uploaded or downloaded.

Parameters:
source - The source folder.
file - The FileElement to be copied.
destination - The destination folder.
Returns:
True if the files has been copied otherwise false.

copyFolder

private boolean copyFolder(java.lang.String source,
                           FolderElement folder,
                           java.lang.String destination)
Creates the folder then uploads or downloads it.

Parameters:
source - The source path of the parent of the given folder. This could be a remote or a local path.
folder - The folder being copied.
destination - The destination path of the parent of the given folder. This could be a remote or a local path. Files will be read only if they are copied from the server to the local workstation only.
Returns:
True if the folder is copied successfully or if no action has been applied to the folder.

createFolder

private boolean createFolder(java.lang.String parentFolder,
                             java.lang.String folderName,
                             FileHandler handler)
Creates the folder at the given parent folder. Note: If the folder already exists, it is not overwritten.

Parameters:
parentFolder - The parent folder.
folderName - The folder to create
handler - The handler to use
Returns:
True if the folder has been created or if the folder already exists, otherwise false.

getNoOfFiles

public int getNoOfFiles()
Gets the number of files affected by the action. Files affected by the action are those files created by the user and will be uploaded to the server. In other words, files in the folders whose ToDestination = true are counted.

Returns:
The number of files affected or -1;