|
|
|
@ -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.Paths.LIST; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; |
|
|
|
import static de.srsoftware.umbrella.time.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.time.Constants.*; |
|
|
|
|
|
|
|
import static java.util.stream.Collectors.toMap; |
|
|
|
|
|
|
|
|
|
|
|
import com.sun.net.httpserver.HttpExchange; |
|
|
|
import com.sun.net.httpserver.HttpExchange; |
|
|
|
import de.srsoftware.configuration.Configuration; |
|
|
|
import de.srsoftware.configuration.Configuration; |
|
|
|
@ -17,10 +18,22 @@ import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
import de.srsoftware.umbrella.core.model.*; |
|
|
|
import de.srsoftware.umbrella.core.model.*; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
public class TimeModule extends BaseHandler implements TimeService { |
|
|
|
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 UserService users; |
|
|
|
private final TimeDb timeDb; |
|
|
|
private final TimeDb timeDb; |
|
|
|
private final TaskService tasks; |
|
|
|
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); |
|
|
|
if (!(json.has(COMPANY_ID) && json.get(COMPANY_ID) instanceof Number cid)) throw missingFieldException(COMPANY_ID); |
|
|
|
long companyId = cid.longValue(); |
|
|
|
long companyId = cid.longValue(); |
|
|
|
if (!companies.membership(companyId,user.id())) throw UmbrellaException.forbidden("You are not a member of compayn {0}",companyId); |
|
|
|
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 projectMap = projects.listProjects(companyId,false).stream().collect(toMap(Project::id, p -> p)); |
|
|
|
var taskMap = tasks.listCompanyTasks(companyId).stream().collect(Collectors.toMap(Task::id,Task::toMap)); |
|
|
|
var taskMap = tasks.listCompanyTasks(companyId).stream().collect(Collectors.toMap(Task::id,t->t)); |
|
|
|
var timesList = timeDb.listTimes(taskMap.keySet()); |
|
|
|
var taskIds = taskMap.keySet(); |
|
|
|
var tasksWithTime = new HashMap<Long,Map<String,Object>>(); |
|
|
|
var timesList = timeDb.listTimes(taskIds).stream().map(); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return sendContent(ex,tree); |
|
|
|
return sendContent(ex,tree); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|