working on time list
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.time;
|
||||
|
||||
import static de.srsoftware.tools.jdbc.Condition.equal;
|
||||
import static de.srsoftware.tools.jdbc.Condition.in;
|
||||
import static de.srsoftware.tools.jdbc.Condition.*;
|
||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||
import static de.srsoftware.tools.jdbc.Query.select;
|
||||
import static de.srsoftware.umbrella.core.Constants.ID;
|
||||
import static de.srsoftware.umbrella.core.Constants.USER_ID;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.model.Time.State.Complete;
|
||||
import static de.srsoftware.umbrella.time.Constants.*;
|
||||
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
@@ -26,7 +25,7 @@ public class SqliteDb implements TimeDb {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Long,Time> listTimes(Collection<Long> taskIds) throws UmbrellaException {
|
||||
public HashMap<Long,Time> listTimes(Collection<Long> taskIds, boolean showClosed) throws UmbrellaException {
|
||||
try {
|
||||
var rs = select(ALL).from(TABLE_TASK_TIMES).where(TASK_ID,in(taskIds.toArray())).exec(db);
|
||||
var mapFromTimesToTasks = new HashMap<Long,HashSet<Long>>();
|
||||
@@ -36,7 +35,9 @@ public class SqliteDb implements TimeDb {
|
||||
mapFromTimesToTasks.computeIfAbsent(timeId, k -> new HashSet<>()).add(taskId);
|
||||
}
|
||||
rs.close();
|
||||
rs = select(ALL).from(TABLE_TIMES).where(ID,in(mapFromTimesToTasks.keySet().toArray())).exec(db);
|
||||
var query = select(ALL).from(TABLE_TIMES).where(ID,in(mapFromTimesToTasks.keySet().toArray()));
|
||||
if (!showClosed) query.where(STATE,lessThan(Complete.code()));
|
||||
rs = query.exec(db);
|
||||
var times = new HashMap<Long,Time>();
|
||||
while (rs.next()) {
|
||||
var time = Time.of(rs);
|
||||
@@ -45,15 +46,17 @@ public class SqliteDb implements TimeDb {
|
||||
}
|
||||
rs.close();
|
||||
return times;
|
||||
} catch (SQLException e) {
|
||||
} catch (Exception e) {
|
||||
throw new UmbrellaException("Failed to load times for task list");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<Long, Time> listUserTimes(long userId) {
|
||||
public HashMap<Long, Time> listUserTimes(long userId, boolean showClosed) {
|
||||
try {
|
||||
var rs = select(ALL).from(TABLE_TIMES).where(USER_ID,equal(userId)).exec(db);
|
||||
var query = select(ALL).from(TABLE_TIMES).where(USER_ID,equal(userId));
|
||||
if (!showClosed) query.where(STATE,lessThan(Complete.code()));
|
||||
var rs = query.exec(db);
|
||||
var times = new HashMap<Long,Time>();
|
||||
while (rs.next()) {
|
||||
var time = Time.of(rs);
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface TimeDb {
|
||||
HashMap<Long,Time> listTimes(Collection<Long> taskIds) throws UmbrellaException;
|
||||
HashMap<Long,Time> listTimes(Collection<Long> taskIds, boolean showClosed) throws UmbrellaException;
|
||||
|
||||
HashMap<Long,Time> listUserTimes(long userId);
|
||||
HashMap<Long,Time> listUserTimes(long userId, boolean showClosed);
|
||||
}
|
||||
|
||||
@@ -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.*;
|
||||
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 {
|
||||
}
|
||||
|
||||
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 {
|
||||
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()))
|
||||
|
||||
Reference in New Issue
Block a user