Первый

This commit is contained in:
Igor I
2024-01-24 08:37:51 +06:00
commit 18d7a228f9
21 changed files with 2780 additions and 0 deletions

34
.gitignore vendored Normal file
View File

@ -0,0 +1,34 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
/out/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/

117
.mvn/wrapper/MavenWrapperDownloader.java vendored Normal file
View File

@ -0,0 +1,117 @@
/*
* Copyright 2007-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}

BIN
.mvn/wrapper/maven-wrapper.jar vendored Normal file

Binary file not shown.

2
.mvn/wrapper/maven-wrapper.properties vendored Normal file
View File

@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.2/apache-maven-3.8.2-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# ccalm_weather
Для обновления данных из картографических сервисов.

310
mvnw vendored Normal file
View File

@ -0,0 +1,310 @@
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
if [ -n "$MVNW_REPOURL" ]; then
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
else
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
fi
while IFS="=" read key value; do
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
esac
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if $cygwin; then
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
fi
if command -v wget > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
wget "$jarUrl" -O "$wrapperJarPath"
else
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
fi
elif command -v curl > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
curl -o "$wrapperJarPath" "$jarUrl" -f
else
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
# For Cygwin, switch paths to Windows format before running javac
if $cygwin; then
javaClass=`cygpath --path --windows "$javaClass"`
fi
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

182
mvnw.cmd vendored Normal file
View File

@ -0,0 +1,182 @@
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%

93
pom.xml Normal file
View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.ccalm</groupId>
<artifactId>weather</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>weather</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<start-class>org.ccalm.weather.WeatherApplication</start-class>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.gdal/gdal -->
<!--dependency>
<groupId>org.gdal</groupId>
<artifactId>gdal</artifactId>
<version>2.4.0</version>
<scope>system</scope>
<systemPath>O:/projects/_Libs/gdal-2.4.0.jar</systemPath>
</dependency-->
<!-- https://mvnrepository.com/artifact/edu.ucar/netcdfAll -->
<dependency>
<groupId>edu.ucar</groupId>
<artifactId>netcdfAll</artifactId>
<version>5.3.1</version>
<!-- Look: https://newbedev.com/how-to-include-system-dependencies-in-war-built-using-maven
<type>jar</type>
<scope>system</scope>
<systemPath>${basedir}/lib/netcdfAll-5.3.1.jar</systemPath>
-->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>install-external</id>
<phase>clean</phase>
<configuration>
<file>${basedir}/src/main/lib/netcdfAll-5.3.1.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>edu.ucar</groupId>
<artifactId>netcdfAll</artifactId>
<version>5.3.1</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,432 @@
package org.ccalm.weather;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.CacheControl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.ServletContextAware;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
//import main.DownloadFromHTTP;
import org.ccalm.weather.WeatherDownload;
import ucar.ma2.Array;
import ucar.nc2.Dimension;
import ucar.nc2.Variable;
import ucar.nc2.dataset.NetcdfDataset;
@Controller
public class AirTemperature implements ServletContextAware {
@Value("${custom.config.db_url}")
private String db_url;
@Value("${custom.config.db_login}")
private String db_login;
@Value("${custom.config.db_password}")
private String db_password;
@Value("${custom.config.data_dir}")
private String data_dir;
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SoilTmperature.class);
private ServletContext context;
//http://127.0.0.1:8080/AirTemperature
@RequestMapping(value = "/geodatalist/AirTemperature",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
@ResponseBody
public Object ajaxTamer(/*@RequestParam(required=true,name="forecast") String forecast,*/@RequestParam(required=false,name="date") String date) {
String forecast = "000";
String result="";
result+="Start!<br>";
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
File dir = new File(data_dir+"temp"+File.separator);
if (!dir.exists()) dir.mkdirs();
//response.getWriter().append("Served at: ").append(request.getContextPath());
Connection conn = null;
try{
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(db_url,db_login,db_password);
if(conn!=null)
{
logger.info("Connect is OK!");
result+="Connect is OK!<br>";
}else
{
logger.info("<br>Connect is ERROR<br>");
result+="Connect is ERROR!<br>";
}
}catch(Exception e)
{
logger.info("<br>Connect Exception:"+e.getMessage()+"<br>");
result+="Connect Exception:"+e.getMessage()+"<br>";
}
//Example request: http://ccalm.org/AirTemperature?date=20210531
//Example request: http://localhost:8080/AirTemperature?date=20210531
if(date==null || date.equals(""))
{
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
date=dateFormat.format(new Date()); //Date like as "20170327".
}
String time = "00"; //00 hours,06 hours,12 hours and 18 hours
String measurement = "TMP:2 m above ground";
//Build URL to download
String URL = "https://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs."+date+"/"+time+"/atmos/gfs.t"+time+"z.pgrb2.0p25.f"+forecast;
File f = new File(data_dir+"temp"+File.separator+"air_text.idx");
if(f.exists()) {
if (!f.delete()) {
System.out.println("Failed to delete the file \"air_text.idx\".");
}
}
WeatherDownload wd = new WeatherDownload();
if(wd.download(URL+".idx", data_dir+"temp"+File.separator+"air_text.idx", "0", ""))
{
result+="Download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"air_text.idx"+"<br>";
String strPos1="";
String strPos2="";
//Read file and find required line.
try {
BufferedReader br = new BufferedReader(new FileReader(data_dir+"temp"+File.separator+"air_text.idx"));
String line;
while ((line = br.readLine()) != null)
{
if (line.contains(measurement))
{
strPos1=line;
strPos2=br.readLine();
break;
}
}
br.close();
} catch (IOException ex) {
logger.info(ex.getMessage());
result+=ex.getMessage()+"<br>";
}
if(!strPos1.equals(""))
{
StringBuffer answer1=new StringBuffer(strPos1);
CutBeforeFirst(answer1,":");
String posStart = CutBeforeFirst(answer1,":");
StringBuffer answer2=new StringBuffer(strPos2);
CutBeforeFirst(answer2,":");
String posEnd = CutBeforeFirst(answer2,":");
if(posEnd==null || posEnd.equals("")) posEnd=""; else
{
posEnd=String.valueOf(Long.parseLong(posEnd)-1);
}
wd.download(URL, data_dir+"temp"+File.separator+"air_text.f000", String.valueOf(posStart), String.valueOf(posEnd));
}
}else
{
result+="Not download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"air_text.idx"+"<br>";
}
Array dataArrayLat=null;
Array dataArrayLon=null;
Array dataArrayTmp=null;
try {
// open netcdf/grib/grib2 file from argument
NetcdfDataset gid = NetcdfDataset.openDataset(data_dir+"temp"+File.separator+"air_text.f000");
//logger.info("Desc: " + gid.getDescription());
logger.info(gid.getDetailInfo());
//logger.info("Feature type: " + gid.getFeatureType().toString());
// get all grid tables in the file
List<Variable> variables = gid.getReferencedFile().getVariables();
for (int i = 0; i < variables.size(); i++)
{
String vName=variables.get(i).getName();
System.out.print(vName+" ");
if(vName.equals("reftime"))
{
logger.info("");
logger.info("Description = "+variables.get(i).getDescription());
logger.info("DimensionsString = "+variables.get(i).getDimensionsString());
logger.info("DataType = "+variables.get(i).getDataType());
logger.info("UnitsString = "+variables.get(i).getUnitsString()); //Hour since 2017-02-28T18:00:00Z
}
if(vName.equals("lon"))
{
dataArrayLon = variables.get(i).read();
}
if(vName.equals("lat"))
{
dataArrayLat = variables.get(i).read();
}
if(vName.equals("Temperature_height_above_ground"))
{
dataArrayTmp = variables.get(i).read();
}
}
logger.info("");
List<Dimension> dims = gid.getDimensions();
logger.info("dims.size() = " + dims.size());
Iterator<Dimension> dimIt = dims.iterator();
while( dimIt.hasNext()) {
Dimension dim = dimIt.next();
logger.info("Dim = " + dim);
logger.info("Dim name = "+dim.getName());
}
dimIt = null;
Statement st=null;
try {
st = conn.createStatement();
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
try {
st.executeUpdate("BEGIN TRANSACTION;");
} catch (SQLException ex) {
logger.info(ex.getMessage());
logger.info(ex.getMessage());
}
result+="Size="+dataArrayLat.getSize()+"<br>";
//Delete old data
System.out.println("Delete old data 1");
try {
String sql="delete from main.air_temperature where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
System.out.println("Delete old data 2");
try {
String sql="delete from main.air_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
int pos=0;
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
{
for(int nLon=0;nLon<dataArrayLon.getSize();nLon++)
{
//WGS84 Bounds: -180.0000, -90.0000, 180.0000, 90.0000
//Projected Bounds: -180.0000, -90.0000, 180.0000, 90.0000
double lon = dataArrayLon.getFloat(nLon);
if(lon>180) lon=lon-360;
double lat = dataArrayLat.getFloat(nLat);
if(lat>29 && lat<67 && lon>17 && lon<180) //Central Asia
{
if(!Float.isNaN(dataArrayTmp.getFloat(pos))) //On the water none temperatyre.
{
String country_id="";
ResultSet rs=null;
try {
String sql="select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1";
rs = st.executeQuery(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
if (rs != null) {
try {
if (rs.next())
country_id=rs.getString(1);
rs.close();
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
}
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
{
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
try {
String sql="insert into main.air_temperature(date,hours,val,geom,country_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+");";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
}
}
}
pos++;
}
}
//Cut data piece from big country of Russia
try {
String sql="update main.air_temperature w set country_id=null where country_id=7 and not ST_Contains(ST_SetSRID(ST_GeomFromText('POLYGON((10.00 66.00,10.00 40.00,179.00 40.00,179.00 66.00,10.00 66.00))'),4326),w.geom);";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
//Delete values where country_id is null
try {
String sql="delete from main.air_temperature where country_id is null;";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
try {
st.executeUpdate("END TRANSACTION;");
} catch (SQLException ex) {
logger.info(ex.getMessage());
logger.info(ex.getMessage());
}
gid.close();
} catch (IOException ex) {
//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
System.out.print("ERROR!");
}
try {conn.close();} catch (SQLException ex) {logger.info(ex.getMessage());}
result+="End!<br>";
return result;
}
//---------------------------------------------------------------------------
@Override
public void setServletContext(ServletContext context) {
this.context=context;
}
//---------------------------------------------------------------------------
public static String CutBeforeFirst(StringBuffer str,String ch)
{
int pos=str.indexOf(ch);
String result="";
if(pos==-1)
{
result.concat(str.toString());
str.delete(0,str.length());
}else
{
result=str.substring(0,pos);
str.delete(0,pos+1);
}
return result;
}
//---------------------------------------------------------------------------
//List of "Air temperature" dates from database in JSON
//@CacheControl(maxAge = 300)
@CrossOrigin
@RequestMapping(value = "/geodatalist/AirTemperatureDates",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
@ResponseBody
public Object ajaxAirDates(HttpServletResponse response) {
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
response.addHeader("Cache-Control", headerValue);
boolean error=false;
String result="";
Connection conn = null;
try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(db_url, db_login, db_password);
if (conn != null) {
logger.info("Connect is OK!");
} else {
error=true;
result="An error occurred while connecting to the database!";
}
} catch (Exception ex) {
logger.info(ex.getMessage());
error=true;
result="<br>SQLException: "+ex.getMessage()+"<br>";
}
if(!error)
{
Statement st;
try {
st = conn.createStatement();
String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,EXTRACT(DAY FROM CURRENT_DATE-date) as day FROM main.air_temperature group by date,hours order by date,hours;";
ResultSet rs = st.executeQuery(sql);
if(rs!=null)
{
boolean exists=false;
result="[";
while (rs.next())
{
exists=true;
try {
result+= "{\"num\":\""+rs.getString("day")+"\", \"hour\":\""+rs.getString("hour")+"\", \"date\":\""+rs.getString("date")+"\"},";
} catch( Exception ex )
{
}
}
if(exists) {
result=result.substring(0, result.length()-1);
result+="]";
}else {
result="[]";
}
}
st.close();
conn.close();
} catch (SQLException ex) {
result="<br>SQLException:"+ex.getMessage()+"<br>";
}
}
return result;
}
//---------------------------------------------------------------------------
}

View File

@ -0,0 +1,231 @@
package org.ccalm.weather;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import org.springframework.http.CacheControl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tctable.Tools;
import javax.servlet.http.HttpServletResponse;
/*
* Server buffer for map tiles.
*/
@Controller
public class GeoTIFFList {
//---------------------------------------------------------------------------
public String dayofyear2date( int day ) {
//int day=Integer.parseInt(sDay)+1;
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_YEAR, day);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String result=format.format(calendar.getTime());
return result;
}
//---------------------------------------------------------------------------
public int[] setUnique(int[] array) {
int[] noDuplicates = IntStream.of(array).distinct().toArray();
return noDuplicates;
}
//---------------------------------------------------------------------------
public int[] toIntarray(Object[] obj){
int length = obj.length;
int intArray[] = new int[length];
for(int i=0; i<length; i++){
intArray[i] = (int) obj[i];
}
return intArray;
}
//---------------------------------------------------------------------------
//List GeoTIFF files
@CrossOrigin
@RequestMapping(value = "/geodatalist/GeoTIFF",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
@ResponseBody
public Object geoTIFFData(HttpServletResponse response,@RequestParam(required=true,name="fn") String fn) {
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
response.addHeader("Cache-Control", headerValue);
String NDVIPath="/opt/tomcat/geoserver/ROOT/data/GeoTIFF/NDVI";
String NDWIPath="/opt/tomcat/geoserver/ROOT/data/GeoTIFF/NDWI";
String NDSIPath="/opt/tomcat/geoserver/ROOT/data/GeoTIFF/NDSI";
String SMAPPath="/opt/tomcat/geoserver/ROOT/data/GeoTIFF/SMAP";
String osName=System.getProperty("os.name");
if(osName.indexOf("Windows")>=0){
NDVIPath="O:\\temp\\CCALM\\NDVI";
NDWIPath="O:\\temp\\CCALM\\NDVI";
NDSIPath="O:\\temp\\CCALM\\NDVI";
SMAPPath="O:\\temp\\CCALM\\SMAP";
}
String result="";
if(fn.equals("ndvi_list")) {
List<Integer> arrlist = new ArrayList<Integer>();
String[] names;
File f = new File(NDVIPath);
names = f.list();
for (String name : names) {
if(Tools.afterLast(name,".").equals("json")){
String val=Tools.beforeFirst(name,".");
if(val.matches("\\d+")) {
arrlist.add(Integer.parseInt(val));
}
}
}
int[] data = setUnique(toIntarray(arrlist.toArray()));
Arrays.sort(data);
if(data.length>0) {
result="[";
for (int value : data){
result += "{\"num\":\""+ String.valueOf(value)+"\", \"date\":\""+dayofyear2date(value)+"\"},";
}
result=result.substring(0, result.length()-1);
result+=']';
}else {
result="[]";
}
}
if(fn.equals("ndwi_list")) {
List<Integer> arrlist = new ArrayList<Integer>();
File f = new File(NDWIPath);
String[] names = f.list();
for (String name : names) {
if(Tools.afterLast(name,".").equals("tiff")){
String val=Tools.beforeFirst(name,"_");
if(val.matches("\\d+")) {
arrlist.add(Integer.parseInt(val));
}else {
//Выбираю json с максимальным номером
int max=0;
File mf = new File(NDWIPath);
String[] mNames = mf.list();
for (String mName : mNames) {
String mVal=Tools.beforeFirst(mName,".");
if(mVal.matches("\\d+")) {
if(max<Integer.parseInt(mVal)) {
max=Integer.parseInt(mVal);
}
}
}
arrlist.add(max);
}
}
}
int[] data = setUnique(toIntarray(arrlist.toArray()));
Arrays.sort(data);
if(data.length>0) {
result="[";
for (int value : data){
result += "{\"num\":\""+ String.valueOf(value)+"\", \"date\":\""+dayofyear2date(value)+"\"},";
}
result=result.substring(0, result.length()-1);
result+=']';
}else {
result="[]";
}
}
if(fn.equals("ndsi_list")) {
List<Integer> arrlist = new ArrayList<Integer>();
File f = new File(NDSIPath);
String[] names = f.list();
for (String name : names) {
if(Tools.afterLast(name,".").equals("tiff")){
String val=Tools.beforeFirst(name,"_");
if(val.matches("\\d+")) {
arrlist.add(Integer.parseInt(val));
}else {
//Выбираю json с максимальным номером
int max=0;
File mf = new File(NDSIPath);
String[] mNames = mf.list();
for (String mName : mNames) {
String mVal=Tools.beforeFirst(mName,".");
if(mVal.matches("\\d+")) {
if(max<Integer.parseInt(mVal)) {
max=Integer.parseInt(mVal);
}
}
}
arrlist.add(max);
}
}
}
int[] data = setUnique(toIntarray(arrlist.toArray()));
Arrays.sort(data);
if(data.length>0) {
result="[";
for (int value : data){
result += "{\"num\":\""+ String.valueOf(value)+"\", \"date\":\""+dayofyear2date(value)+"\"},";
}
result=result.substring(0, result.length()-1);
result+=']';
}else {
result="[]";
}
}
if(fn.equals("smap_list")) {
List<Integer> arrlist = new ArrayList<Integer>();
File f = new File(SMAPPath);
String[] names = f.list();
for (String name : names) {
if(Tools.afterLast(name,".").equals("tiff")){
String val=Tools.beforeFirst(name,"_");
if(val.matches("\\d+")) {
arrlist.add(Integer.parseInt(val));
}else {
//Выбираю json с максимальным номером
int max=0;
File mf = new File(SMAPPath);
String[] mNames = mf.list();
for (String mName : mNames) {
String mVal=Tools.beforeFirst(mName,".");
if(mVal.matches("\\d+")) {
if(max<Integer.parseInt(mVal)) {
max=Integer.parseInt(mVal);
}
}
}
arrlist.add(max);
}
}
}
int[] data = setUnique(toIntarray(arrlist.toArray()));
Arrays.sort(data);
if(data.length>0) {
result="[";
for (int value : data){
result += "{\"num\":\""+ String.valueOf(value)+"\", \"date\":\""+dayofyear2date(value)+"\"},";
}
result=result.substring(0, result.length()-1);
result+=']';
}else {
result="[]";
}
}
return result;
}
}

View File

@ -0,0 +1,33 @@
package org.ccalm.weather;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MainController {
@CrossOrigin
@GetMapping("/")
@ResponseBody
public String getIndex(Model model) {
return "The weather list is working! <br><a href=\"./geodatalist/\">/geodatalist/</a>";
}
@CrossOrigin
@GetMapping("/geodatalist")
@ResponseBody
public String getGeoDataList(Model model) {
String html="";
html+="<a href=\"./AirTemperatureDates\">AirTemperatureDates</a><br><form action=\"./AirTemperature\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20210826\"><input type=\"submit\" value=\"Submit\"></form><br>";
html+="<a href=\"./PrecipitationDates\">PrecipitationDates</a><br><form action=\"./Precipitation\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20210826\"><input type=\"submit\" value=\"Submit\"></form><br>";
html+="<a href=\"./SoilDates\">SoilDates</a><br><form action=\"./DownloadSoil\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20210826\"><label for=\"forecast\">Forecast:</label><input type=\"text\" name=\"forecast\" value=\"000\"><input type=\"submit\" value=\"Submit\"></form><br>";
return html;
}
}

View File

@ -0,0 +1,433 @@
package org.ccalm.weather;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.CacheControl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.ServletContextAware;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
//import main.DownloadFromHTTP;
import org.ccalm.weather.WeatherDownload;
import ucar.ma2.Array;
import ucar.nc2.Dimension;
import ucar.nc2.Variable;
import ucar.nc2.dataset.NetcdfDataset;
@Controller
public class Precipitation implements ServletContextAware {
@Value("${custom.config.db_url}")
private String db_url;
@Value("${custom.config.db_login}")
private String db_login;
@Value("${custom.config.db_password}")
private String db_password;
@Value("${custom.config.data_dir}")
private String data_dir;
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SoilTmperature.class);
private ServletContext context;
//http://127.0.0.1:8080/AirTemperature
@RequestMapping(value = "/geodatalist/Precipitation",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
@ResponseBody
public Object ajaxTamer(HttpServletResponse response,@RequestParam(required=false,name="date") String date) {
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
response.addHeader("Cache-Control", headerValue);
String forecast = "024";
String result="Start!<br>";
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
File dir = new File(data_dir+"temp"+File.separator);
if (!dir.exists()) dir.mkdirs();
//response.getWriter().append("Served at: ").append(request.getContextPath());
Connection conn = null;
try{
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(db_url,db_login,db_password);
if(conn!=null)
{
logger.info("Connect is OK!");
result+="Connect is OK!<br>";
}else
{
logger.info("<br>Connect is ERROR<br>");
result+="Connect is ERROR!<br>";
}
}catch(Exception e)
{
logger.info("<br>Connect Exception:"+e.getMessage()+"<br>");
result+="Connect Exception:"+e.getMessage()+"<br>";
}
//Example request: http://localhost:8080/Precipitation?date=20210531
if(date==null || date.equals(""))
{
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
date=dateFormat.format(new Date()); //Date like as "20170327".
}
String time = "00"; //00 hours,06 hours,12 hours and 18 hours
String measurement = "APCP:surface:0-1 day acc fcst";
//Build URL to download
String URL = "https://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs."+date+"/"+time+"/atmos/gfs.t"+time+"z.pgrb2.0p25.f"+forecast;
File f = new File(data_dir+"temp"+File.separator+"pre_text.idx");
if(f.exists()) {
if (!f.delete()) {
System.out.println("Failed to delete the file \"pre_text.idx\".");
}
}
WeatherDownload wd = new WeatherDownload();
if(wd.download(URL+".idx", data_dir+"temp"+File.separator+"pre_text.idx", "0", ""))
{
result+="Download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"pre_text.idx"+"<br>";
System.out.println("Download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"pre_text.idx"+"<br>");
String strPos1="";
String strPos2="";
//Read file and find required line.
try {
BufferedReader br = new BufferedReader(new FileReader(data_dir+"temp"+File.separator+"pre_text.idx"));
String line;
while ((line = br.readLine()) != null)
{
if (line.contains(measurement))
{
strPos1=line;
strPos2=br.readLine();
break;
}
}
br.close();
} catch (IOException ex) {
logger.info(ex.getMessage());
result+=ex.getMessage()+"<br>";
}
if(!strPos1.equals(""))
{
StringBuffer answer1=new StringBuffer(strPos1);
CutBeforeFirst(answer1,":");
String posStart = CutBeforeFirst(answer1,":");
StringBuffer answer2=new StringBuffer(strPos2);
CutBeforeFirst(answer2,":");
String posEnd = CutBeforeFirst(answer2,":");
if(posEnd==null || posEnd.equals("")) posEnd=""; else
{
posEnd=String.valueOf(Long.parseLong(posEnd)-1);
}
wd.download(URL, data_dir+"temp"+File.separator+"pre_text.f000", String.valueOf(posStart), String.valueOf(posEnd));
}
}else
{
result+="Not download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"pre_text.idx"+"<br>";
}
Array dataArrayLat=null;
Array dataArrayLon=null;
Array dataArrayTmp=null;
try {
// open netcdf/grib/grib2 file from argument
NetcdfDataset gid = NetcdfDataset.openDataset(data_dir+"temp"+File.separator+"pre_text.f000");
//logger.info("Desc: " + gid.getDescription());
logger.info(gid.getDetailInfo());
//logger.info("Feature type: " + gid.getFeatureType().toString());
// get all grid tables in the file
List<Variable> variables = gid.getReferencedFile().getVariables();
for (int i = 0; i < variables.size(); i++)
{
String vName=variables.get(i).getName();
System.out.print(vName+" ");
if(vName.equals("reftime"))
{
logger.info("");
logger.info("Description = "+variables.get(i).getDescription());
logger.info("DimensionsString = "+variables.get(i).getDimensionsString());
logger.info("DataType = "+variables.get(i).getDataType());
logger.info("UnitsString = "+variables.get(i).getUnitsString()); //Hour since 2017-02-28T18:00:00Z
}
if(vName.equals("lon"))
{
dataArrayLon = variables.get(i).read();
}
if(vName.equals("lat"))
{
dataArrayLat = variables.get(i).read();
}
if(vName.equals("Total_precipitation_surface_24_Hour_Accumulation"))
{
dataArrayTmp = variables.get(i).read();
}
}
logger.info("");
List<Dimension> dims = gid.getDimensions();
logger.info("dims.size() = " + dims.size());
Iterator<Dimension> dimIt = dims.iterator();
while( dimIt.hasNext()) {
Dimension dim = dimIt.next();
logger.info("Dim = " + dim);
logger.info("Dim name = "+dim.getName());
}
dimIt = null;
Statement st=null;
try {
st = conn.createStatement();
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
try {
st.executeUpdate("BEGIN TRANSACTION;");
} catch (SQLException ex) {
logger.info(ex.getMessage());
logger.info(ex.getMessage());
}
result+="Size="+dataArrayLat.getSize()+"<br>";
//Delete old data
System.out.println("Delete old data 1");
try {
String sql="delete from main.precipitation where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
System.out.println("Delete old data 2");
try {
String sql="delete from main.precipitation where date<=CURRENT_DATE-'730 days'::INTERVAL";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
int pos=0;
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
{
for(int nLon=0;nLon<dataArrayLon.getSize();nLon++)
{
//WGS84 Bounds: -180.0000, -90.0000, 180.0000, 90.0000
//Projected Bounds: -180.0000, -90.0000, 180.0000, 90.0000
double lon = dataArrayLon.getFloat(nLon);
if(lon>180) lon=lon-360;
double lat = dataArrayLat.getFloat(nLat);
if(lat>29 && lat<67 && lon>17 && lon<180) //Central Asia
{
if(!Float.isNaN(dataArrayTmp.getFloat(pos))) //On the water none temperatyre.
{
String country_id="";
ResultSet rs=null;
try {
rs = st.executeQuery("select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1");
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
if (rs != null) {
try {
if (rs.next())
country_id=rs.getString(1);
rs.close();
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
}
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
{
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
try {
String sql="insert into main.precipitation(date,hours,val,geom,country_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+");";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
}
}
}
pos++;
}
}
//Cut data piece from big country of Russia
try {
String sql="update main.precipitation w set country_id=null where country_id=7 and not ST_Contains(ST_SetSRID(ST_GeomFromText('POLYGON((10.00 66.00,10.00 40.00,179.00 40.00,179.00 66.00,10.00 66.00))'),4326),w.geom);";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
//Delete values where country_id is null
try {
String sql="delete from main.precipitation where country_id is null;";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
try {
st.executeUpdate("END TRANSACTION;");
} catch (SQLException ex) {
logger.info(ex.getMessage());
logger.info(ex.getMessage());
}
gid.close();
} catch (IOException ex) {
//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
System.out.print("ERROR!");
}
try {conn.close();} catch (SQLException ex) {logger.info(ex.getMessage());}
result+="End!<br>";
return result;
}
//---------------------------------------------------------------------------
@Override
public void setServletContext(ServletContext context) {
this.context=context;
}
//---------------------------------------------------------------------------
public static String CutBeforeFirst(StringBuffer str,String ch)
{
int pos=str.indexOf(ch);
String result="";
if(pos==-1)
{
result.concat(str.toString());
str.delete(0,str.length());
}else
{
result=str.substring(0,pos);
str.delete(0,pos+1);
}
return result;
}
//---------------------------------------------------------------------------
//List of "Air temperature" dates from database in JSON
@CrossOrigin
@RequestMapping(value = "/geodatalist/PrecipitationDates",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
@ResponseBody
public Object ajaxAirDates(HttpServletResponse response) {
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
response.addHeader("Cache-Control", headerValue);
boolean error=false;
String result="";
//Load DB configuration from "config.xml"
Connection conn = null;
try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(db_url, db_login, db_password);
if (conn != null) {
logger.info("Connect is OK!");
} else {
error=true;
result="An error occurred while connecting to the database!";
}
} catch (Exception ex) {
logger.info(ex.getMessage());
error=true;
result="<br>SQLException: "+ex.getMessage()+"<br>";
}
if(!error)
{
Statement st;
try {
st = conn.createStatement();
String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,DATE_PART('doy',date)-1 as day FROM main.precipitation group by date,hours order by date,hours";
ResultSet rs = st.executeQuery(sql);
if(rs!=null)
{
boolean exists=false;
result="[";
while (rs.next())
{
exists=true;
try {
result+= "{\"num\":\""+rs.getString("day")+"\", \"hour\":\""+rs.getString("hour")+"\", \"date\":\""+rs.getString("date")+"\"},";
} catch( Exception ex )
{
}
}
if(exists) {
result=result.substring(0, result.length()-1);
result+="]";
}else {
result="[]";
}
}
st.close();
conn.close();
} catch (SQLException ex) {
result="<br>SQLException:"+ex.getMessage()+"<br>";
}
}
return result;
}
//---------------------------------------------------------------------------
}

View File

@ -0,0 +1,458 @@
package org.ccalm.weather;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.CacheControl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.ServletContextAware;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
//import main.DownloadFromHTTP;
import org.ccalm.weather.WeatherDownload;
import ucar.ma2.Array;
import ucar.nc2.Dimension;
import ucar.nc2.Variable;
import ucar.nc2.dataset.NetcdfDataset;
@Controller
public class SoilTmperature implements ServletContextAware {
@Value("${custom.config.db_url}")
private String db_url;
@Value("${custom.config.db_login}")
private String db_login;
@Value("${custom.config.db_password}")
private String db_password;
@Value("${custom.config.data_dir}")
private String data_dir;
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SoilTmperature.class);
private ServletContext context;
//Example: http://127.0.0.1:8081/geodatalist/DownloadSoil?forecast=000
@RequestMapping(value = "/geodatalist/DownloadSoil",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
@ResponseBody
public Object ajaxTamer(HttpServletResponse response,@RequestParam(required=true,name="forecast") String forecast,@RequestParam(required=false,name="date") String date) {
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
response.addHeader("Cache-Control", headerValue);
//String forecast = request.getParameter("forecast"); //Date like as "000".
//response.setContentType("text/html");
//PrintWriter out = response.getWriter();
String result="";
result+="Start!<br>";
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
File dir = new File(data_dir+"temp"+File.separator);
if (!dir.exists()) dir.mkdirs();
//response.getWriter().append("Served at: ").append(request.getContextPath());
Connection conn = null;
try{
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(db_url,db_login,db_password);
if(conn!=null)
{
logger.info("Connect is OK!");
result+="Connect is OK!<br>";
}else
{
logger.info("<br>Connect is ERROR<br>");
result+="Connect is ERROR!<br>";
}
}catch(Exception e)
{
logger.info("<br>Connect Exception:"+e.getMessage()+"<br>");
result+="Connect Exception:"+e.getMessage()+"<br>";
}
//Example request: http://ccalm.org/DownloadWeather?forecast=000&date=20210531
//Example request: http://localhost:8080/CCALM/DownloadWeather?forecast=000
//Example request: http://127.0.0.1:8080/CCALM/DownloadWeather?forecast=000
if(date==null || date.equals(""))
{
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
date=dateFormat.format(new Date()); //Date like as "20170327".
}
//Parameter Table Version 2: https://www.nco.ncep.noaa.gov/pmb/docs/on388/table2.html
String time = "00"; //00 hours,06 hours,12 hours and 18 hours
//String forecast = request.getParameter("forecast"); //Date like as "000".
String measurement = "TSOIL:0-0.1 m below ground";
//String measurement = "TSOIL:0.1-0.4 m below ground";
//Build URL to download
String URL = "https://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs."+date+"/"+time+"/atmos/gfs.t"+time+"z.pgrb2.0p25.f"+forecast;
File f = new File(data_dir+"temp"+File.separator+"text.idx");
if(f.exists()) {
if (!f.delete()) {
System.out.println("Failed to delete the file \"text.idx\".");
}
}
WeatherDownload wd = new WeatherDownload();
if(wd.download(URL+".idx", data_dir+"temp"+File.separator+"text.idx", "0", ""))
{
result+="Download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"text.idx"+"<br>";
String strPos1="";
String strPos2="";
//Read file and find required line.
try {
BufferedReader br = new BufferedReader(new FileReader(data_dir+"temp"+File.separator+"text.idx"));
String line;
while ((line = br.readLine()) != null)
{
//if (line.contains("TSOIL:0-0.1 m below ground"))
if (line.contains(measurement))
{
strPos1=line;
strPos2=br.readLine();
break;
}
}
br.close();
} catch (IOException ex) {
logger.info(ex.getMessage());
result+=ex.getMessage()+"<br>";
}
if(!strPos1.equals(""))
{
//String strPos1 = "250:146339365:d=2017022818:TSOIL:0-0.1 m below ground:anl:"
StringBuffer answer1=new StringBuffer(strPos1);
CutBeforeFirst(answer1,":");
String posStart = CutBeforeFirst(answer1,":");
StringBuffer answer2=new StringBuffer(strPos2);
CutBeforeFirst(answer2,":");
String posEnd = CutBeforeFirst(answer2,":");
if(posEnd==null || posEnd.equals("")) posEnd=""; else
{
posEnd=String.valueOf(Long.parseLong(posEnd)-1);
}
wd.download(URL, data_dir+"temp"+File.separator+"text.f000", String.valueOf(posStart), String.valueOf(posEnd));
}
}else
{
result+="Not download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"text.idx"+"<br>";
}
Array dataArrayLat=null;
Array dataArrayLon=null;
Array dataArrayTmp=null;
try {
// open netcdf/grib/grib2 file from argument
NetcdfDataset gid = NetcdfDataset.openDataset(data_dir+"temp"+File.separator+"text.f000");
//logger.info("Desc: " + gid.getDescription());
logger.info(gid.getDetailInfo());
//logger.info("Feature type: " + gid.getFeatureType().toString());
// get all grid tables in the file
List<Variable> variables = gid.getReferencedFile().getVariables();
for (int i = 0; i < variables.size(); i++)
{
System.out.print(variables.get(i).getName()+" ");
//LatLon_Projection, lat, lon, reftime, time, depth_below_surface_layer, depth_below_surface_layer_bounds, Soil_temperature_depth_below_surface_layer
if(variables.get(i).getName().equals("reftime"))
{
logger.info("");
logger.info("Description = "+variables.get(i).getDescription());
logger.info("DimensionsString = "+variables.get(i).getDimensionsString());
logger.info("DataType = "+variables.get(i).getDataType());
logger.info("UnitsString = "+variables.get(i).getUnitsString()); //Hour since 2017-02-28T18:00:00Z
}
if(variables.get(i).getName().equals("lon"))
{
dataArrayLon = variables.get(i).read();
}
if(variables.get(i).getName().equals("lat"))
{
dataArrayLat = variables.get(i).read();
}
if(variables.get(i).getName().equals("Soil_temperature_depth_below_surface_layer"))
{
//Section sec=new Section();
dataArrayTmp = variables.get(i).read();
/*for(int j=0;j<dataArrayTmp.getSize();j++)
{
logger.info(j+") "+dataArrayTmp.getFloat(j)+",");
}*/
}
}
logger.info("");
List<Dimension> dims = gid.getDimensions();
logger.info("dims.size() = " + dims.size());
Iterator<Dimension> dimIt = dims.iterator();
while( dimIt.hasNext()) {
Dimension dim = dimIt.next();
logger.info("Dim = " + dim);
logger.info("Dim name = "+dim.getName());
}
dimIt = null;
Statement st=null;
try {
st = conn.createStatement();
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
try {
st.executeUpdate("BEGIN TRANSACTION;");
} catch (SQLException ex) {
logger.info(ex.getMessage());
logger.info(ex.getMessage());
}
result+="Size="+dataArrayLat.getSize()+"<br>";
//Delete old data
System.out.println("Delete old data 1");
try {
String sql="delete from main.soil_temperature where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
System.out.println("Delete old data 2");
try {
String sql="delete from main.soil_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
if(Integer.parseInt(forecast)!=0) {
System.out.println("Delete old data 3");
try {
String sql="delete from main.soil_temperature where hours="+forecast;
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
}
int pos=0;
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
{
for(int nLon=0;nLon<dataArrayLon.getSize();nLon++)
{
//WGS84 Bounds: -180.0000, -90.0000, 180.0000, 90.0000
//Projected Bounds: -180.0000, -90.0000, 180.0000, 90.0000
double lon = dataArrayLon.getFloat(nLon);
if(lon>180) lon=lon-360;
double lat = dataArrayLat.getFloat(nLat);
if(lat>29 && lat<67 && lon>17 && lon<180) //Central Asia
{
if(!Float.isNaN(dataArrayTmp.getFloat(pos))) //On the water none temperatyre.
{
String country_id="";
ResultSet rs=null;
try {
rs = st.executeQuery("select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1");
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
if (rs != null) {
try {
if (rs.next())
country_id=rs.getString(1);
rs.close();
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
}
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
{
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
try {
//String sql="insert into main.soil_temperature(weather_type_id,date,hours,val,geom)values(1,cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326));";
//String sql="insert into main.soil_temperature(weather_type_id,date,hours,val,geom,country_id)values(1,cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),(select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1));";
String sql="insert into main.soil_temperature(date,hours,val,geom,country_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+");";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
}
}
}
pos++;
}
}
//Cut data piece from big country of Russia
try {
String sql="update main.soil_temperature w set country_id=null where country_id=7 and not ST_Contains(ST_SetSRID(ST_GeomFromText('POLYGON((10.00 66.00,10.00 40.00,179.00 40.00,179.00 66.00,10.00 66.00))'),4326),w.geom);";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
//Delete values where country_id is null
try {
String sql="delete from main.soil_temperature where country_id is null;";
st.executeUpdate(sql);
} catch (SQLException ex) {
logger.info(ex.getMessage());
}
try {
st.executeUpdate("END TRANSACTION;");
} catch (SQLException ex) {
logger.info(ex.getMessage());
logger.info(ex.getMessage());
}
gid.close();
} catch (IOException ex) {
//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
System.out.print("ERROR!");
}
try {conn.close();} catch (SQLException ex) {logger.info(ex.getMessage());}
result+="End!<br>";
return result;
}
//---------------------------------------------------------------------------
@Override
public void setServletContext(ServletContext context) {
this.context=context;
}
//---------------------------------------------------------------------------
public static String CutBeforeFirst(StringBuffer str,String ch)
{
int pos=str.indexOf(ch);
String result="";
if(pos==-1)
{
result.concat(str.toString());
str.delete(0,str.length());
}else
{
result=str.substring(0,pos);
str.delete(0,pos+1);
}
return result;
}
//---------------------------------------------------------------------------
//List of "Soil temperature" dates from database in JSON
@CrossOrigin
@RequestMapping(value = "/geodatalist/SoilDates",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
@ResponseBody
public Object ajaxSoilDates(HttpServletResponse response) {
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
response.addHeader("Cache-Control", headerValue);
boolean error=false;
String result="";
Connection conn = null;
try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection(db_url, db_login, db_password);
if (conn != null) {
logger.info("Connect is OK!");
} else {
error=true;
result="An error occurred while connecting to the database!";
}
} catch (Exception ex) {
logger.info(ex.getMessage());
error=true;
result="<br>SQLException: "+ex.getMessage()+"<br>";
}
if(!error)
{
Statement st;
try {
st = conn.createStatement();
String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,EXTRACT(DAY FROM CURRENT_DATE-date) as day FROM main.soil_temperature group by date,hours order by date,hours";
ResultSet rs = st.executeQuery(sql);
if(rs!=null)
{
boolean exists=false;
result="[";
while (rs.next())
{
exists=true;
try {
result+= "{\"num\":\""+rs.getString("day")+"\", \"hour\":\""+rs.getString("hour")+"\", \"date\":\""+rs.getString("date")+"\"},";
} catch( Exception ex )
{
}
}
if(exists) {
result=result.substring(0, result.length()-1);
result+="]";
}else {
result="[]";
}
}
st.close();
conn.close();
} catch (SQLException ex) {
result="<br>SQLException:"+ex.getMessage()+"<br>";
}
}
return result;
}
//---------------------------------------------------------------------------
}

View File

@ -0,0 +1,13 @@
package org.ccalm.weather;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class WeatherApplication {
public static void main(String[] args) {
SpringApplication.run(WeatherApplication.class, args);
}
}

View File

@ -0,0 +1,126 @@
package org.ccalm.weather;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
/**
*
* @author ivanov.i
*/
public class WeatherDownload {
private static final int BUFFER_SIZE = 4096;
public boolean download(String strURL,String strFile,String posStart,String posEnd)
{
boolean result=true;
String rez = null;
String inputLine = null;
/*try
{
rez = new String("".getBytes(), "utf-8");
inputLine = new String("".getBytes(), "utf-8");
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}*/
try
{
URL url = new URL(strURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Range","bytes=" + posStart + "-" + posEnd);
conn.connect();
int responseCode = conn.getResponseCode();
if (responseCode / 100 == 2) //Code 206 is "Partial Content"
{
InputStream inputStream = conn.getInputStream();
FileOutputStream outputStream = new FileOutputStream(strFile);
int bytesRead;
byte[] buffer = new byte[BUFFER_SIZE];
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
inputStream.close();
}
conn.disconnect();
}
catch (IOException e)
{
//e.printStackTrace();
result=false;
}
return result;
}
/**
* Downloads a file from a URL
* @param fileURL HTTP URL of the file to be downloaded
* @param saveDir path of the directory to save the file
* @throws IOException
*/
public static void downloadFile(String fileURL, String saveDir)
throws IOException {
URL url = new URL(fileURL);
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
int responseCode = httpConn.getResponseCode();
// always check HTTP response code first
if (responseCode == HttpURLConnection.HTTP_OK) {
String fileName = "";
String disposition = httpConn.getHeaderField("Content-Disposition");
String contentType = httpConn.getContentType();
int contentLength = httpConn.getContentLength();
if (disposition != null) {
// extracts file name from header field
int index = disposition.indexOf("filename=");
if (index > 0) {
fileName = disposition.substring(index + 10,
disposition.length() - 1);
}
} else {
// extracts file name from URL
fileName = fileURL.substring(fileURL.lastIndexOf("/") + 1,
fileURL.length());
}
System.out.println("Content-Type = " + contentType);
System.out.println("Content-Disposition = " + disposition);
System.out.println("Content-Length = " + contentLength);
System.out.println("fileName = " + fileName);
// opens input stream from the HTTP connection
InputStream inputStream = httpConn.getInputStream();
String saveFilePath = saveDir + File.separator + fileName;
// opens an output stream to save into file
FileOutputStream outputStream = new FileOutputStream(saveFilePath);
int bytesRead = -1;
byte[] buffer = new byte[BUFFER_SIZE];
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
inputStream.close();
System.out.println("File downloaded");
} else {
System.out.println("No file to download. Server replied HTTP code: " + responseCode);
}
httpConn.disconnect();
}
}

View File

@ -0,0 +1,14 @@
/**
* Created by IntelliJ IDEA.
* User: igor
* Date: 09.03.2007
* Time: 0:53:45
* To change this template use File | Settings | File Templates.
*/
package tctable;
public class Point
{
public double x=0;
public double y=0;
}

View File

@ -0,0 +1,273 @@
package tctable;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Calendar;
import java.util.TimeZone;
public class Tools {
public static String readStringFromInputStream(InputStream inputStream) {
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
try {
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
} catch (IOException e1) {
e1.printStackTrace();
}
// StandardCharsets.UTF_8.name() > JDK 7
try {
return result.toString("UTF-8");
} catch (UnsupportedEncodingException e) {
}
return "";
}
//Преобразовать арабские и индийские в современные цифры
public static String numConvert(String str)
{
if(str==null) return null;
String persian = "۰۱۲۳۴۵۶۷۸۹";
String arabic = "٩٨٧٦٥٤٣٢١٠";
String num = "0123456789";
//Заменяю персидские
for(int i=0;i<str.length();i++)
{
for(int j=0;j<persian.length();j++)
{
if(str.charAt(i)==persian.charAt(j))
{
str = str.substring(0,i) + num.charAt(j) + str.substring(i+1);
break;
}
}
}
//Заменяю арабские
for(int i=0;i<str.length();i++)
{
for(int j=0;j<arabic.length();j++)
{
if(str.charAt(i)==arabic.charAt(j))
{
str = str.substring(0,i) + num.charAt(j) + str.substring(i+1);
break;
}
}
}
return str;
}
//Получить бит по его номеру нумерация лева на право
public static boolean getBit(byte[] mas, int pos)
{
int n=(int) Math.floor(pos/8.0);
int b=mas[n];
pos=pos - n * 8;
if(((b << pos) & 128) == 128)
return true;
else
return false;
}
//Установить 1й бит в номер нумерация с лева на право
public static void setBit(byte[] mas, int pos)
{
int n=(int) Math.floor(pos/8.0);
pos=pos - n * 8;
mas[n] = (byte)(mas[n] | (128 >> pos));
}
public static String readUTF8_1(InputStream handle) throws IOException
{
byte[] tmp=new byte[handle.read()];
handle.read(tmp);
return new String(tmp, "UTF8");
}
public static float readFloat(DataInputStream InStream) throws IOException
{
float f;
int ch1, ch2, ch3, ch4, count;
ch1 = InStream.readUnsignedByte();
ch2 = InStream.readUnsignedByte();
ch3 = InStream.readUnsignedByte();
ch4 = InStream.readUnsignedByte();
count = (ch4 << 24) | (ch3 << 16) | (ch2 << 8) | ch1;
f = Float.intBitsToFloat(count);
return f;
}
public static int readInt(DataInputStream InStream) throws IOException
{
int ch1, ch2, ch3, ch4, count;
ch1 = InStream.readUnsignedByte();
ch2 = InStream.readUnsignedByte();
ch3 = InStream.readUnsignedByte();
ch4 = InStream.readUnsignedByte();
count = (ch4 << 24) | (ch3 << 16) | (ch2 << 8) | ch1;
return count;
}
public static short readShort(DataInputStream InStream) throws IOException
{
int ch1, ch2, count;
ch1 = InStream.readUnsignedByte();
ch2 = InStream.readUnsignedByte();
count = (ch2 << 8) | ch1;
return (short)count;
}
public static int readUShort(InputStream InStream) throws IOException
{
int ch1, ch2;
ch1 = InStream.read();
ch2 = InStream.read();
return (ch2 << 8) | ch1;
}
public static String afterLast(String str, String ch)
{
int i=str.lastIndexOf(ch);
if(i!=-1)
{
return str.substring(i+ch.length());
}
return "";
}
public static String beforeLast(String str, String ch)
{
int i=str.lastIndexOf(ch);
if(i!=-1)
{
return str.substring(0,i);
}
return "";
}
public static String beforeFirst(String str, String ch)
{
int i=str.indexOf(ch);
if(i!=-1)
{
return str.substring(0,i);
}
return "";
}
//узнать точку пересичений 2х линай если x=0 и y=0 то не пересиклась
public static Point getCrossingLine(Point PHead0, Point PTail0, Point PHead1, Point PTail1)
{
Point rezPoint = new Point();
double a0, b0, c0, a1, b1, c1;
boolean bRez = true;
a0 = PTail0.y - PHead0.y;
b0 = PHead0.x - PTail0.x;
c0 = PTail0.x * PHead0.y - PHead0.x * PTail0.y;
a1 = PTail1.y - PHead1.y;
b1 = PHead1.x - PTail1.x;
c1 = PTail1.x * PHead1.y - PHead1.x * PTail1.y;
if (b1 == 0) rezPoint.x = PHead1.x;//если перпендикулярна oy
else rezPoint.x = (-(b0 * c1 / b1) + c0) / ((b0 * a1 / b1) - a0);
if (a1 == 0) rezPoint.y = PHead1.y;//если перпендикулярна oy
else rezPoint.y = (-(c1 * a0 / a1) + c0) / ((a0 * b1 / a1) - b0);
//проверка на вхождение в отрезоки (с погрешностью 0.0000001 (зачем понадобилась погрешность?))
//по x
if ((rezPoint.x < Math.min(PHead0.x, PTail0.x) - 0.0000001) || (rezPoint.x > Math.max(PHead0.x, PTail0.x) + 0.0000001))
bRez = false;
if ((rezPoint.x < Math.min(PHead1.x, PTail1.x) - 0.0000001) || (rezPoint.x > Math.max(PHead1.x, PTail1.x) + 0.0000001))
bRez = false;
//по y
if ((rezPoint.y < Math.min(PHead0.y, PTail0.y) - 0.0000001) || (rezPoint.y > Math.max(PHead0.y, PTail0.y) + 0.0000001))
bRez = false;
if ((rezPoint.y < Math.min(PHead1.y, PTail1.y) - 0.0000001) || (rezPoint.y > Math.max(PHead1.y, PTail1.y) + 0.0000001))
bRez = false;
if (!bRez)
{
rezPoint.x = 0;
rezPoint.y = 0;
}
return rezPoint;
}
public static Point getCrossingLine2(Point PHead0,Point PTail0,Point PHead1,Point PTail1)
{
boolean bRez=true;
Point rezPoint = new Point();
rezPoint.x=0;
rezPoint.y=0;
double a0,b0,c0,a1,b1,c1;
a0=PTail0.y-PHead0.y;
b0=PHead0.x-PTail0.x;
c0=PTail0.x*PHead0.y-PHead0.x*PTail0.y;
a1=PTail1.y-PHead1.y;
b1=PHead1.x-PTail1.x;
c1=PTail1.x*PHead1.y-PHead1.x*PTail1.y;
if (b1==0) rezPoint.x=PHead1.x;//если перпендикулярна oy
else rezPoint.x=(-(b0*c1/b1)+c0)/((b0*a1/b1)-a0);
if (a1==0) rezPoint.y=PHead1.y;//если перпендикулярна ox
else rezPoint.y=(-(c1*a0/a1)+c0)/((a0*b1/a1)-b0);
//по x
if (rezPoint.x<Math.min(PHead0.x,PTail0.x)||rezPoint.x>Math.max(PHead0.x,PTail0.x))
bRez=false;
if (rezPoint.x<Math.min(PHead1.x,PTail1.x)||rezPoint.x>Math.max(PHead1.x,PTail1.x))
bRez=false;
//по y
if (rezPoint.y<Math.min(PHead0.y,PTail0.y)||rezPoint.y>Math.max(PHead0.y,PTail0.y))
bRez=false;
if (rezPoint.y<Math.min(PHead1.y,PTail1.y)||rezPoint.y>Math.max(PHead1.y,PTail1.y))
bRez=false;
if (!bRez)
{
rezPoint.x=0;
rezPoint.y=0;
}
return rezPoint;
}
//Так как в replaceAll много заморочек с регулярными выражениями
public static String replaceAll(String txt, String val, String rep) {
if(txt==null || val==null || rep==null) return txt;
return txt.replace(val,rep);
/*while(true)
{
String tmpstr=txt.replace(val, rep);
if(tmpstr.equals(txt))
{
txt=tmpstr;
break;
}else
{
txt=tmpstr;
}
}
return txt;*/
}
public static byte[] subArray(byte[] b, int offset, int length) {
byte[] sub = new byte[length];
for (int i = offset; i < offset + length; i++) {
try {
sub[i - offset] = b[i];
} catch (Exception e) {
}
}
return sub;
}
}

Binary file not shown.

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: org.ccalm.weather.WeatherApplication

View File

@ -0,0 +1,10 @@
spring.cache.type=none
#custom.config.db_url=jdbc:postgresql://192.168.0.90:5432/weather
custom.config.db_url=jdbc:postgresql://127.0.0.1:5432/weather
custom.config.db_login=postgres
custom.config.db_password=PasSecrKey1
#custom.config.data_dir=O:\\temp\\CCALM\\
custom.config.data_dir=/temp/CCALM/
server.port=8081
server.servlet.session.timeout=300s

View File

@ -0,0 +1,13 @@
package org.ccalm.weather;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class WeatherApplicationTests {
@Test
void contextLoads() {
}
}