логирование
This commit is contained in:
68
pom.xml
68
pom.xml
@ -10,13 +10,27 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<groupId>org.ccalm</groupId>
|
<groupId>org.ccalm</groupId>
|
||||||
<artifactId>weather</artifactId>
|
<artifactId>weather</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.6-SNAPSHOT</version>
|
||||||
<name>weather</name>
|
<name>weather</name>
|
||||||
<description>Demo project for Spring Boot</description>
|
<description>Demo project for Spring Boot</description>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>11</java.version>
|
<java.version>17</java.version>
|
||||||
<start-class>org.ccalm.weather.WeatherApplication</start-class>
|
<start-class>org.ccalm.weather.WeatherApplication</start-class>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>unidata</id>
|
||||||
|
<name>Unidata UCAR Repository</name>
|
||||||
|
<url>https://artifacts.unidata.ucar.edu/content/repositories/unidata-releases/</url>
|
||||||
|
</repository>
|
||||||
|
<!--repository>
|
||||||
|
<id>boundless</id>
|
||||||
|
<name>Boundless Repository</name>
|
||||||
|
<url>https://repo.boundlessgeo.com/main/</url>
|
||||||
|
</repository-->
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@ -34,6 +48,12 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.logstash.logback</groupId>
|
||||||
|
<artifactId>logstash-logback-encoder</artifactId>
|
||||||
|
<version>6.6</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/org.gdal/gdal -->
|
<!-- https://mvnrepository.com/artifact/org.gdal/gdal -->
|
||||||
<!--dependency>
|
<!--dependency>
|
||||||
<groupId>org.gdal</groupId>
|
<groupId>org.gdal</groupId>
|
||||||
@ -48,14 +68,11 @@
|
|||||||
<groupId>edu.ucar</groupId>
|
<groupId>edu.ucar</groupId>
|
||||||
<artifactId>netcdfAll</artifactId>
|
<artifactId>netcdfAll</artifactId>
|
||||||
<version>5.3.1</version>
|
<version>5.3.1</version>
|
||||||
<!-- Look: https://newbedev.com/how-to-include-system-dependencies-in-war-built-using-maven
|
|
||||||
<type>jar</type>
|
|
||||||
<scope>system</scope>
|
|
||||||
<systemPath>${basedir}/lib/netcdfAll-5.3.1.jar</systemPath>
|
|
||||||
-->
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -64,6 +81,39 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-dependencies</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-dependencies</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>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-install-plugin</artifactId>
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
<executions>
|
<executions>
|
||||||
@ -71,7 +121,7 @@
|
|||||||
<id>install-external</id>
|
<id>install-external</id>
|
||||||
<phase>clean</phase>
|
<phase>clean</phase>
|
||||||
<configuration>
|
<configuration>
|
||||||
<file>${basedir}/src/main/lib/netcdfAll-5.3.1.jar</file>
|
<file>O:/projects/Workspace_Java/CCALM_weather/src/main/lib/netcdfAll-5.3.1.jar</file>
|
||||||
<repositoryLayout>default</repositoryLayout>
|
<repositoryLayout>default</repositoryLayout>
|
||||||
<groupId>edu.ucar</groupId>
|
<groupId>edu.ucar</groupId>
|
||||||
<artifactId>netcdfAll</artifactId>
|
<artifactId>netcdfAll</artifactId>
|
||||||
@ -84,7 +134,7 @@
|
|||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin-->
|
||||||
|
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|||||||
@ -67,15 +67,18 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
|
|
||||||
private ServletContext context;
|
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")
|
@RequestMapping(value = "/geodatalist/AirTemperature",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object ajaxTamer(/*@RequestParam(required=true,name="forecast") String forecast,*/@RequestParam(required=false,name="date") String date) {
|
public Object ajaxTamer(/*@RequestParam(required=true,name="forecast") String forecast,*/@RequestParam(required=false,name="date") String date) {
|
||||||
String forecast = "000";
|
String forecast = "000";
|
||||||
|
|
||||||
String result="";
|
String result="";
|
||||||
result+="Start!<br>";
|
result+="Start!!!<br>";
|
||||||
|
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
||||||
|
|
||||||
@ -96,10 +99,10 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
logger.info("<br>Connect is ERROR<br>");
|
logger.info("<br>Connect is ERROR<br>");
|
||||||
result+="Connect is ERROR!<br>";
|
result+="Connect is ERROR!<br>";
|
||||||
}
|
}
|
||||||
}catch(Exception e)
|
}catch(Exception ex)
|
||||||
{
|
{
|
||||||
logger.info("<br>Connect Exception:"+e.getMessage()+"<br>");
|
logger.error("N1:"+ex.getMessage()+"<br>",ex);
|
||||||
result+="Connect Exception:"+e.getMessage()+"<br>";
|
result+="Connect Exception:"+ex.getMessage()+"<br>";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Example request: http://ccalm.org/AirTemperature?date=20210531
|
//Example request: http://ccalm.org/AirTemperature?date=20210531
|
||||||
@ -145,7 +148,7 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N2:"+ex.getMessage(),ex);
|
||||||
result+=ex.getMessage()+"<br>";
|
result+=ex.getMessage()+"<br>";
|
||||||
}
|
}
|
||||||
if(!strPos1.equals(""))
|
if(!strPos1.equals(""))
|
||||||
@ -162,11 +165,14 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
posEnd=String.valueOf(Long.parseLong(posEnd)-1);
|
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
|
}else
|
||||||
{
|
{
|
||||||
result+="Not download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"air_text.idx"+"<br>";
|
result+="Not download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"air_text.idx"+"<br>";
|
||||||
|
logger.info("Not download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"air_text.idx");
|
||||||
}
|
}
|
||||||
|
|
||||||
Array dataArrayLat=null;
|
Array dataArrayLat=null;
|
||||||
@ -227,35 +233,50 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
st = conn.createStatement();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N3:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("BEGIN TRANSACTION;");
|
st.executeUpdate("BEGIN TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N4:"+ex.getMessage(),ex);
|
||||||
logger.info(ex.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result+="Size="+dataArrayLat.getSize()+"<br>";
|
result+="Size="+dataArrayLat.getSize()+"<br>";
|
||||||
|
|
||||||
//Delete old data
|
//Delete old data
|
||||||
System.out.println("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);
|
st.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} 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 {
|
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);
|
st.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} 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;
|
int pos=0;
|
||||||
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
|
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
|
||||||
@ -278,7 +299,7 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
String sql="select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1";
|
String sql="select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1";
|
||||||
rs = st.executeQuery(sql);
|
rs = st.executeQuery(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N8:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
try {
|
try {
|
||||||
@ -286,17 +307,18 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
country_id=rs.getString(1);
|
country_id=rs.getString(1);
|
||||||
rs.close();
|
rs.close();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N9:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.air_temperature(date,hours,val,geom,country_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+");";
|
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+"));";
|
||||||
st.executeUpdate(sql);
|
st.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N10:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,7 +333,7 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
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.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);";
|
||||||
st.executeUpdate(sql);
|
st.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N11:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete values where country_id is null
|
//Delete values where country_id is null
|
||||||
@ -319,23 +341,21 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
String sql="delete from main.air_temperature where country_id is null;";
|
String sql="delete from main.air_temperature where country_id is null;";
|
||||||
st.executeUpdate(sql);
|
st.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N12:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("END TRANSACTION;");
|
st.executeUpdate("END TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N13:"+ex.getMessage(),ex);
|
||||||
logger.info(ex.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gid.close();
|
gid.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
logger.error("N14:"+ex.getMessage(),ex);
|
||||||
System.out.print("ERROR!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {conn.close();} catch (SQLException ex) {logger.info(ex.getMessage());}
|
try {conn.close();} catch (SQLException ex) {logger.error("N15:"+ex.getMessage(),ex);}
|
||||||
|
|
||||||
result+="End!<br>";
|
result+="End!<br>";
|
||||||
return result;
|
return result;
|
||||||
@ -385,7 +405,7 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
result="An error occurred while connecting to the database!";
|
result="An error occurred while connecting to the database!";
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N16:"+ex.getMessage(),ex);
|
||||||
error=true;
|
error=true;
|
||||||
result="<br>SQLException: "+ex.getMessage()+"<br>";
|
result="<br>SQLException: "+ex.getMessage()+"<br>";
|
||||||
}
|
}
|
||||||
@ -395,7 +415,17 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
Statement st;
|
Statement st;
|
||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
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);
|
ResultSet rs = st.executeQuery(sql);
|
||||||
if(rs!=null)
|
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")+"\"},";
|
result+= "{\"num\":\""+rs.getString("day")+"\", \"hour\":\""+rs.getString("hour")+"\", \"date\":\""+rs.getString("date")+"\"},";
|
||||||
} catch( Exception ex )
|
} catch( Exception ex )
|
||||||
{
|
{
|
||||||
|
logger.error("N17:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(exists) {
|
if(exists) {
|
||||||
@ -417,12 +447,12 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
}else {
|
}else {
|
||||||
result="[]";
|
result="[]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
st.close();
|
st.close();
|
||||||
conn.close();
|
conn.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -24,9 +24,9 @@ public class MainController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String getGeoDataList(Model model) {
|
public String getGeoDataList(Model model) {
|
||||||
String html="";
|
String html="";
|
||||||
html+="<a href=\"./AirTemperatureDates\">AirTemperatureDates</a><br><form action=\"./AirTemperature\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20210826\"><input type=\"submit\" value=\"Submit\"></form><br>";
|
html+="<a href=\"./AirTemperatureDates\">AirTemperatureDates</a><br><form action=\"./AirTemperature\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20240420\"><input type=\"submit\" value=\"Submit\"></form><br>";
|
||||||
html+="<a href=\"./PrecipitationDates\">PrecipitationDates</a><br><form action=\"./Precipitation\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20210826\"><input type=\"submit\" value=\"Submit\"></form><br>";
|
html+="<a href=\"./PrecipitationDates\">PrecipitationDates</a><br><form action=\"./Precipitation\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"\"20240420\"><input type=\"submit\" value=\"Submit\"></form><br>";
|
||||||
html+="<a href=\"./SoilDates\">SoilDates</a><br><form action=\"./DownloadSoil\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20210826\"><label for=\"forecast\">Forecast:</label><input type=\"text\" name=\"forecast\" value=\"000\"><input type=\"submit\" value=\"Submit\"></form><br>";
|
html+="<a href=\"./SoilDates\">SoilDates</a><br><form action=\"./DownloadSoil\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"\"20240420\"><label for=\"forecast\">Forecast:</label><input type=\"text\" name=\"forecast\" value=\"000\"><input type=\"submit\" value=\"Submit\"></form><br>";
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ import org.w3c.dom.Element;
|
|||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
//import main.DownloadFromHTTP;
|
//import main.DownloadFromHTTP;
|
||||||
import org.ccalm.weather.WeatherDownload;
|
//import org.ccalm.weather.WeatherDownload;
|
||||||
import ucar.ma2.Array;
|
import ucar.ma2.Array;
|
||||||
import ucar.nc2.Dimension;
|
import ucar.nc2.Dimension;
|
||||||
import ucar.nc2.Variable;
|
import ucar.nc2.Variable;
|
||||||
@ -63,7 +63,7 @@ public class Precipitation implements ServletContextAware {
|
|||||||
@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 static final org.slf4j.Logger logger = LoggerFactory.getLogger(Precipitation.class);
|
||||||
|
|
||||||
private ServletContext context;
|
private ServletContext context;
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ public class Precipitation implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
}catch(Exception e)
|
}catch(Exception e)
|
||||||
{
|
{
|
||||||
logger.info("<br>Connect Exception:"+e.getMessage()+"<br>");
|
logger.error("N1:"+e.getMessage()+"<br>",e);
|
||||||
result+="Connect Exception:"+e.getMessage()+"<br>";
|
result+="Connect Exception:"+e.getMessage()+"<br>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ public class Precipitation implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N2:"+ex.getMessage(),ex);
|
||||||
result+=ex.getMessage()+"<br>";
|
result+=ex.getMessage()+"<br>";
|
||||||
}
|
}
|
||||||
if(!strPos1.equals(""))
|
if(!strPos1.equals(""))
|
||||||
@ -229,35 +229,50 @@ public class Precipitation implements ServletContextAware {
|
|||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
st = conn.createStatement();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N3:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("BEGIN TRANSACTION;");
|
st.executeUpdate("BEGIN TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N4:"+ex.getMessage(),ex);
|
||||||
logger.info(ex.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result+="Size="+dataArrayLat.getSize()+"<br>";
|
result+="Size="+dataArrayLat.getSize()+"<br>";
|
||||||
|
|
||||||
//Delete old data
|
//Delete old data
|
||||||
System.out.println("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.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} 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 {
|
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.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} 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;
|
int pos=0;
|
||||||
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
|
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
|
||||||
@ -279,7 +294,7 @@ public class Precipitation implements ServletContextAware {
|
|||||||
try {
|
try {
|
||||||
rs = st.executeQuery("select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1");
|
rs = st.executeQuery("select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N8:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
try {
|
try {
|
||||||
@ -287,17 +302,17 @@ public class Precipitation implements ServletContextAware {
|
|||||||
country_id=rs.getString(1);
|
country_id=rs.getString(1);
|
||||||
rs.close();
|
rs.close();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N9:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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)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+");";
|
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);
|
st.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N10:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +327,7 @@ public class Precipitation implements ServletContextAware {
|
|||||||
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.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N11:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete values where country_id is null
|
//Delete values where country_id is null
|
||||||
@ -320,23 +335,21 @@ public class Precipitation implements ServletContextAware {
|
|||||||
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.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N12:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("END TRANSACTION;");
|
st.executeUpdate("END TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N13:"+ex.getMessage(),ex);
|
||||||
logger.info(ex.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gid.close();
|
gid.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
logger.error("N14:"+ex.getMessage(),ex);
|
||||||
System.out.print("ERROR!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {conn.close();} catch (SQLException ex) {logger.info(ex.getMessage());}
|
try {conn.close();} catch (SQLException ex) {logger.info(ex.getMessage(),ex);}
|
||||||
|
|
||||||
result+="End!<br>";
|
result+="End!<br>";
|
||||||
return result;
|
return result;
|
||||||
@ -386,7 +399,7 @@ public class Precipitation implements ServletContextAware {
|
|||||||
result="An error occurred while connecting to the database!";
|
result="An error occurred while connecting to the database!";
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N15:"+ex.getMessage(),ex);
|
||||||
error=true;
|
error=true;
|
||||||
result="<br>SQLException: "+ex.getMessage()+"<br>";
|
result="<br>SQLException: "+ex.getMessage()+"<br>";
|
||||||
}
|
}
|
||||||
@ -396,7 +409,19 @@ public class Precipitation implements ServletContextAware {
|
|||||||
Statement st;
|
Statement st;
|
||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
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);
|
ResultSet rs = st.executeQuery(sql);
|
||||||
if(rs!=null)
|
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")+"\"},";
|
result+= "{\"num\":\""+rs.getString("day")+"\", \"hour\":\""+rs.getString("hour")+"\", \"date\":\""+rs.getString("date")+"\"},";
|
||||||
} catch( Exception ex )
|
} catch( Exception ex )
|
||||||
{
|
{
|
||||||
|
logger.error("N16:"+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(exists) {
|
if(exists) {
|
||||||
@ -418,12 +443,12 @@ public class Precipitation implements ServletContextAware {
|
|||||||
}else {
|
}else {
|
||||||
result="[]";
|
result="[]";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
st.close();
|
st.close();
|
||||||
conn.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -101,10 +101,10 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
logger.info("<br>Connect is ERROR<br>");
|
logger.info("<br>Connect is ERROR<br>");
|
||||||
result+="Connect is ERROR!<br>";
|
result+="Connect is ERROR!<br>";
|
||||||
}
|
}
|
||||||
}catch(Exception e)
|
}catch(Exception ex)
|
||||||
{
|
{
|
||||||
logger.info("<br>Connect Exception:"+e.getMessage()+"<br>");
|
logger.error("N1: "+ex.getMessage()+"<br>",ex);
|
||||||
result+="Connect Exception:"+e.getMessage()+"<br>";
|
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
|
||||||
@ -155,7 +155,7 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
br.close();
|
br.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N2: "+ex.getMessage(),ex);
|
||||||
result+=ex.getMessage()+"<br>";
|
result+=ex.getMessage()+"<br>";
|
||||||
}
|
}
|
||||||
if(!strPos1.equals(""))
|
if(!strPos1.equals(""))
|
||||||
@ -245,42 +245,59 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
st = conn.createStatement();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N3: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("BEGIN TRANSACTION;");
|
st.executeUpdate("BEGIN TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N4: "+ex.getMessage(),ex);
|
||||||
logger.info(ex.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result+="Size="+dataArrayLat.getSize()+"<br>";
|
result+="Size="+dataArrayLat.getSize()+"<br>";
|
||||||
|
|
||||||
//Delete old data
|
//Delete old data
|
||||||
System.out.println("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.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} 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 {
|
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.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N7: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
if(Integer.parseInt(forecast)!=0) {
|
if(Integer.parseInt(forecast)!=0) {
|
||||||
System.out.println("Delete old data 3");
|
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.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} 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;
|
int pos=0;
|
||||||
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
|
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
|
||||||
@ -302,7 +319,8 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
try {
|
try {
|
||||||
rs = st.executeQuery("select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1");
|
rs = st.executeQuery("select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N9: "+ex.getMessage(),ex);
|
||||||
|
throw new Exception("Failed to select country...");
|
||||||
}
|
}
|
||||||
if (rs != null) {
|
if (rs != null) {
|
||||||
try {
|
try {
|
||||||
@ -310,19 +328,19 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
country_id=rs.getString(1);
|
country_id=rs.getString(1);
|
||||||
rs.close();
|
rs.close();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
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!=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.soil_temperature(weather_type_id,date,hours,val,geom)values(1,cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326));";
|
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(weather_type_id,date,hours,val,geom,country_id)values(1,cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),(select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1));";
|
|
||||||
String sql="insert into main.soil_temperature(date,hours,val,geom,country_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+");";
|
|
||||||
st.executeUpdate(sql);
|
st.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N11: "+ex.getMessage(),ex);
|
||||||
|
throw new Exception("Failed insert soil temperature...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +355,7 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
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.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N12: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Delete values where country_id is null
|
//Delete values where country_id is null
|
||||||
@ -345,23 +363,24 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
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.executeUpdate(sql);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N13: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
st.executeUpdate("END TRANSACTION;");
|
st.executeUpdate("END TRANSACTION;");
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N14: "+ex.getMessage(),ex);
|
||||||
logger.info(ex.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gid.close();
|
gid.close();
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
logger.error("N15: "+ex.getMessage(),ex);
|
||||||
System.out.print("ERROR!");
|
|
||||||
}
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
logger.error("N16: "+ex.getMessage(),ex);
|
||||||
|
}
|
||||||
|
|
||||||
try {conn.close();} catch (SQLException ex) {logger.info(ex.getMessage());}
|
try {conn.close();} catch (SQLException ex) {logger.error("N16: "+ex.getMessage(),ex);}
|
||||||
|
|
||||||
result+="End!<br>";
|
result+="End!<br>";
|
||||||
return result;
|
return result;
|
||||||
@ -410,7 +429,7 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
result="An error occurred while connecting to the database!";
|
result="An error occurred while connecting to the database!";
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.info(ex.getMessage());
|
logger.error("N17: "+ex.getMessage(),ex);
|
||||||
error=true;
|
error=true;
|
||||||
result="<br>SQLException: "+ex.getMessage()+"<br>";
|
result="<br>SQLException: "+ex.getMessage()+"<br>";
|
||||||
}
|
}
|
||||||
@ -420,7 +439,17 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
Statement st;
|
Statement st;
|
||||||
try {
|
try {
|
||||||
st = conn.createStatement();
|
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);
|
ResultSet rs = st.executeQuery(sql);
|
||||||
if(rs!=null)
|
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")+"\"},";
|
result+= "{\"num\":\""+rs.getString("day")+"\", \"hour\":\""+rs.getString("hour")+"\", \"date\":\""+rs.getString("date")+"\"},";
|
||||||
} catch( Exception ex )
|
} catch( Exception ex )
|
||||||
{
|
{
|
||||||
|
logger.error("N18: "+ex.getMessage(),ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(exists) {
|
if(exists) {
|
||||||
@ -448,6 +477,7 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
st.close();
|
st.close();
|
||||||
conn.close();
|
conn.close();
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
logger.error("N19: "+ex.getMessage(),ex);
|
||||||
result="<br>SQLException:"+ex.getMessage()+"<br>";
|
result="<br>SQLException:"+ex.getMessage()+"<br>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,6 @@
|
|||||||
package org.ccalm.weather;
|
package org.ccalm.weather;
|
||||||
|
|
||||||
/*
|
import org.slf4j.LoggerFactory;
|
||||||
* 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 java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -19,11 +15,13 @@ import java.net.URL;
|
|||||||
*/
|
*/
|
||||||
public class WeatherDownload {
|
public class WeatherDownload {
|
||||||
|
|
||||||
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(WeatherDownload.class);
|
||||||
|
|
||||||
private static final int BUFFER_SIZE = 4096;
|
private static final int BUFFER_SIZE = 4096;
|
||||||
|
|
||||||
public boolean download(String strURL,String strFile,String posStart,String posEnd)
|
public boolean download(String strURL,String strFile,String posStart,String posEnd)
|
||||||
{
|
{
|
||||||
boolean result=true;
|
boolean result=false;
|
||||||
String rez = null;
|
String rez = null;
|
||||||
String inputLine = null;
|
String inputLine = null;
|
||||||
/*try
|
/*try
|
||||||
@ -53,13 +51,13 @@ public class WeatherDownload {
|
|||||||
}
|
}
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
|
result=true;
|
||||||
}
|
}
|
||||||
conn.disconnect();
|
conn.disconnect();
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
//e.printStackTrace();
|
logger.error(e.getMessage());
|
||||||
result=false;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
23
src/main/resources/logback-spring.xml
Normal file
23
src/main/resources/logback-spring.xml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
|
||||||
|
<!-- Please check if the user has access to the directory from which the application is being executed -->
|
||||||
|
<property name="LOGS" value="/var/log/weather" />
|
||||||
|
|
||||||
|
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<file>${LOGS}/weather.log</file>
|
||||||
|
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>${LOGS}/weather.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||||
|
<maxHistory>30</maxHistory>
|
||||||
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||||
|
<maxFileSize>100MB</maxFileSize>
|
||||||
|
</timeBasedFileNamingAndTriggeringPolicy>
|
||||||
|
</rollingPolicy>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="FILE" />
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
||||||
Reference in New Issue
Block a user