overhauling time list in backend – BROKEN
This commit is contained in:
@@ -9,12 +9,16 @@ import static de.srsoftware.umbrella.core.Util.dateTimeOf;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class Time implements Mappable{
|
||||
|
||||
private final Collection<Long> taskIds;
|
||||
private final LocalDateTime end, start;
|
||||
private final long id, userId;
|
||||
private final String description, subject;
|
||||
private final State state;
|
||||
|
||||
public record Time(long id, long userId, String subject, String description, LocalDateTime start, LocalDateTime end, State state, Set<Long> taskIds) implements Mappable {
|
||||
public enum State{
|
||||
Started(10),
|
||||
Open(20),
|
||||
@@ -44,6 +48,18 @@ public record Time(long id, long userId, String subject, String description, Loc
|
||||
}
|
||||
}
|
||||
|
||||
public Time(long id, long userId, String subject, String description, LocalDateTime start, LocalDateTime end, State state, Collection<Long> taskIds){
|
||||
this.id=id;
|
||||
this.userId = userId;
|
||||
this.subject = subject;
|
||||
this.description = description;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.state = state;
|
||||
this.taskIds = taskIds;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
var map = new HashMap<String,Object>();
|
||||
|
||||
@@ -6,6 +6,7 @@ import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Paths.LIST;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||
import static de.srsoftware.umbrella.time.Constants.*;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import de.srsoftware.configuration.Configuration;
|
||||
@@ -17,10 +18,22 @@ import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
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 {
|
||||
|
||||
private class ExtendedTime extends Time{
|
||||
|
||||
private final Collection<Task> tasks;
|
||||
|
||||
public ExtendedTime(long id, long userId, String subject, String description, LocalDateTime start, LocalDateTime end, State state, Collection<Task> tasks) {
|
||||
super(id, userId, subject, description, start, end, state, tasks.stream().map(Task::id).toList());
|
||||
this.tasks = tasks;
|
||||
}
|
||||
}
|
||||
|
||||
private final UserService users;
|
||||
private final TimeDb timeDb;
|
||||
private final TaskService tasks;
|
||||
@@ -58,35 +71,10 @@ public class TimeModule extends BaseHandler implements TimeService {
|
||||
if (!(json.has(COMPANY_ID) && json.get(COMPANY_ID) instanceof Number cid)) throw missingFieldException(COMPANY_ID);
|
||||
long companyId = cid.longValue();
|
||||
if (!companies.membership(companyId,user.id())) throw UmbrellaException.forbidden("You are not a member of compayn {0}",companyId);
|
||||
var projectMap = projects.listProjects(companyId,false).stream().collect(Collectors.toMap(Project::id,p -> p));
|
||||
var taskMap = tasks.listCompanyTasks(companyId).stream().collect(Collectors.toMap(Task::id,Task::toMap));
|
||||
var timesList = timeDb.listTimes(taskMap.keySet());
|
||||
var tasksWithTime = new HashMap<Long,Map<String,Object>>();
|
||||
var tree = new HashMap<Long,Map<String,Object>>();
|
||||
for (var time : timesList) {
|
||||
if (time.state().code() >= 60) continue;
|
||||
var timeMap = time.toMap();
|
||||
for (var taskId : time.taskIds()) {
|
||||
var task = tasksWithTime.computeIfAbsent(taskId, k -> taskMap.get(taskId));
|
||||
@SuppressWarnings("unchecked")
|
||||
HashMap<Long,Map<String, Object>> taskTimes = (HashMap<Long,Map<String, Object>>) task.computeIfAbsent(TIMES, k -> new HashMap<Long,Map<String, Object>>());
|
||||
taskTimes.put(time.id(),timeMap);
|
||||
while (task.get(PARENT_TASK_ID) instanceof Long parentTaskId){
|
||||
var parentTask = taskMap.get(parentTaskId);
|
||||
@SuppressWarnings("unchecked")
|
||||
HashMap<Long,Map<String, Object>> children = (HashMap<Long,Map<String, Object>>) parentTask.computeIfAbsent(CHILDREN, k -> new HashMap<Long,Map<String, Object>>());
|
||||
children.put(taskId,task);
|
||||
task = parentTask;
|
||||
taskId = parentTaskId;
|
||||
}
|
||||
if (task.get(PROJECT_ID) instanceof Long projectId){
|
||||
var project = tree.computeIfAbsent(projectId,k -> new HashMap<>(projectMap.get(projectId).toMap()));
|
||||
@SuppressWarnings("unchecked")
|
||||
HashMap<Long,Map<String,Object>> projectTasks = (HashMap<Long,Map<String, Object>>) project.computeIfAbsent(TASKS, k -> new HashMap<Long,Map<String,Object>>());
|
||||
projectTasks.put(taskId,task);
|
||||
}
|
||||
}
|
||||
}
|
||||
var projectMap = projects.listProjects(companyId,false).stream().collect(toMap(Project::id, p -> p));
|
||||
var taskMap = tasks.listCompanyTasks(companyId).stream().collect(Collectors.toMap(Task::id,t->t));
|
||||
var taskIds = taskMap.keySet();
|
||||
var timesList = timeDb.listTimes(taskIds).stream().map();
|
||||
return sendContent(ex,tree);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user