diff --git a/org_ccalm_weather.yml b/org_ccalm_weather.yml index 23118b4..e3267a3 100644 --- a/org_ccalm_weather.yml +++ b/org_ccalm_weather.yml @@ -17,14 +17,14 @@ custom: data_dir: /data/ db_all: #url: jdbc:postgresql://92.46.48.43:5444/weather?ApplicationName=kz_mcp_weather&sslmode=require - url: jdbc:postgresql://192.168.0.90:5432/weather?ApplicationName=kz_mcp_weather&sslmode=require - #url: jdbc:postgresql://127.0.0.1:5432/weather?ApplicationName=kz_mcp_weather&sslmode=require + #url: jdbc:postgresql://192.168.0.90:5432/weather?ApplicationName=kz_mcp_weather&sslmode=require + url: jdbc:postgresql://127.0.0.1:5432/weather?ApplicationName=kz_mcp_weather&sslmode=require login: postgres password: PasSecrKey1 db_ru: #url: jdbc:postgresql://92.46.48.43:5444/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require - url: jdbc:postgresql://192.168.0.90:5432/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require - #url: jdbc:postgresql://127.0.0.1:5432/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require + #url: jdbc:postgresql://192.168.0.90:5432/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require + url: jdbc:postgresql://127.0.0.1:5432/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require login: postgres password: PasSecrKey1 diff --git a/src/main/java/org/ccalm/weather/AirTemperature.java b/src/main/java/org/ccalm/weather/AirTemperature.java index 2700121..27e1f27 100644 --- a/src/main/java/org/ccalm/weather/AirTemperature.java +++ b/src/main/java/org/ccalm/weather/AirTemperature.java @@ -292,86 +292,96 @@ public class AirTemperature implements ServletContextAware { } int pos=0; - for(int nLat=0;nLat180) lon=lon-360; - double lat = dataArrayLat.getFloat(nLat); - - if(lat>29 && lat<67 && lon>17 && lon<180) //Central Asia + for(int nLon=0;nLon180) lon=lon-360; + double lat = dataArrayLat.getFloat(nLat); - if(country_id!=null && !country_id.equals("") && !country_id.equals("null")) + if(lat>29 && lat<67 && lon>17 && lon<180) //Central Asia + { + if(!Float.isNaN(dataArrayTmp.getFloat(pos))) //On the water none temperatyre. { - String sql= """ - insert into main.air_temperature( - val, - country_id, - point_id, - air_temperature_date_id - )values( - ?, - ?, - ?, - main.get_air_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?) - ); - """; - String point_id=null; - if(db_all) { - point_id = DBTools.getPointId(st_all, country_id, lon, lat); - if(point_id!=null) { - try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) { - pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); - pstmt.setLong(2, Long.valueOf(country_id)); - pstmt.setLong(3, Long.valueOf(point_id)); - pstmt.setString(4, date + " " + time); - pstmt.setInt(5, Integer.valueOf(forecast)); - pstmt.executeUpdate(); - } catch (SQLException ex) { - logger.error("E10:"+ex.getMessage(),ex); - //throw new Exception("Failed insert ..."); - } - } + String country_id=""; + boolean db_all=false,db_ru=false; + if(st_all!=null && country_id.isEmpty()) { + country_id = DBTools.getCountryId(st_all, lon, lat); + if(!country_id.isEmpty()) db_all=true; } - if(db_ru) { - point_id = DBTools.getPointId(st_ru, country_id, lon, lat); - if(point_id!=null) { - try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { - pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); - pstmt.setLong(2, Long.valueOf(country_id)); - pstmt.setLong(3, Long.valueOf(point_id)); - pstmt.setString(4, date + " " + time); - pstmt.setInt(5, Integer.valueOf(forecast)); - pstmt.executeUpdate(); - } catch (SQLException ex) { - logger.error("E11:"+ex.getMessage(),ex); - //throw new Exception("Failed insert ..."); - } + if(st_ru!=null && country_id.isEmpty()) { + country_id = DBTools.getCountryId(st_ru, lon, lat); + if(!country_id.isEmpty()) db_ru=true; + } + + if(country_id!=null && !country_id.equals("") && !country_id.equals("null")) + { + String sql= """ + insert into main.air_temperature( + val, + country_id, + air_temperature_date_id, + point_id + )values( + ?, + ?, + main.get_air_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?), + main.get_point_id(?,?,?) + ); + """; + //String point_id=null; + if(db_all) { + //point_id = DBTools.getPointId(st_all, country_id, lon, lat); + //if(point_id!=null) { + try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) { + pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); + pstmt.setLong(2, Long.valueOf(country_id)); + //pstmt.setLong(3, Long.valueOf(point_id)); + pstmt.setString(3, date + " " + time); + pstmt.setInt(4, Integer.valueOf(forecast)); + pstmt.setLong(5, Long.valueOf(country_id)); + pstmt.setDouble(6, lon); + pstmt.setDouble(7, lat); + pstmt.executeUpdate(); + } catch (SQLException ex) { + logger.error("E10:"+ex.getMessage(),ex); + throw new Exception("Failed insert ..."); + } + //} + } + if(db_ru) { + //point_id = DBTools.getPointId(st_ru, country_id, lon, lat); + //if(point_id!=null) { + try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { + pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); + pstmt.setLong(2, Long.valueOf(country_id)); + //pstmt.setLong(3, Long.valueOf(point_id)); + pstmt.setString(3, date + " " + time); + pstmt.setInt(4, Integer.valueOf(forecast)); + pstmt.setLong(5, Long.valueOf(country_id)); + pstmt.setDouble(6, lon); + pstmt.setDouble(7, lat); + pstmt.executeUpdate(); + } catch (SQLException ex) { + logger.error("E11:"+ex.getMessage(),ex); + throw new Exception("Failed insert ..."); + } + //} } } } } + pos++; } - pos++; } + } 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));"; @@ -410,6 +420,7 @@ public class AirTemperature implements ServletContextAware { try { if(conn_ru!=null) conn_ru.close();} catch (SQLException ex) {logger.error("N15:"+ex.getMessage(),ex);} result+="End!
"; + System.out.println("Done download and save"); return result; } diff --git a/src/main/java/org/ccalm/weather/Precipitation.java b/src/main/java/org/ccalm/weather/Precipitation.java index 18b78b0..9124c09 100644 --- a/src/main/java/org/ccalm/weather/Precipitation.java +++ b/src/main/java/org/ccalm/weather/Precipitation.java @@ -365,7 +365,7 @@ public class Precipitation implements ServletContextAware { pstmt.executeUpdate(); } catch (SQLException ex) { logger.error("E10:"+ex.getMessage(),ex); - //throw new Exception("Failed insert precipitation..."); + throw new Exception("Failed insert precipitation..."); } } } @@ -381,7 +381,7 @@ public class Precipitation implements ServletContextAware { pstmt.executeUpdate(); } catch (SQLException ex) { logger.error("E10:"+ex.getMessage(),ex); - //throw new Exception("Failed insert precipitation..."); + throw new Exception("Failed insert precipitation..."); } } } diff --git a/src/main/java/org/ccalm/weather/SoilTmperature.java b/src/main/java/org/ccalm/weather/SoilTmperature.java index 7859bba..44c1367 100644 --- a/src/main/java/org/ccalm/weather/SoilTmperature.java +++ b/src/main/java/org/ccalm/weather/SoilTmperature.java @@ -385,7 +385,7 @@ public class SoilTmperature implements ServletContextAware { pstmt.executeUpdate(); } catch (SQLException ex) { logger.error("E10:"+ex.getMessage(),ex); - //throw new Exception("Failed insert soil temperature..."); + throw new Exception("Failed insert soil temperature..."); } } } @@ -401,7 +401,7 @@ public class SoilTmperature implements ServletContextAware { pstmt.executeUpdate(); } catch (SQLException ex) { logger.error("E10:"+ex.getMessage(),ex); - //throw new Exception("Failed insert soil temperature..."); + throw new Exception("Failed insert soil temperature..."); } } }