|
|
@@ -26,14 +26,14 @@ public class ObservationRestUtil {
|
|
|
*/
|
|
|
public static List<LastObsTimestampBean> getLastTimestampPerGroup(String groupName, Integer groupId) throws SQLException {
|
|
|
String query;
|
|
|
- if(groupName.isEmpty() && groupId != null) {
|
|
|
+ if(groupName == null && groupId != null) {
|
|
|
query = "SELECT * FROM public.units_sensors_lastobs WHERE id = "+groupId+";";
|
|
|
}
|
|
|
else if(!groupName.isEmpty() && groupId == null) {
|
|
|
query = "SELECT * FROM public.units_sensors_lastobs WHERE group_name = '"+groupName+"';";
|
|
|
}
|
|
|
else {
|
|
|
- query = "SELECT * FROM public.units_sensors_lastobs WHERE id = "+groupId+" AND group_name = '"+groupName+"';";
|
|
|
+ throw new SQLException("Group identification must be provided!");
|
|
|
}
|
|
|
List<LastObsTimestampBean> obsList = new LinkedList<LastObsTimestampBean>();
|
|
|
|
|
|
@@ -54,4 +54,74 @@ public class ObservationRestUtil {
|
|
|
}
|
|
|
return obsList;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param unitIds
|
|
|
+ * @return
|
|
|
+ * @throws SQLException
|
|
|
+ */
|
|
|
+ public static List<LastObsTimestampBean> getLastTimestampPerUnit(String unitIds) throws SQLException {
|
|
|
+ String query;
|
|
|
+ if(unitIds != null) {
|
|
|
+ query = "SELECT DISTINCT ON (unit_id, sensor_id) unit_id, description, sensor_id, sensor_name, last_timestamp"
|
|
|
+ + " FROM public.units_sensors_lastobs"
|
|
|
+ + " WHERE unit_id IN ("+unitIds+")"
|
|
|
+ + " ORDER BY unit_id, sensor_id;";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ throw new SQLException("Unit identification must be provided!");
|
|
|
+ }
|
|
|
+ List<LastObsTimestampBean> obsList = new LinkedList<LastObsTimestampBean>();
|
|
|
+
|
|
|
+ ResultSet res = SQLExecutor.getInstance().executeQuery(query);
|
|
|
+ if(res != null) {
|
|
|
+ while (res.next()) {
|
|
|
+ LastObsTimestampBean obs = new LastObsTimestampBean(
|
|
|
+ res.getLong("unit_id"),
|
|
|
+ res.getString("description"),
|
|
|
+ res.getLong("sensor_id"),
|
|
|
+ res.getString("sensor_name"),
|
|
|
+ res.getString("last_timestamp")
|
|
|
+ );
|
|
|
+ obsList.add(obs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return obsList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param sensorIds
|
|
|
+ * @return
|
|
|
+ * @throws SQLException
|
|
|
+ */
|
|
|
+ public static List<LastObsTimestampBean> getLastTimestampPerSensor(String sensorIds) throws SQLException {
|
|
|
+ String query;
|
|
|
+ if(sensorIds != null) {
|
|
|
+ query = "SELECT DISTINCT ON (unit_id, sensor_id) unit_id, description, sensor_id, sensor_name, last_timestamp"
|
|
|
+ + " FROM public.units_sensors_lastobs"
|
|
|
+ + " WHERE sensor_id IN ("+sensorIds+")"
|
|
|
+ + " ORDER BY unit_id, sensor_id;";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ throw new SQLException("Sensor identification must be provided!");
|
|
|
+ }
|
|
|
+ List<LastObsTimestampBean> obsList = new LinkedList<LastObsTimestampBean>();
|
|
|
+
|
|
|
+ ResultSet res = SQLExecutor.getInstance().executeQuery(query);
|
|
|
+ if(res != null) {
|
|
|
+ while (res.next()) {
|
|
|
+ LastObsTimestampBean obs = new LastObsTimestampBean(
|
|
|
+ res.getLong("unit_id"),
|
|
|
+ res.getString("description"),
|
|
|
+ res.getLong("sensor_id"),
|
|
|
+ res.getString("sensor_name"),
|
|
|
+ res.getString("last_timestamp")
|
|
|
+ );
|
|
|
+ obsList.add(obs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return obsList;
|
|
|
+ }
|
|
|
}
|