org.bibalex.daf.entities.phase
Class Phase

java.lang.Object
  extended by org.bibalex.daf.entities.AdminModuleBase
      extended by org.bibalex.daf.entities.phase.Phase

public class Phase
extends AdminModuleBase

Handles the checks and actions associated with the phase.

Author:
Shehab.Kamal

Field Summary
private  DBConnection conn
           
private  java.lang.String description
           
private  int id
           
private  int jobType
           
private  int maxPeriod
           
private  java.lang.String name
           
private  int noOfFiles
          Holds the number of files uploaded to server after finishing the PhysicalAction
private  int sequence
           
private  org.w3c.dom.Node userData
          Holds the user data that he entered in response to the DatabaseAction.
private  java.lang.String xmlDescription
           
 
Constructor Summary
Phase()
          Creates a new instance of Phase.
Phase(DataTable table)
          Creates a new instance of Phase.
This constructor fills all the fields from the DataTable.
Remarks: Fields that correspond to null database columns are left to default values, i.e.
Phase(int phaseID, int jobTypeID)
          Creates a new instance of Phase.
 
Method Summary
 OperationInfo add()
          Adds this instance to the Phase table.
 void applyActions(ActionContext context, Job job, FileHandler handler, java.lang.String source, java.lang.String destination)
          Applies the pre-phase or post-phase actions as defined in the physical, reflection and database sections of the phase definition.
 void applyChecks(ActionContext context, FileHandler fileHandler, java.lang.String jobPath, ActionContext alternateContext, FileHandler alternateHandler, java.lang.String alternatePath)
          Applies pre-phase or post-phase checks as defined in the physical section of the phase definition.
 void applyPostPhaseActions(Job job, FileHandler handler, java.lang.String source, java.lang.String destination)
          Applies the post-phase checks as defined in the physical, reflection and database sections of the phase definition.
 void applyPostPhaseChecks(java.lang.String localPath, FileHandler ftpHandler, java.lang.String serverPath)
          Applies the post-phase checks as defined in the physical section of the phase definition.
 void applyPrePhaseActions(Job job, FileHandler handler, java.lang.String source, java.lang.String destination)
          Applies the pre-phase checks as defined in the physical, reflection and database sections of the phase definition.
 void applyPrePhaseChecks(java.lang.String serverPath, FileHandler ftpHandler, java.lang.String localPath)
          Applies the pre-phase checks as defined in the physical section of the phase definition.
 OperationInfo delete()
          Deletes this instance from the Phase table.
 OperationInfo deleteCascade()
          Deletes this instance from the Phase table.
 OperationInfo getAllUsers()
          Gets all the users who can work in this phase.
static OperationInfo getByID(int phaseID, int jobTypeID)
          Gets the phase specified by the phaseID and jobTypeID.
static OperationInfo getByName(java.lang.String phaseName)
          Gets the phase with the given name.
 java.lang.String getDescription()
          Gets the description of the phase.
 OperationInfo getFinishedJobs(int collID, int batchID)
          Gets finished jobs for this phase.
 OperationInfo getFinishedJobsMoreThanOnce(int collID, int batchID)
          Gets finished jobs for this phase more than one time.
 OperationInfo getFinishedJobsOnce(int collID, int batchID)
          Gets finished jobs for this phase one time.
 int getID()
          Gets the ID of the phase.
 int getJobType()
          Gets the job type of the phase.
private  DatabaseInfoDef getLastFinishedDatabaseInfo(Job job)
          Gets the phase last finished information.
This method logs any error that might occur as warnings.
static int getLastUser(int jobID, int phaseID, int jsID)
          Gets the last user who has done thie phase
 int getMaxPeriod()
          Gets the maximum period of the phase.
 java.lang.String getName()
          Gets the name of the phase
 OperationInfo getNextPhase()
          Gets next phase of the current one
 int getNoOfFiles()
          Gets the number of files uploaded to the server after applying the PhysicalAction.
Caution: Don't call this method before applying the phase actions.
 OperationInfo getPendingJobs(int collID, int batchID)
          Gets pending jobs for this phase.
 OperationInfo getPendingJobsMoreThanOnce(int collID, int batchID)
          Gets the jobs pending in this phase more than one time.
 OperationInfo getPendingJobsOnce(int collID, int batchID)
          Gets the jobs pending in this phase for one time.
 OperationInfo getProcessingJobs(int collID, int batchID)
          Gets the jobs that are in this phase.
 OperationInfo getProcessingJobsMoreThanOnce(int collID, int batchID)
          Gets the jobs that are in this phase more than one time.
 OperationInfo getProcessingJobsOnce(int collID, int batchID)
          Gets the jobs that are in this phase one time.
private  SemiPhaseDef getSemiPhaseDef(ActionContext context)
          Gets the SemiPhaseDef of the phase xml description.
 int getSequence()
          Gets the sequence of the phase.
private  DatabaseInfoDef getStartDatabaseInfo(Job job)
          Gets the phase last finished information.
This method logs any error that might occur as warnings.
 org.w3c.dom.Node getUserData()
          Gets the user data that he entered in response for the DatabaseAction.
Caution: Don't call this method before applying the phase actions.
 java.lang.String getXmlDescription()
          Gets the Xml description of the book.
 boolean isLastPhase()
          Determines whether this phase is the last phase or not.
A phase is considered as last phase in the following two cases:
1) It is the last phase in the job type sequence.
2) It is not included in the sequence at all
static OperationInfo loadAll()
          Loads all the entries form the Phase table.
static OperationInfo loadSpecial()
          Gets all the Phases
 void setDescription(java.lang.String description)
          Sets the description of the phase.
 void setFieldsFromDataTable(DataTable table)
          Uses the given DataTable to set the fields.
 void setID(int phaseID)
          Sets the ID of the phase.
 void setJobType(int jobType)
          Sets the job type of the phase.
 void setMaxPeriod(int maxPeriod)
          Sets the maximum period of the phase.
 void setName(java.lang.String name)
          Sets the name of the phase.
 void setSequence(int sequence)
          Sets the sequence of the phase.
 void setXmlDescription(java.lang.String xmlDescription)
          Sets the Xml description of the phase.
 java.lang.String toString()
          Returns the string representation of this object.
 OperationInfo update()
          Updates this instance in the Phase table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

conn

private DBConnection conn

id

private int id

name

private java.lang.String name

sequence

private int sequence

maxPeriod

private int maxPeriod

description

private java.lang.String description

xmlDescription

private java.lang.String xmlDescription

jobType

private int jobType

noOfFiles

private int noOfFiles
Holds the number of files uploaded to server after finishing the PhysicalAction


userData

private org.w3c.dom.Node userData
Holds the user data that he entered in response to the DatabaseAction.

Constructor Detail

Phase

public Phase()
Creates a new instance of Phase. This constructor leaves all the fields empty.


Phase

public Phase(int phaseID,
             int jobTypeID)
      throws java.lang.Exception
Creates a new instance of Phase. This constructor fills all the fields from the database. Remarks: Fields that correspond to null database columns are left to default values, i.e. String and Date will be null and int will be 0.

Parameters:
phaseID - The ID of the Phase.
jobTypeID - The ID of the JobType.
Throws:
java.lang.Exception - If the phase couldn't be retrieved from the database.

Phase

public Phase(DataTable table)
      throws java.lang.Exception
Creates a new instance of Phase.
This constructor fills all the fields from the DataTable.
Remarks: Fields that correspond to null database columns are left to default values, i.e. String and Date will be null and int will be 0.

Parameters:
table - The DataTable used to construct the object.
Throws:
java.lang.Exception - If the phase couldn't be constructed from the DataTable.
Method Detail

setFieldsFromDataTable

public void setFieldsFromDataTable(DataTable table)
Uses the given DataTable to set the fields.

Parameters:
table - The DataTable used to set the fields.

setID

public void setID(int phaseID)
Sets the ID of the phase.

Parameters:
phaseID - The ID of the phase.

getID

public int getID()
Gets the ID of the phase.

Returns:
the ID of the phase.

setName

public void setName(java.lang.String name)
Sets the name of the phase.

Parameters:
name - The name of the phase.

getName

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

Returns:
The name of the phase.

setSequence

public void setSequence(int sequence)
Sets the sequence of the phase.

Parameters:
sequence - The sequence of the phase.

getSequence

public int getSequence()
Gets the sequence of the phase.

Returns:
The sequence of the phase.

setMaxPeriod

public void setMaxPeriod(int maxPeriod)
Sets the maximum period of the phase.

Parameters:
maxPeriod - The maximum period of the phase.

getMaxPeriod

public int getMaxPeriod()
Gets the maximum period of the phase.

Returns:
The maximum period of the phase.

setDescription

public void setDescription(java.lang.String description)
Sets the description of the phase.

Parameters:
description - The description of the phase.

getDescription

public java.lang.String getDescription()
Gets the description of the phase.

Returns:
The description of the phase.

setXmlDescription

public void setXmlDescription(java.lang.String xmlDescription)
Sets the Xml description of the phase.

Parameters:
xmlDescription - The Xml description of the phase.

getXmlDescription

public java.lang.String getXmlDescription()
Gets the Xml description of the book.

Returns:
The Xml description of the phase.

setJobType

public void setJobType(int jobType)
Sets the job type of the phase.

Parameters:
jobType - The job type of the phase.

getJobType

public int getJobType()
Gets the job type of the phase.

Returns:
The job type of the phase.

loadAll

public static OperationInfo loadAll()
Loads all the entries form the Phase table.

Returns:
An OperationInfo instance whose result is a DataTable holding all the entries from the phase table

getByID

public static OperationInfo getByID(int phaseID,
                                    int jobTypeID)
Gets the phase specified by the phaseID and jobTypeID.

Parameters:
phaseID - The ID of the phase.
jobTypeID - The ID of the job type.
Returns:
An OperationInfo instance whose result is a DataTable containg the phases that match the given criterion.

getByName

public static OperationInfo getByName(java.lang.String phaseName)
Gets the phase with the given name.

Parameters:
phaseName - The name of the phase to search for.
Returns:
An OperationInfo whose result has the phase with the given name.

getLastUser

public static int getLastUser(int jobID,
                              int phaseID,
                              int jsID)
Gets the last user who has done thie phase

Parameters:
jobID - the job that passed the phase
phaseID - the phase to be checked
jsID - the job status that the phase and job are on
Returns:
userId as int

getAllUsers

public OperationInfo getAllUsers()
Gets all the users who can work in this phase.

Returns:
An OperationInfo instance whose result is a DataTable containg the users who can work in this phase.

loadSpecial

public static OperationInfo loadSpecial()
Gets all the Phases

Returns:
An OperationInfo instance whose result is a DataTable containg all Phases

isLastPhase

public boolean isLastPhase()
Determines whether this phase is the last phase or not.
A phase is considered as last phase in the following two cases:
1) It is the last phase in the job type sequence.
2) It is not included in the sequence at all

Returns:
True if this phase is the last one, otherwise false.
If the database cannot be queried, flase is returned.

getNextPhase

public OperationInfo getNextPhase()
Gets next phase of the current one

Returns:
An OperationInfo instance whose result is a DataTable containg the next phase

add

public OperationInfo add()
Adds this instance to the Phase table.

Specified by:
add in class AdminModuleBase
Returns:
An OperationInfo instance whose result is a DataTable holding the instance that has been added.

delete

public OperationInfo delete()
Deletes this instance from the Phase table.

Specified by:
delete in class AdminModuleBase
Returns:
An OperationInfo instance whose result is null.

getFinishedJobs

public OperationInfo getFinishedJobs(int collID,
                                     int batchID)
Gets finished jobs for this phase.

Parameters:
collID - The collection to filter on .
batchID - The batch to filter on.
Returns:
An OperationInfo instance whose result is a DataTable holding the jobs that have finished this phase.

getFinishedJobsOnce

public OperationInfo getFinishedJobsOnce(int collID,
                                         int batchID)
Gets finished jobs for this phase one time.

Parameters:
collID - The collection to filter on .
batchID - The batch to filter on.
Returns:
An OperationInfo instance whose result is a DataTable holding the jobs that have finished this phase.

getFinishedJobsMoreThanOnce

public OperationInfo getFinishedJobsMoreThanOnce(int collID,
                                                 int batchID)
Gets finished jobs for this phase more than one time.

Parameters:
collID - The collection to filter on .
batchID - The batch to filter on.
Returns:
An OperationInfo instance whose result is a DataTable holding the jobs that have finished this phase.

getPendingJobs

public OperationInfo getPendingJobs(int collID,
                                    int batchID)
Gets pending jobs for this phase.

Parameters:
collID - The collection to filter on .
batchID - The batch to filter on.
Returns:
An OperationInfo instance whose result is null.

getPendingJobsOnce

public OperationInfo getPendingJobsOnce(int collID,
                                        int batchID)
Gets the jobs pending in this phase for one time.

Parameters:
collID - The collection to filter on .
batchID - The batch to filter on.
Returns:
An OperationInfo instance whose result is a DataTable holding the jobs that has are pending in this phase.

getPendingJobsMoreThanOnce

public OperationInfo getPendingJobsMoreThanOnce(int collID,
                                                int batchID)
Gets the jobs pending in this phase more than one time.

Parameters:
collID - The collection to filter on .
batchID - The batch to filter on.
Returns:
An OperationInfo instance whose result is a DataTable holding the jobs that has are pending in this phase.

getProcessingJobs

public OperationInfo getProcessingJobs(int collID,
                                       int batchID)
Gets the jobs that are in this phase.

Parameters:
collID - The collection to filter on .
batchID - The batch to filter on.
Returns:
An OperationInfo instance whose result is a DataTable holding the jobs in this phase.

getProcessingJobsOnce

public OperationInfo getProcessingJobsOnce(int collID,
                                           int batchID)
Gets the jobs that are in this phase one time.

Parameters:
collID - The collection to filter on .
batchID - The batch to filter on.
Returns:
An OperationInfo instance whose result is a DataTable holding the jobs in this phase.

getProcessingJobsMoreThanOnce

public OperationInfo getProcessingJobsMoreThanOnce(int collID,
                                                   int batchID)
Gets the jobs that are in this phase more than one time.

Parameters:
collID - The collection to filter on .
batchID - The batch to filter on.
Returns:
An OperationInfo instance whose result is a DataTable holding the jobs in this phase.

deleteCascade

public OperationInfo deleteCascade()
Deletes this instance from the Phase table.

Returns:
An OperationInfo instance whose result is null.

update

public OperationInfo update()
Updates this instance in the Phase table.

Specified by:
update in class AdminModuleBase
Returns:
An OperationInfo whose result is a DataTable containing the updated record.

applyPrePhaseChecks

public void applyPrePhaseChecks(java.lang.String serverPath,
                                FileHandler ftpHandler,
                                java.lang.String localPath)
                         throws PhaseCheckException
Applies the pre-phase checks as defined in the physical section of the phase definition. Pre-phase checks are performed at the server.

Parameters:
serverPath - The complete path to the job folder. The path is assumed to be an FTP path.
ftpHandler - The FTP connection to the server.
localPath - The complete path to the job folder. The path is assumed to be a local path.
Throws:
PhaseCheckException - If the checks fails or couldn't be started.

applyPostPhaseChecks

public void applyPostPhaseChecks(java.lang.String localPath,
                                 FileHandler ftpHandler,
                                 java.lang.String serverPath)
                          throws PhaseCheckException
Applies the post-phase checks as defined in the physical section of the phase definition. Post-phase checks are performed at the local workstation.

Parameters:
localPath - The complete path to the job folder. The path is assumed to be a local path.
ftpHandler - The FTP connection to the server.
serverPath - The complete path to the job folder. The path is assumed to be an FTP path.
Throws:
PhaseCheckException - If the checks fails.

applyChecks

public void applyChecks(ActionContext context,
                        FileHandler fileHandler,
                        java.lang.String jobPath,
                        ActionContext alternateContext,
                        FileHandler alternateHandler,
                        java.lang.String alternatePath)
                 throws PhaseCheckException
Applies pre-phase or post-phase checks as defined in the physical section of the phase definition. Pre-phase checks are performed at the server. Post-phase checks are performed at the local workstation.

Parameters:
context - Whether it is Post-Phase or Pre-Phase.
fileHandler - The FileHandler used to check the job folder.
jobPath - The complete path to the job folder.
alternateContext - Whether it is Post-Phase or Pre-Phase.
alternateHandler - The alternate FileHandler used to check the job folder.
alternatePath - The complete alternate path to the job folder.
Throws:
PhaseCheckException - If the checks fails or couldn't be started.

applyPrePhaseActions

public void applyPrePhaseActions(Job job,
                                 FileHandler handler,
                                 java.lang.String source,
                                 java.lang.String destination)
                          throws PhaseActionException
Applies the pre-phase checks as defined in the physical, reflection and database sections of the phase definition.

Parameters:
job - The job to which actions are being applied.
handler - The FTP connection to the server.
source - The folder at which the job folder exists.
destination - The folder to which the folder will be copied.
Throws:
PhaseActionException - If the actions fails or couldn't be started.

applyPostPhaseActions

public void applyPostPhaseActions(Job job,
                                  FileHandler handler,
                                  java.lang.String source,
                                  java.lang.String destination)
                           throws PhaseActionException
Applies the post-phase checks as defined in the physical, reflection and database sections of the phase definition.

Parameters:
job - The job to which actions are being applied.
handler - The FTP connection to the server.
source - The folder at which the job folder exists.
destination - The folder to which the folder will be copied.
Throws:
PhaseActionException - If the checks fails.

applyActions

public void applyActions(ActionContext context,
                         Job job,
                         FileHandler handler,
                         java.lang.String source,
                         java.lang.String destination)
                  throws PhaseActionException
Applies the pre-phase or post-phase actions as defined in the physical, reflection and database sections of the phase definition. The oputput of each phase is stored for further handling.

Parameters:
context - Whether it is a pre-phase or post-phase.
job - The job to which actions are being applied.
handler - The FTP connection to the server.
source - The folder at which the job folder exists.
destination - The folder to which the folder will be copied.
Throws:
PhaseActionException - If the actions fails or couldn't be started.

getUserData

public org.w3c.dom.Node getUserData()
Gets the user data that he entered in response for the DatabaseAction.
Caution: Don't call this method before applying the phase actions. Failing to adhere to this rule will lead to unexpected results.

Returns:
A Node holding the user data.

getNoOfFiles

public int getNoOfFiles()
Gets the number of files uploaded to the server after applying the PhysicalAction.
Caution: Don't call this method before applying the phase actions. Failing to adhere to this rule will lead to unexpected results.

Returns:
The number of files uploaded to the server.

getSemiPhaseDef

private SemiPhaseDef getSemiPhaseDef(ActionContext context)
                              throws PhaseDefinitionException
Gets the SemiPhaseDef of the phase xml description.

Parameters:
context - Determines whether to get prePhase or postPhase definition.
Returns:
The SemiPhaseDef that corresponds to the given context.
Throws:
PhaseDefinitionException - If the phase xml description couldn't be parsed.

getLastFinishedDatabaseInfo

private DatabaseInfoDef getLastFinishedDatabaseInfo(Job job)
Gets the phase last finished information.
This method logs any error that might occur as warnings.

Parameters:
job - The job that might have been finished in this pahse.
Returns:
A DatabaseInfoDef that holds the database section of the status data.
Null is returned if the TransactionLog entry couldn't be obtained or couldn't be parsed

getStartDatabaseInfo

private DatabaseInfoDef getStartDatabaseInfo(Job job)
Gets the phase last finished information.
This method logs any error that might occur as warnings.

Parameters:
job - The job that might have been finished in this pahse.
Returns:
A DatabaseInfoDef that holds the database section of the status data.
Null is returned if the TransactionLog entry couldn't be obtained or couldn't be parsed

toString

public java.lang.String toString()
Returns the string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
The string representation of this object.