#!/bin/bash

######################### CONFIG OPTIONS ############################
INFO_GEW="/vol1/projects/Geospatial/flys-3.0/testdaten/saar.gew"
BACKEND_USER="flys28"
BACKEND_PASS="flys28"
BACKEND_HOST="czech-republic.atlas.intevation.de"
BACKEND_PORT="1521"
BACKEND_NAME="XE"
LOG4J_CONFIG="conf/log4j.properties"
#####################################################################


########################## Oracle Settings ##########################
BACKEND_DB_PREFIX="jdbc:oracle:thin:@"
BACKEND_DB_DRIVER="oracle.jdbc.OracleDriver"
BACKEND_DB_DIALECT="org.hibernate.dialect.OracleDialect"
BACKEND_URL=$BACKEND_DB_PREFIX//$BACKEND_HOST:$BACKEND_PORT/$BACKEND_NAME
#####################################################################


######################## Custom Importer Settings ###################
IMPORTER_DRY_RUN=false
IMPORTER_MAINVALUE_TYPES=QWTD
IMPORTER_ANNOTATION_TYPES="conf/annotation-types.xml"

IMPORTER_SKIP_GAUGES=false
IMPORTER_SKIP_HISTORICAL_DISCHARGE_GAUGES=false
IMPORTER_SKIP_BWASTR=false
IMPORTER_SKIP_ANNOTATIONS=false
IMPORTER_SKIP_WST=false
IMPORTER_SKIP_PRFS=false
IMPORTER_SKIP_DA50S=false
IMPORTER_SKIP_DA66S=false
IMPORTER_SKIP_W80S=false
IMPORTER_SKIP_HYKS=false
IMPORTER_SKIP_EXTRA_WST=false
IMPORTER_SKIP_FIXATIONS=false
IMPORTER_SKIP_OFFICIAL_LINES=false
IMPORTER_SKIP_FLOOD_WATER=false
IMPORTER_SKIP_FLOOD_PROTECTION=false

IMPORTER_SKIP_BED_HEIGHT_SINGLE=false
IMPORTER_SKIP_BED_HEIGHT_EPOCH=false
IMPORTER_SKIP_SEDIMENT_DENSITY=false
IMPORTER_SKIP_MORPHOLOGICAL_WIDTH=false
IMPORTER_SKIP_FLOW_VELOCITY=false
IMPORTER_SKIP_SEDIMENT_YIELD=false
IMPORTER_SKIP_WATERLEVELS=false
IMPORTER_SKIP_WATERLEVEL_DIFFERENCES=false
IMPORTER_SKIP_SQ_RELATION=false
#####################################################################

#MIN_MEMORY="8192m"
MIN_MEMORY="1024m"


########################## Importer Settings ########################
APP="de.intevation.flys.importer.Importer"
DIR=`dirname $0`
DIR=`readlink -f "$DIR/.."`
#####################################################################


########################## Collect required libraries ###############
CLASSPATH=
for l in `find "$DIR/lib" -name \*.jar -print`; do
   CLASSPATH=$CLASSPATH:$l
done

export CLASSPATH
#####################################################################


######################### Run Importer ##############################
exec java \
    -Xmx$MIN_MEMORY \
    -server \
    -Dlog4j.configuration=file://`readlink -f $LOG4J_CONFIG` \
    -Dflys.backend.importer.infogew.file=$INFO_GEW \
    -Dflys.backend.main.value.types=$IMPORTER_MAINVALUE_TYPES \
    -Dflys.backend.importer.annotation.types=$IMPORTER_ANNOTATION_TYPES \
    -Dflys.backend.importer.dry.run=$IMPORTER_DRY_RUN \
    -Dflys.backend.importer.skip.historical.discharge.tables=$IMPORTER_SKIP_HISTORICAL_DISCHARGE_GAUGES \
    -Dflys.backend.importer.skip.bwastr=$IMPORTER_SKIP_BWASTR \
    -Dflys.backend.importer.skip.gauges=$IMPORTER_SKIP_GAUGES \
    -Dflys.backend.importer.skip.annotations=$IMPORTER_SKIP_ANNOTATIONS \
    -Dflys.backend.importer.skip.prfs=$IMPORTER_SKIP_PRFS \
    -Dflys.backend.importer.skip.w80s=$IMPORTER_SKIP_W80S \
    -Dflys.backend.importer.skip.da50s=$IMPORTER_SKIP_DA50S \
    -Dflys.backend.importer.skip.da66s=$IMPORTER_SKIP_DA66S \
    -Dflys.backend.importer.skip.hyks=$IMPORTER_SKIP_HYKS \
    -Dflys.backend.importer.skip.wst=$IMPORTER_SKIP_WST \
    -Dflys.backend.importer.skip.extra.wsts=$IMPORTER_SKIP_EXTRA_WST \
    -Dflys.backend.importer.skip.fixations=$IMPORTER_SKIP_FIXATIONS \
    -Dflys.backend.importer.skip.official.lines=$IMPORTER_SKIP_OFFICIAL_LINES \
    -Dflys.backend.importer.skip.flood.water=$IMPORTER_SKIP_FLOOD_WATER \
    -Dflys.backend.importer.skip.flood.protection=$IMPORTER_SKIP_FLOOD_PROTECTION \
    -Dflys.backend.importer.skip.bed.height.single=$IMPORTER_SKIP_BED_HEIGHT_SINGLE \
    -Dflys.backend.importer.skip.bed.height.epoch=$IMPORTER_SKIP_BED_HEIGHT_EPOCH \
    -Dflys.backend.importer.skip.sediment.density=$IMPORTER_SKIP_SEDIMENT_DENSITY \
    -Dflys.backend.importer.skip.morphological.width=$IMPORTER_SKIP_MORPHOLOGICAL_WIDTH \
    -Dflys.backend.importer.skip.flow.velocity=$IMPORTER_SKIP_FLOW_VELOCITY \
    -Dflys.backend.importer.skip.sediment.yield=$IMPORTER_SKIP_SEDIMENT_YIELD \
    -Dflys.backend.importer.skip.waterlevels=$IMPORTER_SKIP_WATERLEVELS \
    -Dflys.backend.importer.skip.waterlevel.differences=$IMPORTER_SKIP_WATERLEVEL_DIFFERENCES \
    -Dflys.backend.importer.skip.sq.relation=$IMPORTER_SKIP_SQ_RELATION \
    -Dflys.backend.user=$BACKEND_USER \
    -Dflys.backend.password=$BACKEND_PASS \
    -Dflys.backend.url=$BACKEND_URL \
    -Dflys.backend.driver=$BACKEND_DB_DRIVER \
    -Dflys.backend.dialect=$BACKEND_DB_DIALECT \
     $APP
