com.ptc.windchill.upgrade.ius
Class UpgradeContext

java.lang.Object
  extended bycom.ptc.windchill.upgrade.ius.UpgradeContext
All Implemented Interfaces:
ConnectionProvider

public class UpgradeContext
extends Object
implements ConnectionProvider


Nested Class Summary
private  class UpgradeContext.SystemPropertyCop
          This thread will very frequently monitor the Properties object being used for System properties.
private  class UpgradeContext.SystemPropertyMonitor
          This class will monitory System.getProperties() for property adds, changes, and removes.
 
Field Summary
private static String ACCESS_CONTROL_PROPERTY_NAME
           
private static String ADD_CONSTRAINTS_DIR
           
private static String COMPARE_SCHEMA_DIR
           
private  String currentPhase_
           
private  boolean currentStepInProgress
           
private  boolean currentStepSuccessful
           
private  boolean firstUpgrade_
           
private  String indexDate_
           
private  InstallAndUpgradeHistory installAndUpgradeHistory_
           
private static UpgradeContext instance__
           
private static String JAR_FILE_NAME
           
private  UpgradeContextListener listener_
           
private  int num_of_phases_executed
           
private  File phasePath_
           
private  ReleaseId[] sourceVersions_
           
private  ArrayList steps_
           
private  ReleaseId[] targetVersions_
           
private  File tempJarFile_
           
private  boolean updateDirectivesInstalled_
           
private  UpdateStore updateStore_
           
private static String UPGRADE_SCHEMA_DIR
           
private  File upgradeDir_
           
private  File upgradePhasesDir_
           
private  HashMap upgradePhaseStores_
           
private  UpgradePhaseType upgradePhaseType_
           
private  HashMap upgradePhaseTypeHashMap_
           
private  HashMap upgradePhaseValues_
           
private  HashMap upgradePhaseValuesTrimmed_
           
private  HashMap upgradePhaseValuesTrimmedForReports_
           
private  File upgradeReportsDir_
           
private  UpgradeStep upgradeStep_
           
private  WTProperties wtProperties_
           
 
Constructor Summary
private UpgradeContext(String[] args)
          Initializes a UpgradeContext object.
 
Method Summary
 UpgradeStep advanceStep()
          Determines the next step, after the initial step is determined by currentStep().
private  String convertToValueOfEnumeratedTypeTrimmed(String instance)
          Converts the getDisplay() value with spaces to one without spaces this is needed for the folders that store the migrators and the reports.
private  void copyMissingToSystemProperties(Properties orig)
           
private  void copyWtToSystemProperties()
           
static void createInstance(String[] args)
          Create the context instance.
private  ReleaseId[] determineSourceVersions()
          The Source ReleaseId data is read from the database and may be multiple sorted entries.
private  void ensureCompletedInstallationExistsForSourceVersions(ReleaseId[] source_versions)
          Records the specified source version as complete in the install and upgrade history.
 String fileDateTS(Date generated_file_date)
          Date and Time Stamp format is chosen for adding to the report name
 String formattedHostPortSid()
          Obtain the database host:port:sid from db.properties.
 Connection getConnection()
          Created a connection to the database
 String getCurrentPhase()
           
 UpgradeStep getCurrentStep()
          upgradeStep_ is set to a value as soon as the UpgradeManager is started.
 String getDbServiceName()
           
 String getDbUser()
           
 InstallAndUpgradeHistory getInstallAndUpgradeHistory()
           
static UpgradeContext getInstance()
          Loads the instance_
 boolean getIsFirstUpgrade()
           
private  ReleaseId[] getLikelySourceVersions()
          Look up the most recent version step's version from the update history.
private  MethodContext getMethodContext()
           
 File getPhaseAddConstraintsPath()
           
 File getPhaseCompareSchemaPath()
           
 File getPhasePath()
           
 File getPhaseReportPath()
          Return a File for the directory WT_HOME/UpgradeReports/appropriate_step
 String getPhaseTrimmedString()
           
 File getPhaseUpgradeSchemaPath()
           
 String getPhaseValue(UpgradePhaseType verify_phase)
           
 PersistentObjectManager getPom()
           
 File getReportAddConstraintsPath()
           
 File getReportCompareSchemaPath()
           
 String getReportFolderTrimmed()
          Folder of the report for each step matches the new names of the step
 String getReportIndexDateTS()
           
 File getReportJarFile()
           
 File getReportPath()
           
 File getReportUpgradeSchemaPath()
           
 ReleaseId[] getSourceVersions()
          May return a null array.
 ArrayList getStepList()
           
 ReleaseId[] getTargetVersions()
          Retrieves the Windchill Version the user is upgrading to.
private  boolean getUpdateDirectivesInstalled()
           
 UpdateStore getUpdateStore()
          Retrieves the UpdateStore that was set in setUpgradeStore
 File getUpgradePath()
           
 File getUpgradePhasePath()
          phasePath_ is the path to folders of the UpgradePhases and the directories with migrators are located.
 UpgradePhaseType getUpgradePhaseType()
          A getter method
 Object[] getUpgradeStores()
          Called by the class ListIncrementalUpdates, to retrieve all the different directories used by the UpgradeManager.
private  WTProperties getWtProperties()
          returns wtProperties_ WTProperties
 void initializeInstallAndUpgradeHistory()
          Connects to the resource providing the install and upgrade history creating an initial version if necessary.
 void initializePhaseStores()
          Loads ALL the UpdateStores and places values in the variables: upgradePhaseValues_, upgradePhaseValuesTrimmed_, upgradePhaseStores_, upgradePhaseTypeHashMap_
 void initializeVersions()
          Initializes source and target versions.
 void installUpdateDirectives()
          The directive(s) for the upgradePhaseType_ is being loaded as needed.
 boolean isStepInProgress()
          Used by PhaseTitleSideBanner to determine if a step should be marked in progress or not
 boolean isStepSuccessful()
          Used by PhaseTitleSideBanner to determine if a step should be marked successful or not If false is returned the step will be marked as failed, if true is returned the step will be marked as successful.
private  void markPrecedingUpgradePhasesIncomplete()
          A failure occurred at step UpgradeStep.UPGRADE_SCHEMA or UpgradeStep.ADD_CONSTRAINTS, all the preceding steps that have phases associated with it should be marked incomplete.
 void markStepFailed()
          Notifies the UpgradeContextListener to mark the current step with the appropriate icon Failed.
 void markStepInProgress()
          Notifies the UpgradeContextListener to mark the current step with the appropriate icon InProgress.
 void markStepSuccessful()
          The step that was just completed was successful and is marked accordingly in the database and in the left-hand menu with the appropriate icon.
 void reset()
          This method is executed every time an User clicks the 'Restart' button.
 void resetServerVariables()
          Loads wtproperties, overrides a few property values, copies all properties to System properties, calls service method to init InfoEngine, then remerges any System properties back into system properties in case the InfoEngine code removed them with System.setProperties().
 void setDateFormatForReportIndex(Date start)
          sets the date that will be used in the Index.xsl file to format the index.html file
 void setStepList(ArrayList upg_steps)
          Steps to be listed on the left-hand side of the UpgradeManager.
 void settingValueOfIsFirstUpgrade()
           
 void setUpdateDirectivesInstalled(boolean installed)
          When a phase has been marked as completed, the directives needed have to be reset.
 void setUpgradeContextListener(UpgradeContextListener upg_listener)
          Sets an instance of UpgradeContextListener
(package private)  void setUpgradePhaseType(UpgradePhaseType phase_type)
           
 void setUpgradePhaseTypeByUpdateStore(UpdateStore current_store)
          upgradePhaseType_ needs to have a value other than null when using the UpgradeManager -listius option to determine the correct dtd file for the UpdateStore being loaded.
 void setUpgradeStore(UpgradePhaseType phase)
          Once the UpgradePhaseType has been determined the appropriate folder is loaded and the appropriate step is marked as in progress.
private  boolean sourceVersionsConsistentWithTargetVersions(ReleaseId[] source_versions)
          Checks that user is upgrading ProjectLink to ProjectLink or Windchill to a new Windchill release.
 void stepStatusNotifyChange(UpgradeStep step)
          This method is used by the PhaseTitleSideBanner class to reflect the steps status with the appropriate icon.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPARE_SCHEMA_DIR

private static final String COMPARE_SCHEMA_DIR
See Also:
Constant Field Values

UPGRADE_SCHEMA_DIR

private static final String UPGRADE_SCHEMA_DIR
See Also:
Constant Field Values

ADD_CONSTRAINTS_DIR

private static final String ADD_CONSTRAINTS_DIR
See Also:
Constant Field Values

JAR_FILE_NAME

private static final String JAR_FILE_NAME
See Also:
Constant Field Values

ACCESS_CONTROL_PROPERTY_NAME

private static final String ACCESS_CONTROL_PROPERTY_NAME
See Also:
Constant Field Values

instance__

private static UpgradeContext instance__

steps_

private ArrayList steps_

currentStepInProgress

private boolean currentStepInProgress

currentStepSuccessful

private boolean currentStepSuccessful

updateDirectivesInstalled_

private boolean updateDirectivesInstalled_

firstUpgrade_

private boolean firstUpgrade_

upgradeDir_

private File upgradeDir_

upgradePhasesDir_

private File upgradePhasesDir_

upgradeReportsDir_

private File upgradeReportsDir_

phasePath_

private File phasePath_

tempJarFile_

private File tempJarFile_

upgradePhaseStores_

private HashMap upgradePhaseStores_

upgradePhaseTypeHashMap_

private HashMap upgradePhaseTypeHashMap_

upgradePhaseValues_

private HashMap upgradePhaseValues_

upgradePhaseValuesTrimmed_

private HashMap upgradePhaseValuesTrimmed_

upgradePhaseValuesTrimmedForReports_

private HashMap upgradePhaseValuesTrimmedForReports_

installAndUpgradeHistory_

private InstallAndUpgradeHistory installAndUpgradeHistory_

updateStore_

private UpdateStore updateStore_

upgradeStep_

private UpgradeStep upgradeStep_

listener_

private UpgradeContextListener listener_

upgradePhaseType_

private UpgradePhaseType upgradePhaseType_

currentPhase_

private String currentPhase_

indexDate_

private String indexDate_

num_of_phases_executed

private int num_of_phases_executed

targetVersions_

private ReleaseId[] targetVersions_

sourceVersions_

private ReleaseId[] sourceVersions_

wtProperties_

private WTProperties wtProperties_
Constructor Detail

UpgradeContext

private UpgradeContext(String[] args)
                throws UpgradeContextException
Initializes a UpgradeContext object.

Parameters:
args - String[] Command line arguments when the UpgradeManager is started.
Method Detail

setUpgradeContextListener

public void setUpgradeContextListener(UpgradeContextListener upg_listener)
Sets an instance of UpgradeContextListener

Parameters:
upg_listener - UpgradeContextListener

resetServerVariables

public void resetServerVariables()
                          throws UpgradeContextException
Loads wtproperties, overrides a few property values, copies all properties to System properties, calls service method to init InfoEngine, then remerges any System properties back into system properties in case the InfoEngine code removed them with System.setProperties().

Throws:
UpgradeContextException - It is thrown when having problems loading the wt.properties

copyWtToSystemProperties

private void copyWtToSystemProperties()

copyMissingToSystemProperties

private void copyMissingToSystemProperties(Properties orig)

setStepList

public void setStepList(ArrayList upg_steps)
Steps to be listed on the left-hand side of the UpgradeManager. It could be one or thirteen, it depends on if the user wants to do only CompareSchema or if they want to go through the whole upgrade process.


getStepList

public ArrayList getStepList()
Returns:
steps_ ArrayList of all the steps that need to be done.

getCurrentStep

public UpgradeStep getCurrentStep()
                           throws IUHException
upgradeStep_ is set to a value as soon as the UpgradeManager is started. So a visual can be displayed to the user as to what step is in progress and the screens for the appropriate step are determined correctly.

Returns:
upgradeStep_
Throws:
IUHException

createInstance

public static void createInstance(String[] args)
                           throws UpgradeContextException
Create the context instance. Creation is explicit to allow clients to pass in args which will also be passed to WTContext. Initialization methods must be explicitly called by clients before use.

Throws:
UpgradeContextException - if the context cannot be initialized for some reason
See Also:
initializeInstallAndUpgradeHistory(), initializeVersions()

getInstance

public static UpgradeContext getInstance()
Loads the instance_

Returns:
instance_ UpgradeContext
Throws:
IllegalStateException - when an instance of UpgradeContext has not been created before UpgradeContext.getInstance() is called.

initializeVersions

public void initializeVersions()
                        throws UpgradeContextException
Initializes source and target versions. Update history is implicitly initialized if not already done.

Throws:
UpgradeContextException

initializeInstallAndUpgradeHistory

public void initializeInstallAndUpgradeHistory()
                                        throws UpgradeContextException
Connects to the resource providing the install and upgrade history creating an initial version if necessary.

Throws:
UpgradeContextException

initializePhaseStores

public void initializePhaseStores()
Loads ALL the UpdateStores and places values in the variables: upgradePhaseValues_, upgradePhaseValuesTrimmed_, upgradePhaseStores_, upgradePhaseTypeHashMap_


convertToValueOfEnumeratedTypeTrimmed

private String convertToValueOfEnumeratedTypeTrimmed(String instance)
Converts the getDisplay() value with spaces to one without spaces this is needed for the folders that store the migrators and the reports.


installUpdateDirectives

public void installUpdateDirectives()
                             throws UpgradeContextException
The directive(s) for the upgradePhaseType_ is being loaded as needed.

Throws:
UpgradeContextException

setUpgradeStore

public final void setUpgradeStore(UpgradePhaseType phase)
                           throws IUHException
Once the UpgradePhaseType has been determined the appropriate folder is loaded and the appropriate step is marked as in progress.

Parameters:
phase - UpgradePhaseType
Throws:
IUHException - An error has been encountered when loading the UpdateStore

setUpgradePhaseType

final void setUpgradePhaseType(UpgradePhaseType phase_type)

getUpgradePhaseType

public UpgradePhaseType getUpgradePhaseType()
A getter method

Returns:
upgradePhaseType_ UpgradePhaseType

getUpgradePhasePath

public final File getUpgradePhasePath()
phasePath_ is the path to folders of the UpgradePhases and the directories with migrators are located.

Returns:
phasePath_ File

getUpgradeStores

public Object[] getUpgradeStores()
Called by the class ListIncrementalUpdates, to retrieve all the different directories used by the UpgradeManager.

Returns:
stores Object[]

getUpdateStore

public final UpdateStore getUpdateStore()
Retrieves the UpdateStore that was set in setUpgradeStore


getInstallAndUpgradeHistory

public final InstallAndUpgradeHistory getInstallAndUpgradeHistory()

getSourceVersions

public final ReleaseId[] getSourceVersions()
May return a null array. May return an empty array.


getTargetVersions

public final ReleaseId[] getTargetVersions()
Retrieves the Windchill Version the user is upgrading to.


getMethodContext

private MethodContext getMethodContext()
                                throws UnsupportedPDSException,
                                       UnknownHostException
Throws:
UnsupportedPDSException
UnknownHostException

getConnection

public final Connection getConnection()
                               throws Exception
Created a connection to the database

Specified by:
getConnection in interface ConnectionProvider
Throws:
Exception

getPom

public final PersistentObjectManager getPom()
                                     throws Exception
Throws:
Exception

getLikelySourceVersions

private ReleaseId[] getLikelySourceVersions()
                                     throws UpgradeContextException
Look up the most recent version step's version from the update history.

Returns:
May be null if the database table does not exist, or an empty array if database table is empty.
Throws:
UpgradeContextException

getDbServiceName

public String getDbServiceName()
Returns:
the service name of the database being upgraded.

getDbUser

public String getDbUser()
Returns:
the name of the database being upgraded.

reset

public void reset()
           throws IUHException
This method is executed every time an User clicks the 'Restart' button.

Throws:
IUHException

advanceStep

public UpgradeStep advanceStep()
                        throws IUHException
Determines the next step, after the initial step is determined by currentStep().

Returns:
upgradeStep_ UpgradeStep
Throws:
IUHException - If a problem is encountered when retrieving the InstallAndUpgradeHistory

markPrecedingUpgradePhasesIncomplete

private void markPrecedingUpgradePhasesIncomplete()
                                           throws IUHException
A failure occurred at step UpgradeStep.UPGRADE_SCHEMA or UpgradeStep.ADD_CONSTRAINTS, all the preceding steps that have phases associated with it should be marked incomplete. This is because there have been database changes.

Throws:
IUHException - If a problem is encountered when retrieving the InstallAndUpgradeHistory

markStepSuccessful

public void markStepSuccessful()
                        throws IUHException
The step that was just completed was successful and is marked accordingly in the database and in the left-hand menu with the appropriate icon.

Throws:
IUHException - If a problem is encountered when retrieving the InstallAndUpgradeHistory

markStepFailed

public void markStepFailed()
                    throws IUHException
Notifies the UpgradeContextListener to mark the current step with the appropriate icon Failed. If it failed at step UpgradeStep.UPGRADE_SCHEMA or UpgradeStep.ADD_CONSTRAINTS, all the preceding steps that have phases associated with it will be marked incomplete. This is because there have been database changes.

Throws:
IUHException - If a problem is encountered when retrieving the InstallAndUpgradeHistory

markStepInProgress

public void markStepInProgress()
                        throws IUHException
Notifies the UpgradeContextListener to mark the current step with the appropriate icon InProgress.

Throws:
IUHException - If a problem is encountered when retrieving the InstallAndUpgradeHistory

fileDateTS

public String fileDateTS(Date generated_file_date)
Date and Time Stamp format is chosen for adding to the report name

Parameters:
generated_file_date - Current date and time
Returns:
returns the date and time in the format specified in the method

formattedHostPortSid

public String formattedHostPortSid()
Obtain the database host:port:sid from db.properties.

Returns:
The host_port_sid without any ":" characters.

setDateFormatForReportIndex

public void setDateFormatForReportIndex(Date start)
sets the date that will be used in the Index.xsl file to format the index.html file


getReportIndexDateTS

public String getReportIndexDateTS()

getCurrentPhase

public String getCurrentPhase()
Returns:
currentPhase_ String value of upgradePhaseType_

setUpgradePhaseTypeByUpdateStore

public void setUpgradePhaseTypeByUpdateStore(UpdateStore current_store)
upgradePhaseType_ needs to have a value other than null when using the UpgradeManager -listius option to determine the correct dtd file for the UpdateStore being loaded.

Parameters:
current_store - UpdateStore

getPhaseValue

public String getPhaseValue(UpgradePhaseType verify_phase)
Returns:
could be null if a step without a corresponding UpgradePhaseType has been executed

getReportJarFile

public File getReportJarFile()
Returns:
the location for the UpgradeManagerOutputs.jar which is WT_HOME/Upgrade

ensureCompletedInstallationExistsForSourceVersions

private void ensureCompletedInstallationExistsForSourceVersions(ReleaseId[] source_versions)
Records the specified source version as complete in the install and upgrade history.

Throws:
WTRuntimeException - if an error occurs recording the version in the history

isStepInProgress

public boolean isStepInProgress()
Used by PhaseTitleSideBanner to determine if a step should be marked in progress or not

Returns:
currentStepInProgress

isStepSuccessful

public boolean isStepSuccessful()
Used by PhaseTitleSideBanner to determine if a step should be marked successful or not If false is returned the step will be marked as failed, if true is returned the step will be marked as successful.

Returns:
currentStepSuccessful boolean

determineSourceVersions

private ReleaseId[] determineSourceVersions()
                                     throws UpgradeContextException
The Source ReleaseId data is read from the database and may be multiple sorted entries.

Returns:
could be null if the database table does not exist, or an empty array if database table is empty.
Throws:
UpgradeContextException

sourceVersionsConsistentWithTargetVersions

private boolean sourceVersionsConsistentWithTargetVersions(ReleaseId[] source_versions)
Checks that user is upgrading ProjectLink to ProjectLink or Windchill to a new Windchill release. And that someone is not trying to upgrade Windchill to PDMLink.


stepStatusNotifyChange

public void stepStatusNotifyChange(UpgradeStep step)
This method is used by the PhaseTitleSideBanner class to reflect the steps status with the appropriate icon.


getWtProperties

private WTProperties getWtProperties()
returns wtProperties_ WTProperties


setUpdateDirectivesInstalled

public void setUpdateDirectivesInstalled(boolean installed)
When a phase has been marked as completed, the directives needed have to be reset. Therefore, the updateDirectivesInstalled_ is used to determine if directives need to be loaded.

Parameters:
installed - boolean

getUpdateDirectivesInstalled

private boolean getUpdateDirectivesInstalled()

getUpgradePath

public File getUpgradePath()
Returns:
A File for the directory WT_HOME/Upgrade

getPhasePath

public File getPhasePath()
Returns:
A File for the directory WT_HOME/Upgrade/UpgradePhases

getReportPath

public File getReportPath()
Returns:
A File for the directory WT_HOME/Upgrade/UpgradeReport

getPhaseCompareSchemaPath

public File getPhaseCompareSchemaPath()
Returns:
the path and folder of the CompareSchema under UpgradePhase

getPhaseUpgradeSchemaPath

public File getPhaseUpgradeSchemaPath()
Returns:
the path and folder of where the sql files for Upgrade Schema should be stored

getPhaseAddConstraintsPath

public File getPhaseAddConstraintsPath()
Returns:
the path and folder of where the sql files for Add Constraints should be stored

getReportCompareSchemaPath

public File getReportCompareSchemaPath()
Returns:
@return the path and folder of where the spool files for Compare Schema should be stored

getReportUpgradeSchemaPath

public File getReportUpgradeSchemaPath()
Returns:
the path and folder of where the spool files for Upgrade Schema should be stored

getReportAddConstraintsPath

public File getReportAddConstraintsPath()
Returns:
@return the path and folder of where the spool files for Add Constraints should be stored

getPhaseTrimmedString

public String getPhaseTrimmedString()
Returns:
could be null if a step without a corresponding UpgradePhaseType has been executed

getReportFolderTrimmed

public String getReportFolderTrimmed()
Folder of the report for each step matches the new names of the step

Returns:
folder name without spaces

getPhaseReportPath

public File getPhaseReportPath()
Return a File for the directory WT_HOME/UpgradeReports/appropriate_step

Returns:
could be null if a step without a corresponding UpgradePhaseType has been executed

settingValueOfIsFirstUpgrade

public void settingValueOfIsFirstUpgrade()
                                  throws IUHException
Throws:
IUHException

getIsFirstUpgrade

public boolean getIsFirstUpgrade()