|
|
|
@ -6,20 +6,24 @@ import static de.srsoftware.umbrella.core.Util.*; |
|
|
|
import static java.time.ZoneOffset.UTC; |
|
|
|
import static java.time.ZoneOffset.UTC; |
|
|
|
|
|
|
|
|
|
|
|
import de.srsoftware.tools.Mappable; |
|
|
|
import de.srsoftware.tools.Mappable; |
|
|
|
|
|
|
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.time.Duration; |
|
|
|
import java.time.Duration; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
import org.json.JSONObject; |
|
|
|
|
|
|
|
|
|
|
|
public class Time implements Mappable{ |
|
|
|
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 final HashSet<Long> taskIds = new HashSet<>(); |
|
|
|
private LocalDateTime end; |
|
|
|
private LocalDateTime end; |
|
|
|
private final LocalDateTime start; |
|
|
|
private LocalDateTime start; |
|
|
|
private long id; |
|
|
|
private long id; |
|
|
|
private final long userId; |
|
|
|
private final long userId; |
|
|
|
private final String description, subject; |
|
|
|
private String description; |
|
|
|
|
|
|
|
private String subject; |
|
|
|
private State state; |
|
|
|
private State state; |
|
|
|
|
|
|
|
|
|
|
|
public enum State{ |
|
|
|
public enum State{ |
|
|
|
@ -49,9 +53,8 @@ public class Time implements Mappable{ |
|
|
|
default -> throw new IllegalArgumentException(); |
|
|
|
default -> throw new IllegalArgumentException(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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, LocalDateTime start, LocalDateTime end, State state, Collection<Long> taskIds){ |
|
|
|
this.id=id; |
|
|
|
this.id=id; |
|
|
|
this.userId = userId; |
|
|
|
this.userId = userId; |
|
|
|
@ -62,6 +65,7 @@ public class Time implements Mappable{ |
|
|
|
this.state = state; |
|
|
|
this.state = state; |
|
|
|
if (taskIds != null) this.taskIds.addAll(taskIds); |
|
|
|
if (taskIds != null) this.taskIds.addAll(taskIds); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String description(){ |
|
|
|
public String description(){ |
|
|
|
return description; |
|
|
|
return description; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -104,6 +108,15 @@ public class Time implements Mappable{ |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Time patch(JSONObject json) { |
|
|
|
|
|
|
|
if (json.has(SUBJECT) && json.get(SUBJECT) instanceof String s) subject = s; |
|
|
|
|
|
|
|
if (json.has(DESCRIPTION) && json.get(DESCRIPTION) instanceof String d) description = d; |
|
|
|
|
|
|
|
if (json.has(START_TIME) && json.get(START_TIME) instanceof String st) start = LocalDateTime.parse(st, DT); |
|
|
|
|
|
|
|
if (json.has(END_TIME) && json.get(END_TIME) instanceof String e) end = LocalDateTime.parse(e,DT); |
|
|
|
|
|
|
|
if (end != null && !start.isBefore(end)) throw UmbrellaException.invalidFieldException(END_TIME,"after start_time"); |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setId(long newValue) { |
|
|
|
public void setId(long newValue) { |
|
|
|
id = newValue; |
|
|
|
id = newValue; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -117,7 +130,7 @@ public class Time implements Mappable{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public State state(){ |
|
|
|
public State state(){ |
|
|
|
return state; |
|
|
|
return state; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Time stop(LocalDateTime endTime) { |
|
|
|
public Time stop(LocalDateTime endTime) { |
|
|
|
|