Merge branch 'master' of https://git.dirt.kz/igor/CCALM_weather
# Conflicts: # pom.xml # src/main/java/org/ccalm/weather/AirTemperature.java # src/main/java/org/ccalm/weather/Precipitation.java # src/main/java/org/ccalm/weather/SoilTmperature.java # src/main/resources/logback-spring.xml
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -24,6 +24,7 @@ target/
|
|||||||
/nbproject/private/
|
/nbproject/private/
|
||||||
/nbbuild/
|
/nbbuild/
|
||||||
/dist/
|
/dist/
|
||||||
|
/logs/
|
||||||
/nbdist/
|
/nbdist/
|
||||||
/.nb-gradle/
|
/.nb-gradle/
|
||||||
build/
|
build/
|
||||||
|
|||||||
28
org_ccalm_weather.yml
Normal file
28
org_ccalm_weather.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
server:
|
||||||
|
port: 8081
|
||||||
|
servlet:
|
||||||
|
session:
|
||||||
|
timeout: 300s
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: kz_mcp_weather
|
||||||
|
cache:
|
||||||
|
type: none
|
||||||
|
|
||||||
|
#custom.config.db_url=jdbc:postgresql://192.168.0.90:5432/weather
|
||||||
|
custom:
|
||||||
|
config:
|
||||||
|
data_dir: O:\\temp\\CCALM\\
|
||||||
|
#data_dir: /temp/CCALM/
|
||||||
|
db_all:
|
||||||
|
#url: jdbc:postgresql://127.0.0.1:5432/weather?ApplicationName=kz_mcp_weather
|
||||||
|
url: jdbc:postgresql://92.46.48.43:5433/weather?ApplicationName=kz_mcp_weather
|
||||||
|
login: postgres
|
||||||
|
password: PasSecrKey10
|
||||||
|
db_ru:
|
||||||
|
#url: jdbc:postgresql://92.46.48.43:5433/weather_ru?ApplicationName=kz_mcp_weather
|
||||||
|
url: jdbc:postgresql://127.0.0.1:5432/weather_ru?ApplicationName=kz_mcp_weather
|
||||||
|
login: postgres
|
||||||
|
password: PasSecrKey1
|
||||||
|
|
||||||
65
pom.xml
65
pom.xml
@ -5,12 +5,12 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.5.4</version>
|
<version>3.3.3</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.ccalm</groupId>
|
<groupId>org.ccalm</groupId>
|
||||||
<artifactId>weather</artifactId>
|
<artifactId>weather</artifactId>
|
||||||
<version>0.0.6-SNAPSHOT</version>
|
<version>0.0.7-SNAPSHOT</version>
|
||||||
<name>weather</name>
|
<name>weather</name>
|
||||||
<description>Demo project for Spring Boot</description>
|
<description>Demo project for Spring Boot</description>
|
||||||
<properties>
|
<properties>
|
||||||
@ -78,64 +78,25 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
|
||||||
<version>3.2.0</version>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>copy-dependencies</id>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
<goals>
|
||||||
<goal>copy-dependencies</goal>
|
<goal>build-info</goal>
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
|
||||||
<includeScope>runtime</includeScope>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<version>3.2.0</version>
|
|
||||||
<configuration>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
<classpathPrefix>lib/</classpathPrefix>
|
|
||||||
<mainClass>org.ccalm.weather.WeatherApplication</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<!--plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-install-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>install-external</id>
|
|
||||||
<phase>clean</phase>
|
|
||||||
<configuration>
|
|
||||||
<file>O:/projects/Workspace_Java/CCALM_weather/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>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin-->
|
</plugin-->
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.2</version>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<spring.config.location>file:org_ccalm_weather.yml</spring.config.location>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|||||||
@ -5,11 +5,7 @@ import java.io.File;
|
|||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -54,19 +50,96 @@ import ucar.nc2.dataset.NetcdfDataset;
|
|||||||
@Controller
|
@Controller
|
||||||
public class AirTemperature implements ServletContextAware {
|
public class AirTemperature implements ServletContextAware {
|
||||||
|
|
||||||
@Value("${custom.config.db_url}")
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(AirTemperature.class);
|
||||||
private String db_url;
|
|
||||||
@Value("${custom.config.db_login}")
|
@Value("${custom.config.db_all.url}")
|
||||||
private String db_login;
|
private String db_url_all;
|
||||||
@Value("${custom.config.db_password}")
|
@Value("${custom.config.db_all.login}")
|
||||||
private String db_password;
|
private String db_login_all;
|
||||||
|
@Value("${custom.config.db_all.password}")
|
||||||
|
private String db_password_all;
|
||||||
|
|
||||||
|
@Value("${custom.config.db_ru.url}")
|
||||||
|
private String db_url_ru;
|
||||||
|
@Value("${custom.config.db_ru.login}")
|
||||||
|
private String db_login_ru;
|
||||||
|
@Value("${custom.config.db_ru.password}")
|
||||||
|
private String db_password_ru;
|
||||||
|
|
||||||
@Value("${custom.config.data_dir}")
|
@Value("${custom.config.data_dir}")
|
||||||
private String data_dir;
|
private String data_dir;
|
||||||
|
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SoilTmperature.class);
|
private jakarta.servlet.ServletContext context;
|
||||||
|
|
||||||
private ServletContext context;
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setServletContext(jakarta.servlet.ServletContext servletContext) {
|
||||||
|
this.context = servletContext;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
public String getCountryId(Statement st,double lon,double lat) {
|
||||||
|
String country_id = "";
|
||||||
|
try {
|
||||||
|
String sql = "select c.id from main.countries c where del=false and ST_Contains(c.geom,ST_SetSRID(st_makepoint(" + lon + "," + lat + "),4326)) limit 1";
|
||||||
|
try (ResultSet rs = st.executeQuery(sql)) {
|
||||||
|
if (rs.next()) {
|
||||||
|
country_id = rs.getString(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.error("N9: " + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
return country_id;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
public String getPointId(Statement st, String country_id, double lon, double lat) {
|
||||||
|
String point_id = "";
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
try {
|
||||||
|
String sql = "SELECT id FROM main.points WHERE lon = ? AND lat = ? LIMIT 1";
|
||||||
|
pstmt = st.getConnection().prepareStatement(sql);
|
||||||
|
pstmt.setDouble(1, lon);
|
||||||
|
pstmt.setDouble(2, lat);
|
||||||
|
try (ResultSet rs = pstmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
point_id = rs.getString(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.error("N9: " + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
if(point_id.isEmpty()){
|
||||||
|
try {
|
||||||
|
String sql = "insert into main.points(country_id,geom,lon,lat)values(?,ST_SetSRID(st_makepoint(?,?),4326),?,?) RETURNING id";
|
||||||
|
pstmt = st.getConnection().prepareStatement(sql);
|
||||||
|
pstmt.setLong(1, Long.valueOf(country_id));
|
||||||
|
pstmt.setDouble(2, lon);
|
||||||
|
pstmt.setDouble(3, lat);
|
||||||
|
pstmt.setDouble(4, lon);
|
||||||
|
pstmt.setDouble(5, lat);
|
||||||
|
try (ResultSet rs = pstmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
point_id = rs.getString(1); // Получаем ID, возвращаемый SQL-запросом
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.error("N11: " + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return point_id;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
public Connection getConn(String url, String login,String password){
|
||||||
|
Connection conn = null;
|
||||||
|
try{
|
||||||
|
Class.forName("org.postgresql.Driver");
|
||||||
|
conn = DriverManager.getConnection(url,login,password);
|
||||||
|
}catch(Exception ex)
|
||||||
|
{
|
||||||
|
logger.error("N1: "+ex.getMessage()+"<br>",ex);
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* This function is run every day from CRON, to see the settings call the function: "sudo crontab -e -u tomcat" on PC 127.0.0.1
|
* This function is run every day from CRON, to see the settings call the function: "sudo crontab -e -u tomcat" on PC 127.0.0.1
|
||||||
* @param date - If the field is empty, it is filled in automatically with the current day (When running from CRON, this field is empty)
|
* @param date - If the field is empty, it is filled in automatically with the current day (When running from CRON, this field is empty)
|
||||||
@ -86,24 +159,8 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
if (!dir.exists()) dir.mkdirs();
|
if (!dir.exists()) dir.mkdirs();
|
||||||
|
|
||||||
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||||
Connection conn = null;
|
Connection conn_all = getConn(db_url_all,db_login_all,db_password_all);
|
||||||
try{
|
Connection conn_ru = getConn(db_url_ru,db_login_ru,db_password_ru);
|
||||||
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 ex)
|
|
||||||
{
|
|
||||||
logger.error("N1:"+ex.getMessage()+"<br>",ex);
|
|
||||||
result+="Connect Exception:"+ex.getMessage()+"<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
//Example request: http://ccalm.org/AirTemperature?date=20210531
|
//Example request: http://ccalm.org/AirTemperature?date=20210531
|
||||||
//Example request: http://localhost:8080/AirTemperature?date=20210531
|
//Example request: http://localhost:8080/AirTemperature?date=20210531
|
||||||
@ -229,15 +286,19 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
dimIt = null;
|
dimIt = null;
|
||||||
|
|
||||||
Statement st=null;
|
Statement st_all=null;
|
||||||
|
Statement st_ru=null;
|
||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
if(conn_all!=null) st_all = conn_all.createStatement();
|
||||||
|
if(conn_ru!=null) st_ru = conn_ru.createStatement();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N3:"+ex.getMessage(),ex);
|
logger.error("N3:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("BEGIN TRANSACTION;");
|
String sql = "BEGIN TRANSACTION;";
|
||||||
|
if(st_all!=null) st_all.executeUpdate(sql);
|
||||||
|
if(st_ru!=null) st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N4:"+ex.getMessage(),ex);
|
logger.error("N4:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -245,35 +306,41 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
result+="Size="+dataArrayLat.getSize()+"<br>";
|
result+="Size="+dataArrayLat.getSize()+"<br>";
|
||||||
|
|
||||||
//Delete old data
|
//Delete old data
|
||||||
logger.info("Delete old data 1");
|
/*logger.info("Delete old data 1");
|
||||||
try {
|
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;
|
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);
|
if(st_all!=null) st_all.executeUpdate(sql);
|
||||||
|
if(st_ru!=null) st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N5:"+ex.getMessage(),ex);
|
logger.error("N5:"+ex.getMessage(),ex);
|
||||||
}
|
}*/
|
||||||
logger.info("Delete old data 2");
|
logger.info("Delete old data 2");
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.air_temperature_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
String sql="delete from main.air_temperature_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
||||||
st.executeUpdate(sql);
|
if(st_all!=null) st_all.executeUpdate(sql);
|
||||||
|
if(st_ru!=null) st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N6:"+ex.getMessage(),ex);
|
logger.error("N6:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
logger.info("Delete old data 3");
|
logger.info("Delete old data 3");
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.air_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
//String sql="delete from main.air_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
||||||
st.executeUpdate(sql);
|
String sql="delete from main.air_temperature_dates where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
||||||
|
if(st_all!=null) st_all.executeUpdate(sql);
|
||||||
|
if(st_ru!=null) st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N7:"+ex.getMessage(),ex);
|
logger.error("N7:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("END TRANSACTION;");
|
if(st_all!=null) st_all.executeUpdate("END TRANSACTION;");
|
||||||
|
if(st_ru!=null) st_ru.executeUpdate("END TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N7.1:"+ex.getMessage(),ex);
|
logger.error("N7.1:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("BEGIN TRANSACTION;");
|
if(st_all!=null) st_all.executeUpdate("BEGIN TRANSACTION;");
|
||||||
|
if(st_ru!=null) st_ru.executeUpdate("BEGIN TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N7.2:"+ex.getMessage(),ex);
|
logger.error("N7.2:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -294,29 +361,30 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
if(!Float.isNaN(dataArrayTmp.getFloat(pos))) //On the water none temperatyre.
|
if(!Float.isNaN(dataArrayTmp.getFloat(pos))) //On the water none temperatyre.
|
||||||
{
|
{
|
||||||
String country_id="";
|
String country_id="";
|
||||||
ResultSet rs=null;
|
boolean db_all=false,db_ru=false;
|
||||||
try {
|
if(st_all!=null && country_id.isEmpty()) {
|
||||||
String sql="select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1";
|
country_id = getCountryId(st_all, lon, lat);
|
||||||
rs = st.executeQuery(sql);
|
if(!country_id.isEmpty()) db_all=true;
|
||||||
} catch (SQLException ex) {
|
|
||||||
logger.error("N8:"+ex.getMessage(),ex);
|
|
||||||
}
|
|
||||||
if (rs != null) {
|
|
||||||
try {
|
|
||||||
if (rs.next())
|
|
||||||
country_id=rs.getString(1);
|
|
||||||
rs.close();
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
logger.error("N9:"+ex.getMessage(),ex);
|
|
||||||
}
|
}
|
||||||
|
if(st_ru!=null && country_id.isEmpty()) {
|
||||||
|
country_id = getCountryId(st_ru, lon, lat);
|
||||||
|
if(!country_id.isEmpty()) db_ru=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
|
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
|
||||||
{
|
{
|
||||||
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
|
|
||||||
try {
|
try {
|
||||||
String sql="insert into main.air_temperature(date,hours,val,geom,country_id,air_temperature_date_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+",main.get_air_temperature_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
|
String point_id="";
|
||||||
st.executeUpdate(sql);
|
if(db_all) {
|
||||||
|
point_id = getPointId(st_all, country_id, lon, lat);
|
||||||
|
String sql="insert into main.air_temperature(val,point_id,country_id,air_temperature_date_id)values("+dataArrayTmp.getFloat(pos)+","+point_id+","+country_id+",main.get_air_temperature_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
|
||||||
|
st_all.executeUpdate(sql);
|
||||||
|
}
|
||||||
|
if(db_ru) {
|
||||||
|
point_id = getPointId(st_ru, country_id, lon, lat);
|
||||||
|
String sql="insert into main.air_temperature(val,point_id,country_id,air_temperature_date_id)values("+dataArrayTmp.getFloat(pos)+","+point_id+","+country_id+",main.get_air_temperature_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N10:"+ex.getMessage(),ex);
|
logger.error("N10:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -330,22 +398,26 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
|
|
||||||
//Cut data piece from big country of Russia
|
//Cut data piece from big country of Russia
|
||||||
try {
|
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);";
|
String sql="update main.points 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);
|
if(st_all!=null) st_all.executeUpdate(sql);
|
||||||
|
if(st_ru!=null) st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N11:"+ex.getMessage(),ex);
|
logger.error("N11:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete values where country_id is null
|
//Delete values where country_id is null
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.air_temperature where country_id is null;";
|
String sql="delete from main.points where country_id is null;";
|
||||||
st.executeUpdate(sql);
|
if(st_all!=null) st_all.executeUpdate(sql);
|
||||||
|
if(st_ru!=null) st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N12:"+ex.getMessage(),ex);
|
logger.error("N12:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("END TRANSACTION;");
|
String sql = "END TRANSACTION;";
|
||||||
|
if(st_all!=null) st_all.executeUpdate(sql);
|
||||||
|
if(st_ru!=null) st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N13:"+ex.getMessage(),ex);
|
logger.error("N13:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -355,16 +427,13 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
logger.error("N14:"+ex.getMessage(),ex);
|
logger.error("N14:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {conn.close();} catch (SQLException ex) {logger.error("N15:"+ex.getMessage(),ex);}
|
try { if(conn_all!=null) conn_all.close(); } catch (SQLException ex) {logger.error("N15:"+ex.getMessage(),ex);}
|
||||||
|
try { if(conn_ru!=null) conn_ru.close();} catch (SQLException ex) {logger.error("N15:"+ex.getMessage(),ex);}
|
||||||
|
|
||||||
result+="End!<br>";
|
result+="End!<br>";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
|
||||||
@Override
|
|
||||||
public void setServletContext(ServletContext context) {
|
|
||||||
this.context=context;
|
|
||||||
}
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
public static String CutBeforeFirst(StringBuffer str,String ch)
|
public static String CutBeforeFirst(StringBuffer str,String ch)
|
||||||
{
|
{
|
||||||
@ -394,28 +463,13 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
boolean error=false;
|
boolean error=false;
|
||||||
String result="";
|
String result="";
|
||||||
|
|
||||||
Connection conn = null;
|
Connection conn_all = getConn(db_url_all,db_login_all,db_password_all);
|
||||||
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.error("N16:"+ex.getMessage(),ex);
|
|
||||||
error=true;
|
|
||||||
result="<br>SQLException: "+ex.getMessage()+"<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!error)
|
if(!error)
|
||||||
{
|
{
|
||||||
Statement st;
|
Statement st_all;
|
||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
st_all = conn_all.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;";
|
|
||||||
String sql = """
|
String sql = """
|
||||||
SELECT
|
SELECT
|
||||||
to_char(date, 'YYYY-MM-DD') as date,
|
to_char(date, 'YYYY-MM-DD') as date,
|
||||||
@ -426,7 +480,7 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
group by date,hours
|
group by date,hours
|
||||||
order by date,hours
|
order by date,hours
|
||||||
""";
|
""";
|
||||||
ResultSet rs = st.executeQuery(sql);
|
ResultSet rs = st_all.executeQuery(sql);
|
||||||
if(rs!=null)
|
if(rs!=null)
|
||||||
{
|
{
|
||||||
boolean exists=false;
|
boolean exists=false;
|
||||||
@ -448,11 +502,13 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
result="[]";
|
result="[]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
st.close();
|
st_all.close();
|
||||||
conn.close();
|
conn_all.close();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
result="<br>SQLException:"+ex.getMessage()+"<br>";
|
result="<br>SQLException:"+ex.getMessage()+"<br>";
|
||||||
logger.error("N18:"+ex.getMessage(),ex);
|
logger.error("N18:"+ex.getMessage(),ex);
|
||||||
|
}finally{
|
||||||
|
try { conn_all.close(); } catch (SQLException ex) { logger.error("N19: "+ex.getMessage(),ex); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -18,13 +18,14 @@ import java.util.List;
|
|||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
@ -54,21 +55,87 @@ import ucar.nc2.dataset.NetcdfDataset;
|
|||||||
@Controller
|
@Controller
|
||||||
public class Precipitation implements ServletContextAware {
|
public class Precipitation implements ServletContextAware {
|
||||||
|
|
||||||
@Value("${custom.config.db_url}")
|
private static final Logger logger = LogManager.getLogger(Precipitation.class);
|
||||||
private String db_url;
|
|
||||||
@Value("${custom.config.db_login}")
|
@Value("${custom.config.db_all.url}")
|
||||||
private String db_login;
|
private String db_url_all;
|
||||||
@Value("${custom.config.db_password}")
|
@Value("${custom.config.db_all.login}")
|
||||||
private String db_password;
|
private String db_login_all;
|
||||||
|
@Value("${custom.config.db_all.password}")
|
||||||
|
private String db_password_all;
|
||||||
|
|
||||||
|
@Value("${custom.config.db_ru.url}")
|
||||||
|
private String db_url_ru;
|
||||||
|
@Value("${custom.config.db_ru.login}")
|
||||||
|
private String db_login_ru;
|
||||||
|
@Value("${custom.config.db_ru.password}")
|
||||||
|
private String db_password_ru;
|
||||||
|
|
||||||
@Value("${custom.config.data_dir}")
|
@Value("${custom.config.data_dir}")
|
||||||
private String data_dir;
|
private String data_dir;
|
||||||
|
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Precipitation.class);
|
private jakarta.servlet.ServletContext context;
|
||||||
|
|
||||||
private ServletContext context;
|
|
||||||
|
|
||||||
//http://127.0.0.1:8080/AirTemperature
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
@Override
|
||||||
|
public void setServletContext(jakarta.servlet.ServletContext servletContext) {
|
||||||
|
this.context=servletContext;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
public String getCountryId(Statement st,double lon,double lat) {
|
||||||
|
String country_id = "";
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
rs = st.executeQuery("select c.id from main.countries c where del=false and ST_Contains(c.geom,ST_SetSRID(st_makepoint(" + lon + "," + lat + "),4326)) limit 1");
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.error("N9: " + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
if (rs != null) {
|
||||||
|
try {
|
||||||
|
if (rs.next())
|
||||||
|
country_id = rs.getString(1);
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.error("N10: " + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return country_id;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
public Connection getConn(String url, String login,String password){
|
||||||
|
Connection conn = null;
|
||||||
|
try{
|
||||||
|
Class.forName("org.postgresql.Driver");
|
||||||
|
conn = DriverManager.getConnection(url,login,password);
|
||||||
|
}catch(Exception ex)
|
||||||
|
{
|
||||||
|
logger.error("N1: "+ex.getMessage()+"<br>",ex);
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Example http://127.0.0.1:8080/AirTemperature
|
||||||
|
* @param response
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(value = "/geodatalist/Precipitation",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
|
@RequestMapping(value = "/geodatalist/Precipitation",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object ajaxTamer(HttpServletResponse response,@RequestParam(required=false,name="date") String date) {
|
public Object ajaxTamer(HttpServletResponse response,@RequestParam(required=false,name="date") String date) {
|
||||||
@ -85,24 +152,8 @@ public class Precipitation implements ServletContextAware {
|
|||||||
if (!dir.exists()) dir.mkdirs();
|
if (!dir.exists()) dir.mkdirs();
|
||||||
|
|
||||||
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||||
Connection conn = null;
|
Connection conn_all = getConn(db_url_all,db_login_all,db_password_all);
|
||||||
try{
|
Connection conn_ru = getConn(db_url_ru,db_login_ru,db_password_ru);
|
||||||
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.error("N1:"+e.getMessage()+"<br>",e);
|
|
||||||
result+="Connect Exception:"+e.getMessage()+"<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
//Example request: http://localhost:8080/Precipitation?date=20210531
|
//Example request: http://localhost:8080/Precipitation?date=20210531
|
||||||
if(date==null || date.equals(""))
|
if(date==null || date.equals(""))
|
||||||
@ -225,15 +276,18 @@ public class Precipitation implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
dimIt = null;
|
dimIt = null;
|
||||||
|
|
||||||
Statement st=null;
|
Statement st_all=null;
|
||||||
|
Statement st_ru=null;
|
||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
st_all = conn_all.createStatement();
|
||||||
|
st_ru = conn_ru.createStatement();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N3:"+ex.getMessage(),ex);
|
logger.error("N3:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("BEGIN TRANSACTION;");
|
st_all.executeUpdate("BEGIN TRANSACTION;");
|
||||||
|
st_ru.executeUpdate("BEGIN TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N4:"+ex.getMessage(),ex);
|
logger.error("N4:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -244,11 +298,28 @@ public class Precipitation implements ServletContextAware {
|
|||||||
logger.info("Delete old data 1");
|
logger.info("Delete old data 1");
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.precipitation where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
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);
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N5:"+ex.getMessage(),ex);
|
logger.error("N5:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
logger.info("Delete old data 2");
|
logger.info("Delete old data 2");
|
||||||
|
try {
|
||||||
|
String sql="delete from main.precipitation_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
||||||
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.error("N6:"+ex.getMessage(),ex);
|
||||||
|
}
|
||||||
|
logger.info("Delete old data 3");
|
||||||
|
try {
|
||||||
|
String sql="delete from main.precipitation_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
||||||
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.info(ex.getMessage());
|
||||||
|
}
|
||||||
|
System.out.println("Delete old data 3");
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.precipitation_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
String sql="delete from main.precipitation_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
||||||
st.executeUpdate(sql);
|
st.executeUpdate(sql);
|
||||||
@ -258,18 +329,21 @@ public class Precipitation implements ServletContextAware {
|
|||||||
logger.info("Delete old data 3");
|
logger.info("Delete old data 3");
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.precipitation where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
String sql="delete from main.precipitation where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
||||||
st.executeUpdate(sql);
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N7:"+ex.getMessage(),ex);
|
logger.error("N7:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("END TRANSACTION;");
|
st_all.executeUpdate("END TRANSACTION;");
|
||||||
|
st_ru.executeUpdate("END TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N7.1:"+ex.getMessage(),ex);
|
logger.error("N7.1:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("BEGIN TRANSACTION;");
|
st_all.executeUpdate("BEGIN TRANSACTION;");
|
||||||
|
st_ru.executeUpdate("BEGIN TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N7.2:"+ex.getMessage(),ex);
|
logger.error("N7.2:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -290,29 +364,28 @@ public class Precipitation implements ServletContextAware {
|
|||||||
if(!Float.isNaN(dataArrayTmp.getFloat(pos))) //On the water none temperatyre.
|
if(!Float.isNaN(dataArrayTmp.getFloat(pos))) //On the water none temperatyre.
|
||||||
{
|
{
|
||||||
String country_id="";
|
String country_id="";
|
||||||
ResultSet rs=null;
|
boolean db_all=false,db_ru=false;
|
||||||
try {
|
if(country_id.isEmpty()) {
|
||||||
rs = st.executeQuery("select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1");
|
country_id = getCountryId(st_all, lon, lat);
|
||||||
} catch (SQLException ex) {
|
if(!country_id.isEmpty()) db_all=true;
|
||||||
logger.error("N8:"+ex.getMessage(),ex);
|
|
||||||
}
|
|
||||||
if (rs != null) {
|
|
||||||
try {
|
|
||||||
if (rs.next())
|
|
||||||
country_id=rs.getString(1);
|
|
||||||
rs.close();
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
logger.error("N9:"+ex.getMessage(),ex);
|
|
||||||
}
|
}
|
||||||
|
if(country_id.isEmpty()) {
|
||||||
|
country_id = getCountryId(st_ru, lon, lat);
|
||||||
|
if(!country_id.isEmpty()) db_ru=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
|
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
|
||||||
{
|
{
|
||||||
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
|
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
|
||||||
try {
|
try {
|
||||||
String sql="insert into main.precipitation(date,hours,val,geom,country_id,precipitation_date_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+",main.get_precipitation_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
|
String sql="insert into main.precipitation(date,hours,val,geom,country_id,precipitation_date_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+",main.get_precipitation_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
|
||||||
st.executeUpdate(sql);
|
if(db_all)
|
||||||
|
st_all.executeUpdate(sql);
|
||||||
|
if(db_ru)
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N10:"+ex.getMessage(),ex);
|
logger.error("N10:"+ex.getMessage(),ex);
|
||||||
|
throw new Exception("Failed insert precipitation...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,7 +398,8 @@ public class Precipitation implements ServletContextAware {
|
|||||||
//Cut data piece from big country of Russia
|
//Cut data piece from big country of Russia
|
||||||
try {
|
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);";
|
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);
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N11:"+ex.getMessage(),ex);
|
logger.error("N11:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -333,13 +407,16 @@ public class Precipitation implements ServletContextAware {
|
|||||||
//Delete values where country_id is null
|
//Delete values where country_id is null
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.precipitation where country_id is null;";
|
String sql="delete from main.precipitation where country_id is null;";
|
||||||
st.executeUpdate(sql);
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N12:"+ex.getMessage(),ex);
|
logger.error("N12:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("END TRANSACTION;");
|
String sql="END TRANSACTION;";
|
||||||
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N13:"+ex.getMessage(),ex);
|
logger.error("N13:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -347,34 +424,16 @@ public class Precipitation implements ServletContextAware {
|
|||||||
gid.close();
|
gid.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.error("N14:"+ex.getMessage(),ex);
|
logger.error("N14:"+ex.getMessage(),ex);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
logger.error("N15: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {conn.close();} catch (SQLException ex) {logger.info(ex.getMessage(),ex);}
|
try {conn_all.close();} catch (SQLException ex) {logger.error("N16: "+ex.getMessage(),ex);}
|
||||||
|
try {conn_ru.close();} catch (SQLException ex) {logger.error("N16: "+ex.getMessage(),ex);}
|
||||||
|
|
||||||
result+="End!<br>";
|
result+="End!<br>";
|
||||||
return result;
|
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
|
//List of "Air temperature" dates from database in JSON
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@ -388,28 +447,13 @@ public class Precipitation implements ServletContextAware {
|
|||||||
String result="";
|
String result="";
|
||||||
|
|
||||||
//Load DB configuration from "config.xml"
|
//Load DB configuration from "config.xml"
|
||||||
Connection conn = null;
|
Connection conn_all = getConn(db_url_all,db_login_all,db_password_all);
|
||||||
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.error("N15:"+ex.getMessage(),ex);
|
|
||||||
error=true;
|
|
||||||
result="<br>SQLException: "+ex.getMessage()+"<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!error)
|
if(!error)
|
||||||
{
|
{
|
||||||
Statement st;
|
Statement st_all=null;
|
||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
st_all = conn_all.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";
|
|
||||||
String sql = """
|
String sql = """
|
||||||
SELECT
|
SELECT
|
||||||
to_char(date, 'YYYY-MM-DD') as date,
|
to_char(date, 'YYYY-MM-DD') as date,
|
||||||
@ -422,7 +466,7 @@ public class Precipitation implements ServletContextAware {
|
|||||||
hours
|
hours
|
||||||
order by date,hours
|
order by date,hours
|
||||||
""";
|
""";
|
||||||
ResultSet rs = st.executeQuery(sql);
|
ResultSet rs = st_all.executeQuery(sql);
|
||||||
if(rs!=null)
|
if(rs!=null)
|
||||||
{
|
{
|
||||||
boolean exists=false;
|
boolean exists=false;
|
||||||
@ -444,11 +488,12 @@ public class Precipitation implements ServletContextAware {
|
|||||||
result="[]";
|
result="[]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
st.close();
|
st_all.close();
|
||||||
conn.close();
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
result="<br>SQLException:"+ex.getMessage()+"<br>";
|
result="<br>SQLException:"+ex.getMessage()+"<br>";
|
||||||
logger.error("N17:"+ex.getMessage(),ex);
|
logger.error("N17:"+ex.getMessage(),ex);
|
||||||
|
}finally{
|
||||||
|
try { conn_all.close(); } catch (SQLException ex) { logger.error("N18: "+ex.getMessage(),ex); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -54,21 +54,88 @@ import ucar.nc2.dataset.NetcdfDataset;
|
|||||||
@Controller
|
@Controller
|
||||||
public class SoilTmperature implements ServletContextAware {
|
public class SoilTmperature implements ServletContextAware {
|
||||||
|
|
||||||
@Value("${custom.config.db_url}")
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SoilTmperature.class);
|
||||||
private String db_url;
|
|
||||||
@Value("${custom.config.db_login}")
|
@Value("${custom.config.db_all.url}")
|
||||||
private String db_login;
|
private String db_url_all;
|
||||||
@Value("${custom.config.db_password}")
|
@Value("${custom.config.db_all.login}")
|
||||||
private String db_password;
|
private String db_login_all;
|
||||||
|
@Value("${custom.config.db_all.password}")
|
||||||
|
private String db_password_all;
|
||||||
|
|
||||||
|
@Value("${custom.config.db_ru.url}")
|
||||||
|
private String db_url_ru;
|
||||||
|
@Value("${custom.config.db_ru.login}")
|
||||||
|
private String db_login_ru;
|
||||||
|
@Value("${custom.config.db_ru.password}")
|
||||||
|
private String db_password_ru;
|
||||||
|
|
||||||
@Value("${custom.config.data_dir}")
|
@Value("${custom.config.data_dir}")
|
||||||
private String data_dir;
|
private String data_dir;
|
||||||
|
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SoilTmperature.class);
|
|
||||||
|
|
||||||
private ServletContext context;
|
private ServletContext context;
|
||||||
|
|
||||||
//Example: http://127.0.0.1:8081/geodatalist/DownloadSoil?forecast=000
|
//---------------------------------------------------------------------------
|
||||||
|
@Override
|
||||||
|
public void setServletContext(jakarta.servlet.ServletContext servletContext) {
|
||||||
|
this.context=context;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
public Connection getConn(String url, String login,String password){
|
||||||
|
Connection conn = null;
|
||||||
|
try{
|
||||||
|
Class.forName("org.postgresql.Driver");
|
||||||
|
conn = DriverManager.getConnection(url,login,password);
|
||||||
|
}catch(Exception ex)
|
||||||
|
{
|
||||||
|
logger.error("N1: "+ex.getMessage()+"<br>",ex);
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
public String getCountryId(Statement st,double lon,double lat) {
|
||||||
|
String country_id = "";
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
rs = st.executeQuery("select c.id from main.countries c where del=false and ST_Contains(c.geom,ST_SetSRID(st_makepoint(" + lon + "," + lat + "),4326)) limit 1");
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.error("N9: " + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
if (rs != null) {
|
||||||
|
try {
|
||||||
|
if (rs.next())
|
||||||
|
country_id = rs.getString(1);
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
logger.error("N10: " + ex.getMessage(), ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return country_id;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Example: http://127.0.0.1:8081/geodatalist/DownloadSoil?forecast=000
|
||||||
|
* @param response
|
||||||
|
* @param forecast
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@RequestMapping(value = "/geodatalist/DownloadSoil",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
|
@RequestMapping(value = "/geodatalist/DownloadSoil",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object ajaxTamer(HttpServletResponse response,@RequestParam(required=true,name="forecast") String forecast,@RequestParam(required=false,name="date") String date) {
|
public Object ajaxTamer(HttpServletResponse response,@RequestParam(required=true,name="forecast") String forecast,@RequestParam(required=false,name="date") String date) {
|
||||||
@ -88,24 +155,9 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
if (!dir.exists()) dir.mkdirs();
|
if (!dir.exists()) dir.mkdirs();
|
||||||
|
|
||||||
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||||
Connection conn = null;
|
Connection conn_all = getConn(db_url_all,db_login_all,db_password_all);
|
||||||
try{
|
Connection conn_ru = getConn(db_url_ru,db_login_ru,db_password_ru);
|
||||||
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 ex)
|
|
||||||
{
|
|
||||||
logger.error("N1: "+ex.getMessage()+"<br>",ex);
|
|
||||||
result+="Connect Exception:"+ex.getMessage()+"<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
//Example request: http://ccalm.org/DownloadWeather?forecast=000&date=20210531
|
//Example request: http://ccalm.org/DownloadWeather?forecast=000&date=20210531
|
||||||
//Example request: http://localhost:8080/CCALM/DownloadWeather?forecast=000
|
//Example request: http://localhost:8080/CCALM/DownloadWeather?forecast=000
|
||||||
@ -241,15 +293,18 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
dimIt = null;
|
dimIt = null;
|
||||||
|
|
||||||
Statement st=null;
|
Statement st_all=null;
|
||||||
|
Statement st_ru=null;
|
||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
st_all = conn_all.createStatement();
|
||||||
|
st_ru = conn_all.createStatement();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N3: "+ex.getMessage(),ex);
|
logger.error("N3: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("BEGIN TRANSACTION;");
|
st_all.executeUpdate("BEGIN TRANSACTION;");
|
||||||
|
st_ru.executeUpdate("BEGIN TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N4: "+ex.getMessage(),ex);
|
logger.error("N4: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -260,21 +315,24 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
logger.info("Delete old data 1");
|
logger.info("Delete old data 1");
|
||||||
try {
|
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;
|
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);
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N5: "+ex.getMessage(),ex);
|
logger.error("N5: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
logger.info("Delete old data 2");
|
logger.info("Delete old data 2");
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.soil_temperature_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
String sql="delete from main.soil_temperature_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
||||||
st.executeUpdate(sql);
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N6: "+ex.getMessage(),ex);
|
logger.error("N6: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
logger.info("Delete old data 3");
|
logger.info("Delete old data 3");
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.soil_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
String sql="delete from main.soil_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
||||||
st.executeUpdate(sql);
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N7: "+ex.getMessage(),ex);
|
logger.error("N7: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -282,19 +340,22 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
logger.info("Delete old data 4");
|
logger.info("Delete old data 4");
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.soil_temperature where hours="+forecast;
|
String sql="delete from main.soil_temperature where hours="+forecast;
|
||||||
st.executeUpdate(sql);
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N8: "+ex.getMessage(),ex);
|
logger.error("N8: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("END TRANSACTION;");
|
st_all.executeUpdate("END TRANSACTION;");
|
||||||
|
st_ru.executeUpdate("END TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N8.1:"+ex.getMessage(),ex);
|
logger.error("N8.1:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("BEGIN TRANSACTION;");
|
st_all.executeUpdate("BEGIN TRANSACTION;");
|
||||||
|
st_ru.executeUpdate("BEGIN TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N8.2:"+ex.getMessage(),ex);
|
logger.error("N8.2:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -315,29 +376,24 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
if(!Float.isNaN(dataArrayTmp.getFloat(pos))) //On the water none temperatyre.
|
if(!Float.isNaN(dataArrayTmp.getFloat(pos))) //On the water none temperatyre.
|
||||||
{
|
{
|
||||||
String country_id="";
|
String country_id="";
|
||||||
ResultSet rs=null;
|
boolean db_all=false,db_ru=false;
|
||||||
try {
|
if(country_id.isEmpty()) {
|
||||||
rs = st.executeQuery("select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1");
|
country_id = getCountryId(st_all, lon, lat);
|
||||||
} catch (SQLException ex) {
|
if(!country_id.isEmpty()) db_all=true;
|
||||||
logger.error("N9: "+ex.getMessage(),ex);
|
|
||||||
throw new Exception("Failed to select country...");
|
|
||||||
}
|
}
|
||||||
if (rs != null) {
|
if(country_id.isEmpty()) {
|
||||||
try {
|
country_id = getCountryId(st_ru, lon, lat);
|
||||||
if (rs.next())
|
if(!country_id.isEmpty()) db_ru=true;
|
||||||
country_id=rs.getString(1);
|
|
||||||
rs.close();
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
logger.error("N10: "+ex.getMessage(),ex);
|
|
||||||
throw new Exception("Failed to select country...");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
|
if(!country_id.isEmpty() && !country_id.equals("null"))
|
||||||
{
|
{
|
||||||
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
|
|
||||||
try {
|
try {
|
||||||
String sql="insert into main.soil_temperature(date,hours,val,geom,country_id,soil_temperature_date_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+",main.get_soil_temperature_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
|
String sql="insert into main.soil_temperature(date,hours,val,geom,country_id,soil_temperature_date_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+",main.get_soil_temperature_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
|
||||||
st.executeUpdate(sql);
|
if(db_all)
|
||||||
|
st_all.executeUpdate(sql);
|
||||||
|
if(db_ru)
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N11: "+ex.getMessage(),ex);
|
logger.error("N11: "+ex.getMessage(),ex);
|
||||||
throw new Exception("Failed insert soil temperature...");
|
throw new Exception("Failed insert soil temperature...");
|
||||||
@ -353,7 +409,8 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
//Cut data piece from big country of Russia
|
//Cut data piece from big country of Russia
|
||||||
try {
|
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);";
|
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);
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N12: "+ex.getMessage(),ex);
|
logger.error("N12: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -361,13 +418,16 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
//Delete values where country_id is null
|
//Delete values where country_id is null
|
||||||
try {
|
try {
|
||||||
String sql="delete from main.soil_temperature where country_id is null;";
|
String sql="delete from main.soil_temperature where country_id is null;";
|
||||||
st.executeUpdate(sql);
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N13: "+ex.getMessage(),ex);
|
logger.error("N13: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("END TRANSACTION;");
|
String sql="END TRANSACTION;";
|
||||||
|
st_all.executeUpdate(sql);
|
||||||
|
st_ru.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N14: "+ex.getMessage(),ex);
|
logger.error("N14: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
@ -375,37 +435,16 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
gid.close();
|
gid.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.error("N15: "+ex.getMessage(),ex);
|
logger.error("N15: "+ex.getMessage(),ex);
|
||||||
}
|
} catch (Exception ex) {
|
||||||
catch (Exception ex) {
|
|
||||||
logger.error("N16: "+ex.getMessage(),ex);
|
logger.error("N16: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {conn.close();} catch (SQLException ex) {logger.error("N16: "+ex.getMessage(),ex);}
|
try {conn_all.close();} catch (SQLException ex) {logger.error("N16: "+ex.getMessage(),ex);}
|
||||||
|
try {conn_ru.close();} catch (SQLException ex) {logger.error("N16: "+ex.getMessage(),ex);}
|
||||||
|
|
||||||
result+="End!<br>";
|
result+="End!<br>";
|
||||||
return result;
|
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
|
//List of "Soil temperature" dates from database in JSON
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@ -418,27 +457,14 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
boolean error=false;
|
boolean error=false;
|
||||||
String result="";
|
String result="";
|
||||||
|
|
||||||
Connection conn = null;
|
Connection conn_all = getConn(db_url_all,db_login_all,db_password_all);
|
||||||
try {
|
//Connection conn_ru = getConn(db_url_ru,db_login_ru,db_password_ru);
|
||||||
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.error("N17: "+ex.getMessage(),ex);
|
|
||||||
error=true;
|
|
||||||
result="<br>SQLException: "+ex.getMessage()+"<br>";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!error)
|
if(!error)
|
||||||
{
|
{
|
||||||
Statement st;
|
Statement st;
|
||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
st = conn_all.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";
|
//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";
|
||||||
String sql = """
|
String sql = """
|
||||||
SELECT
|
SELECT
|
||||||
@ -475,10 +501,12 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
|
|
||||||
}
|
}
|
||||||
st.close();
|
st.close();
|
||||||
conn.close();
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.error("N19: "+ex.getMessage(),ex);
|
logger.error("N19: "+ex.getMessage(),ex);
|
||||||
result="<br>SQLException:"+ex.getMessage()+"<br>";
|
result="<br>SQLException:"+ex.getMessage()+"<br>";
|
||||||
|
}finally {
|
||||||
|
if(conn_all!=null) try{ conn_all.close(); } catch (SQLException ignored){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
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
|
|
||||||
@ -2,25 +2,33 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
|
|
||||||
<!-- Please check if the user has access to the directory from which the application is being executed -->
|
<!-- Please check if the user has access to the directory from which the application is being executed -->
|
||||||
<property name="LOGS" value="/var/log/weather" />
|
<property name="LOGS" value="logs" />
|
||||||
|
<springProperty scope="context" name="appName" source="spring.application.name"/>
|
||||||
|
|
||||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<file>${LOGS}/weather.log</file>
|
<file>${LOGS}/${appName}.log</file>
|
||||||
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
|
<encoder>
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
<pattern>{"timestamp":"%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'}","thread":"[%thread]","level":"%level","logger":"%logger{36}","marker":"%X{marker}","message":"%msg"}%n</pattern>
|
||||||
<!-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -->
|
</encoder>
|
||||||
<fileNamePattern>${LOGS}/weather.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
<!-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> -->
|
<fileNamePattern>${LOGS}/${appName}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
|
||||||
<maxFileSize>100MB</maxFileSize>
|
|
||||||
<!-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> -->
|
|
||||||
<maxHistory>30</maxHistory>
|
<maxHistory>30</maxHistory>
|
||||||
<!-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>) -->
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||||
<totalSizeCap>3GB</totalSizeCap>
|
<maxFileSize>100MB</maxFileSize>
|
||||||
|
</timeBasedFileNamingAndTriggeringPolicy>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<root level="info">
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'} | %level | %logger{36} | %X{marker} | %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!--root level="info"-->
|
||||||
|
<root level="warn">
|
||||||
<appender-ref ref="FILE" />
|
<appender-ref ref="FILE" />
|
||||||
|
<appender-ref ref="CONSOLE" />
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
Reference in New Issue
Block a user