Ver Fonte

Fixed /GetUnits service for units without defined position

mkepka há 4 anos atrás
pai
commit
44abfd0dc6

+ 1 - 1
src/main/java/cz/hsrs/db/model/UnitPosition.java

@@ -284,7 +284,7 @@ public class UnitPosition implements DBObject {
      * @throws SQLException
      */
     public Date internalGetTimestamp() throws SQLException {
-        if (timeStamp == null) {
+        if (timeStamp != null) {
             try {
                 return DateUtil.parseTimestamp(time_stamp);
             } catch (ParseException e) {

+ 8 - 2
src/main/java/cz/hsrs/db/util/UserUtil.java

@@ -125,9 +125,9 @@ public class UserUtil extends GroupUtil {
          * AND units_to_groups.unit_id =last_units_positions.unit_id ;
          */
         String last_pos_table = SQLExecutor.getUnitsLastPositions_table();
+        /*
         String queryObservations = "SELECT gid, st_x(the_geom), st_y(the_geom), st_srid(the_geom), speed, "
-                + last_pos_table
-                + ".unit_id, time_stamp, units_to_groups.group_id "
+                + last_pos_table + ".unit_id, time_stamp, units_to_groups.group_id "
                 + "FROM "
                 + last_pos_table
                 + ", "
@@ -137,6 +137,12 @@ public class UserUtil extends GroupUtil {
                 + ") AND units_to_groups.unit_id = "
                 + last_pos_table
                 + ".unit_id; ";
+        */
+        String queryObservations = "SELECT units_to_groups.group_id, units_to_groups.unit_id,"
+        		+ " lpt.gid, lpt.time_stamp, st_x(lpt.the_geom), st_y(lpt.the_geom), st_srid(lpt.the_geom), lpt.speed"
+        		+ " FROM units_to_groups"
+        		+ " LEFT JOIN "+last_pos_table+" lpt ON units_to_groups.unit_id = lpt.unit_id"
+        		+ " WHERE ("+ this.getWhereStatemant(user_name, "units_to_groups.group_id") + ");";
         return stmt.executeQuery(queryObservations);
     }
 

+ 12 - 2
src/main/java/cz/hsrs/db/util/factory/UnitPositionFactory.java

@@ -51,12 +51,22 @@ public class UnitPositionFactory {
         /* Kdyz auto nema senzor na klicek urci se jestli jede podle casu posledni pozice */
         else {
             /* Kdyz je posledni pozice starsi nez confTime tak auto nejede */
-            isRunning = (new Date()).getTime() - pos.internalGetTimestamp().getTime() <= (confTime * 1000);
+        	if (pos.internalGetTimestamp() != null) {
+        		isRunning = (new Date()).getTime() - pos.internalGetTimestamp().getTime() <= (confTime * 1000);
+        	}
+        	else {
+        		isRunning = false;
+        	}
         }
         map.put(LastPosition.IS_RUNNING, isRunning);
 
         /* Kdyz auto neposila po urcitou dobu pozice (5* conftime), bere se jako offline */
-        isOnline = ((new Date()).getTime() - pos.internalGetTimestamp().getTime()) <= 24 * 3600 * 1000;
+        if(pos.internalGetTimestamp() != null) {
+        	isOnline = ((new Date()).getTime() - pos.internalGetTimestamp().getTime()) <= 24 * 3600 * 1000;
+        }
+        else {
+        	isOnline = false;
+        }        
         map.put("is_online", isOnline);
 
         /*Pouzivat pokud neni synchronizace mezi skutecnou posledni pozici a pozici u observace*/

+ 1 - 0
src/main/java/cz/hsrs/rest/provider/TestRest.java

@@ -91,6 +91,7 @@ public class TestRest {
     
     /**
      * /rest/test/testdb?message=<>
+     * /rest/test/testdb?message=pokus
      * @param testValue
      * @return
      * @throws SQLException 

+ 2 - 2
src/main/java/cz/hsrs/servlet/provider/DBServlet.java

@@ -68,8 +68,8 @@ public abstract class DBServlet extends HttpServlet {
             if (SQLExecutor.getConfigFile()!=null) {
                 conffile  = SQLExecutor.getConfigFile();
             }
-            FileInputStream fstrem = new FileInputStream(
-                new File(getServletContext().getRealPath("WEB-INF/"+conffile)));
+            //FileInputStream fstrem = new FileInputStream(new File(getServletContext().getRealPath("WEB-INF/"+conffile)));
+            FileInputStream fstrem = new FileInputStream(new File(getServletContext().getRealPath(conffile)));
             LogManager.getLogManager().readConfiguration(fstrem);
             LogManager.getLogManager().addLogger(logger);
         

+ 2 - 0
src/main/java/cz/hsrs/servlet/provider/DataService.java

@@ -25,6 +25,8 @@ import cz.hsrs.servlet.security.LoginUser;
  * Servlet implementation class DataService
  * 
  * /DataService?Operation=GetDataByUserName&user=pepa&limit=100
+ * /DataService?Operation=GetUnitsList
+ * /DataService?Operation=GetUnits
  */
 public class DataService extends DBServlet {