|
@@ -4,13 +4,14 @@
|
|
|
package cz.hsrs.rest.provider;
|
|
package cz.hsrs.rest.provider;
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
import java.sql.SQLException;
|
|
|
-import java.time.*;
|
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.logging.Logger;
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
import javax.naming.AuthenticationException;
|
|
import javax.naming.AuthenticationException;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.validation.constraints.NotNull;
|
|
|
|
|
import javax.ws.rs.DefaultValue;
|
|
import javax.ws.rs.DefaultValue;
|
|
|
import javax.ws.rs.GET;
|
|
import javax.ws.rs.GET;
|
|
|
import javax.ws.rs.Path;
|
|
import javax.ws.rs.Path;
|
|
@@ -54,6 +55,10 @@ public class ObservationRest {
|
|
|
* /rest/observation/export?group_id=25&sensor_id=340340092&from_time=2021-05-30&to_time=2021-05-31&style=crosstab
|
|
* /rest/observation/export?group_id=25&sensor_id=340340092&from_time=2021-05-30&to_time=2021-05-31&style=crosstab
|
|
|
* /rest/observation/export?group_id=25&sensor_id=340340092&from_time=2021-05-30&to_time=2021-05-30+04:00:00&style=crosstab&nullable=false
|
|
* /rest/observation/export?group_id=25&sensor_id=340340092&from_time=2021-05-30&to_time=2021-05-30+04:00:00&style=crosstab&nullable=false
|
|
|
* /rest/observation/export?unit_id=1305167563044155,1305167563032199,1305167563051210&sensor_id=340340092&from_time=2021-05-30&to_time=2021-05-30+04:00:00&style=crosstab&nullable=false
|
|
* /rest/observation/export?unit_id=1305167563044155,1305167563032199,1305167563051210&sensor_id=340340092&from_time=2021-05-30&to_time=2021-05-30+04:00:00&style=crosstab&nullable=false
|
|
|
|
|
+ * /rest/observation/export?group_id=25&sensor_id=340340092&from_time=2021-05-30&to_time=2021-05-31&style=timeseries
|
|
|
|
|
+ * /rest/observation/export?unit_id=1305167563044724,1305167563025379&sensor_id=340340092&from_time=2021-05-30&to_time=2021-05-31&style=timeseries
|
|
|
|
|
+ * /rest/observation/export?group_id=25&sensor_id=340340092&month_of_year=4&year=2021&style=timeseries
|
|
|
|
|
+ *
|
|
|
*/
|
|
*/
|
|
|
@Path("/export")
|
|
@Path("/export")
|
|
|
@GET
|
|
@GET
|
|
@@ -88,14 +93,13 @@ public class ObservationRest {
|
|
|
else {
|
|
else {
|
|
|
CSV = ExportUtil.getObservationsBySensorByGroupCross(sensorId, groupId, fromTime, toTime, nullable);
|
|
CSV = ExportUtil.getObservationsBySensorByGroupCross(sensorId, groupId, fromTime, toTime, nullable);
|
|
|
}
|
|
}
|
|
|
- } else if(exportStyle.equalsIgnoreCase(ParamsList.REVERSE_TAB_STYLE)) {
|
|
|
|
|
|
|
+ } else if(exportStyle.equalsIgnoreCase(ParamsList.TIMESERIES_STYLE)) {
|
|
|
if (sensorId == null) {
|
|
if (sensorId == null) {
|
|
|
return Response.status(HttpStatus.ORDINAL_400_Bad_Request)
|
|
return Response.status(HttpStatus.ORDINAL_400_Bad_Request)
|
|
|
- .entity(String.format("Request does not contain sensor id. Define: '%s'.", ParamsList.SENSOR_ID))
|
|
|
|
|
|
|
+ .entity(String.format("Request does not contain sensor_id. Define: '%s'.", ParamsList.SENSOR_ID))
|
|
|
.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN)
|
|
.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN)
|
|
|
.build();
|
|
.build();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
LocalDateTime fromTimestamp;
|
|
LocalDateTime fromTimestamp;
|
|
|
LocalDateTime toTimestamp;
|
|
LocalDateTime toTimestamp;
|
|
|
if (monthOfYear != null && monthOfYear > 0 && year != null && year > 0) {
|
|
if (monthOfYear != null && monthOfYear > 0 && year != null && year > 0) {
|
|
@@ -103,7 +107,8 @@ public class ObservationRest {
|
|
|
fromTimestamp = LocalDateTime.of(date, LocalTime.MIN);
|
|
fromTimestamp = LocalDateTime.of(date, LocalTime.MIN);
|
|
|
toTimestamp = fromTimestamp.plusMonths(1);
|
|
toTimestamp = fromTimestamp.plusMonths(1);
|
|
|
} else if (fromTime != null && toTime != null) {
|
|
} else if (fromTime != null && toTime != null) {
|
|
|
- final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
|
+ final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+
|
|
|
fromTimestamp = LocalDateTime.parse(fromTime, formatter);
|
|
fromTimestamp = LocalDateTime.parse(fromTime, formatter);
|
|
|
toTimestamp = LocalDateTime.parse(toTime, formatter);
|
|
toTimestamp = LocalDateTime.parse(toTime, formatter);
|
|
|
} else {
|
|
} else {
|
|
@@ -135,7 +140,8 @@ public class ObservationRest {
|
|
|
.build();
|
|
.build();
|
|
|
} catch (AuthenticationException e) {
|
|
} catch (AuthenticationException e) {
|
|
|
return Response.status(HttpStatus.ORDINAL_401_Unauthorized)
|
|
return Response.status(HttpStatus.ORDINAL_401_Unauthorized)
|
|
|
- .entity(new ExceptionBean(e.getClass().getName(), e.getLocalizedMessage()))
|
|
|
|
|
|
|
+ .entity(new ExceptionBean(e.getClass().getName(), e.getMessage()))
|
|
|
|
|
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
|
|
|
.build();
|
|
.build();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -147,14 +153,14 @@ public class ObservationRest {
|
|
|
JSONArray arr = new JSONArray();
|
|
JSONArray arr = new JSONArray();
|
|
|
/* crosstab style*/
|
|
/* crosstab style*/
|
|
|
JSONObject obj1 = new JSONObject();
|
|
JSONObject obj1 = new JSONObject();
|
|
|
- obj1.put("style_id", "crosstab");
|
|
|
|
|
|
|
+ obj1.put("style_id", ParamsList.CROSS_TAB_STYLE);
|
|
|
obj1.put("style_name", "Cross table");
|
|
obj1.put("style_name", "Cross table");
|
|
|
obj1.put("description", "Table with dates in rows and units/sensors in columns.");
|
|
obj1.put("description", "Table with dates in rows and units/sensors in columns.");
|
|
|
arr.add(obj1);
|
|
arr.add(obj1);
|
|
|
|
|
|
|
|
/* timeseries style*/
|
|
/* timeseries style*/
|
|
|
JSONObject obj2 = new JSONObject();
|
|
JSONObject obj2 = new JSONObject();
|
|
|
- obj2.put("style_id", "timeseries");
|
|
|
|
|
|
|
+ obj2.put("style_id", ParamsList.TIMESERIES_STYLE);
|
|
|
obj2.put("style_name", "Time series table");
|
|
obj2.put("style_name", "Time series table");
|
|
|
obj2.put("description", "Table with units in rows and dates in columns, available for one observed property.");
|
|
obj2.put("description", "Table with units in rows and dates in columns, available for one observed property.");
|
|
|
arr.add(obj2);
|
|
arr.add(obj2);
|