started implementing listTimes – way to complicated
This commit is contained in:
@@ -19,13 +19,17 @@ public class Constants {
|
||||
public static final String DEFAULT_THEME = "winter";
|
||||
public static final String DESCRIPTION = "description";
|
||||
public static final String DOMAIN = "domain";
|
||||
public static final String DUE_DATE = "due_date";
|
||||
public static final String EMAIL = "email";
|
||||
public static final String END_TIME = "end_time";
|
||||
|
||||
public static final String ERROR_FAILED_CREATE_TABLE = "Failed to create \"{0}\" table!";
|
||||
public static final String ERROR_INVALID_FIELD = "Expected {0} to be {1}!";
|
||||
public static final String ERROR_MISSING_CONFIG = "Config is missing value for {0}!";
|
||||
public static final String ERROR_MISSING_FIELD = "Json is missing {0} field!";
|
||||
public static final String ERROR_READ_TABLE = "Failed to read {0} from {1} table";
|
||||
public static final String EST_TIME = "est_time";
|
||||
public static final String ESTIMATED_TIME = "estimated_time";
|
||||
|
||||
public static final String EXPIRATION = "expiration";
|
||||
public static final String GET = "GET";
|
||||
@@ -37,11 +41,14 @@ public class Constants {
|
||||
public static final String MESSAGES = "messages";
|
||||
public static final String NAME = "name";
|
||||
public static final String MIME = "mime";
|
||||
public static final String NO_INDEX = "no_index";
|
||||
public static final String NUMBER = "number";
|
||||
public static final String OPTIONAL = "optional";
|
||||
public static final String PARENT_TASK_ID = "parent_task_id";
|
||||
public static final String PASS = "pass";
|
||||
public static final String PASSWORD = "password";
|
||||
public static final String POST = "POST";
|
||||
public static final String PROJECT_ID = "project_id";
|
||||
|
||||
public static final String RECEIVERS = "receivers";
|
||||
public static final String REDIRECT = "redirect";
|
||||
@@ -50,6 +57,8 @@ public class Constants {
|
||||
public static final String SETTINGS = "settings";
|
||||
public static final String SHOW_CLOSED = "show_closed";
|
||||
public static final String SOURCE = "source";
|
||||
public static final String START_DATE = "start_date";
|
||||
public static final String START_TIME = "start_time";
|
||||
public static final String STATE = "state";
|
||||
public static final String STATUS = "status";
|
||||
public static final String STATUS_CODE = "code";
|
||||
|
||||
@@ -15,6 +15,9 @@ import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import org.json.JSONObject;
|
||||
@@ -140,4 +143,8 @@ public class Util {
|
||||
LOG.log(INFO,"Using plantuml @ {0}",file.getAbsolutePath());
|
||||
plantumlJar = file;
|
||||
}
|
||||
|
||||
public static LocalDateTime dateTimeOf(long epocSecs){
|
||||
return LocalDateTime.ofInstant(Instant.ofEpochSecond(epocSecs), ZoneId.systemDefault());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.api;
|
||||
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.Task;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface TaskService {
|
||||
CompanyService companyService();
|
||||
Collection<Task> listCompanyTasks(long companyId) throws UmbrellaException;
|
||||
ProjectService projectService();
|
||||
|
||||
UserService userService();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.api;
|
||||
|
||||
public interface TimeService {
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import static de.srsoftware.tools.Optionals.nullIfEmpty;
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.markdown;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public record Task(long id, long projectId, Long parentTaskId, String name, String description, int status, Double estimatedTime, LocalDate start, LocalDate dueDate,boolean showClosed, boolean noIndex) implements Mappable {
|
||||
public static Task of(ResultSet rs) throws SQLException {
|
||||
var estTime = rs.getDouble(EST_TIME);
|
||||
var parentTaskId = rs.getLong(PARENT_TASK_ID);
|
||||
var startDate = nullIfEmpty(rs.getString(START_DATE));
|
||||
var dueDate = nullIfEmpty(rs.getString(DUE_DATE));
|
||||
return new Task(
|
||||
rs.getLong(ID),
|
||||
rs.getLong(PROJECT_ID),
|
||||
parentTaskId == 0d ? null : parentTaskId,
|
||||
rs.getString(NAME),
|
||||
rs.getString(DESCRIPTION),
|
||||
rs.getInt(STATUS),
|
||||
estTime == 0d ? null : estTime,
|
||||
startDate != null ? LocalDate.parse(startDate) : null,
|
||||
dueDate != null ? LocalDate.parse(dueDate) : null,
|
||||
rs.getBoolean(SHOW_CLOSED),
|
||||
rs.getBoolean(NO_INDEX)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
var map = new HashMap<String,Object>();
|
||||
map.put(ID, id);
|
||||
map.put(PROJECT_ID, projectId);
|
||||
map.put(PARENT_TASK_ID, parentTaskId);
|
||||
map.put(NAME, name);
|
||||
map.put(DESCRIPTION, Map.of(SOURCE,description,RENDERED,markdown(description)));
|
||||
map.put(STATUS, status);
|
||||
map.put(ESTIMATED_TIME, estimatedTime);
|
||||
map.put(START_DATE,start);
|
||||
map.put(DUE_DATE,dueDate);
|
||||
map.put(SHOW_CLOSED,showClosed);
|
||||
map.put(NO_INDEX,noIndex);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.model;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
|
||||
import static de.srsoftware.umbrella.core.Constants.*;
|
||||
import static de.srsoftware.umbrella.core.Util.dateTimeOf;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public record Time(long id, long userId, String subject, String description, LocalDateTime start, LocalDateTime end, State state, Set<Long> taskIds) implements Mappable {
|
||||
public enum State{
|
||||
Started(10),
|
||||
Open(20),
|
||||
Pending(40),
|
||||
Complete(60),
|
||||
Cancelled(100);
|
||||
|
||||
private int code;
|
||||
|
||||
State(int code){
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int code(){
|
||||
return code;
|
||||
}
|
||||
|
||||
public static State of(int code){
|
||||
return switch (code){
|
||||
case 10 -> Started;
|
||||
case 20 -> Open;
|
||||
case 40 -> Pending;
|
||||
case 60 -> Complete;
|
||||
case 100 -> Cancelled;
|
||||
default -> throw new IllegalArgumentException();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
var map = new HashMap<String,Object>();
|
||||
map.put(ID,id);
|
||||
map.put(USER_ID,userId);
|
||||
map.put(SUBJECT,subject);
|
||||
map.put(DESCRIPTION,description);
|
||||
map.put(START_TIME,start);
|
||||
map.put(END_TIME,end);
|
||||
map.put(STATE,Map.of(STATUS_CODE,state.code,NAME,state.name()));
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Time of(ResultSet rs) throws SQLException {
|
||||
var startTimestamp = rs.getLong(START_TIME);
|
||||
var start = startTimestamp == 0 ? null : dateTimeOf(startTimestamp);
|
||||
var endTimestamp = rs.getLong(END_TIME);
|
||||
var end = endTimestamp == 0 ? null : dateTimeOf(endTimestamp);
|
||||
|
||||
return new Time(
|
||||
rs.getLong(ID),
|
||||
rs.getLong(USER_ID),
|
||||
rs.getString(SUBJECT),
|
||||
rs.getString(DESCRIPTION),
|
||||
start,
|
||||
end,
|
||||
State.of(rs.getInt(STATE)),
|
||||
new HashSet<>()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user