rem ----------------------------------------------------------------------------
rem !! JT Export/Update TC !!
rem ----------------------------------------------------------------------------

setlocal
 call :JTgenSetEnvironBase
 call :JtTCUpdateGenList
 if exist "%ObjectList_SP_DPNE%" call :JtTCUpdateSp "%ObjectList_SP_DPNE%"
 if exist "%ObjectList_AP_DPNE%" call :JtTCUpdateAP "%ObjectList_AP_DPNE%"
 call :JtTCResultEval
endlocal
goto :eof

rem ----------------------------------------------------------------------------

:JtTCUpdateGenList

 set toRun=%JobManagerCmdTools_L%
 set toRun=%toRun% -Action "NxDataProcessing_2013_09"
 set toRun=%toRun% -SubAction "JTUpdateInputListGen"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 set toRun=%toRun% -ObjectList_SP_DPNE "%ObjectList_SP_DPNE%"
 set toRun=%toRun% -ObjectList_AP_DPNE "%ObjectList_AP_DPNE%"
 set toRun=%toRun% -JobData1ToProcessDoPrint

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
   set toRun=%toRun% -verbose -pauseOnEnd
   Echo #Debug.: befor: [%~0]
   set toRunForPrint=%toRun:"=%
   call Echo " %~0 toRun:%toRunForPrint% " "" "xxNOECHO"
   pause
:JumbOverDebug

 call %toRun%

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
   Echo #Debug.: after: [%~0]
   pause
:JumbOverDebug
goto :eof

rem ----------------------------------------------------------------------------
:JtTCResultEval

 REM 2. Jt Log File Evaluation
 set LogFilesDir=%tmp%
 set toRun=%JobManagerCmdTools_L%
 set toRun=%toRun% -Action "NxDataProcessing_2013_09"
 set toRun=%toRun% -SubAction "JTUpdateLogFileEval"
 set toRun=%toRun% -JobRoot_DP "%CmdCurRoot_DP%"
 set toRun=%toRun% -LogFilesDir "%LogFilesDir%"
 set toRun=%toRun% -JobData2ResultsDoPrint

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
   set toRun=%toRun% -verbose -pauseOnEnd
   Echo #Debug.: befor: [%~0]
   set toRunForPrint=%toRun:"=%
   call Echo " %~0 toRun:%toRunForPrint% " "" "xxNOECHO"
   pause
:JumbOverDebug

 call %toRun%

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
   Echo #Debug.: after: [%~0]
   pause
:JumbOverDebug

goto :eof

rem ----------------------------------------------------------------------------
:JtTCUpdateSp
  set CurActionTitle=JtTCUpdate[SP]
  set JtTCUpdateList_DPNE=%~1

  rem call set custom Env for JtTCUpdate
  call NXDP02_CustomSetEnv.cmd "JtTCUpdateSp"

  rem
  call :JTgenSetEnvironJob JtTCUpdateSp

  set toRun="%UGII_BASE_DIR%\PVTRANS\ugtopv.exe"
  set toRun=%toRun% "%JtTCUpdateList_DPNE%"
  set toRun=%toRun% -noupdate
  set toRun=%toRun% -config="%tessConfig_DPNE%"
  set toRun=%toRun% -single_part
  set toRun=%toRun% -pim=yes -u=%JobMgr_TcUser% -g=%JobMgr_TcGroup%

  Echo tessConfig_DPNE .. : [%tessConfig_DPNE%]
  set >>"%temp%\zzEnvironBevorJtTCUpdateSp.txt"

 if /i "%JobMgr_Debug%" neq "ON" goto :JumbOverDebug
   Echo #Debug.: BEVOR: [%~0]
   set toRunForPrint=%toRun:"='%
   call Echo " %toRunForPrint%"
   pause
:JumbOverDebug

  rem Printausgabe
  Call Echo "%CurActionTitle% start JTTCUpdate"

  call %toRun% -p=%JobMgr_TcPw%

  rem Printausgabe
  Call Echo "%CurActionTitle% end"
 goto :eof

rem ----------------------------------------------------------------------------
:JTTCUpdateAP

   set JtTCUpdateList_DPNE=%~1
   set CurActionTitle=JTTCUpdate[AP]
   rem Printausgabe
   Call Echo  "%CurActionTitle% start"
   call :JTgenSetEnvironJob JTTCUpdateAP

   rem die Assembly Einzeln erstellen lassen da -honour_structure nur geht wenn der CLIName übergeben wird!
   FOR /F %%i in (%JtTCUpdateList_DPNE%) do call :JTTCUpdateAPRun "%%i"

   rem -- Auswerten der Logfiles --> check Results
   rem FOR /F "tokens=1,2,3,4 delims=;" %%i in (%ExportControlListNXMasterAp_DPNE%) do call :JTTCUpdateReportresults "%%i" "%%j" "%%k" "%%l" "AP"

   rem Printausgabe
   Call Echo  "%CurActionTitle% end"
 goto :eof
rem ---------------------------------------------------------------------------------
:JTTCUpdateAPRun
  setlocal
    set CliName=%1
    rem - ugtopv.exe .. toRun for TC NX zusammenstellen
    set tessConfig_DPNE=%CmdCurRoot_DP%\%tess_file%

    set toRun="%UGII_BASE_DIR%\PVTRANS\ugtopv.exe" -pim=yes -u=%TceUser% -p=%TceUserPassword%

    set JobParameter=%CliName%
    set JobParameter=%JobParameter% -noupdate
    set JobParameter=%JobParameter% -config="%tessConfig_DPNE%"
    set JobParameter=%JobParameter% -honour_structure
    rem command vollständig zusammensetzen
    set toRun=%toRun% %JobParameter%


    rem for /d %%i in (%toRun%) do Echo ToRun: %%i
    rem -- start JT GEN --
    %toRun%
  endlocal
 goto :eof

rem ----------------------------------------------------------------------------
:JTgenSetEnvironBase
  set ObjectList_SP_DPNE=%CmdCurRoot_DP%\JtTCUpdateSp\InputList_SP.txt
  set ObjectList_AP_DPNE=%CmdCurRoot_DP%\JtTCUpdateSp\InputList_AP.txt
 goto :eof
rem ----------------------------------------------------------------------------
:JTgenSetEnvironJob
  rem -- setz fuer alle JTgen Vorgaenge die Umgebung ein

  rem #Step: temp dir Organiesieren
  set Job_PP=%~1
  set temp=%CmdCurRoot_DP%\%Job_PP%
  if not exist "%temp%" md "%temp%"
  cd /D "%temp%"

  set tmp=%temp%
  set JobTemp=%temp%
  set UGII_TMP_DIR=%temp%
  set UGII_KEEP_SYSTEM_LOG=TRUE
  set UGII_SMP_ENABLE=

  set TC_TMP_DIR=%temp%
  set TC_KEEP_SYSTEM_LOG=TRUE

  rem - ugtopv.exe .. toRun for TC NX zusammenstellen
  if not defined tessConfig_PPNE set tessConfig_PPNE=startup\tess_JTSp.config
  if not defined tessConfig_DPNE set tessConfig_DPNE=%CmdCurRoot_DP%\%tessConfig_PPNE%

goto :eof
