Просмотр исходного кода

Update management utils by SQL commands

Michal Kepka 4 лет назад
Родитель
Сommit
490fbc57c3

+ 10 - 2
src/main/java/cz/hsrs/db/util/ManagementUtil.java

@@ -11,6 +11,7 @@ import cz.hsrs.db.model.NoItemFoundException;
 import cz.hsrs.db.model.Phenomenon;
 import cz.hsrs.db.model.Sensor;
 import cz.hsrs.db.model.insert.UnitInsert;
+import cz.hsrs.db.pool.SQLExecutor;
 
 
 /**
@@ -40,8 +41,13 @@ public class ManagementUtil extends DBUtil {
 
                 for (Sensor sensor : sensors) {
                     long sensorId = sensor.getSensorId();
+                    String del = "DELETE FROM units_to_sensors WHERE sensor_id = "+sensorId + " AND unit_id = " + unitId;
+                    int result = SQLExecutor.executeUpdate(del);
 
-                    // TODO delete sensor in the database
+                    // TODO delete sensor in the database 
+                    //- delete sensor pokud je pouze u teto jednotky
+                    //- delete pouze units_to_sensors pokud je u vice jednotek - typ senzoru - OK
+                    
 
                 }
                 return new UnitInsert(unitId, null, sensors);
@@ -115,7 +121,7 @@ public class ManagementUtil extends DBUtil {
 
             for (Sensor sensor : sensors) {
                 long sensorId = sensor.getSensorId();
-
+                // 2. iterace
                 // TODO UPDATE sensor attribute in the database
 
             }
@@ -133,6 +139,8 @@ public class ManagementUtil extends DBUtil {
                 throw new NoItemFoundException("Attribute 'unit_id' is required.");
             }
             long unitId = unitJson.getLong("unit_id");
+            String updUnit = "UPDATE units SET description = '"+unitJson.getString("description")+"' WHERE unit_id = "+unitId;
+            int result = SQLExecutor.executeUpdate(updUnit);
 
             // TODO UPDATE unit attributes in the database
 

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

@@ -91,7 +91,12 @@ public class ManagementService extends DBServlet {
             throw new JSONException(e.getMessage());
         }
     }
-
+/* -- Prihlasovani -- */
+    /**
+     * 
+     * @param user
+     * @return
+     */
     private boolean isNotAuthorized(String user) {
         if(user == null || user.isEmpty()) {
             return true;
@@ -111,7 +116,8 @@ public class ManagementService extends DBServlet {
     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         response.addHeader(HttpHeaders.CONTENT_TYPE, JSON_CONTENT);
         response.addHeader("Access-Control-Allow-Origin", "*");
-
+        
+        /* -- Prihlasovani -- */
         String user = request.getParameter("user");
         if (isNotAuthorized(user)) {
             throw new ServletException("Authentication failure for request: "+ request.getQueryString());