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 515ffd9..041dc3e 100644
--- a/hoot-services/src/main/java/hoot/services/utils/DbUtils.java
+++ b/hoot-services/src/main/java/hoot/services/utils/DbUtils.java
@@ -27,6 +27,7 @@
package hoot.services.utils;
+import static hoot.services.HootProperties.CHANGESETS_FOLDER;
import static hoot.services.models.db.QFolderMapMappings.folderMapMappings;
import static hoot.services.models.db.QFolders.folders;
import static hoot.services.models.db.QJobStatus.jobStatus;
@@ -34,6 +35,7 @@ import static hoot.services.models.db.QMaps.maps;
import static hoot.services.models.db.QReviewBookmarks.reviewBookmarks;
import static hoot.services.models.db.QUsers.users;
+import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -54,6 +56,7 @@ import javax.ws.rs.BadRequestException;
import javax.ws.rs.NotFoundException;
import javax.ws.rs.WebApplicationException;
+import com.querydsl.sql.dml.SQLUpdateClause;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
@@ -80,6 +83,7 @@ import com.querydsl.sql.types.EnumAsObjectType;
import hoot.services.ApplicationContextUtils;
import hoot.services.command.CommandResult;
+import hoot.services.controllers.osm.user.UserResource;
import hoot.services.models.db.Folders;
import hoot.services.models.db.JobStatus;
import hoot.services.models.db.Maps;
@@ -284,7 +288,7 @@ public class DbUtils {
.select(folders)
.from(folders)
.where(folders.id.ne(0L));
- if(userId != null) {
+ if (userId != null && !UserResource.adminUserCheck(getUser(userId))) {
sql.where(
folders.userId.eq(userId).or(folders.publicCol.isTrue())
);
@@ -304,6 +308,36 @@ public class DbUtils {
return childrenFolders;
}
+
+
+ public static List<Tuple> getMapsForUser(Users user) {
+
+ // return empty list if user is null
+ if(user == null) {
+ return Collections.emptyList();
+ }
+
+ SQLQuery<Tuple> q = createQuery()
+ .select(maps, folders.id, folders.publicCol)
+ .from(maps)
+ .leftJoin(folderMapMappings).on(folderMapMappings.mapId.eq(maps.id))
+ .leftJoin(folders).on(folders.id.eq(folderMapMappings.folderId))
+ .orderBy(maps.displayName.asc());
+ // if user is not admin enforce visiblity rules
+ // admins can see everything
+ if (!UserResource.adminUserCheck(user)) {
+ BooleanExpression isVisible = maps.userId.eq(user.getId()) // Owned by the current user
+ // or not in a folder
+ .or(folderMapMappings.id.isNull().or(folderMapMappings.folderId.eq(0L))
+ // or in a public folder
+ .or(folders.publicCol.isTrue()));
+ q.where(isVisible);
+ }
+ List<Tuple> mapLayerRecords = q.fetch();
+
+ return mapLayerRecords;
+ }
+
/*
* --Deletes folders that are empty (no child datasets or folders)
DELETE
@@ -346,14 +380,21 @@ NOT EXISTS
* Sets the parent directory for the specified folder
*
* @param folderId folder id whos parent we are setting
- * @param parentId parent directory id that the folder will get linked to
+ * @param parent parent folder that the folder will get linked to
*/
- public static void setFolderParent(Long folderId, Long parentId) {
- createQuery()
+ public static void setFolderParent(Long folderId, Folders parent) {
+ SQLUpdateClause query = createQuery()
.update(folders)
.where(folders.id.eq(folderId))
- .set(folders.parentId, parentId)
- .execute();
+ .set(folders.parentId, parent.getId());
+
+ // dont want a private folder moved to root to become public
+ // otherwise inherit the visibility of the new parent folder
+ if(parent.getId() != 0) {
+ query.set(folders.publicCol, parent.getPublicCol());
+ }
+
+ query.execute();
}
public static String getDisplayNameById(long mapId) {
@@ -631,7 +672,7 @@ NOT EXISTS
*/
private static BooleanExpression getStale(Timestamp ts) {
- return (Expressions.stringTemplate("tags->'lastAccessed'").isNotNull().and(maps.createdAt.lt(ts)))
+ return (Expressions.stringTemplate("tags->'lastAccessed'").isNull().and(maps.createdAt.lt(ts)))
.or(Expressions.dateTimeTemplate(Timestamp.class, "TO_TIMESTAMP(tags -> 'lastAccessed', 'YYYY-MM-DD\"T\"HH24:MI:SS.MS\"Z\"')").lt(ts));
}
@@ -700,6 +741,10 @@ NOT EXISTS
.fetchCount() == 1;
}
+ public static Users getUser(Long id) {
+ return createQuery().select(users).from(users).where(users.id.eq(id)).fetchFirst();
+ }
+
/**
* Returns the record ID associated with the record request input string for
* the given DAO type. First attempts to parse the request string as a
@@ -824,6 +869,29 @@ NOT EXISTS
}
}
+ // Sets the specified upload changeset job to a status detail of CONFLICTS
+ // if a diff-error.osc file is present in the parent job workspace
+ public static void checkConflicted(String jobId, String parentId) {
+ File workDir = new File(CHANGESETS_FOLDER, parentId);
+ File diffError = new File(workDir, "diff-error.osc");
+ if (diffError.exists()) {
+ // 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, "CONFLICTS")
+ .execute();
+ }
+ }
+ }
+
/**
* 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