|
|
|
|
@ -4,9 +4,10 @@ package de.srsoftware.umbrella.time;
@@ -4,9 +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.exceptions.UmbrellaException.forbidden; |
|
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; |
|
|
|
|
import static de.srsoftware.umbrella.time.Constants.*; |
|
|
|
|
import static java.util.stream.Collectors.toMap; |
|
|
|
|
import static java.util.function.Predicate.not; |
|
|
|
|
|
|
|
|
|
import com.sun.net.httpserver.HttpExchange; |
|
|
|
|
import de.srsoftware.configuration.Configuration; |
|
|
|
|
@ -16,7 +17,6 @@ import de.srsoftware.umbrella.core.BaseHandler;
@@ -16,7 +17,6 @@ import de.srsoftware.umbrella.core.BaseHandler;
|
|
|
|
|
import de.srsoftware.umbrella.core.api.*; |
|
|
|
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
|
import de.srsoftware.umbrella.core.model.*; |
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.*; |
|
|
|
|
@ -66,15 +66,68 @@ public class TimeModule extends BaseHandler implements TimeService {
@@ -66,15 +66,68 @@ public class TimeModule extends BaseHandler implements TimeService {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
{ |
|
|
|
|
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 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
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(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); |
|
|
|
|
var companyId = cid.longValue(); |
|
|
|
|
var company = companies.get(companyId); |
|
|
|
|
if (!companies.membership(companyId,user.id())) throw forbidden("You are mot a member of company {0}",company.name()); |
|
|
|
|
if (!(json.has(PROJECT_ID) && json.get(PROJECT_ID) instanceof Number pid)) throw missingFieldException(PROJECT_ID); |
|
|
|
|
long projectId = pid.longValue(); |
|
|
|
|
Map<Long,Task> tasksOfProject = tasks.listProjectTasks(projectId).stream().collect(Collectors.toMap(Task::id,t->t)); |
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> times = timeDb.listTimes(tasksOfProject.keySet()) |
|
|
|
|
.stream().filter(not(Time::isClosed)) |
|
|
|
|
.sorted(Comparator.comparing(Time::start)) |
|
|
|
|
.map(time -> { |
|
|
|
|
var map = time.toMap(); |
|
|
|
|
var timeTasks = time.taskIds().stream().map(tasksOfProject::get).map(Task::toMap).toList(); |
|
|
|
|
map.put(TASKS,timeTasks); |
|
|
|
|
return map; |
|
|
|
|
}).toList(); |
|
|
|
|
|
|
|
|
|
return sendContent(ex,times); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|