|
|
|
|
@ -4,12 +4,10 @@ package de.srsoftware.umbrella.time;
@@ -4,12 +4,10 @@ package de.srsoftware.umbrella.time;
|
|
|
|
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect; |
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
|
import static de.srsoftware.umbrella.core.Paths.LIST; |
|
|
|
|
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_NOT_IMPLEMENTED; |
|
|
|
|
import static de.srsoftware.umbrella.core.Util.mapValues; |
|
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.forbidden; |
|
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; |
|
|
|
|
import static de.srsoftware.umbrella.time.Constants.*; |
|
|
|
|
import static java.util.function.Predicate.not; |
|
|
|
|
import static java.util.stream.Collectors.toSet; |
|
|
|
|
|
|
|
|
|
import com.sun.net.httpserver.HttpExchange; |
|
|
|
|
import de.srsoftware.configuration.Configuration; |
|
|
|
|
@ -23,6 +21,7 @@ import de.srsoftware.umbrella.core.model.*;
@@ -23,6 +21,7 @@ import de.srsoftware.umbrella.core.model.*;
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
public class TimeModule extends BaseHandler implements TimeService { |
|
|
|
|
|
|
|
|
|
@ -82,54 +81,24 @@ public class TimeModule extends BaseHandler implements TimeService {
@@ -82,54 +81,24 @@ public class TimeModule extends BaseHandler implements TimeService {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean getUserTimes(UmbrellaUser user, HttpExchange ex) throws IOException { |
|
|
|
|
// TODO
|
|
|
|
|
var taskIds = new HashSet<Long>(); |
|
|
|
|
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); |
|
|
|
|
times.putAll(timeDb.listUserTimes(user.id())); |
|
|
|
|
return sendContent(ex,mapValues(times)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
{ |
|
|
|
|
1 : { |
|
|
|
|
name: Projekt 1 |
|
|
|
|
id: 1 |
|
|
|
|
times: { |
|
|
|
|
3:{ |
|
|
|
|
name: time 3 |
|
|
|
|
start: 123456 |
|
|
|
|
end: 78901 |
|
|
|
|
}, |
|
|
|
|
4:{ |
|
|
|
|
name: time 4 |
|
|
|
|
start: 234567 |
|
|
|
|
end: 890123 |
|
|
|
|
tasks:{ |
|
|
|
|
5:{ |
|
|
|
|
name: task5 |
|
|
|
|
}, |
|
|
|
|
6:{ |
|
|
|
|
name: task6 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
2: { |
|
|
|
|
name: Projekt 2 |
|
|
|
|
id: 2 |
|
|
|
|
times: { |
|
|
|
|
7:{ |
|
|
|
|
name: time 7 |
|
|
|
|
start: 456789 |
|
|
|
|
end: 012345 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
boolean showClosed = false; |
|
|
|
|
var times = timeDb.listTimes(taskIds, showClosed); |
|
|
|
|
times.putAll(timeDb.listUserTimes(user.id(), showClosed)); |
|
|
|
|
taskIds = times.values().stream().map(Time::taskIds).flatMap(Collection::stream).collect(toSet()); |
|
|
|
|
var tasks = taskService().load(taskIds); |
|
|
|
|
var result = new HashMap<Long,Map<String,Object>>(); |
|
|
|
|
for (var entry : times.entrySet()) { |
|
|
|
|
var time = entry.getValue(); |
|
|
|
|
var map = time.toMap(); |
|
|
|
|
map.remove(TASK_IDS); |
|
|
|
|
map.put(TASKS,time.taskIds().stream().collect(Collectors.toMap(tid -> tid, tid -> tasks.get(tid).name()))); |
|
|
|
|
result.put(entry.getKey(),map); |
|
|
|
|
} |
|
|
|
|
return sendContent(ex,result); |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
private boolean listTimes(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException { |
|
|
|
|
var json = json(ex); |
|
|
|
|
@ -141,7 +110,7 @@ public class TimeModule extends BaseHandler implements TimeService {
@@ -141,7 +110,7 @@ public class TimeModule extends BaseHandler implements TimeService {
|
|
|
|
|
long projectId = pid.longValue(); |
|
|
|
|
Map<Long,Task> tasksOfProject = taskService().listProjectTasks(projectId); |
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> times = timeDb.listTimes(tasksOfProject.keySet()) |
|
|
|
|
List<Map<String, Object>> times = timeDb.listTimes(tasksOfProject.keySet(), true) |
|
|
|
|
.entrySet().stream() |
|
|
|
|
.filter(entry -> !entry.getValue().isClosed()) |
|
|
|
|
.sorted(Comparator.comparing(entry ->entry.getValue().start())) |
|
|
|
|
|