#!/bin/csh 
################################################################################
#
# routine: InteractiveIngResponse.csh 
#
# purpose: Script to run the java InteractiveIngestResponse task.
#
# modification history:
#
#   date    opr     who     reason
# -------- -----  --------  ----------------------------------------------------
# 06/30/04 51319  jschultz  initial version
# 10/22/09 63755  MSwam     support Java classpath wildcard
# 09/02/10 64432  MSwam     add DADS_CLASSPATH for MSSQL lib access
# 10/28/10 64432  Sherbert  UNDO hard-coded dbType
# 
################################################################################
#
#--------------
# set variables
#--------------
set OK = 0           #exit status for succcess
set NOTOK = 99       #exit status for error
set dbType = SYBASE  
set opustime = ( eval "date '+%Y%j%H%M%S'" )
echo "`${opustime}`-I-INFO-executable is $0 "

#-----------------------------------
# check number of cmd line arguments 
#-----------------------------------
if ( $#argv != 3 ) then
   echo ' ' 
   echo '  USAGE: InteractiveIngResponse <dataset name> <data id> <file input directory>' 
   echo ' '
   exit $NOTOK
endif

#-------------------------------------------------------
# make sure all needed environment variables are defined
#-------------------------------------------------------
set error = 0
if ( ! $?OPUS_CLASSPATH ) then
   echo ' '
   echo '    ERROR: OPUS_CLASSPATH enviroment variable must be defined'
   set error = 1
endif
if ( ! $?DADS_CLASSPATH ) then
   echo ' '
   echo '    ERROR: DADS_CLASSPATH enviroment variable must be defined'
   set error = 1
endif
if ( ! $?OPUS_SERVER ) then
   echo ' '
   echo '    ERROR: OPUS_SERVER enviroment variable must be defined'
   set error = 1
endif
#
if ( ! $?OPUS_DB ) then
   echo ' '
   echo '    ERROR: OPUS_DB enviroment variable must be defined'
   set error = 1
endif
#
if ( ! $?ARCH_SERVER ) then
   echo ' '
   echo '    ERROR: ARCH_SERVER enviroment variable must be defined'
   set error = 1
endif
#
if ( ! $?ARCH_DB ) then
   echo ' '
   echo '    ERROR: ARCH_DB enviroment variable must be defined'
   set error = 1
endif
#
if ( ! $?DB_TYPE ) then
   echo ' '
   echo '    ERROR: DB_TYPE enviroment variable must be defined'
   set error = 1
endif
#
if ($error == 1) then
   echo ' *** define the above variables in your opus_login.csh file'
   echo ' '  
   exit $NOTOK
endif

#-----------------------------------------------
# invoke the java InteractiveIngestResponse task
#-----------------------------------------------
eval java -classpath "`replace_javawildcard OPUS_CLASSPATH`":"`replace_javawildcard DADS_CLASSPATH`" INGRESPONSE.InteractiveIngestResponse -dsName $1 \
     -dataId $2 -dbType ${DB_TYPE} -oDbServ ${OPUS_SERVER} -oDbName ${OPUS_DB} \
     -aDbServ ${ARCH_SERVER} -aDbName ${ARCH_DB} -dsDir $3
     
#-----------------------------
# exit with appropriate status
#-----------------------------
if ($status != 0) then
   exit $NOTOK
endif
exit $OK
