com.ptc.windchill.repairtools.multiplePrimaries
Class PrimaryFix

java.lang.Object
  extended bycom.ptc.windchill.repairtools.multiplePrimaries.PrimaryFix

public class PrimaryFix
extends Object

Utilities that are run from inside of wt.load.LoadFromFile to cleanup a data corruption issue where multiple primaries have been associated with one document. This can happen when the multipl iterations/versions of a document are created using the loader in 6.2.6 DSU 6 and 7.0 (before the general patch) or in customizations prior to that. A patch went into both 6.2.6 DSU 7 and the 7.0 general patch that should stop this condition from happening anymore, however existing customizations that have this problem and are not corrected could continue to create multiple primaries if they are not corrected.

The instructions for using this tool are in com.ptc.windchill.repairtools.multiplePrimaries.RunPrimaryFix. RunPrimaryFix bundles together and automates the methods in this class.

The load methods use a wt.load.StandardLoadService cache to cache document masters and file output writers to improve performance. This class and methods are only supported for the purpose defined in this javadoc, it will not be part the regular codebase in any release.

See Also:
StandardLoadService

Nested Class Summary
private  class PrimaryFix.DocIteration
          Used to record the information about one iteration of a document.
private  class PrimaryFix.FileEntry
          Record information about one file, used with DocIteration to record all of the information about one document.
 
Field Summary
private  HashMap allDocs
           
private static String DATA
           
private  StringBuffer deleteString
           
private static String EMPTY
           
private static String ERROR
           
private  boolean errorFlag
           
private static String PRIMARYFIX_CSVDELETEFILEOUTPUTSTREAM
           
private static String PRIMARYFIX_ERRORFILEOUTPUTSTREAM
           
private static String PRIMARYFIX_NICEFILEOUTPUTSTREAM
           
private static String PRIMARYFIX_OLDMASTER
           
private static ResourceBundle rb
          Resource bundle object for localizing message text
private static String RESOURCE
           
private  int size
           
static boolean VERBOSE
          Flag to control verbose debugging output during document loading.
 
Constructor Summary
(package private) PrimaryFix(int size)
           
 
Method Summary
private  void addDoc(WTDocument doc, WTDocumentMaster master)
          Creates a DocIteration instance for a document and populates the primary file entries for that document.
private  void addErrorDoc(WTDocument doc, WTDocumentMaster master, String check_message)
          Creates a DocIteration instance for a document and populates the error field for that document.
private  void appendDeleteString(StringBuffer delete_str)
           
static boolean cleanupPrimaries(Hashtable nv, Hashtable cmd_line, Vector return_objects)
          Analyzes one document and determines which primary files of that document are extras.
static boolean closeOutputFiles(Hashtable nv, Hashtable cmd_line, Vector return_objects)
          Use this method at the end of the file for cleanupPrimaries to close the output files.
static boolean deleteExtraPrimaries(Hashtable nv, Hashtable cmd_line, Vector return_objects)
          Reads in a csv file that has the oid of the document and the oids of the files split out for keeping and deleteing, and then deletes the files that in the delete list.
private  String getDeleteString()
           
private  boolean getErrorFlag()
           
private  int getSize()
           
private  Vector markDuplicates(PrimaryFix.DocIteration docIter, Vector primaries)
          Loop through the documents file information and mark the files that have been seen before.
static boolean openOutputFiles(Hashtable nv, Hashtable cmd_line, Vector return_objects)
          Use this method at the begining of the file for cleanupPrimaries to open up the output files.
private  void outputDocuments()
          Output the documents and the information that we have gathered about their primary files.
private static String outputQuery(PrintWriter outputCsv, QueryResult qr, String csvMethod, String reportFirstLine)
          Output for new csv file from results.
private static PrimaryFix putIterationsInOrder(WTDocument doc, WTDocumentMaster master, PrimaryFix fix_set)
           
private static PrimaryFix putVersionsInOrder(WTDocumentMaster master, WTDocument doc)
           
private static int query(Iterated iteration)
           
private static String queryApplicationDataPrimaries(PrintWriter outputCsv, String reportFirstLine)
          Query for multiple primary files.
private static WTDocument queryDocument(String number, String oid)
          Get a document given it's oid.
private static String queryURLDataPrimaries(PrintWriter outputCsv, String reportFirstLine)
          Query for multiple primary URLs.
private  void removeDocs()
           
static boolean reportMultiplePrimaries(Hashtable nv, Hashtable cmd_line, Vector return_objects)
          Create report that replaces the manual sql query to generate the second set of reports.
private  void setErrorFlag()
           
private  void setSize(int size)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static String RESOURCE

rb

private static ResourceBundle rb
Resource bundle object for localizing message text


PRIMARYFIX_NICEFILEOUTPUTSTREAM

private static final String PRIMARYFIX_NICEFILEOUTPUTSTREAM
See Also:
Constant Field Values

PRIMARYFIX_ERRORFILEOUTPUTSTREAM

private static final String PRIMARYFIX_ERRORFILEOUTPUTSTREAM
See Also:
Constant Field Values

PRIMARYFIX_CSVDELETEFILEOUTPUTSTREAM

private static final String PRIMARYFIX_CSVDELETEFILEOUTPUTSTREAM
See Also:
Constant Field Values

PRIMARYFIX_OLDMASTER

private static final String PRIMARYFIX_OLDMASTER
See Also:
Constant Field Values

VERBOSE

public static boolean VERBOSE
Flag to control verbose debugging output during document loading. This constant is controlled via wt.properties file entry
wt.doc.load.verbose

The default value is false.


allDocs

private HashMap allDocs

size

private int size

errorFlag

private boolean errorFlag

deleteString

private StringBuffer deleteString

ERROR

private static String ERROR

EMPTY

private static String EMPTY

DATA

private static String DATA
Constructor Detail

PrimaryFix

PrimaryFix(int size)
Method Detail

setSize

private void setSize(int size)

getSize

private int getSize()

getErrorFlag

private boolean getErrorFlag()

setErrorFlag

private void setErrorFlag()

getDeleteString

private String getDeleteString()

appendDeleteString

private void appendDeleteString(StringBuffer delete_str)

addDoc

private void addDoc(WTDocument doc,
                    WTDocumentMaster master)
             throws WTException,
                    WTPropertyVetoException
Creates a DocIteration instance for a document and populates the primary file entries for that document. This instance along with the other version/iterations DocIteration instances of the document are used to figure out which primaries are extra.

Throws:
WTException
WTPropertyVetoException

addErrorDoc

private void addErrorDoc(WTDocument doc,
                         WTDocumentMaster master,
                         String check_message)
                  throws WTException
Creates a DocIteration instance for a document and populates the error field for that document. This instance along with the other version/iterations DocIteration instances of the document are output to the report file.

Throws:
WTException

removeDocs

private void removeDocs()

reportMultiplePrimaries

public static boolean reportMultiplePrimaries(Hashtable nv,
                                              Hashtable cmd_line,
                                              Vector return_objects)
Create report that replaces the manual sql query to generate the second set of reports.


queryApplicationDataPrimaries

private static String queryApplicationDataPrimaries(PrintWriter outputCsv,
                                                    String reportFirstLine)
Query for multiple primary files.


outputQuery

private static String outputQuery(PrintWriter outputCsv,
                                  QueryResult qr,
                                  String csvMethod,
                                  String reportFirstLine)
Output for new csv file from results.


queryURLDataPrimaries

private static String queryURLDataPrimaries(PrintWriter outputCsv,
                                            String reportFirstLine)
Query for multiple primary URLs.


cleanupPrimaries

public static boolean cleanupPrimaries(Hashtable nv,
                                       Hashtable cmd_line,
                                       Vector return_objects)
Analyzes one document and determines which primary files of that document are extras. Uses all iterations/versions of the document to determine that. Uses the PRIMARYFIX_OLDMASTER cache to determine if this document has already been analyzed. Uses PRIMARYFIX_NICEFILEOUTPUTSTREAM and PRIMARYFIX_CSVDELETEFILEOUTPUTSTREAM caches to output the information to files. Make sure that the input csv file has the following record at the beginning of the file to define the output files:

OpenOutputFiles,C:\Windchill\loadFiles\run.output,C:\Windchill\loadFiles\outputDelete.csv

And the following line at the end of the csv file to close the output files defined on the first line.

CloseOutputFiles

See the javadoc for this class for more explanation about these files and how to run this method.


putIterationsInOrder

private static PrimaryFix putIterationsInOrder(WTDocument doc,
                                               WTDocumentMaster master,
                                               PrimaryFix fix_set)
                                        throws WTException,
                                               WTPropertyVetoException,
                                               VersionControlException
Throws:
WTException
WTPropertyVetoException
VersionControlException

putVersionsInOrder

private static PrimaryFix putVersionsInOrder(WTDocumentMaster master,
                                             WTDocument doc)
                                      throws WTException,
                                             VersionControlException,
                                             WTPropertyVetoException
Throws:
WTException
VersionControlException
WTPropertyVetoException

query

private static int query(Iterated iteration)
                  throws WTException
Throws:
WTException

outputDocuments

private void outputDocuments()
                      throws WTException,
                             IOException,
                             WTPropertyVetoException
Output the documents and the information that we have gathered about their primary files.

Throws:
WTException
IOException
WTPropertyVetoException

markDuplicates

private Vector markDuplicates(PrimaryFix.DocIteration docIter,
                              Vector primaries)
                       throws WTPropertyVetoException,
                              WTException
Loop through the documents file information and mark the files that have been seen before.

Throws:
WTPropertyVetoException
WTException

queryDocument

private static WTDocument queryDocument(String number,
                                        String oid)
Get a document given it's oid. The number and version attributes are mainly to output messages if there are errors.


deleteExtraPrimaries

public static boolean deleteExtraPrimaries(Hashtable nv,
                                           Hashtable cmd_line,
                                           Vector return_objects)
Reads in a csv file that has the oid of the document and the oids of the files split out for keeping and deleteing, and then deletes the files that in the delete list. Used after cleanupPrimaries has already been run to determine which primary files of a document are extras and output into the csv file that is used to run this method. See the javadoc for this class for more explanation about how to create the file that runs this method.


openOutputFiles

public static boolean openOutputFiles(Hashtable nv,
                                      Hashtable cmd_line,
                                      Vector return_objects)
Use this method at the begining of the file for cleanupPrimaries to open up the output files. See the javadoc for this class for more information.

csvmapfile entry for this method: OpenOutputFiles~create~com.ptc.windchill.repairtools.multiplePrimaries.PrimaryFix.openOutputFile~infofilename~csvdeletefilename

Example csv file entry to call this method: OpenOutputFiles,C:\Temp\infooutput.html,C:\Temp\deleteprimaries.csv


closeOutputFiles

public static boolean closeOutputFiles(Hashtable nv,
                                       Hashtable cmd_line,
                                       Vector return_objects)
Use this method at the end of the file for cleanupPrimaries to close the output files. See the javadoc for this class for more information.

csvmapfile entry for this method: CloseOutputFiles~create~com.ptc.windchill.repairtools.multiplePrimaries.PrimaryFix.closeOutputFiles

Example csv file entry to call this method: CloseOutputFiles