diff --git a/pom.xml b/pom.xml
index 5bc8487..159da39 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,13 +10,27 @@
org.ccalm
weather
- 0.0.1-SNAPSHOT
+ 0.0.6-SNAPSHOT
weather
Demo project for Spring Boot
- 11
+ 17
org.ccalm.weather.WeatherApplication
+
+
+
+ unidata
+ Unidata UCAR Repository
+ https://artifacts.unidata.ucar.edu/content/repositories/unidata-releases/
+
+
+
+
org.springframework.boot
@@ -34,6 +48,12 @@
test
+
+ net.logstash.logback
+ logstash-logback-encoder
+ 6.6
+
+
+
+
@@ -64,6 +81,39 @@
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 3.2.0
+
+
+ copy-dependencies
+ package
+
+ copy-dependencies
+
+
+ ${project.build.directory}/lib
+ runtime
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 3.2.0
+
+
+
+ true
+ lib/
+ org.ccalm.weather.WeatherApplication
+
+
+
+
+
+
diff --git a/src/main/java/org/ccalm/weather/AirTemperature.java b/src/main/java/org/ccalm/weather/AirTemperature.java
index 081da02..271fc54 100644
--- a/src/main/java/org/ccalm/weather/AirTemperature.java
+++ b/src/main/java/org/ccalm/weather/AirTemperature.java
@@ -67,15 +67,18 @@ public class AirTemperature implements ServletContextAware {
private ServletContext context;
- //http://127.0.0.1:8080/AirTemperature
-
+ /**
+ * 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)
+ * @return HTML string
+ */
@RequestMapping(value = "/geodatalist/AirTemperature",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
@ResponseBody
public Object ajaxTamer(/*@RequestParam(required=true,name="forecast") String forecast,*/@RequestParam(required=false,name="date") String date) {
String forecast = "000";
String result="";
- result+="Start!
";
+ result+="Start!!!
";
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
@@ -96,10 +99,10 @@ public class AirTemperature implements ServletContextAware {
logger.info("
Connect is ERROR
");
result+="Connect is ERROR!
";
}
- }catch(Exception e)
+ }catch(Exception ex)
{
- logger.info("
Connect Exception:"+e.getMessage()+"
");
- result+="Connect Exception:"+e.getMessage()+"
";
+ logger.error("N1:"+ex.getMessage()+"
",ex);
+ result+="Connect Exception:"+ex.getMessage()+"
";
}
//Example request: http://ccalm.org/AirTemperature?date=20210531
@@ -145,7 +148,7 @@ public class AirTemperature implements ServletContextAware {
}
br.close();
} catch (IOException ex) {
- logger.info(ex.getMessage());
+ logger.error("N2:"+ex.getMessage(),ex);
result+=ex.getMessage()+"
";
}
if(!strPos1.equals(""))
@@ -162,11 +165,14 @@ public class AirTemperature implements ServletContextAware {
posEnd=String.valueOf(Long.parseLong(posEnd)-1);
}
- wd.download(URL, data_dir+"temp"+File.separator+"air_text.f000", String.valueOf(posStart), String.valueOf(posEnd));
+ if(!wd.download(URL, data_dir+"temp"+File.separator+"air_text.f000", String.valueOf(posStart), String.valueOf(posEnd))){
+ logger.info("Error download file: "+URL);
+ }
}
}else
{
result+="Not download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"air_text.idx"+"
";
+ logger.info("Not download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"air_text.idx");
}
Array dataArrayLat=null;
@@ -227,36 +233,51 @@ public class AirTemperature implements ServletContextAware {
try {
st = conn.createStatement();
} catch (SQLException ex) {
- logger.info(ex.getMessage());
+ logger.error("N3:"+ex.getMessage(),ex);
}
try {
st.executeUpdate("BEGIN TRANSACTION;");
} catch (SQLException ex) {
- logger.info(ex.getMessage());
- logger.info(ex.getMessage());
+ logger.error("N4:"+ex.getMessage(),ex);
}
result+="Size="+dataArrayLat.getSize()+"
";
//Delete old data
- System.out.println("Delete old data 1");
+ logger.info("Delete old data 1");
try {
String sql="delete from main.air_temperature where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
st.executeUpdate(sql);
} catch (SQLException ex) {
- logger.info(ex.getMessage());
+ logger.error("N5:"+ex.getMessage(),ex);
}
- System.out.println("Delete old data 2");
+ logger.info("Delete old data 2");
+ 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;
+ st.executeUpdate(sql);
+ } catch (SQLException ex) {
+ logger.error("N6:"+ex.getMessage(),ex);
+ }
+ logger.info("Delete old data 3");
try {
String sql="delete from main.air_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
st.executeUpdate(sql);
} catch (SQLException ex) {
- logger.info(ex.getMessage());
+ logger.error("N7:"+ex.getMessage(),ex);
}
-
-
-
+
+ try {
+ st.executeUpdate("END TRANSACTION;");
+ } catch (SQLException ex) {
+ logger.error("N7.1:"+ex.getMessage(),ex);
+ }
+ try {
+ st.executeUpdate("BEGIN TRANSACTION;");
+ } catch (SQLException ex) {
+ logger.error("N7.2:"+ex.getMessage(),ex);
+ }
+
int pos=0;
for(int nLat=0;nLat";
return result;
@@ -385,17 +405,27 @@ public class AirTemperature implements ServletContextAware {
result="An error occurred while connecting to the database!";
}
} catch (Exception ex) {
- logger.info(ex.getMessage());
+ logger.error("N16:"+ex.getMessage(),ex);
error=true;
result="
SQLException: "+ex.getMessage()+"
";
}
-
+
if(!error)
{
Statement st;
try {
st = conn.createStatement();
- String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,EXTRACT(DAY FROM CURRENT_DATE-date) as day FROM main.air_temperature group by date,hours order by date,hours;";
+ //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 = """
+ SELECT
+ to_char(date, 'YYYY-MM-DD') as date,
+ hours as hour,
+ EXTRACT(DAY FROM CURRENT_DATE-date) as day
+ FROM
+ main.air_temperature_dates
+ group by date,hours
+ order by date,hours
+ """;
ResultSet rs = st.executeQuery(sql);
if(rs!=null)
{
@@ -408,7 +438,7 @@ public class AirTemperature implements ServletContextAware {
result+= "{\"num\":\""+rs.getString("day")+"\", \"hour\":\""+rs.getString("hour")+"\", \"date\":\""+rs.getString("date")+"\"},";
} catch( Exception ex )
{
-
+ logger.error("N17:"+ex.getMessage(),ex);
}
}
if(exists) {
@@ -417,12 +447,12 @@ public class AirTemperature implements ServletContextAware {
}else {
result="[]";
}
-
}
st.close();
conn.close();
} catch (SQLException ex) {
result="
SQLException:"+ex.getMessage()+"
";
+ logger.error("N18:"+ex.getMessage(),ex);
}
}
return result;
diff --git a/src/main/java/org/ccalm/weather/MainController.java b/src/main/java/org/ccalm/weather/MainController.java
index 0f6849d..761914f 100644
--- a/src/main/java/org/ccalm/weather/MainController.java
+++ b/src/main/java/org/ccalm/weather/MainController.java
@@ -24,9 +24,9 @@ public class MainController {
@ResponseBody
public String getGeoDataList(Model model) {
String html="";
- html+="AirTemperatureDates
";
- html+="PrecipitationDates
";
- html+="SoilDates
";
+ html+="AirTemperatureDates
";
+ html+="PrecipitationDates
";
+ html+="SoilDates
";
return html;
}
diff --git a/src/main/java/org/ccalm/weather/Precipitation.java b/src/main/java/org/ccalm/weather/Precipitation.java
index 307c7d0..3a4b679 100644
--- a/src/main/java/org/ccalm/weather/Precipitation.java
+++ b/src/main/java/org/ccalm/weather/Precipitation.java
@@ -45,7 +45,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
//import main.DownloadFromHTTP;
-import org.ccalm.weather.WeatherDownload;
+//import org.ccalm.weather.WeatherDownload;
import ucar.ma2.Array;
import ucar.nc2.Dimension;
import ucar.nc2.Variable;
@@ -63,7 +63,7 @@ public class Precipitation implements ServletContextAware {
@Value("${custom.config.data_dir}")
private String data_dir;
- private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SoilTmperature.class);
+ private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Precipitation.class);
private ServletContext context;
@@ -100,7 +100,7 @@ public class Precipitation implements ServletContextAware {
}
}catch(Exception e)
{
- logger.info("
Connect Exception:"+e.getMessage()+"
");
+ logger.error("N1:"+e.getMessage()+"
",e);
result+="Connect Exception:"+e.getMessage()+"
";
}
@@ -147,7 +147,7 @@ public class Precipitation implements ServletContextAware {
}
br.close();
} catch (IOException ex) {
- logger.info(ex.getMessage());
+ logger.error("N2:"+ex.getMessage(),ex);
result+=ex.getMessage()+"
";
}
if(!strPos1.equals(""))
@@ -229,35 +229,50 @@ public class Precipitation implements ServletContextAware {
try {
st = conn.createStatement();
} catch (SQLException ex) {
- logger.info(ex.getMessage());
+ logger.error("N3:"+ex.getMessage(),ex);
}
try {
st.executeUpdate("BEGIN TRANSACTION;");
} catch (SQLException ex) {
- logger.info(ex.getMessage());
- logger.info(ex.getMessage());
+ logger.error("N4:"+ex.getMessage(),ex);
}
result+="Size="+dataArrayLat.getSize()+"
";
//Delete old data
- System.out.println("Delete old data 1");
+ logger.info("Delete old data 1");
try {
String sql="delete from main.precipitation where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
st.executeUpdate(sql);
} catch (SQLException ex) {
- logger.info(ex.getMessage());
+ logger.error("N5:"+ex.getMessage(),ex);
}
- System.out.println("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.executeUpdate(sql);
+ } catch (SQLException ex) {
+ logger.error("N6:"+ex.getMessage(),ex);
+ }
+ logger.info("Delete old data 3");
try {
String sql="delete from main.precipitation where date<=CURRENT_DATE-'730 days'::INTERVAL";
st.executeUpdate(sql);
} catch (SQLException ex) {
- logger.info(ex.getMessage());
+ logger.error("N7:"+ex.getMessage(),ex);
+ }
+
+ try {
+ st.executeUpdate("END TRANSACTION;");
+ } catch (SQLException ex) {
+ logger.error("N7.1:"+ex.getMessage(),ex);
+ }
+ try {
+ st.executeUpdate("BEGIN TRANSACTION;");
+ } catch (SQLException ex) {
+ logger.error("N7.2:"+ex.getMessage(),ex);
}
-
-
int pos=0;
for(int nLat=0;nLat";
return result;
@@ -386,7 +399,7 @@ public class Precipitation implements ServletContextAware {
result="An error occurred while connecting to the database!";
}
} catch (Exception ex) {
- logger.info(ex.getMessage());
+ logger.error("N15:"+ex.getMessage(),ex);
error=true;
result="
SQLException: "+ex.getMessage()+"
";
}
@@ -396,7 +409,19 @@ public class Precipitation implements ServletContextAware {
Statement st;
try {
st = conn.createStatement();
- String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,DATE_PART('doy',date)-1 as day FROM main.precipitation group by date,hours order by date,hours";
+ //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 = """
+ SELECT
+ to_char(date, 'YYYY-MM-DD') as date,
+ hours as hour,
+ DATE_PART('doy',date)-1 as day
+ FROM
+ main.precipitation_dates
+ group by
+ date,
+ hours
+ order by date,hours
+ """;
ResultSet rs = st.executeQuery(sql);
if(rs!=null)
{
@@ -409,7 +434,7 @@ public class Precipitation implements ServletContextAware {
result+= "{\"num\":\""+rs.getString("day")+"\", \"hour\":\""+rs.getString("hour")+"\", \"date\":\""+rs.getString("date")+"\"},";
} catch( Exception ex )
{
-
+ logger.error("N16:"+ex.getMessage(),ex);
}
}
if(exists) {
@@ -418,12 +443,12 @@ public class Precipitation implements ServletContextAware {
}else {
result="[]";
}
-
}
st.close();
conn.close();
} catch (SQLException ex) {
result="
SQLException:"+ex.getMessage()+"
";
+ logger.error("N17:"+ex.getMessage(),ex);
}
}
return result;
diff --git a/src/main/java/org/ccalm/weather/SoilTmperature.java b/src/main/java/org/ccalm/weather/SoilTmperature.java
index 53eda48..c8dd7c5 100644
--- a/src/main/java/org/ccalm/weather/SoilTmperature.java
+++ b/src/main/java/org/ccalm/weather/SoilTmperature.java
@@ -101,10 +101,10 @@ public class SoilTmperature implements ServletContextAware {
logger.info("
Connect is ERROR
");
result+="Connect is ERROR!
";
}
- }catch(Exception e)
+ }catch(Exception ex)
{
- logger.info("
Connect Exception:"+e.getMessage()+"
");
- result+="Connect Exception:"+e.getMessage()+"
";
+ logger.error("N1: "+ex.getMessage()+"
",ex);
+ result+="Connect Exception:"+ex.getMessage()+"
";
}
//Example request: http://ccalm.org/DownloadWeather?forecast=000&date=20210531
@@ -155,7 +155,7 @@ public class SoilTmperature implements ServletContextAware {
}
br.close();
} catch (IOException ex) {
- logger.info(ex.getMessage());
+ logger.error("N2: "+ex.getMessage(),ex);
result+=ex.getMessage()+"
";
}
if(!strPos1.equals(""))
@@ -245,42 +245,59 @@ public class SoilTmperature implements ServletContextAware {
try {
st = conn.createStatement();
} catch (SQLException ex) {
- logger.info(ex.getMessage());
+ logger.error("N3: "+ex.getMessage(),ex);
}
try {
st.executeUpdate("BEGIN TRANSACTION;");
} catch (SQLException ex) {
- logger.info(ex.getMessage());
- logger.info(ex.getMessage());
+ logger.error("N4: "+ex.getMessage(),ex);
}
result+="Size="+dataArrayLat.getSize()+"
";
//Delete old data
- System.out.println("Delete old data 1");
+ logger.info("Delete old data 1");
try {
String sql="delete from main.soil_temperature where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
st.executeUpdate(sql);
} catch (SQLException ex) {
- logger.info(ex.getMessage());
+ logger.error("N5: "+ex.getMessage(),ex);
}
- System.out.println("Delete old data 2");
+ logger.info("Delete old data 2");
+ 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;
+ st.executeUpdate(sql);
+ } catch (SQLException ex) {
+ logger.error("N6: "+ex.getMessage(),ex);
+ }
+ logger.info("Delete old data 3");
try {
String sql="delete from main.soil_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
st.executeUpdate(sql);
} catch (SQLException ex) {
- logger.info(ex.getMessage());
+ logger.error("N7: "+ex.getMessage(),ex);
}
if(Integer.parseInt(forecast)!=0) {
- System.out.println("Delete old data 3");
+ logger.info("Delete old data 4");
try {
String sql="delete from main.soil_temperature where hours="+forecast;
st.executeUpdate(sql);
} catch (SQLException ex) {
- logger.info(ex.getMessage());
+ logger.error("N8: "+ex.getMessage(),ex);
}
}
+ try {
+ st.executeUpdate("END TRANSACTION;");
+ } catch (SQLException ex) {
+ logger.error("N8.1:"+ex.getMessage(),ex);
+ }
+
+ try {
+ st.executeUpdate("BEGIN TRANSACTION;");
+ } catch (SQLException ex) {
+ logger.error("N8.2:"+ex.getMessage(),ex);
+ }
int pos=0;
for(int nLat=0;nLat";
return result;
@@ -410,7 +429,7 @@ public class SoilTmperature implements ServletContextAware {
result="An error occurred while connecting to the database!";
}
} catch (Exception ex) {
- logger.info(ex.getMessage());
+ logger.error("N17: "+ex.getMessage(),ex);
error=true;
result="
SQLException: "+ex.getMessage()+"
";
}
@@ -420,8 +439,18 @@ public class SoilTmperature implements ServletContextAware {
Statement st;
try {
st = conn.createStatement();
- String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,EXTRACT(DAY FROM CURRENT_DATE-date) as day FROM main.soil_temperature group by date,hours order by date,hours";
-
+ //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_dates
+ group by date,hours
+ order by date,hours
+ """;
+
ResultSet rs = st.executeQuery(sql);
if(rs!=null)
{
@@ -434,7 +463,7 @@ public class SoilTmperature implements ServletContextAware {
result+= "{\"num\":\""+rs.getString("day")+"\", \"hour\":\""+rs.getString("hour")+"\", \"date\":\""+rs.getString("date")+"\"},";
} catch( Exception ex )
{
-
+ logger.error("N18: "+ex.getMessage(),ex);
}
}
if(exists) {
@@ -448,6 +477,7 @@ public class SoilTmperature implements ServletContextAware {
st.close();
conn.close();
} catch (SQLException ex) {
+ logger.error("N19: "+ex.getMessage(),ex);
result="
SQLException:"+ex.getMessage()+"
";
}
}
diff --git a/src/main/java/org/ccalm/weather/WeatherDownload.java b/src/main/java/org/ccalm/weather/WeatherDownload.java
index d027c80..441a69b 100644
--- a/src/main/java/org/ccalm/weather/WeatherDownload.java
+++ b/src/main/java/org/ccalm/weather/WeatherDownload.java
@@ -1,10 +1,6 @@
package org.ccalm.weather;
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
+import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileOutputStream;
@@ -18,12 +14,14 @@ import java.net.URL;
* @author ivanov.i
*/
public class WeatherDownload {
-
+
+ private static final org.slf4j.Logger logger = LoggerFactory.getLogger(WeatherDownload.class);
+
private static final int BUFFER_SIZE = 4096;
public boolean download(String strURL,String strFile,String posStart,String posEnd)
{
- boolean result=true;
+ boolean result=false;
String rez = null;
String inputLine = null;
/*try
@@ -53,13 +51,13 @@ public class WeatherDownload {
}
outputStream.close();
inputStream.close();
+ result=true;
}
conn.disconnect();
}
catch (IOException e)
{
- //e.printStackTrace();
- result=false;
+ logger.error(e.getMessage());
}
return result;
}
diff --git a/src/main/lib/netcdfAll-5.3.1.jar b/src/main/lib/netcdfAll-5.3.1.jar
deleted file mode 100644
index 298de65..0000000
Binary files a/src/main/lib/netcdfAll-5.3.1.jar and /dev/null differ
diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml
new file mode 100644
index 0000000..9081a3a
--- /dev/null
+++ b/src/main/resources/logback-spring.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+ ${LOGS}/weather.log
+
+
+ ${LOGS}/weather.%d{yyyy-MM-dd}.%i.log.gz
+ 30
+
+ 100MB
+
+
+
+
+
+
+
+
+