Делаю предупреждение по нажатию
This commit is contained in:
@ -22,14 +22,21 @@ custom:
|
|||||||
data_dir: /data/
|
data_dir: /data/
|
||||||
db_all:
|
db_all:
|
||||||
#url: jdbc:postgresql://92.46.48.43:5444/weather?ApplicationName=kz_mcp_weather&sslmode=require
|
#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://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://127.0.0.1:5432/weather?ApplicationName=kz_mcp_weather&sslmode=require
|
||||||
login: postgres
|
login: postgres
|
||||||
password: PasSecrKey1
|
password: PasSecrKey1
|
||||||
db_ru:
|
db_ru:
|
||||||
#url: jdbc:postgresql://92.46.48.43:5444/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require
|
#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://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://127.0.0.1:5432/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require
|
||||||
login: postgres
|
login: postgres
|
||||||
password: PasSecrKey1
|
password: PasSecrKey1
|
||||||
|
|
||||||
|
|
||||||
|
springdoc:
|
||||||
|
api-docs:
|
||||||
|
path: /api-docs
|
||||||
|
swagger-ui:
|
||||||
|
disable-swagger-default-url: true
|
||||||
|
path: /myproject
|
||||||
41
pom.xml
41
pom.xml
@ -5,12 +5,12 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>3.3.3</version>
|
<version>3.4.2</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.ccalm</groupId>
|
<groupId>org.ccalm</groupId>
|
||||||
<artifactId>weather</artifactId>
|
<artifactId>weather</artifactId>
|
||||||
<version>0.0.8-SNAPSHOT</version>
|
<version>0.0.9-SNAPSHOT</version>
|
||||||
<name>weather</name>
|
<name>weather</name>
|
||||||
<description>Weather APP</description>
|
<description>Weather APP</description>
|
||||||
<properties>
|
<properties>
|
||||||
@ -45,6 +45,25 @@
|
|||||||
<artifactId>logstash-logback-encoder</artifactId>
|
<artifactId>logstash-logback-encoder</artifactId>
|
||||||
<version>6.6</version>
|
<version>6.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
<version>20231013</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Исключаю зависимость из другой библиотеки а то в логе конфликт -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.vaadin.external.google</groupId>
|
||||||
|
<artifactId>android-json</artifactId>
|
||||||
|
<version>0.0.20131108.vaadin1</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.json</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/edu.ucar/netcdfAll -->
|
<!-- https://mvnrepository.com/artifact/edu.ucar/netcdfAll -->
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -53,6 +72,24 @@
|
|||||||
<version>5.3.1</version>
|
<version>5.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springdoc</groupId>
|
||||||
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
|
<version>2.6.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.webjars</groupId>
|
||||||
|
<artifactId>webjars-locator</artifactId>
|
||||||
|
<version>0.52</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.36</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -4,44 +4,36 @@ import java.io.BufferedReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
//import javax.servlet.http.HttpServletResponse;
|
//import javax.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
|
|
||||||
|
import org.ccalm.weather.models.PointModel;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import tools.DBTools;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
import org.springframework.http.CacheControl;
|
import org.springframework.http.CacheControl;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.context.ServletContextAware;
|
import org.springframework.web.context.ServletContextAware;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
//import main.DownloadFromHTTP;
|
//import main.DownloadFromHTTP;
|
||||||
import org.ccalm.weather.WeatherDownload;
|
|
||||||
import tctable.Tools;
|
import tctable.Tools;
|
||||||
|
import tools.StdTools;
|
||||||
import ucar.ma2.Array;
|
import ucar.ma2.Array;
|
||||||
import ucar.nc2.Dimension;
|
import ucar.nc2.Dimension;
|
||||||
import ucar.nc2.Variable;
|
import ucar.nc2.Variable;
|
||||||
import ucar.nc2.dataset.NetcdfDataset;
|
import ucar.nc2.dataset.NetcdfDataset;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class AirTemperature implements ServletContextAware {
|
public class AirTemperature implements ServletContextAware {
|
||||||
@ -72,6 +64,25 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
this.context = servletContext;
|
this.context = servletContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
public JSONObject createJSONError(int code, String message, String setting, String marker) {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
//try {
|
||||||
|
json.put("error_code", code);
|
||||||
|
if(message!=null && !message.isBlank()) {
|
||||||
|
json.put("error_message", Arrays.asList(message));
|
||||||
|
}
|
||||||
|
if(setting!=null && !setting.isBlank()) {
|
||||||
|
json.put("error_setting", Arrays.asList(setting));
|
||||||
|
}
|
||||||
|
if(marker!=null && !marker.isBlank()) {
|
||||||
|
json.put("error_marker", marker);
|
||||||
|
}
|
||||||
|
//} catch (JSONException e) {
|
||||||
|
// logger.error(e);
|
||||||
|
//}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* 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
|
* 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
|
||||||
@ -133,12 +144,18 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
//Build URL to download
|
//Build URL to download
|
||||||
String URL = "https://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs."+date+"/"+time+"/atmos/gfs.t"+time+"z.pgrb2.0p25.f"+forecast;
|
String URL = "https://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs."+date+"/"+time+"/atmos/gfs.t"+time+"z.pgrb2.0p25.f"+forecast;
|
||||||
|
|
||||||
File f = new File(data_dir+"temp"+File.separator+"air_text.idx");
|
File f1 = new File(data_dir+"temp"+File.separator+"air_text.idx");
|
||||||
if(f.exists()) {
|
if(f1.exists()) {
|
||||||
if (!f.delete()) {
|
if (!f1.delete()) {
|
||||||
System.out.println("Failed to delete the file \"air_text.idx\".");
|
System.out.println("Failed to delete the file \"air_text.idx\".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File f2 = new File(data_dir+"temp"+File.separator+"air_text.f000");
|
||||||
|
if(f2.exists()) {
|
||||||
|
if (!f2.delete()) {
|
||||||
|
System.out.println("Failed to delete the file \"air_text.f000\".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WeatherDownload wd = new WeatherDownload();
|
WeatherDownload wd = new WeatherDownload();
|
||||||
if(wd.download(URL+".idx", data_dir+"temp"+File.separator+"air_text.idx", "0", ""))
|
if(wd.download(URL+".idx", data_dir+"temp"+File.separator+"air_text.idx", "0", ""))
|
||||||
@ -507,68 +524,90 @@ public class AirTemperature implements ServletContextAware {
|
|||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@RequestMapping(value = "/geodatalist/getAirTemperature",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
|
@RequestMapping(value = "/geodatalist/getAirTemperature",method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json;charset=utf-8")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Object getAirTemperature(@RequestParam("date") String date,@RequestParam("hours") int hours,@RequestParam("lat") double lat, @RequestParam("lon") double lon,HttpServletResponse response) {
|
public ResponseEntity<Object> getAirTemperature(HttpServletResponse response, HttpServletRequest request, @RequestBody PointModel pointModel, @CookieValue(value = "lng", defaultValue = "1") String language_id) {
|
||||||
|
|
||||||
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
|
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
|
||||||
response.addHeader("Cache-Control", headerValue);
|
response.addHeader("Cache-Control", headerValue);
|
||||||
|
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
float temperature = -999;
|
float val = -999;
|
||||||
|
|
||||||
Connection conn_all = DBTools.getConn(db_url_all,db_login_all,db_password_all);
|
Connection conn_all = DBTools.getConn(db_url_all,db_login_all,db_password_all);
|
||||||
Connection conn_ru = DBTools.getConn(db_url_ru,db_login_ru,db_password_ru);
|
Connection conn_ru = DBTools.getConn(db_url_ru,db_login_ru,db_password_ru);
|
||||||
|
|
||||||
String sql = """
|
String sql;
|
||||||
select main.get_air_temperature(?::timestamp,?,?,?)-273.15;
|
|
||||||
|
if(pointModel.getDate()==null){
|
||||||
|
//I assume that the dates in all databases are the same.
|
||||||
|
sql = """
|
||||||
|
select max(date) from main.air_temperature_dates where hours=?;
|
||||||
""";
|
""";
|
||||||
if(conn_all!=null) {
|
if(conn_all!=null){
|
||||||
try (Statement st = conn_all.createStatement()) {
|
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
|
||||||
PreparedStatement pstmt = st.getConnection().prepareStatement(sql);
|
pstmt.setInt(1, pointModel.getHours());
|
||||||
pstmt.setString(1, date);
|
|
||||||
pstmt.setInt(2, hours);
|
|
||||||
pstmt.setDouble(3, lon);
|
|
||||||
pstmt.setDouble(4, lat);
|
|
||||||
try (ResultSet rs = pstmt.executeQuery()) {
|
try (ResultSet rs = pstmt.executeQuery()) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
temperature = rs.getFloat(1);
|
pointModel.setDate(rs.getString(1));
|
||||||
if (rs.wasNull()) {
|
|
||||||
temperature = -999;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
logger.error(uuid,e);
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
|
||||||
logger.error("N4:" + ex.getMessage(), ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(temperature == -999){
|
sql = """
|
||||||
if(conn_ru!=null) {
|
select main.get_air_temperature(?::TIMESTAMP WITHOUT TIME ZONE,?,?,?)-273.15;
|
||||||
try (Statement st = conn_ru.createStatement()) {
|
""";
|
||||||
PreparedStatement pstmt = st.getConnection().prepareStatement(sql);
|
if(conn_all!=null) {
|
||||||
pstmt.setString(1, date);
|
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
|
||||||
pstmt.setInt(2, hours);
|
pstmt.setString(1, pointModel.getDate());
|
||||||
pstmt.setDouble(3, lon);
|
pstmt.setInt(2, pointModel.getHours());
|
||||||
pstmt.setDouble(4, lat);
|
pstmt.setDouble(3, pointModel.getLon());
|
||||||
|
pstmt.setDouble(4, pointModel.getLat());
|
||||||
try (ResultSet rs = pstmt.executeQuery()) {
|
try (ResultSet rs = pstmt.executeQuery()) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
temperature = rs.getFloat(1);
|
val = rs.getFloat(1);
|
||||||
if (rs.wasNull()) {
|
if (rs.wasNull()) {
|
||||||
temperature = -999;
|
val = -999;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException e) {
|
||||||
logger.error("N4:" + ex.getMessage(), ex);
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
logger.error(uuid,e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(conn_ru!=null && val == -999) {
|
||||||
|
try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
|
||||||
|
pstmt.setString(1, pointModel.getDate());
|
||||||
|
pstmt.setInt(2, pointModel.getHours());
|
||||||
|
pstmt.setDouble(3, pointModel.getLon());
|
||||||
|
pstmt.setDouble(4, pointModel.getLat());
|
||||||
|
try (ResultSet rs = pstmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
val = rs.getFloat(1);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
val = -999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
logger.error(uuid,e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.put("error_code", 0);
|
result.put("error_code", 0);
|
||||||
result.put("temperature", temperature);
|
result.put("date", pointModel.getDate());
|
||||||
|
if(val!=-999){
|
||||||
return result;
|
result.put("value", val);
|
||||||
|
}else{
|
||||||
|
result.put("value", null);
|
||||||
|
}
|
||||||
|
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
30
src/main/java/org/ccalm/weather/BookController.java
Normal file
30
src/main/java/org/ccalm/weather/BookController.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.awt.print.Book;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/book")
|
||||||
|
public class BookController {
|
||||||
|
|
||||||
|
//@Autowired
|
||||||
|
//private BookRepository repository;
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public String findById(@PathVariable long id) {
|
||||||
|
return "";//repository.findById(id) .orElseThrow(() -> new BookNotFoundException());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/")
|
||||||
|
public String findBooks() {
|
||||||
|
return "";//repository.getBooks();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
@ResponseStatus(HttpStatus.OK)
|
||||||
|
public String updateBook(@PathVariable("id") final String id, @RequestBody final Book book) {
|
||||||
|
return "";//book;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,47 +4,33 @@ import java.io.BufferedReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
//import javax.servlet.http.HttpServletResponse;
|
//import javax.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.ccalm.weather.models.PointModel;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import tctable.Tools;
|
||||||
|
import tools.DBTools;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
import org.springframework.http.CacheControl;
|
import org.springframework.http.CacheControl;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
import org.springframework.web.context.ServletContextAware;
|
import org.springframework.web.context.ServletContextAware;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
//import main.DownloadFromHTTP;
|
//import main.DownloadFromHTTP;
|
||||||
//import org.ccalm.weather.WeatherDownload;
|
//import org.ccalm.weather.WeatherDownload;
|
||||||
import tctable.Tools;
|
|
||||||
import ucar.ma2.Array;
|
import ucar.ma2.Array;
|
||||||
import ucar.nc2.Dimension;
|
import ucar.nc2.Dimension;
|
||||||
import ucar.nc2.Variable;
|
import ucar.nc2.Variable;
|
||||||
@ -74,6 +60,25 @@ public class Precipitation implements ServletContextAware {
|
|||||||
|
|
||||||
private jakarta.servlet.ServletContext context;
|
private jakarta.servlet.ServletContext context;
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
public JSONObject createJSONError(int code, String message, String setting, String marker) {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
//try {
|
||||||
|
json.put("error_code", code);
|
||||||
|
if(message!=null && !message.isBlank()) {
|
||||||
|
json.put("error_message", Arrays.asList(message));
|
||||||
|
}
|
||||||
|
if(setting!=null && !setting.isBlank()) {
|
||||||
|
json.put("error_setting", Arrays.asList(setting));
|
||||||
|
}
|
||||||
|
if(marker!=null && !marker.isBlank()) {
|
||||||
|
json.put("error_marker", marker);
|
||||||
|
}
|
||||||
|
//} catch (JSONException e) {
|
||||||
|
// logger.error(e);
|
||||||
|
//}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@Override
|
@Override
|
||||||
public void setServletContext(jakarta.servlet.ServletContext servletContext) {
|
public void setServletContext(jakarta.servlet.ServletContext servletContext) {
|
||||||
@ -156,12 +161,18 @@ public class Precipitation implements ServletContextAware {
|
|||||||
//Build URL to download
|
//Build URL to download
|
||||||
String URL = "https://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs."+date+"/"+time+"/atmos/gfs.t"+time+"z.pgrb2.0p25.f"+forecast;
|
String URL = "https://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs."+date+"/"+time+"/atmos/gfs.t"+time+"z.pgrb2.0p25.f"+forecast;
|
||||||
|
|
||||||
File f = new File(data_dir+"temp"+File.separator+"pre_text.idx");
|
File f1 = new File(data_dir+"temp"+File.separator+"pre_text.idx");
|
||||||
if(f.exists()) {
|
if(f1.exists()) {
|
||||||
if (!f.delete()) {
|
if (!f1.delete()) {
|
||||||
System.out.println("Failed to delete the file \"pre_text.idx\".");
|
System.out.println("Failed to delete the file \"pre_text.idx\".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File f2 = new File(data_dir+"temp"+File.separator+"pre_text.idx");
|
||||||
|
if(f2.exists()) {
|
||||||
|
if (!f2.delete()) {
|
||||||
|
System.out.println("Failed to delete the file \"pre_text.f000\".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WeatherDownload wd = new WeatherDownload();
|
WeatherDownload wd = new WeatherDownload();
|
||||||
if(wd.download(URL+".idx", data_dir+"temp"+File.separator+"pre_text.idx", "0", ""))
|
if(wd.download(URL+".idx", data_dir+"temp"+File.separator+"pre_text.idx", "0", ""))
|
||||||
@ -524,5 +535,91 @@ public class Precipitation implements ServletContextAware {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
//Weighted interpolation
|
||||||
|
@RequestMapping(value = "/geodatalist/getPrecipitation",method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json;charset=utf-8")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity<Object> getPrecipitation(HttpServletResponse response, HttpServletRequest request, @RequestBody PointModel pointModel, @CookieValue(value = "lng", defaultValue = "1") String language_id) {
|
||||||
|
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
|
||||||
|
response.addHeader("Cache-Control", headerValue);
|
||||||
|
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
Connection conn_all = DBTools.getConn(db_url_all,db_login_all,db_password_all);
|
||||||
|
Connection conn_ru = DBTools.getConn(db_url_ru,db_login_ru,db_password_ru);
|
||||||
|
float val=-999;
|
||||||
|
|
||||||
|
String sql;
|
||||||
|
|
||||||
|
if(pointModel.getDate()==null){
|
||||||
|
//I assume that the dates in all databases are the same.
|
||||||
|
sql = """
|
||||||
|
select max(date) from main.precipitation_dates where hours=?;
|
||||||
|
""";
|
||||||
|
if(conn_all!=null){
|
||||||
|
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
|
||||||
|
pstmt.setInt(1, pointModel.getHours());
|
||||||
|
try (ResultSet rs = pstmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
pointModel.setDate(rs.getString(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
logger.error(uuid,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sql="""
|
||||||
|
select main.get_precipitation(?::TIMESTAMP WITHOUT TIME ZONE,?,?,?)
|
||||||
|
""";
|
||||||
|
if(conn_all!=null) {
|
||||||
|
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
|
||||||
|
pstmt.setString(1, pointModel.getDate());
|
||||||
|
pstmt.setInt(2, pointModel.getHours());
|
||||||
|
pstmt.setDouble(3, pointModel.getLon());
|
||||||
|
pstmt.setDouble(4, pointModel.getLat());
|
||||||
|
try (ResultSet rs = pstmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
val = rs.getFloat(1);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
val = -999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
logger.error(uuid,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(conn_ru!=null && val == -999) {
|
||||||
|
try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
|
||||||
|
pstmt.setString(1, pointModel.getDate());
|
||||||
|
pstmt.setInt(2, pointModel.getHours());
|
||||||
|
pstmt.setDouble(3, pointModel.getLon());
|
||||||
|
pstmt.setDouble(4, pointModel.getLat());
|
||||||
|
try (ResultSet rs = pstmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
val = rs.getFloat(1);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
val = -999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
logger.error(uuid,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.put("error_code", 0);
|
||||||
|
result.put("date", pointModel.getDate());
|
||||||
|
if(val!=-999){
|
||||||
|
result.put("value", val);
|
||||||
|
}else{
|
||||||
|
result.put("value", null);
|
||||||
|
}
|
||||||
|
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,46 +4,31 @@ import java.io.BufferedReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
//import javax.servlet.http.HttpServletResponse;
|
//import javax.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
|
|
||||||
|
import org.ccalm.weather.models.PointModel;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import tools.DBTools;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
import org.springframework.http.CacheControl;
|
import org.springframework.http.CacheControl;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
import org.springframework.web.context.ServletContextAware;
|
import org.springframework.web.context.ServletContextAware;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
|
|
||||||
//import main.DownloadFromHTTP;
|
//import main.DownloadFromHTTP;
|
||||||
import org.ccalm.weather.WeatherDownload;
|
|
||||||
import tctable.Tools;
|
import tctable.Tools;
|
||||||
import ucar.ma2.Array;
|
import ucar.ma2.Array;
|
||||||
import ucar.nc2.Dimension;
|
import ucar.nc2.Dimension;
|
||||||
@ -74,6 +59,25 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
|
|
||||||
private ServletContext context;
|
private ServletContext context;
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
public JSONObject createJSONError(int code, String message, String setting, String marker) {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
//try {
|
||||||
|
json.put("error_code", code);
|
||||||
|
if(message!=null && !message.isBlank()) {
|
||||||
|
json.put("error_message", Arrays.asList(message));
|
||||||
|
}
|
||||||
|
if(setting!=null && !setting.isBlank()) {
|
||||||
|
json.put("error_setting", Arrays.asList(setting));
|
||||||
|
}
|
||||||
|
if(marker!=null && !marker.isBlank()) {
|
||||||
|
json.put("error_marker", marker);
|
||||||
|
}
|
||||||
|
//} catch (JSONException e) {
|
||||||
|
// logger.error(e);
|
||||||
|
//}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@Override
|
@Override
|
||||||
public void setServletContext(jakarta.servlet.ServletContext servletContext) {
|
public void setServletContext(jakarta.servlet.ServletContext servletContext) {
|
||||||
@ -163,12 +167,18 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
//Build URL to download
|
//Build URL to download
|
||||||
String URL = "https://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs."+date+"/"+time+"/atmos/gfs.t"+time+"z.pgrb2.0p25.f"+forecast;
|
String URL = "https://www.ftp.ncep.noaa.gov/data/nccf/com/gfs/prod/gfs."+date+"/"+time+"/atmos/gfs.t"+time+"z.pgrb2.0p25.f"+forecast;
|
||||||
|
|
||||||
File f = new File(data_dir+"temp"+File.separator+"text.idx");
|
File f1 = new File(data_dir+"temp"+File.separator+"text.idx");
|
||||||
if(f.exists()) {
|
if(f1.exists()) {
|
||||||
if (!f.delete()) {
|
if (!f1.delete()) {
|
||||||
System.out.println("Failed to delete the file \"text.idx\".");
|
System.out.println("Failed to delete the file \"text.idx\".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File f2 = new File(data_dir+"temp"+File.separator+"text.f000");
|
||||||
|
if(f2.exists()) {
|
||||||
|
if (!f2.delete()) {
|
||||||
|
System.out.println("Failed to delete the file \"text.f000\".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WeatherDownload wd = new WeatherDownload();
|
WeatherDownload wd = new WeatherDownload();
|
||||||
if(wd.download(URL+".idx", data_dir+"temp"+File.separator+"text.idx", "0", ""))
|
if(wd.download(URL+".idx", data_dir+"temp"+File.separator+"text.idx", "0", ""))
|
||||||
@ -539,5 +549,91 @@ public class SoilTmperature implements ServletContextAware {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
//Weighted interpolation
|
||||||
|
@RequestMapping(value = "/geodatalist/getSoil",method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json;charset=utf-8")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity<Object> getSoil(HttpServletResponse response, HttpServletRequest request, @RequestBody PointModel pointModel, @CookieValue(value = "lng", defaultValue = "1") String language_id) {
|
||||||
|
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
|
||||||
|
response.addHeader("Cache-Control", headerValue);
|
||||||
|
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
Connection conn_all = DBTools.getConn(db_url_all,db_login_all,db_password_all);
|
||||||
|
Connection conn_ru = DBTools.getConn(db_url_ru,db_login_ru,db_password_ru);
|
||||||
|
float val=-999;
|
||||||
|
|
||||||
|
String sql;
|
||||||
|
|
||||||
|
if(pointModel.getDate()==null){
|
||||||
|
//I assume that the dates in all databases are the same.
|
||||||
|
sql = """
|
||||||
|
select max(date) from main.soil_temperature_dates where hours=?;
|
||||||
|
""";
|
||||||
|
if(conn_all!=null){
|
||||||
|
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
|
||||||
|
pstmt.setInt(1, pointModel.getHours());
|
||||||
|
try (ResultSet rs = pstmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
pointModel.setDate(rs.getString(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
logger.error(uuid,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sql="""
|
||||||
|
select main.get_soil_temperature(?::TIMESTAMP WITHOUT TIME ZONE,?,?,?)
|
||||||
|
""";
|
||||||
|
if(conn_all!=null) {
|
||||||
|
try (PreparedStatement pstmt = conn_all.prepareStatement(sql)) {
|
||||||
|
pstmt.setString(1, pointModel.getDate());
|
||||||
|
pstmt.setInt(2, pointModel.getHours());
|
||||||
|
pstmt.setDouble(3, pointModel.getLon());
|
||||||
|
pstmt.setDouble(4, pointModel.getLat());
|
||||||
|
try (ResultSet rs = pstmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
val = rs.getFloat(1);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
val = -999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
logger.error(uuid,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(conn_ru!=null && val == -999) {
|
||||||
|
try (PreparedStatement pstmt = conn_ru.prepareStatement(sql)) {
|
||||||
|
pstmt.setString(1, pointModel.getDate());
|
||||||
|
pstmt.setInt(2, pointModel.getHours());
|
||||||
|
pstmt.setDouble(3, pointModel.getLon());
|
||||||
|
pstmt.setDouble(4, pointModel.getLat());
|
||||||
|
try (ResultSet rs = pstmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
val = rs.getFloat(1);
|
||||||
|
if (rs.wasNull()) {
|
||||||
|
val = -999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
|
logger.error(uuid,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.put("error_code", 0);
|
||||||
|
result.put("date", pointModel.getDate());
|
||||||
|
if(val!=-999){
|
||||||
|
result.put("value", val);
|
||||||
|
}else{
|
||||||
|
result.put("value", null);
|
||||||
|
}
|
||||||
|
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
54
src/main/java/org/ccalm/weather/Translation.java
Normal file
54
src/main/java/org/ccalm/weather/Translation.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package org.ccalm.weather;
|
||||||
|
|
||||||
|
//import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
|
|
||||||
|
public class Translation {
|
||||||
|
/*public int language_id;
|
||||||
|
public NamedParameterJdbcTemplate jdbcTemplate;
|
||||||
|
Translation(String lng, NamedParameterJdbcTemplate jdbcTemplate){
|
||||||
|
language_id=1;
|
||||||
|
switch (lng) {
|
||||||
|
case "kz":
|
||||||
|
case "kk":
|
||||||
|
language_id = 2;
|
||||||
|
break;
|
||||||
|
case "en":
|
||||||
|
language_id = 3;
|
||||||
|
break;
|
||||||
|
case "uz":
|
||||||
|
language_id = 4;
|
||||||
|
break;
|
||||||
|
case "ru":
|
||||||
|
default:
|
||||||
|
language_id = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
String trt(String text){
|
||||||
|
/*String sql = """
|
||||||
|
select
|
||||||
|
translation
|
||||||
|
from
|
||||||
|
main._translations
|
||||||
|
where
|
||||||
|
del=false
|
||||||
|
and language_id=:language_id
|
||||||
|
and identifier=:identifier;
|
||||||
|
""";
|
||||||
|
MapSqlParameterSource parameters = new MapSqlParameterSource();
|
||||||
|
parameters.addValue("language_id", language_id);
|
||||||
|
parameters.addValue("identifier", text);
|
||||||
|
List<String> ret = jdbcTemplate.query(sql, parameters, new DBTools.JsonRowMapper());
|
||||||
|
int i = 0;
|
||||||
|
for (i = 0; i < ret.size(); i++) {
|
||||||
|
JSONObject json = new JSONObject(ret.get(i));
|
||||||
|
text = json.getString("translation");
|
||||||
|
}
|
||||||
|
if(i==0){
|
||||||
|
text = text.replace("_", " ");
|
||||||
|
}*/
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,96 @@
|
|||||||
|
package org.ccalm.weather.models;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Schema(
|
||||||
|
description = "Error API response",
|
||||||
|
example = "{ \"error_code\": 10000, \"error_message\": [\"Internal_Server_Error\",\"Please_log_in\"], \"error_setting\": [\"99;day\",\"1;2\"], \"error_marker\": \"2a449883-c7c6-468e-b3ae-5f73fc96627d\" }"
|
||||||
|
)
|
||||||
|
|
||||||
|
public class ErrorResponseModel {
|
||||||
|
|
||||||
|
@Schema(description = "Error code", example = "10000")
|
||||||
|
@JsonProperty("error_code")
|
||||||
|
private int errorCode;
|
||||||
|
|
||||||
|
@Schema(description = "List of error descriptions", example = "[\"Internal_Server_Error\",\"Please_log_in\"]")
|
||||||
|
@JsonProperty("error_message")
|
||||||
|
private List<String> errorMessage;
|
||||||
|
|
||||||
|
@Schema(description = "Options for translated text", example = "[\"99;day\",\"1;2\"]")
|
||||||
|
@JsonProperty("error_setting")
|
||||||
|
private List<String> errorSetting;
|
||||||
|
|
||||||
|
@Schema(description = "Unique identifier for searching in the database", example = "4260aad8-f7ee-4be4-b52c-15d56ec83232")
|
||||||
|
@JsonProperty("error_marker")
|
||||||
|
private String errorMarker;
|
||||||
|
|
||||||
|
public ErrorResponseModel(int errorCode) {
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
this.errorMessage = null;
|
||||||
|
this.errorSetting = null;
|
||||||
|
this.errorMarker = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponseModel(int errorCode, List<String> errorMessage, String errorMarker) {
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
this.errorMarker = errorMarker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponseModel(int errorCode, String errorMessage, String errorMarker) {
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
this.errorMessage = Collections.singletonList(errorMessage);
|
||||||
|
this.errorMarker = errorMarker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponseModel(int errorCode, String errorMessage, String errorSetting, String errorMarker) {
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
this.errorMessage = Collections.singletonList(errorMessage);
|
||||||
|
this.errorSetting = Collections.singletonList(errorSetting);
|
||||||
|
this.errorMarker = errorMarker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponseModel(int errorCode, List<String> errorMessage, List<String> errorSetting, String errorMarker) {
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
this.errorSetting = errorSetting;
|
||||||
|
this.errorMarker = errorMarker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getError_code() {
|
||||||
|
return errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setError_code(int errorCode) {
|
||||||
|
this.errorCode = errorCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getError_message() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setError_message(List<String> errorMessage) {
|
||||||
|
this.errorMessage = errorMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setError_setting(List<String> errorSetting) {
|
||||||
|
this.errorSetting = errorSetting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getError_setting() {
|
||||||
|
return errorSetting;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setError_marker(String errorMarker) {
|
||||||
|
this.errorMarker = errorMarker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getError_marker() {
|
||||||
|
return errorMarker;
|
||||||
|
}
|
||||||
|
}
|
||||||
43
src/main/java/org/ccalm/weather/models/PointModel.java
Normal file
43
src/main/java/org/ccalm/weather/models/PointModel.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package org.ccalm.weather.models;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
public class PointModel {
|
||||||
|
|
||||||
|
@JsonProperty("date")
|
||||||
|
String date;
|
||||||
|
@JsonProperty("hours")
|
||||||
|
int hours;
|
||||||
|
@JsonProperty("lon")
|
||||||
|
double lon;
|
||||||
|
@JsonProperty("lat")
|
||||||
|
double lat;
|
||||||
|
|
||||||
|
public String getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
public void setDate(String date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHours() {
|
||||||
|
return hours;
|
||||||
|
}
|
||||||
|
public void setHours(int hours) {
|
||||||
|
this.hours = hours;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLon() {
|
||||||
|
return lon;
|
||||||
|
}
|
||||||
|
public void setLon(double lon) {
|
||||||
|
this.lon = lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLat() {
|
||||||
|
return lat;
|
||||||
|
}
|
||||||
|
public void setLat(double lat) {
|
||||||
|
this.lat = lat;
|
||||||
|
}
|
||||||
|
}
|
||||||
71
src/main/java/tools/CustomException.java
Normal file
71
src/main/java/tools/CustomException.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package tools;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.ccalm.weather.models.ErrorResponseModel;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
public class CustomException extends Exception {
|
||||||
|
private static final Logger logger = LogManager.getLogger(CustomException.class);
|
||||||
|
|
||||||
|
private ErrorResponseModel error;
|
||||||
|
|
||||||
|
public CustomException(int errorCode, String errorMessage, String marker) {
|
||||||
|
super(errorMessage);
|
||||||
|
error = new ErrorResponseModel(errorCode, errorMessage, marker);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomException(int errorCode, String errorMessage, String errorSetting, String marker) {
|
||||||
|
super(errorMessage);
|
||||||
|
error = new ErrorResponseModel(errorCode, errorMessage, errorSetting, marker);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomException(int errorCode, List<String> errorMessages, String marker) {
|
||||||
|
super(String.join(" ", errorMessages));
|
||||||
|
error = new ErrorResponseModel(errorCode, errorMessages, marker);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomException(int errorCode, List<String> errorMessages, List<String> errorSettings, String marker) {
|
||||||
|
super(String.join(" ", errorMessages));
|
||||||
|
error = new ErrorResponseModel(errorCode, errorMessages, errorSettings, marker);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getErrorCode() {
|
||||||
|
return error.getError_code();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getErrorMarker() {
|
||||||
|
return error.getError_marker();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getErrorMessages() {
|
||||||
|
return error.getError_message();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getErrorSettings() {
|
||||||
|
return error.getError_setting();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject getJson() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
try {
|
||||||
|
json.put("error_code", this.getErrorCode());
|
||||||
|
json.put("error_message", this.getErrorMessages());
|
||||||
|
json.put("error_setting", this.getErrorSettings());
|
||||||
|
json.put("error_marker", this.getErrorMarker());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
logger.error("Error", e);
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ErrorResponseModel getErrorResponseModel() {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package org.ccalm.weather;
|
package tools;
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
30
src/main/java/tools/StdTools.java
Normal file
30
src/main/java/tools/StdTools.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package tools;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class StdTools {
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
private static final Logger logger = LogManager.getLogger(StdTools.class);
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
public JSONObject createJSONError(int code, String message, String setting, String marker) {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
try {
|
||||||
|
json.put("error_code", code);
|
||||||
|
json.put("error_message", Arrays.asList(message));
|
||||||
|
json.put("error_setting", Arrays.asList(setting));
|
||||||
|
json.put("error_marker", marker);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
logger.error(e);
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user