From 29888de73bd21b9b6e9e0a184b22c635df002a2e Mon Sep 17 00:00:00 2001 From: Igor I Date: Thu, 9 Jan 2025 18:41:02 +0500 Subject: [PATCH] + SSL --- org_ccalm_weather.yml | 13 +- .../org/ccalm/weather/AirTemperature.java | 64 +++++----- .../java/org/ccalm/weather/Precipitation.java | 114 +++++++++--------- .../org/ccalm/weather/SoilTmperature.java | 103 ++++++++-------- src/main/resources/keystore.jks | Bin 0 -> 2746 bytes 5 files changed, 145 insertions(+), 149 deletions(-) create mode 100644 src/main/resources/keystore.jks diff --git a/org_ccalm_weather.yml b/org_ccalm_weather.yml index e3267a3..fcc61fe 100644 --- a/org_ccalm_weather.yml +++ b/org_ccalm_weather.yml @@ -1,5 +1,10 @@ server: port: 8081 + ssl: + key-store: classpath:keystore.jks + key-store-password: QyKtWPZB + key-store-type: JKS + key-alias: weather servlet: session: timeout: 300s @@ -17,14 +22,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 27e1f27..9b17969 100644 --- a/src/main/java/org/ccalm/weather/AirTemperature.java +++ b/src/main/java/org/ccalm/weather/AirTemperature.java @@ -318,7 +318,7 @@ public class AirTemperature implements ServletContextAware { if(!country_id.isEmpty()) db_ru=true; } - if(country_id!=null && !country_id.equals("") && !country_id.equals("null")) + if(country_id!=null && !country_id.isEmpty() && !country_id.equals("null")) { String sql= """ insert into main.air_temperature( @@ -333,44 +333,36 @@ public class AirTemperature implements ServletContextAware { 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 ..."); - } - //} + try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) { + pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); + pstmt.setLong(2, Long.valueOf(country_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 ..."); - } - //} + try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) { + pstmt.setFloat(1, dataArrayTmp.getFloat(pos)); + pstmt.setLong(2, Long.valueOf(country_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 ..."); + } } } } diff --git a/src/main/java/org/ccalm/weather/Precipitation.java b/src/main/java/org/ccalm/weather/Precipitation.java index 9124c09..0baec4c 100644 --- a/src/main/java/org/ccalm/weather/Precipitation.java +++ b/src/main/java/org/ccalm/weather/Precipitation.java @@ -312,72 +312,71 @@ public class Precipitation 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.precipitation( - val, - country_id, - point_id, - air_temperature_date_id - )values( - ?, - ?, - ?, - main.get_precipitation_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) { + String country_id=""; + boolean db_all=false,db_ru=false; + if(country_id.isEmpty()) { + country_id = DBTools.getCountryId(st_all, lon, lat); + if(!country_id.isEmpty()) db_all=true; + } + if(country_id.isEmpty()) { + country_id = DBTools.getCountryId(st_ru, lon, lat); + if(!country_id.isEmpty()) db_ru=true; + } + + if(country_id!=null && !country_id.isEmpty() && !country_id.equals("null")) + { + String sql= """ + insert into main.precipitation( + val, + country_id, + air_temperature_date_id, + point_id + )values( + ?, + ?, + main.get_precipitation_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?), + main.get_point_id(?,?,?) + ); + """; + if(db_all) { 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.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 precipitation..."); } } - } - if(db_ru) { - point_id = DBTools.getPointId(st_ru, country_id, lon, lat); - if(point_id!=null) { + if(db_ru) { 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.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); @@ -385,14 +384,15 @@ public class Precipitation implements ServletContextAware { } } } - } - - } - } - 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));"; diff --git a/src/main/java/org/ccalm/weather/SoilTmperature.java b/src/main/java/org/ccalm/weather/SoilTmperature.java index 44c1367..2fc28a8 100644 --- a/src/main/java/org/ccalm/weather/SoilTmperature.java +++ b/src/main/java/org/ccalm/weather/SoilTmperature.java @@ -331,73 +331,71 @@ public class SoilTmperature 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(lat>29 && lat<67 && lon>17 && lon<180) //Central Asia { - String country_id=""; - boolean db_all=false,db_ru=false; - if(country_id.isEmpty()) { - country_id = DBTools.getCountryId(st_all, lon, lat); - if(!country_id.isEmpty()) db_all=true; - } - if(country_id.isEmpty()) { - country_id = DBTools.getCountryId(st_ru, lon, lat); - if(!country_id.isEmpty()) db_ru=true; - } - - if(!country_id.isEmpty() && !country_id.equals("null")) + if(!Float.isNaN(dataArrayTmp.getFloat(pos))) //On the water none temperatyre. { + String country_id=""; + boolean db_all=false,db_ru=false; + if(country_id.isEmpty()) { + country_id = DBTools.getCountryId(st_all, lon, lat); + if(!country_id.isEmpty()) db_all=true; + } + if(country_id.isEmpty()) { + country_id = DBTools.getCountryId(st_ru, lon, lat); + if(!country_id.isEmpty()) db_ru=true; + } - String sql=""" - insert into main.soil_temperature( - val, - country_id, - point_id, - soil_temperature_date_id - )values( - ?, - ?, - ?, - main.get_soil_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) { + if(country_id!=null && !country_id.isEmpty() && !country_id.equals("null")) + { + String sql=""" + insert into main.soil_temperature( + val, + country_id, + soil_temperature_date_id, + point_id + )values( + ?, + ?, + main.get_soil_temperature_date(cast(to_timestamp(?, 'YYYYMMDD HH24') as timestamp without time zone),?), + main.get_point_id(?,?,?) + ); + """; + if(db_all) { 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.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 soil temperature..."); } } - } - if(db_ru) { - point_id = DBTools.getPointId(st_ru, country_id, lon, lat); - if(point_id!=null) { + if(db_ru) { 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.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); @@ -406,11 +404,12 @@ public class SoilTmperature implements ServletContextAware { } } } - } + pos++; } - pos++; } + } catch (Exception ex) { + logger.error(ex.getMessage(),ex); } //Cut data piece from big country of Russia diff --git a/src/main/resources/keystore.jks b/src/main/resources/keystore.jks new file mode 100644 index 0000000000000000000000000000000000000000..90460fce2a3c9da20104417c88cadf959371bc93 GIT binary patch literal 2746 zcma);X*d*$8pjzkma&XwkYyO5>}D)ytYHX;$dY|0J4MD;CX6LQYDQ!oiO4dxgN7lZ zNuombknK>ebqa%Wo#&pX^W0DOet4h%^Zx(u`+odAF9HW{1u!xpa9~enHn~*O)O}7y z7RFK>*cylfTb$azBXFRG|B675fjCg{shxjX51HBj-r@i=0!ncp{Zms1;rD9;#EEc1 zX#CT1AmoA2eN=%u*`_6a6u zeVKraazJh~WEK%-C(J*g8yA+t;4K2g0YA*Fz;d}dNjK)X2)R5eT$ud30v0h1A?>X$ zh6WLdgn;8J`zBTq`u+T2N5Q*^$<9`78byu4=LBj$36T^lrNIsU`(b3;e*dXBcMhXZ zU-_G00(z}hw;o|X4owvAnMxt_pY8&=ZuDYPfIcDU2J)=Hdspxe5{wQ+L zJ<3IVjajdbw>>kJ=?URZ-<62_1ERu1n`~?G{S@z);8udYP#X0C zIy5Dm0e_DSpZQ_OlP@~9X4V!s+A5(uTAk+~CL5j{>(8ket1xc_)QePEeNXza)ROFBG5Zzzj{n130*7d{wS2@Rx>&T*))^If$keg%o!y=~> z(K(|qPxnRlre(eK!+@o73?19Om#5e~_o97UP_@#dOOOlf$(G;Poa8FNBl;s|td#Us zg@)OFcaH*5{HVI1G5qZCYGWs1$LM9Gs;EWbgH1I@y^q6e{O zU5A|2JeQ<`_R-p%5*@qEg5P$l?&eZHyp<+NcFXQPEBsN|Q--{Ta%S%oQ+L(|ak2Wz$e)QGkRg;zR3Rgig*$3>E_)%#@ zs9Krn^R5@u_?we<$GRcrA)R%jCLI^QW_-o&B(oZ!cf5mhe#gADgoijs?0J5+ZD%!= z8*9E|l(BM23dXYK3(!vyw&kWr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