#!/bin/bash
#	Copyright 2007, IBM Corporation

#      fullIntegrityVerify.sh - Do master.sh, ghost items check, and bad blob reporting, 
#       for a given source catalog and all its associated collaboration areas catalogs.

#
# Usage 
#if [[ $# -lt 1 || $# -gt 2 ]]
#then
 #   echo "Usage "
 #   echo "fullIntegrityVerify.sh --code=<cmp code>"
 #   echo "to verify all the corruptions"
 #   echo "OR"
 #   echo "fullIntegrityVerify.sh --code=<cmp code> --report=<reporttype>"
 #   echo " where reporttype is basic or workflow or serialization"

  #  exit 0
#fi 

if [[ $# -lt 4 ]]
then
    echo "Usage "
    echo "fullIntegrityVerify.sh --code=<cmp code> --basic=<y/n> --wf=<y/n> --serialization=<y/n>"
    echo "For example to verify all the corruptions"
    echo "fullIntegrityVerify.sh --code=trigo --basic=y --wf=y --serialization=y"
    echo "To verify only serialization corruptions"
    echo "fullIntegrityVerify.sh --code=<cmp code> --basic=n --wf=n --serialization=y"

    exit 0
fi 

#Declare variable
CMPCODE=`echo $1 | cut -d "=" -f2`;export CMPCODE
RUNBASIC=`echo $2 | cut -d "=" -f2`;export RUNBASIC
RUNWF=`echo $3 | cut -d "=" -f2`;export RUNWF
RUNSER=`echo $4 | cut -d "=" -f2`;export RUNSER 

if [ ${CCD_DB} = "db2" ]
then
    ./fullIntegrityVerifyDb2.sh --code=$CMPCODE --basic=$RUNBASIC --wf=$RUNWF --serialization=$RUNSER
    exit 0
fi

curdir="`pwd`"
. ${TOP}/bin/get_params.sh
. ${TOP}/src/db/schema/util/set_db.sh --confirm_db=no

cd $curdir
#Declare variable
#CMPCODE=`echo $1 | cut -d "=" -f2`;export CMPCODE
#RUNBASIC=`echo $2 | cut -d "=" -f2`;export RUNBASIC
#RUNWF=`echo $3 | cut -d "=" -f2`;export RUNWF
#RUNSER=`echo $4 | cut -d "=" -f2`;export RUNSER 

echo "===================================================================================================================="
echo ">>>> STARTING FULL INTEGRITY CHECK;  DIRECTORY IS $curdir <<<<<<<<<<"
echo "===================================================================================================================="
echo " "
if [[ $RUNBASIC = 'y' ]]
then
        cd ../basic/oracle
        echo "==============================================="
        echo "NOW RUNNING BASIC INTEGRITY VERIFY.SH"
        echo "==============================================="
        echo $DB_USER_NAME
        CONNECTION=${DB_USER_NAME}/${DB_USR_PWD}@${DB_SERVICE_NAME}
        ./basic_integrity_verify.sh --code=$CMPCODE
       cd $curdir
# Redundant, but matches with analagous redundant line that will be produced in ghost items and bad blobs runs
        echo "==============================================="
        echo "DIRECTORY NOW IS `pwd`"
        echo "==============================================="

        # Be sure we're in original working directory
       echo "================================================"
       echo "DONE WITH BASIC INTEGRITY VERIFY.SH;  DIRECTORY NOW IS `pwd`"
   fi
   if [ $RUNWF = 'y' ]
   then
        cd workflow/oracle
        echo "==============================================="

        echo "NOW RUNNING WORKFLOW INTEGRITY CHECKS"
        echo "==============================================="

        ./workflow_integrity_verify.sh --code=$CMPCODE

        # Go back to original working directory
        cd $curdir
        echo "================================================"
        echo "DONE WITH WORKFLOW INTEGRITY ITEM CHECKS;  DIRECTORY NOW IS `pwd`"
        echo "================================================"
    fi
    if [ ${RUNSER} = 'y' ]
    then

        cd serialization/oracle
        echo "==============================================="
        echo "NOW RUNNING SERIALIZATION INTEGRITY CHECKS"
        echo "==============================================="
        echo $CMPCODE
        ./serialization_integrity_verify.sh --code=$CMPCODE 
        #./doreportbloball.sh --code=$CMPCODE

        # Go back to original working directory
        cd $curdir
        echo "================================================"
        echo "DONE WITH SERIALIZATION INTEGRITY CHECKS;  DIRECTORY NOW IS `pwd`"
        echo "================================================"
        echo " "
    fi
     

#ReportFile="${CtgID}`date |awk '{print "fullIntegrityVerify_"$2"_"$3"_"$6"_"$4}'|sed s/":"//g`.txt";export ReportFile
#ConsoleReportFile="${CtgID}`date |awk '{print "console_fullIntegrityVerify_"$2"_"$3"_"$6"_"$4}'|sed s/":"//g`.txt";export ConsoleReportFile
#
# initialize output file
#echo "" > ${ReportFile}
#
# Logging directory
#if [ "$TOP" ]
#then
#mkdir ${TOP}/logs  >>${ReportFile} 2>&1
#mkdir ${TOP}/logs/fullVerifyReports   >>${ReportFile} 2>&1
#else
#mkdir logs  >>${ReportFile} 2>&1
#mkdir logs/fullVerifyReports  >>${ReportFile} 2>&1
#fi 

# Run master.sh

curdir="`pwd`"

# get src connection descriptor
#cd masterAndCleanup



# Run dobadblob checks

# get src connection descriptor
#./doreportbloball.sh --code=$CMPCODE

# Go back to original working directory
echo " "
echo " "



# save logs to proper location
#if [ "$TOP" ]
#then
#mv ${ReportFile}  ${TOP}/logs/fullVerifyReports
#mv ${ConsoleReportFile}  ${TOP}/logs/fullVerifyReports
#else
#mv ${ReportFile}  logs/fullVerifyReports
#mv ${ConsoleReportFile}  logs/fullVerifyReports
#fi    >>${ReportFile} 2>&1


echo "===================================================================================================================="
echo ">>>> FINISHED FULL INTEGRITY CHECK; DIRETORY NOW IS `pwd` <<<<<<<<<<"
echo "===================================================================================================================="
echo " "



# done
exit $?

