|
|
|
|
@ -75,8 +75,7 @@ public class TimeModule extends BaseHandler implements TimeService {
@@ -75,8 +75,7 @@ public class TimeModule extends BaseHandler implements TimeService {
|
|
|
|
|
var head = path.pop(); |
|
|
|
|
return switch (head) { |
|
|
|
|
case STARTED -> getStartedTime(user.get(),ex); |
|
|
|
|
case null -> getUserTimes(user.get(),ex); |
|
|
|
|
default -> super.doGet(path,ex); |
|
|
|
|
case null, default -> super.doGet(path,ex); |
|
|
|
|
}; |
|
|
|
|
} catch (UmbrellaException e){ |
|
|
|
|
return send(ex,e); |
|
|
|
|
@ -119,6 +118,7 @@ public class TimeModule extends BaseHandler implements TimeService {
@@ -119,6 +118,7 @@ public class TimeModule extends BaseHandler implements TimeService {
|
|
|
|
|
case LIST -> listTimes(ex,user.get()); |
|
|
|
|
case SEARCH -> postSearch(ex, user.get()); |
|
|
|
|
case TRACK_TASK -> trackTask(user.get(),path,ex); |
|
|
|
|
case null -> postUserTimeList(user.get(),ex); |
|
|
|
|
default -> { |
|
|
|
|
try { |
|
|
|
|
long timeId = Long.parseLong(head); |
|
|
|
|
@ -199,31 +199,6 @@ public class TimeModule extends BaseHandler implements TimeService {
@@ -199,31 +199,6 @@ public class TimeModule extends BaseHandler implements TimeService {
|
|
|
|
|
return send(ex,UmbrellaException.notFound("no started time")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean getUserTimes(UmbrellaUser user, HttpExchange ex) throws IOException { |
|
|
|
|
Set<Long> taskIds = new HashSet<>(); |
|
|
|
|
Map<Long, Project> projects = projectService().listUserProjects(user.id(), true); |
|
|
|
|
for (var pid : projects.keySet()) taskIds.addAll(taskService().listProjectTasks(pid).keySet()); |
|
|
|
|
boolean showClosed = false; |
|
|
|
|
var times = timeDb.listTimes(taskIds, showClosed); |
|
|
|
|
times.putAll(timeDb.listUserTimes(user.id(), showClosed)); |
|
|
|
|
taskIds.clear(); |
|
|
|
|
var userIds = new HashSet<Long>(); |
|
|
|
|
times.values().forEach(time -> { |
|
|
|
|
taskIds.addAll(time.taskIds()); |
|
|
|
|
userIds.add(time.userId()); |
|
|
|
|
}); |
|
|
|
|
var tasks = taskService().load(taskIds); |
|
|
|
|
var users = userService().list(null,null,userIds); |
|
|
|
|
var result = new HashMap<String,Object>(); |
|
|
|
|
var docList = documentService().docsReferencedByTimes(times.keySet()); |
|
|
|
|
result.put(DOCUMENTS,docList); |
|
|
|
|
result.put(TIMES,mapValues(times)); |
|
|
|
|
result.put(TASKS,mapValues(tasks)); |
|
|
|
|
result.put(PROJECTS,mapValues(projects)); |
|
|
|
|
result.put(USERS,mapValues(users)); |
|
|
|
|
return sendContent(ex,result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean listTimes(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException { |
|
|
|
|
var json = json(ex); |
|
|
|
|
if (!(json.has(COMPANY_ID) && json.get(COMPANY_ID) instanceof Number cid)) throw missingFieldException(COMPANY_ID); |
|
|
|
|
@ -281,6 +256,32 @@ public class TimeModule extends BaseHandler implements TimeService {
@@ -281,6 +256,32 @@ public class TimeModule extends BaseHandler implements TimeService {
|
|
|
|
|
return sendContent(ex,mapValues(notes)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean postUserTimeList(UmbrellaUser user, HttpExchange ex) throws IOException { |
|
|
|
|
var json = json(ex); |
|
|
|
|
var showClosed = json.has(CLOSED) && json.get(CLOSED) instanceof Boolean b ? b : false; |
|
|
|
|
Set<Long> taskIds = new HashSet<>(); |
|
|
|
|
Map<Long, Project> projects = projectService().listUserProjects(user.id(), true); |
|
|
|
|
for (var pid : projects.keySet()) taskIds.addAll(taskService().listProjectTasks(pid).keySet()); |
|
|
|
|
var times = timeDb.listTimes(taskIds, showClosed); |
|
|
|
|
times.putAll(timeDb.listUserTimes(user.id(), showClosed)); |
|
|
|
|
taskIds.clear(); |
|
|
|
|
var userIds = new HashSet<Long>(); |
|
|
|
|
times.values().forEach(time -> { |
|
|
|
|
taskIds.addAll(time.taskIds()); |
|
|
|
|
userIds.add(time.userId()); |
|
|
|
|
}); |
|
|
|
|
var tasks = taskService().load(taskIds); |
|
|
|
|
var users = userService().list(null,null,userIds); |
|
|
|
|
var result = new HashMap<String,Object>(); |
|
|
|
|
var docList = documentService().docsReferencedByTimes(times.keySet()); |
|
|
|
|
result.put(DOCUMENTS,docList); |
|
|
|
|
result.put(TIMES,mapValues(times)); |
|
|
|
|
result.put(TASKS,mapValues(tasks)); |
|
|
|
|
result.put(PROJECTS,mapValues(projects)); |
|
|
|
|
result.put(USERS,mapValues(users)); |
|
|
|
|
return sendContent(ex,result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean trackTask(UmbrellaUser user, Path path, HttpExchange ex) throws IOException { |
|
|
|
|
if (path.empty()) throw missingFieldException(TASK_ID); |
|
|
|
|
Task task; |
|
|
|
|
|