Skip to content

v0.2.47..v0.2.48 changeset DbUtils.java

Garret Voltz edited this page Sep 27, 2019 · 1 revision
diff --git a/hoot-services/src/main/java/hoot/services/utils/DbUtils.java b/hoot-services/src/main/java/hoot/services/utils/DbUtils.java
index 2615c7f..6f64234 100644
--- a/hoot-services/src/main/java/hoot/services/utils/DbUtils.java
+++ b/hoot-services/src/main/java/hoot/services/utils/DbUtils.java
@@ -50,6 +50,9 @@ import javax.ws.rs.BadRequestException;
 import javax.ws.rs.NotFoundException;
 import javax.ws.rs.WebApplicationException;
 
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.ApplicationContext;
@@ -71,6 +74,7 @@ import com.querydsl.sql.types.EnumAsObjectType;
 
 import hoot.services.ApplicationContextUtils;
 import hoot.services.command.CommandResult;
+import hoot.services.models.db.JobStatus;
 import hoot.services.models.db.QUsers;
 
 
@@ -324,6 +328,29 @@ public class DbUtils {
         return sourceInfo != null && sourceInfo.equals("rails");
     }
 
+    public static String getConflationType(long inputId) {
+        String conflationType = null;
+        Map<String, String> tags = getMapsTableTags(inputId);
+        String sourceInfo = tags.get("params");
+
+        if(sourceInfo != null) {
+            JSONParser parser = new JSONParser();
+            JSONObject expectedObj;
+
+            try {
+                sourceInfo = sourceInfo.replace("\\", ""); // have to unescape
+                expectedObj = (JSONObject) parser.parse(sourceInfo);
+            }
+            catch (ParseException e) {
+                throw new RuntimeException("Error parsing params json string.  mapId = " + inputId, e);
+            }
+
+            conflationType = expectedObj.get("CONFLATION_TYPE").toString();
+        }
+
+        return conflationType;
+    }
+
     /**
      * Check to see if the map contains the tag bbox and return it, else null
      * @param mapId
@@ -337,6 +364,18 @@ public class DbUtils {
     }
 
     /**
+     * Retrieves the maps reference layer id
+     * @param mapId
+     * @return reference layer id
+     */
+    public static Long getMergedReference(long mapId) {
+        Map<String, String> tags = getMapsTableTags(mapId);
+        String referenceId = tags.get("input1");
+
+        return Long.parseLong(referenceId);
+    }
+
+    /**
      * Inserts a mapid to the folder mapping table if it doesn't exist
      * Updates mapid's parent if it does exist
      *
@@ -581,6 +620,38 @@ public class DbUtils {
         return -1;
     }
 
+    // Returns the parentId for the specified jobId job
+    public static String getParentId(String jobId) {
+        return createQuery()
+                .select(jobStatus.parentId)
+                .from(jobStatus)
+                .where(jobStatus.jobId.eq(jobId))
+                .fetchFirst();
+    }
+
+    // Sets the specified job to a status detail of stale and recurses up to the parent jobs to do the same
+    public static void setStale(String jobId) {
+        // Find the job
+        JobStatus job = createQuery()
+                .select(jobStatus)
+                .from(jobStatus)
+                .where(jobStatus.jobId.eq(jobId))
+                .fetchFirst();
+
+        if(job != null) {
+            createQuery()
+                .update(jobStatus)
+                .where(jobStatus.jobId.eq(jobId))
+                .set(jobStatus.statusDetail, "STALE")
+                .execute();
+
+            // If it has a parent, make the parent stale too
+            if(job.getParentId() != null && !job.getParentId().equals("")) {
+                setStale(job.getParentId());
+            }
+        }
+    }
+
     /**
      * Inserts the command_status if it doesn't exist already, else update the stdout, stderr, and percent_complete for the command
      * This function will also call updateJobProgress
Clone this wiki locally