implemented task legacy code
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -15,10 +15,7 @@ import de.srsoftware.umbrella.core.Util;
|
|||||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||||
import de.srsoftware.umbrella.documents.DocumentApi;
|
import de.srsoftware.umbrella.documents.DocumentApi;
|
||||||
import de.srsoftware.umbrella.items.ItemApi;
|
import de.srsoftware.umbrella.items.ItemApi;
|
||||||
import de.srsoftware.umbrella.legacy.CompanyLegacy;
|
import de.srsoftware.umbrella.legacy.*;
|
||||||
import de.srsoftware.umbrella.legacy.NotesLegacy;
|
|
||||||
import de.srsoftware.umbrella.legacy.ProjectLegacy;
|
|
||||||
import de.srsoftware.umbrella.legacy.UserLegacy;
|
|
||||||
import de.srsoftware.umbrella.markdown.MarkdownApi;
|
import de.srsoftware.umbrella.markdown.MarkdownApi;
|
||||||
import de.srsoftware.umbrella.message.MessageSystem;
|
import de.srsoftware.umbrella.message.MessageSystem;
|
||||||
import de.srsoftware.umbrella.notes.NoteModule;
|
import de.srsoftware.umbrella.notes.NoteModule;
|
||||||
@@ -79,6 +76,7 @@ public class Application {
|
|||||||
new ProjectModule(registry, config).bindPath("/api/project").on(server);
|
new ProjectModule(registry, config).bindPath("/api/project").on(server);
|
||||||
new ProjectLegacy(registry,config).bindPath("/legacy/project").on(server);
|
new ProjectLegacy(registry,config).bindPath("/legacy/project").on(server);
|
||||||
new TaskModule(registry, config).bindPath("/api/task").on(server);
|
new TaskModule(registry, config).bindPath("/api/task").on(server);
|
||||||
|
new TaskLegacy(registry, config).bindPath("/legacy/task").on(server);
|
||||||
new TimeModule(registry, config).bindPath("/api/times").on(server);
|
new TimeModule(registry, config).bindPath("/api/times").on(server);
|
||||||
new WebHandler(registry).bindPath("/").on(server);
|
new WebHandler(registry).bindPath("/").on(server);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
/* © SRSoftware 2025 */
|
/* © SRSoftware 2025 */
|
||||||
package de.srsoftware.umbrella.core;
|
package de.srsoftware.umbrella.core;
|
||||||
|
|
||||||
import static java.text.MessageFormat.format;
|
|
||||||
|
|
||||||
import de.srsoftware.umbrella.core.api.*;
|
import de.srsoftware.umbrella.core.api.*;
|
||||||
|
|
||||||
@@ -20,6 +19,8 @@ public class ModuleRegistry {
|
|||||||
private Translator translator;
|
private Translator translator;
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ModuleRegistry add(Object service) {
|
public ModuleRegistry add(Object service) {
|
||||||
switch (service) {
|
switch (service) {
|
||||||
case BookmarkService bs: bookmarkService = bs; break;
|
case BookmarkService bs: bookmarkService = bs; break;
|
||||||
@@ -35,7 +36,8 @@ public class ModuleRegistry {
|
|||||||
case TimeService ts: timeService = ts; break;
|
case TimeService ts: timeService = ts; break;
|
||||||
case Translator tr: translator = tr; break;
|
case Translator tr: translator = tr; break;
|
||||||
case UserService us: userService = us; break;
|
case UserService us: userService = us; break;
|
||||||
default: throw new RuntimeException(format("Trying to add unknown service ({0}) to {1}",service.getClass().getSimpleName(),getClass().getSimpleName()));
|
case null: break;
|
||||||
|
default: System.getLogger(getClass().getSimpleName()).log(System.Logger.Level.WARNING,"Trying to add untracked class {0} to {1}",service.getClass().getSimpleName(),getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import java.util.List;
|
|||||||
public interface TaskService {
|
public interface TaskService {
|
||||||
HashMap<Long, Task> listCompanyTasks(long companyId) throws UmbrellaException;
|
HashMap<Long, Task> listCompanyTasks(long companyId) throws UmbrellaException;
|
||||||
HashMap<Long, Task> listProjectTasks(long projectId) throws UmbrellaException;
|
HashMap<Long, Task> listProjectTasks(long projectId) throws UmbrellaException;
|
||||||
|
HashMap<Long, Task> load(List<Long> taskIds);
|
||||||
Collection<Task> loadMembers(Collection<Task> tasks);
|
Collection<Task> loadMembers(Collection<Task> tasks);
|
||||||
|
|
||||||
default Task loadMembers(Task task){
|
default Task loadMembers(Task task){
|
||||||
loadMembers(List.of(task));
|
loadMembers(List.of(task));
|
||||||
return task;
|
return task;
|
||||||
|
|||||||
@@ -27,26 +27,12 @@ public class CompanyLegacy extends BaseHandler {
|
|||||||
this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules"));
|
this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doDelete(Path path, HttpExchange ex) throws IOException {
|
|
||||||
return super.doDelete(path, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
||||||
if (path.empty()) return sendRedirect(ex, url(ex).replaceAll("/legacy/","/"));
|
if (path.empty()) return sendRedirect(ex, url(ex).replaceAll("/legacy/","/"));
|
||||||
return super.doGet(path, ex);
|
return super.doGet(path, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doOptions(Path path, HttpExchange ex) throws IOException {
|
|
||||||
return super.doOptions(path, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doPatch(Path path, HttpExchange ex) throws IOException {
|
|
||||||
return super.doPatch(path, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doPost(Path path, HttpExchange ex) throws IOException{
|
public boolean doPost(Path path, HttpExchange ex) throws IOException{
|
||||||
|
|||||||
@@ -31,27 +31,12 @@ public class NotesLegacy extends BaseHandler {
|
|||||||
this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules"));
|
this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doDelete(Path path, HttpExchange ex) throws IOException {
|
|
||||||
return super.doDelete(path, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
||||||
if (path.empty()) return sendRedirect(ex, url(ex).replaceAll("/legacy/","/"));
|
if (path.empty()) return sendRedirect(ex, url(ex).replaceAll("/legacy/","/"));
|
||||||
return super.doGet(path, ex);
|
return super.doGet(path, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doOptions(Path path, HttpExchange ex) throws IOException {
|
|
||||||
return super.doOptions(path, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doPatch(Path path, HttpExchange ex) throws IOException {
|
|
||||||
return super.doPatch(path, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doPost(Path path, HttpExchange ex) throws IOException {
|
public boolean doPost(Path path, HttpExchange ex) throws IOException {
|
||||||
var params = formData(ex);
|
var params = formData(ex);
|
||||||
|
|||||||
@@ -38,16 +38,6 @@ public class ProjectLegacy extends BaseHandler {
|
|||||||
return super.doGet(path, ex);
|
return super.doGet(path, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doOptions(Path path, HttpExchange ex) throws IOException {
|
|
||||||
return super.doOptions(path, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doPatch(Path path, HttpExchange ex) throws IOException {
|
|
||||||
return super.doPatch(path, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doPost(Path path, HttpExchange ex) throws IOException{
|
public boolean doPost(Path path, HttpExchange ex) throws IOException{
|
||||||
var params = formData(ex);
|
var params = formData(ex);
|
||||||
|
|||||||
@@ -2,11 +2,12 @@
|
|||||||
package de.srsoftware.umbrella.legacy;
|
package de.srsoftware.umbrella.legacy;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import static de.srsoftware.tools.Optionals.nullable;
|
import static de.srsoftware.tools.Optionals.nullable;
|
||||||
import static de.srsoftware.umbrella.core.Constants.TOKEN;
|
import static de.srsoftware.umbrella.core.Constants.TOKEN;
|
||||||
import static de.srsoftware.umbrella.core.Constants.USERS;
|
|
||||||
import static de.srsoftware.umbrella.core.Paths.JSON;
|
import static de.srsoftware.umbrella.core.Paths.JSON;
|
||||||
import static de.srsoftware.umbrella.core.Util.mapValues;
|
import static de.srsoftware.umbrella.core.Util.mapValues;
|
||||||
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.unprocessable;
|
||||||
|
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
import de.srsoftware.configuration.Configuration;
|
import de.srsoftware.configuration.Configuration;
|
||||||
@@ -28,11 +29,6 @@ public class TaskLegacy extends BaseHandler {
|
|||||||
this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules"));
|
this.config = config.subset("umbrella.modules").orElseThrow(() -> new RuntimeException("Missing configuration: umbrella.modules"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doDelete(Path path, HttpExchange ex) throws IOException {
|
|
||||||
return super.doDelete(path, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
public boolean doGet(Path path, HttpExchange ex) throws IOException {
|
||||||
if (path.empty()) return sendRedirect(ex, url(ex).replaceAll("/legacy/","/"));
|
if (path.empty()) return sendRedirect(ex, url(ex).replaceAll("/legacy/","/"));
|
||||||
@@ -40,17 +36,7 @@ public class TaskLegacy extends BaseHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean doOptions(Path path, HttpExchange ex) throws IOException {
|
public boolean doPost(Path path, HttpExchange ex) throws IOException {
|
||||||
return super.doOptions(path, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doPatch(Path path, HttpExchange ex) throws IOException {
|
|
||||||
return super.doPatch(path, ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean doPost(Path path, HttpExchange ex) throws IOException{
|
|
||||||
var params = formData(ex);
|
var params = formData(ex);
|
||||||
|
|
||||||
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
Optional<Token> token = SessionToken.from(ex).map(Token::of);
|
||||||
@@ -59,14 +45,17 @@ public class TaskLegacy extends BaseHandler {
|
|||||||
if (user.isEmpty()) return unauthorized(ex);
|
if (user.isEmpty()) return unauthorized(ex);
|
||||||
|
|
||||||
return switch (path.pop()){
|
return switch (path.pop()){
|
||||||
case JSON -> postProjectJson(ex,params,user.get());
|
case JSON -> postJson(user.get(),params,ex);
|
||||||
default -> super.doPost(path, ex);
|
case null, default -> super.doPost(path,ex);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean postProjectJson(HttpExchange ex, Map<String, Object> params, UmbrellaUser user) throws IOException {
|
private boolean postJson(UmbrellaUser umbrellaUser, Map<String, Object> params, HttpExchange ex) throws IOException {
|
||||||
var includeUsers = "1".equals(params.get(USERS));
|
LOG.log(System.Logger.Level.DEBUG,params);
|
||||||
var projects = projectService().listUserProjects(user.id(), false);
|
if (params.get("ids") instanceof Map<?,?> taskIdMap){
|
||||||
return sendContent(ex, mapValues(projects));
|
var taskIds = taskIdMap.values().stream().map(Object::toString).map(Long::parseLong).toList();
|
||||||
|
return sendContent(ex,mapValues(taskService().load(taskIds)));
|
||||||
|
}
|
||||||
|
throw unprocessable("Invalid request");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import de.srsoftware.umbrella.core.model.Token;
|
|||||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@@ -214,6 +215,16 @@ public class TaskModule extends BaseHandler implements TaskService {
|
|||||||
return taskDb.listTasks(List.of(projectId));
|
return taskDb.listTasks(List.of(projectId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap<Long, Task> load(List<Long> taskIds) {
|
||||||
|
try {
|
||||||
|
var map = taskIds.stream().map(taskDb::load).collect(Collectors.toMap(Task::id, t -> t));
|
||||||
|
return new HashMap<>(map);
|
||||||
|
} catch (Exception e){
|
||||||
|
throw new UmbrellaException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Task> loadMembers(Collection<Task> taskList) {
|
public Collection<Task> loadMembers(Collection<Task> taskList) {
|
||||||
var userMap = new HashMap<Long,UmbrellaUser>();
|
var userMap = new HashMap<Long,UmbrellaUser>();
|
||||||
|
|||||||
Reference in New Issue
Block a user