HiRISE

HiRISE.HiCat.Utilities
Class HiCat_File_Verify

java.lang.Object
  extended by HiRISE.HiCat.Utilities.HiCat_File_Verify

public class HiCat_File_Verify
extends Object

A database file existence verifier. Many databases store pointers to filenames, but without some form of file verification, there is no way to tell if the file stored in the database actually exists. This class will perform this verification, and report missing files to standard out or a log file, if logging is enabled.

The main method of this class retrieves records from a database table containing an identification field and verifies the existance of the file stored in the pathname field. If the file does not exist, a line of output indicating the record containing the missing file is either written to the terminal or a log file (if logging is specified).

The permissions of a file are checked also to ensure that that the file is accessible (world read permission are set).

In addition, if a PATHNAMES_MAP group has been defined in the configuration file, this program can optionally convert the path stored in the database to the logical path defined in the the PATHNAMES_MAP group.

Configuration File

A PVL configuration file (default: DEFAULT_CONFIGURATION_FILE) should contain the connection parameters needed to establish a connection to the database.

In addition, the configuration file contains additional parameters that can for tuning what records get checked. Each database to be checked should have a GROUP = DATABASE_NAME grouping set up. This gouping can contain additional table level parameters that can be used to tune how a give table within the database is queried.

Version:
1.19
Author:
Rodney Heyd - UA/PIRL

Field Summary
 String Base_Pathname
          The base path used to check if the file path is already in logical form
 String Catalog
          The name of the catalog (database) to use to run the queries on.
static String DEFAULT_CONFIGURATION_FILENAME
          The name of the default configuration file.
static int EXIT_CONFIGURATION_ERROR
          Exit status: Configuration Error
static int EXIT_DATABASE_ERROR
          Exit status: Database Error
static int EXIT_FILE_PERMISSIONS_ERRORS
          Exit status: File permissions errors
static int EXIT_INVALID_COMMAND_LINE_SYNTAX
          Exit status: Invalid command line syntax
static int EXIT_MISSING_AND_PERMISSIONS
          Exit status: Missing files and permissions errors
static int EXIT_MISSING_FILES
          Exit status: Missing files.
static int EXIT_SUCCESS
          Exit status: Success
 Vector Field_List
          A vector of strings containing the name of the database record id column and the name of the file column.
 String File_Field
          The name of the column in the database table containing the file information.
static String ID
           
 PrintWriter Log
          An object to write logging information to.
static String Logfile_Base_Name
          The base log file name.
static String Logfile_extension
          The extension to be appended to the end of the log file name.
 Configuration Pathnames_Map
          A configuration containing a Pathnames_Map group that can be used to update file paths.
 String Record_Identifier
          The name of the identification column that should be used as a record identifier.
 String Table_Name
          The name of the table being operated on.
 Database The_Database
          The database object.
 
Constructor Summary
HiCat_File_Verify(Vector Files, Configuration Pathnames_Map, Database The_Database, String Table_Name, String Base_Pathname, Vector Field_List, PrintWriter Log)
          Construct a file verify and object and initialize all the resources required by the various methods.
 
Method Summary
 void Fix_Paths(boolean update)
          Set to true if paths that are not in a logical form should be converted to a logical form.
static void main(String[] arguments)
          Check filenames stored in a database for existance and convert the paths to logical paths if enabled.
 int Missing_Files()
          Get the number of missing files found.
 int Non_Logical_Paths()
          The number of paths not in logical form that were not updated.
 int Unreadable_Files()
          Get the number of unreadable files found.
 void Update_Path(String Id, File file)
          Update the path of a file stored in the database to a logical path.
 int Updated_Paths()
          The number of paths updated in the database.
static void Usage()
          Prints command line usage syntax.
 void Verify_Files()
          Verifies the existence of the files containted within the Files Vector created at the time of construction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ID

public static final String ID
See Also:
Constant Field Values

DEFAULT_CONFIGURATION_FILENAME

public static final String DEFAULT_CONFIGURATION_FILENAME
The name of the default configuration file.

See Also:
Constant Field Values

Logfile_Base_Name

public static final String Logfile_Base_Name
The base log file name. The path will be prepended to this value, and the date and .log extension will be appended to the end of this value.

See Also:
Constant Field Values

Logfile_extension

public static final String Logfile_extension
The extension to be appended to the end of the log file name.

See Also:
Constant Field Values

Base_Pathname

public String Base_Pathname
The base path used to check if the file path is already in logical form


Pathnames_Map

public Configuration Pathnames_Map
A configuration containing a Pathnames_Map group that can be used to update file paths.


Log

public PrintWriter Log
An object to write logging information to.


The_Database

public Database The_Database
The database object.


Field_List

public Vector Field_List
A vector of strings containing the name of the database record id column and the name of the file column. The first item in the vector should be the record identifier field, the second the file field.


Table_Name

public String Table_Name
The name of the table being operated on.


Record_Identifier

public String Record_Identifier
The name of the identification column that should be used as a record identifier.


File_Field

public String File_Field
The name of the column in the database table containing the file information.


Catalog

public String Catalog
The name of the catalog (database) to use to run the queries on.


EXIT_SUCCESS

public static final int EXIT_SUCCESS
Exit status: Success

See Also:
Constant Field Values

EXIT_MISSING_FILES

public static final int EXIT_MISSING_FILES
Exit status: Missing files.

See Also:
Constant Field Values

EXIT_FILE_PERMISSIONS_ERRORS

public static final int EXIT_FILE_PERMISSIONS_ERRORS
Exit status: File permissions errors

See Also:
Constant Field Values

EXIT_MISSING_AND_PERMISSIONS

public static final int EXIT_MISSING_AND_PERMISSIONS
Exit status: Missing files and permissions errors

See Also:
Constant Field Values

EXIT_CONFIGURATION_ERROR

public static final int EXIT_CONFIGURATION_ERROR
Exit status: Configuration Error

See Also:
Constant Field Values

EXIT_DATABASE_ERROR

public static final int EXIT_DATABASE_ERROR
Exit status: Database Error

See Also:
Constant Field Values

EXIT_INVALID_COMMAND_LINE_SYNTAX

public static final int EXIT_INVALID_COMMAND_LINE_SYNTAX
Exit status: Invalid command line syntax

See Also:
Constant Field Values
Constructor Detail

HiCat_File_Verify

public HiCat_File_Verify(Vector Files,
                         Configuration Pathnames_Map,
                         Database The_Database,
                         String Table_Name,
                         String Base_Pathname,
                         Vector Field_List,
                         PrintWriter Log)
                  throws SQLException
Construct a file verify and object and initialize all the resources required by the various methods.

Parameters:
Files - A vector containing a list of record Ids and filenames retrieved from a database. Each element of the vector should be another vector. The first element of the vector should the the record Id, the second element should be the file.
Pathnames_Map - A configuration containing a Pathnames_Map group to be used for mapping canonical paths to a logical paths.
The_Database - The database object the original files were retrieved from.
Table_Name - The name of the table containing the list of files.
Base_Pathname - The Base_Pathname used to determine if a file is already in logical form.
Field_List - a two element vector. The first element is the column name of the record identifier column, the second is the column name of the file column.
Log - - PrintWriter object to be used for logging.
Throws:
SQLException
Method Detail

Verify_Files

public void Verify_Files()
Verifies the existence of the files containted within the Files Vector created at the time of construction. This method performs two existence passes.

On the first pass, the entire list of input files are checked for existance, and to ensure that the paths stored in the database are in a logical form. If the Fix_Paths(boolean) method has set to true, then any paths found that are not in a logical form and can be matched to a logical path defined in the Configuration will have their paths stored in the database updated to the matching logical path.

On the second pass, any files that were found to be missing will be checked a second time. Only files missing on the first pass will be checked a second time. This second pass is required since it is possible that a file might have been moved during the time it took for the first pass to run. Only if a file comes up missing after both passes will it be logged as missing.

See Also:
Update_Path(String, File), File

Update_Path

public void Update_Path(String Id,
                        File file)
                 throws SQLException
Update the path of a file stored in the database to a logical path. The update only occurs if the Fix_Paths() method has been passed a boolean true argument first. Otherwise, the NonLogical_Paths counter is incremented everytime a non-logical path is seen.

Parameters:
Id - The record identifier to be used as a key for updating the proper record
file - The test file.
Throws:
SQLException - if a bad parameters is passed to the prepared statement.

Fix_Paths

public void Fix_Paths(boolean update)
Set to true if paths that are not in a logical form should be converted to a logical form.


Missing_Files

public int Missing_Files()
Get the number of missing files found.

Returns:
the number of missing files found after running the Verify_Files() method.

Unreadable_Files

public int Unreadable_Files()
Get the number of unreadable files found.

Returns:
the number of unreadable files found after running the Verify_Files() method.

Updated_Paths

public int Updated_Paths()
The number of paths updated in the database.

Returns:
the number of paths converted to logical paths after running the Verify_Files method. This will always be zero unless updates are enabled (the -Update command line option)
See Also:
Usage()

Non_Logical_Paths

public int Non_Logical_Paths()
The number of paths not in logical form that were not updated.

Returns:
the number of files found that are not in logical path form. This can be fixed using the -Update command line option.
See Also:
Usage()

main

public static void main(String[] arguments)
Check filenames stored in a database for existance and convert the paths to logical paths if enabled.

Command line syntax is described in the Usage() method.

Each file field of each record retrieved from the database will be checked for existance, if the file does not exist, notification will be sent to the controling terminal or a log file if logging is enabled.

Exit Status Values

0 - Success
1 - One or more missing files
2 - File permissions errors
3 - Both missing files and permissions errors found
4 - Configuration Error
5 - Database Error
6 - Invalid Command Line Syntax

Parameters:
arguments - Array of command line argument strings.

Usage

public static void Usage()
Prints command line usage syntax.

Usage: HiCat_File_Verify 
  Options -
    [-Configuration ] (default: HiCat_File_Verify.conf)
    [-Database ]
    [-Id ]
    [-File ]
    [-Log-to-file]
    [-Table ]
    [-Update] (update paths that are not in logical form, default: false)
    [-Where ]
    [-Help]


HiRISE

Copyright (C) Arizona Board of Regents on behalf of the Planetary Image Research Laboratory, Lunar and Planetary Laboratory at the University of Arizona