refactored timetracking to only use client-supplied times
This commit is contained in:
@@ -3,7 +3,6 @@ package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.*;
|
||||
import static java.time.ZoneOffset.UTC;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
@@ -18,8 +17,8 @@ import org.json.JSONObject;
|
||||
public class Time implements Mappable{
|
||||
private static final DateTimeFormatter DT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||
private final HashSet<Long> taskIds = new HashSet<>();
|
||||
private LocalDateTime end;
|
||||
private LocalDateTime start;
|
||||
private long start;
|
||||
private Long end;
|
||||
private long id;
|
||||
private final long userId;
|
||||
private String description;
|
||||
@@ -33,7 +32,7 @@ public class Time implements Mappable{
|
||||
Complete(60),
|
||||
Cancelled(100);
|
||||
|
||||
private int code;
|
||||
private final int code;
|
||||
|
||||
State(int code){
|
||||
this.code = code;
|
||||
@@ -55,7 +54,7 @@ public class Time implements Mappable{
|
||||
}
|
||||
}
|
||||
|
||||
public Time(long id, long userId, String subject, String description, LocalDateTime start, LocalDateTime end, State state, Collection<Long> taskIds){
|
||||
public Time(long id, long userId, String subject, String description, long start, Long end, State state, Collection<Long> taskIds){
|
||||
this.id=id;
|
||||
this.userId = userId;
|
||||
this.subject = subject;
|
||||
@@ -70,14 +69,10 @@ public class Time implements Mappable{
|
||||
return description;
|
||||
}
|
||||
|
||||
public LocalDateTime end(){
|
||||
public Long end(){
|
||||
return end;
|
||||
}
|
||||
|
||||
public Long endSecond(){
|
||||
return end == null ? null : end.toEpochSecond(UTC);
|
||||
}
|
||||
|
||||
public long id(){
|
||||
return id;
|
||||
}
|
||||
@@ -90,11 +85,10 @@ public class Time implements Mappable{
|
||||
}
|
||||
|
||||
public static Time of(ResultSet rs) throws SQLException {
|
||||
var startTimestamp = rs.getLong(START_TIME);
|
||||
var start = startTimestamp == 0 ? null : LocalDateTime.ofEpochSecond(startTimestamp,0,UTC);
|
||||
var endTimestamp = rs.getLong(END_TIME);
|
||||
var start = rs.getLong(START_TIME);
|
||||
Long end = rs.getLong(END_TIME);
|
||||
|
||||
var end = endTimestamp == 0 ? null : LocalDateTime.ofEpochSecond(endTimestamp,0,UTC);
|
||||
if (end == 0) end = null;
|
||||
|
||||
return new Time(
|
||||
rs.getLong(ID),
|
||||
@@ -120,9 +114,9 @@ public class Time implements Mappable{
|
||||
if (o instanceof JSONObject nested && nested.get(SOURCE) instanceof String src) o = src;
|
||||
if (o instanceof String d) description = d;
|
||||
}
|
||||
if (json.has(START_TIME) && json.get(START_TIME) instanceof String st) start = parse(st);
|
||||
if (json.has(END_TIME) && json.get(END_TIME) instanceof String e) end = parse(e);
|
||||
if (end != null && end.isBefore(start)) throw UmbrellaException.invalidFieldException(END_TIME,"after start_time");
|
||||
if (json.has(START_TIME) && json.get(START_TIME) instanceof Number st) start = st.longValue();
|
||||
if (json.has(END_TIME) && json.get(END_TIME) instanceof Number e) end = e.longValue();
|
||||
if (end != null && end < start) throw UmbrellaException.invalidFieldException(END_TIME,"after start_time");
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -130,21 +124,18 @@ public class Time implements Mappable{
|
||||
id = newValue;
|
||||
}
|
||||
|
||||
public LocalDateTime start(){
|
||||
public long start(){
|
||||
return start;
|
||||
}
|
||||
|
||||
public Long startSecond(){
|
||||
return start == null ? null : start.toEpochSecond(UTC);
|
||||
}
|
||||
|
||||
|
||||
public State state(){
|
||||
return state;
|
||||
}
|
||||
|
||||
public Time stop(LocalDateTime endTime) {
|
||||
end = endTime.withSecond(0).withNano(0);
|
||||
start = start.withSecond(0).withNano(0);
|
||||
public Time stop(long endTime) {
|
||||
end = endTime;
|
||||
state = State.Open;
|
||||
return this;
|
||||
}
|
||||
@@ -164,10 +155,10 @@ public class Time implements Mappable{
|
||||
map.put(USER_ID,userId);
|
||||
map.put(SUBJECT,subject);
|
||||
map.put(DESCRIPTION,mapMarkdown(description));
|
||||
map.put(START_TIME,start.toString().replace("T"," "));
|
||||
map.put(END_TIME,end == null ? null : end.toString().replace("T"," "));
|
||||
map.put(START_TIME,start);
|
||||
map.put(END_TIME,end);
|
||||
map.put(STATE,Map.of(STATUS_CODE,state.code,NAME,state.name()));
|
||||
map.put(DURATION,end == null ? null : Duration.between(start,end).toMinutes()/60d);
|
||||
map.put(DURATION,end == null ? null : (end - start)/3600d);
|
||||
map.put(TASK_IDS,taskIds);
|
||||
return map;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user