diff --git a/pom.xml b/pom.xml
index 1b10231..5551499 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.ccalm
weather
- 0.0.7-SNAPSHOT
+ 0.0.8-SNAPSHOT
weather
Weather APP
diff --git a/src/main/java/org/ccalm/weather/AirTemperature.java b/src/main/java/org/ccalm/weather/AirTemperature.java
index 9b17969..312bbbb 100644
--- a/src/main/java/org/ccalm/weather/AirTemperature.java
+++ b/src/main/java/org/ccalm/weather/AirTemperature.java
@@ -107,9 +107,33 @@ public class AirTemperature implements ServletContextAware {
//response.getWriter().append("Served at: ").append(request.getContextPath());
Connection conn_all = getConn(db_url_all,db_login_all,db_password_all);
Connection conn_ru = getConn(db_url_ru,db_login_ru,db_password_ru);
+ Statement st_all=null;
+ Statement st_ru=null;
+ try {
+ if(conn_all!=null) st_all = conn_all.createStatement();
+ if(conn_ru!=null) st_ru = conn_ru.createStatement();
+ } catch (SQLException ex) {
+ logger.error("N3:"+ex.getMessage(),ex);
+ }
//Example request: http://ccalm.org/AirTemperature?date=20210531
- //Example request: http://localhost:8080/AirTemperature?date=20210531
+ //Example request: http://127.0.0.1:8080/AirTemperature?date=20210531
+ if(date==null || date.equals(""))
+ {
+ //Если день не задан то ищем максимальный день не старше 10 дней и прибавляем 1 день
+ String sql="select to_char(max(date)+'1 days'::interval, 'YYYYMMDD') from main.air_temperature_dates where hours=0 and date > now() - '10 days'::interval";
+ if(st_all!=null) {
+ try {
+ try (ResultSet rs = st_all.executeQuery(sql)) {
+ if (rs.next()) {
+ date = rs.getString(1);
+ }
+ }
+ } catch (SQLException ex) {
+ logger.error("N4:"+ex.getMessage(),ex);
+ }
+ }
+ }
if(date==null || date.equals(""))
{
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
@@ -232,14 +256,6 @@ public class AirTemperature implements ServletContextAware {
}
dimIt = null;
- Statement st_all=null;
- Statement st_ru=null;
- try {
- if(conn_all!=null) st_all = conn_all.createStatement();
- if(conn_ru!=null) st_ru = conn_ru.createStatement();
- } catch (SQLException ex) {
- logger.error("N3:"+ex.getMessage(),ex);
- }
try {
String sql = "BEGIN TRANSACTION;";
@@ -347,7 +363,6 @@ public class AirTemperature implements ServletContextAware {
logger.error("E10:"+ex.getMessage(),ex);
throw new Exception("Failed insert ...");
}
-
}
if(db_ru) {
try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
@@ -374,13 +389,39 @@ public class AirTemperature implements ServletContextAware {
logger.error(ex.getMessage(),ex);
}
- //Cut data piece from big country of Russia
- try {
- String sql="delete from main.points p 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),ST_SetSRID(st_makepoint(p.lon,p.lat),4326));";
- if(st_all!=null) st_all.executeUpdate(sql);
- if(st_ru!=null) st_ru.executeUpdate(sql);
- } catch (SQLException ex) {
- logger.error("N11:"+ex.getMessage(),ex);
+ //Deleting readings located in northern latitudes since locusts do not live there.
+ {
+ //String sql="delete from main.points p 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),ST_SetSRID(st_makepoint(p.lon,p.lat),4326));";
+ String sql= """
+ delete from main.air_temperature where id in
+ (
+ select a.id from
+ main.air_temperature a
+ join main.points p on p.id=a.point_id
+ where
+ a.country_id=7
+ and a.air_temperature_date_id = main.get_air_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?)
+ 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),ST_SetSRID(st_makepoint(p.lon,p.lat),4326))
+ )
+ """;
+ if(conn_all!=null) {
+ try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
+ pstmt.setString(1, date + " " + time);
+ pstmt.setInt(2, Integer.valueOf(forecast));
+ pstmt.executeUpdate();
+ } catch (SQLException ex) {
+ logger.error("E10.1:"+ex.getMessage(),ex);
+ }
+ }
+ if(conn_ru!=null) {
+ try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
+ pstmt.setString(1, date + " " + time);
+ pstmt.setInt(2, Integer.valueOf(forecast));
+ pstmt.executeUpdate();
+ } catch (SQLException ex) {
+ logger.error("E11:"+ex.getMessage(),ex);
+ }
+ }
}
try {
diff --git a/src/main/java/org/ccalm/weather/MainController.java b/src/main/java/org/ccalm/weather/MainController.java
index 9f93080..e446456 100644
--- a/src/main/java/org/ccalm/weather/MainController.java
+++ b/src/main/java/org/ccalm/weather/MainController.java
@@ -9,6 +9,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
+import java.io.InputStream;
+import java.util.Properties;
+
@Controller
public class MainController {
@@ -16,18 +19,61 @@ public class MainController {
@GetMapping("/")
@ResponseBody
public String getIndex(Model model) {
- return "The weather list is working!
/geodatalist";
+ String buildDate="";
+ //String buildVersion="";
+ try {
+ InputStream inputStream = MainController.class.getClassLoader().getResourceAsStream("META-INF/build-info.properties");
+ if (inputStream != null) {
+ Properties properties = new Properties();
+ properties.load(inputStream);
+ buildDate = properties.getProperty("build.time");
+ //buildVersion = properties.getProperty("build.version");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ String result="buildDate = " + buildDate + "
";
+ result+="""
+ The weather list is working!
/geodatalist
+ """;
+ return result;
+ }
+
+ @CrossOrigin
+ @GetMapping("/geodatalist/")
+ @ResponseBody
+ public String getIndex2(Model model) {
+ String buildDate="";
+ //String buildVersion="";
+ try {
+ InputStream inputStream = MainController.class.getClassLoader().getResourceAsStream("META-INF/build-info.properties");
+ if (inputStream != null) {
+ Properties properties = new Properties();
+ properties.load(inputStream);
+ buildDate = properties.getProperty("build.time");
+ //buildVersion = properties.getProperty("build.version");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ String result="buildDate = " + buildDate + "
";
+ result+="""
+ The weather list is working!
/geodatalist
+ """;
+ return result;
}
@CrossOrigin
@GetMapping("/geodatalist")
@ResponseBody
public String getGeoDataList(Model model) {
- return """
- AirTemperatureDates
- PrecipitationDates
- SoilDates
- """;
+ return """
+ AirTemperatureDates
+ PrecipitationDates
+ SoilDates
+ """;
}
}
\ No newline at end of file
diff --git a/src/main/java/org/ccalm/weather/Precipitation.java b/src/main/java/org/ccalm/weather/Precipitation.java
index 0baec4c..4826d96 100644
--- a/src/main/java/org/ccalm/weather/Precipitation.java
+++ b/src/main/java/org/ccalm/weather/Precipitation.java
@@ -108,10 +108,10 @@ public class Precipitation implements ServletContextAware {
}
//---------------------------------------------------------------------------
/**
- * Example http://127.0.0.1:8080/AirTemperature
+ * Example https://127.0.0.1:8081/geodatalist/Precipitation or https://127.0.0.1:8081/geodatalist/Precipitation?date=20250531
* @param response
* @param date
- * @return
+ * @return HTML string
*/
@RequestMapping(value = "/geodatalist/Precipitation",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
@ResponseBody
@@ -131,8 +131,30 @@ public class Precipitation implements ServletContextAware {
//response.getWriter().append("Served at: ").append(request.getContextPath());
Connection conn_all = getConn(db_url_all,db_login_all,db_password_all);
Connection conn_ru = getConn(db_url_ru,db_login_ru,db_password_ru);
-
- //Example request: http://localhost:8080/Precipitation?date=20210531
+ Statement st_all=null;
+ Statement st_ru=null;
+ try {
+ st_all = conn_all.createStatement();
+ st_ru = conn_ru.createStatement();
+ } catch (SQLException ex) {
+ logger.error("N3:"+ex.getMessage(),ex);
+ }
+ if(date==null || date.equals(""))
+ {
+ //Если день не задан то ищем максимальный день не старше 10 дней и прибавляем 1 день
+ String sql="select to_char(max(date)+'1 days'::interval, 'YYYYMMDD') from main.precipitation_dates where hours=0 and date > now() - '10 days'::interval";
+ if(st_all!=null) {
+ try {
+ try (ResultSet rs = st_all.executeQuery(sql)) {
+ if (rs.next()) {
+ date = rs.getString(1);
+ }
+ }
+ } catch (SQLException ex) {
+ logger.error("N4:"+ex.getMessage(),ex);
+ }
+ }
+ }
if(date==null || date.equals(""))
{
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
@@ -253,14 +275,6 @@ public class Precipitation implements ServletContextAware {
}
dimIt = null;
- Statement st_all=null;
- Statement st_ru=null;
- try {
- st_all = conn_all.createStatement();
- st_ru = conn_ru.createStatement();
- } catch (SQLException ex) {
- logger.error("N3:"+ex.getMessage(),ex);
- }
try {
st_all.executeUpdate("BEGIN TRANSACTION;");
@@ -288,16 +302,16 @@ public class Precipitation implements ServletContextAware {
} catch (SQLException ex) {
logger.error("N7:"+ex.getMessage(),ex);
}
- if(Integer.parseInt(forecast)!=0) {
- logger.info("Delete all old forecasts");
- try {
- String sql="delete from main.precipitation_dates where hours="+forecast;
- st_all.executeUpdate(sql);
- st_ru.executeUpdate(sql);
- } catch (SQLException ex) {
- logger.error("N8: "+ex.getMessage(),ex);
- }
- }
+// if(Integer.parseInt(forecast)!=0) {
+// logger.info("Delete all old forecasts");
+// try {
+// String sql="delete from main.precipitation_dates where hours="+forecast; у меня всё 24 часа вот и всё и удалит..... не раскоментировать!
+// st_all.executeUpdate(sql);
+// st_ru.executeUpdate(sql);
+// } catch (SQLException ex) {
+// logger.error("N8: "+ex.getMessage(),ex);
+// }
+// }
try {
st_all.executeUpdate("END TRANSACTION;");
st_ru.executeUpdate("END TRANSACTION;");
@@ -344,7 +358,7 @@ public class Precipitation implements ServletContextAware {
insert into main.precipitation(
val,
country_id,
- air_temperature_date_id,
+ precipitation_date_id,
point_id
)values(
?,
@@ -393,13 +407,39 @@ public class Precipitation implements ServletContextAware {
} catch (Exception ex) {
logger.error(ex.getMessage(),ex);
}
- //Cut data piece from big country of Russia
- try {
- String sql="delete from main.points p 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),ST_SetSRID(st_makepoint(p.lon,p.lat),4326));";
- st_all.executeUpdate(sql);
- st_ru.executeUpdate(sql);
- } catch (SQLException ex) {
- logger.error("N11:"+ex.getMessage(),ex);
+ //Deleting readings located in northern latitudes since locusts do not live there.
+ {
+ //String sql="delete from main.points p 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),ST_SetSRID(st_makepoint(p.lon,p.lat),4326));";
+ String sql= """
+ delete from main.precipitation where id in
+ (
+ select a.id from
+ main.precipitation a
+ join main.points p on p.id=a.point_id
+ where
+ a.country_id=7
+ and a.precipitation_date_id = main.get_precipitation_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?)
+ 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),ST_SetSRID(st_makepoint(p.lon,p.lat),4326))
+ )
+ """;
+ if(conn_all!=null) {
+ try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
+ pstmt.setString(1, date + " " + time);
+ pstmt.setInt(2, Integer.valueOf(forecast));
+ pstmt.executeUpdate();
+ } catch (SQLException ex) {
+ logger.error("E10.1:"+ex.getMessage(),ex);
+ }
+ }
+ if(conn_ru!=null) {
+ try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
+ pstmt.setString(1, date + " " + time);
+ pstmt.setInt(2, Integer.valueOf(forecast));
+ pstmt.executeUpdate();
+ } catch (SQLException ex) {
+ logger.error("E11:"+ex.getMessage(),ex);
+ }
+ }
}
try {
diff --git a/src/main/java/org/ccalm/weather/SoilTmperature.java b/src/main/java/org/ccalm/weather/SoilTmperature.java
index 2fc28a8..180a223 100644
--- a/src/main/java/org/ccalm/weather/SoilTmperature.java
+++ b/src/main/java/org/ccalm/weather/SoilTmperature.java
@@ -112,7 +112,7 @@ public class SoilTmperature implements ServletContextAware {
* @param response
* @param forecast
* @param date
- * @return
+ * @return HTML string
*/
@RequestMapping(value = "/geodatalist/DownloadSoil",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
@ResponseBody
@@ -135,11 +135,30 @@ public class SoilTmperature implements ServletContextAware {
//response.getWriter().append("Served at: ").append(request.getContextPath());
Connection conn_all = getConn(db_url_all,db_login_all,db_password_all);
Connection conn_ru = getConn(db_url_ru,db_login_ru,db_password_ru);
-
-
- //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
+ Statement st_all=null;
+ Statement st_ru=null;
+ try {
+ st_all = conn_all.createStatement();
+ st_ru = conn_ru.createStatement();
+ } catch (SQLException ex) {
+ logger.error("N3:"+ex.getMessage(),ex);
+ }
+ if(date==null || date.equals(""))
+ {
+ //Если день не задан то ищем максимальный день не старше 10 дней и прибавляем 1 день
+ String sql="select to_char(max(date)+'1 days'::interval, 'YYYYMMDD') from main.soil_temperature_dates where hours=0 and date > now() - '10 days'::interval";
+ if(st_all!=null) {
+ try {
+ try (ResultSet rs = st_all.executeQuery(sql)) {
+ if (rs.next()) {
+ date = rs.getString(1);
+ }
+ }
+ } catch (SQLException ex) {
+ logger.error("N4:"+ex.getMessage(),ex);
+ }
+ }
+ }
if(date==null || date.equals(""))
{
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
@@ -271,15 +290,6 @@ public class SoilTmperature implements ServletContextAware {
}
dimIt = null;
- Statement st_all=null;
- Statement st_ru=null;
- try {
- st_all = conn_all.createStatement();
- st_ru = conn_all.createStatement();
- } catch (SQLException ex) {
- logger.error("N3: "+ex.getMessage(),ex);
- }
-
try {
st_all.executeUpdate("BEGIN TRANSACTION;");
st_ru.executeUpdate("BEGIN TRANSACTION;");
@@ -412,13 +422,39 @@ public class SoilTmperature implements ServletContextAware {
logger.error(ex.getMessage(),ex);
}
- //Cut data piece from big country of Russia
- try {
- String sql="delete from main.points p 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),ST_SetSRID(st_makepoint(p.lon,p.lat),4326));";
- st_all.executeUpdate(sql);
- st_ru.executeUpdate(sql);
- } catch (SQLException ex) {
- logger.error("N12: "+ex.getMessage(),ex);
+ //Deleting readings located in northern latitudes since locusts do not live there.
+ {
+ //String sql="delete from main.points p 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),ST_SetSRID(st_makepoint(p.lon,p.lat),4326));";
+ String sql= """
+ delete from main.soil_temperature where id in
+ (
+ select a.id from
+ main.soil_temperature a
+ join main.points p on p.id=a.point_id
+ where
+ a.country_id=7
+ and a.soil_temperature_date_id = main.get_soil_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?)
+ 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),ST_SetSRID(st_makepoint(p.lon,p.lat),4326))
+ )
+ """;
+ if(conn_all!=null) {
+ try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
+ pstmt.setString(1, date + " " + time);
+ pstmt.setInt(2, Integer.valueOf(forecast));
+ pstmt.executeUpdate();
+ } catch (SQLException ex) {
+ logger.error("E10.1:"+ex.getMessage(),ex);
+ }
+ }
+ if(conn_ru!=null) {
+ try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
+ pstmt.setString(1, date + " " + time);
+ pstmt.setInt(2, Integer.valueOf(forecast));
+ pstmt.executeUpdate();
+ } catch (SQLException ex) {
+ logger.error("E11:"+ex.getMessage(),ex);
+ }
+ }
}
try {