Compare commits

...

1 Commits

  1. 6
      core/src/main/java/de/srsoftware/umbrella/core/api/EntityId.java
  2. 8
      core/src/main/java/de/srsoftware/umbrella/core/api/TagService.java
  3. 25
      core/src/main/java/de/srsoftware/umbrella/core/model/LongId.java
  4. 4
      core/src/main/java/de/srsoftware/umbrella/core/model/Project.java
  5. 4
      core/src/main/java/de/srsoftware/umbrella/core/model/Task.java
  6. 2
      project/src/main/java/de/srsoftware/umbrella/project/ProjectModule.java
  7. 23
      tags/src/main/java/de/srsoftware/umbrella/tags/SqliteDb.java
  8. 11
      tags/src/main/java/de/srsoftware/umbrella/tags/TagDB.java
  9. 16
      tags/src/main/java/de/srsoftware/umbrella/tags/TagModule.java
  10. 4
      task/src/main/java/de/srsoftware/umbrella/task/TaskModule.java

6
core/src/main/java/de/srsoftware/umbrella/core/api/EntityId.java

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.core.api;
public interface EntityId<T> {
public T unwrap();
}

8
core/src/main/java/de/srsoftware/umbrella/core/api/TagService.java

@ -6,11 +6,11 @@ import de.srsoftware.umbrella.core.model.UmbrellaUser; @@ -6,11 +6,11 @@ import de.srsoftware.umbrella.core.model.UmbrellaUser;
import java.util.Collection;
public interface TagService {
void deleteEntity(String task, long taskId);
void deleteEntity(String module, EntityId<?> entityId);
Collection<String> getTags(String module, long entityId, UmbrellaUser user) throws UmbrellaException;
Collection<String> getTags(String module, EntityId<?> entityId, UmbrellaUser user) throws UmbrellaException;
void save(String module, long entityId, Collection<Long> userIds, Collection<String> tags);
void save(String module, EntityId<?> entityId, Collection<Long> userIds, Collection<String> tags);
String save(String module, long entityId, Collection<Long> userIds, String tag);
String save(String module, EntityId<?> entityId, Collection<Long> userIds, String tag);
}

25
core/src/main/java/de/srsoftware/umbrella/core/model/LongId.java

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.core.model;
import de.srsoftware.umbrella.core.api.EntityId;
public record LongId(long id) implements EntityId<Long> {
public static LongId of(long id){
return new LongId(id);
}
public static LongId of (String stringRepresentation){
return new LongId(Long.parseLong(stringRepresentation));
}
@Override
public Long unwrap() {
return id;
}
@Override
public String toString() {
return ""+id;
}
}

4
core/src/main/java/de/srsoftware/umbrella/core/model/Project.java

@ -7,6 +7,7 @@ import static de.srsoftware.umbrella.core.Util.mapMarkdown; @@ -7,6 +7,7 @@ import static de.srsoftware.umbrella.core.Util.mapMarkdown;
import static de.srsoftware.umbrella.core.model.Status.PREDEFINED;
import de.srsoftware.tools.Mappable;
import de.srsoftware.umbrella.core.api.EntityId;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
@ -77,6 +78,9 @@ public class Project implements Mappable { @@ -77,6 +78,9 @@ public class Project implements Mappable {
return dirtyFields.contains(field);
}
public EntityId<Long> entityId(){
return new LongId(id);
}
public Map<Long,Member> members(){
return members;

4
core/src/main/java/de/srsoftware/umbrella/core/model/Task.java

@ -66,6 +66,10 @@ public class Task implements Mappable { @@ -66,6 +66,10 @@ public class Task implements Mappable {
return dueDate;
}
public LongId entityId() {
return LongId.of(id);
}
public Double estimatedTime(){
return estimatedTime;
}

2
project/src/main/java/de/srsoftware/umbrella/project/ProjectModule.java

@ -265,7 +265,7 @@ public class ProjectModule extends BaseHandler implements ProjectService { @@ -265,7 +265,7 @@ public class ProjectModule extends BaseHandler implements ProjectService {
if (json.has(TAGS) && json.get(TAGS) instanceof JSONArray arr){
var tagList = arr.toList().stream().filter(elem -> elem instanceof String).map(String.class::cast).toList();
tags.save(PROJECT,prj.id(),null,tagList);
tags.save(PROJECT,prj.entityId(),null,tagList);
}
return sendContent(ex,prj);

23
tags/src/main/java/de/srsoftware/umbrella/tags/SqliteDb.java

@ -14,6 +14,7 @@ import static java.lang.System.Logger.Level.INFO; @@ -14,6 +14,7 @@ import static java.lang.System.Logger.Level.INFO;
import static java.text.MessageFormat.format;
import de.srsoftware.tools.jdbc.Query;
import de.srsoftware.umbrella.core.api.EntityId;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import java.sql.Connection;
import java.sql.SQLException;
@ -84,13 +85,13 @@ CREATE TABLE IF NOT EXISTS "{0}" ( @@ -84,13 +85,13 @@ CREATE TABLE IF NOT EXISTS "{0}" (
}
@Override
public String delete(long userId, String module, long entityId, String tag) {
public String delete(long userId, String module, EntityId<?> entity, String tag) {
try {
Query.delete().from(TABLE_TAGS)
.where(TAG,equal(tag)).where(MODULE,equal(module)).where(ID,equal(entityId)).where(USER_ID,equal(userId))
.where(TAG,equal(tag)).where(MODULE,equal(module)).where(ID,equal(entity.unwrap())).where(USER_ID,equal(userId))
.execute(db);
Query.delete().from(TABLE_TAGS)
.where(TAG,equal(tag)).where(MODULE,equal(module)).where(ID,equal(entityId)).where(USER_ID,isNull())
.where(TAG,equal(tag)).where(MODULE,equal(module)).where(ID,equal(entity.unwrap())).where(USER_ID,isNull())
.execute(db);
return tag;
} catch (SQLException e){
@ -99,10 +100,10 @@ CREATE TABLE IF NOT EXISTS "{0}" ( @@ -99,10 +100,10 @@ CREATE TABLE IF NOT EXISTS "{0}" (
}
@Override
public void deleteEntity(String module, long entityId) {
public void deleteEntity(String module, EntityId<?> entityId) {
try {
Query.delete().from(TABLE_TAGS)
.where(MODULE,equal(module)).where(ID,equal(entityId))
.where(MODULE,equal(module)).where(ID,equal(entityId.unwrap()))
.execute(db);
} catch (SQLException e){
throw new UmbrellaException("Failed to save tags ({0} {1})",module,entityId);
@ -139,12 +140,12 @@ CREATE TABLE IF NOT EXISTS "{0}" ( @@ -139,12 +140,12 @@ CREATE TABLE IF NOT EXISTS "{0}" (
}
@Override
public Set<String> list(long userId, String module, long entityId) {
public Set<String> list(long userId, String module, EntityId<?> entityId) {
try {
var tags = new HashSet<String>();
var rs = select(TAG).from(TABLE_TAGS).where(MODULE,equal(module)).where(ID,equal(entityId)).where(USER_ID,equal(userId)).exec(db);
var rs = select(TAG).from(TABLE_TAGS).where(MODULE,equal(module)).where(ID,equal(entityId.unwrap())).where(USER_ID,equal(userId)).exec(db);
while (rs.next()) tags.add(rs.getString(1));
rs = select(TAG).from(TABLE_TAGS).where(MODULE,equal(module)).where(ID,equal(entityId)).where(USER_ID,isNull()).exec(db);
rs = select(TAG).from(TABLE_TAGS).where(MODULE,equal(module)).where(ID,equal(entityId.unwrap())).where(USER_ID,isNull()).exec(db);
while (rs.next()) tags.add(rs.getString(1));
rs.close();
return tags;
@ -154,14 +155,14 @@ CREATE TABLE IF NOT EXISTS "{0}" ( @@ -154,14 +155,14 @@ CREATE TABLE IF NOT EXISTS "{0}" (
}
@Override
public void save(Collection<Long> userIds, String module, long entityId, Collection<String> tags) {
public void save(Collection<Long> userIds, String module, EntityId<?> entityId, Collection<String> tags) {
try {
var query = replaceInto(TABLE_TAGS,USER_ID,MODULE,ID,TAG);
for (var tag : tags) {
if (userIds == null) { // tags not assigned to a user are available to all users
query.values(null, module, entityId, tag);
query.values(null, module, entityId.unwrap(), tag);
} else for (var userId : userIds) {
query.values(userId,module,entityId,tag);
query.values(userId,module,entityId.unwrap(),tag);
}
}
query.execute(db).close();

11
tags/src/main/java/de/srsoftware/umbrella/tags/TagDB.java

@ -1,19 +1,20 @@ @@ -1,19 +1,20 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.tags;
import de.srsoftware.umbrella.core.api.EntityId;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface TagDB {
String delete(long userId, String module, long entityId, String tag);
String delete(long userId, String module, EntityId<?> entityId, String tag);
void deleteEntity(String module, long entityId);
void deleteEntity(String module, EntityId<?> entityId);
Map<String, List<Long>> getUses(String tag, long id);
Map<String, List<Long>> getUses(String tag, long userId);
Set<String> list(long userId, String module, long entityId);
Set<String> list(long userId, String module, EntityId<?> entityId);
void save(Collection<Long> userIds, String module, long entityId, Collection<String> tags);
void save(Collection<Long> userIds, String module, EntityId<?> entityId, Collection<String> tags);
}

16
tags/src/main/java/de/srsoftware/umbrella/tags/TagModule.java

@ -15,9 +15,11 @@ import de.srsoftware.configuration.Configuration; @@ -15,9 +15,11 @@ import de.srsoftware.configuration.Configuration;
import de.srsoftware.tools.Path;
import de.srsoftware.tools.SessionToken;
import de.srsoftware.umbrella.core.BaseHandler;
import de.srsoftware.umbrella.core.api.EntityId;
import de.srsoftware.umbrella.core.api.TagService;
import de.srsoftware.umbrella.core.api.UserService;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.LongId;
import de.srsoftware.umbrella.core.model.Token;
import de.srsoftware.umbrella.core.model.UmbrellaUser;
import java.io.IOException;
@ -35,7 +37,7 @@ public class TagModule extends BaseHandler implements TagService { @@ -35,7 +37,7 @@ public class TagModule extends BaseHandler implements TagService {
}
@Override
public void deleteEntity(String module, long entityId) {
public void deleteEntity(String module, EntityId<?> entityId) {
tagDb.deleteEntity(module,entityId);
}
@ -49,7 +51,7 @@ public class TagModule extends BaseHandler implements TagService { @@ -49,7 +51,7 @@ public class TagModule extends BaseHandler implements TagService {
var module = path.pop();
if (module == null) throw unprocessable("Module missing in path.");
var head = path.pop();
long entityId = Long.parseLong(head);
var entityId = LongId.of(head);
var tag = tagDb.delete(user.get().id(),module,entityId,body(ex));
return sendContent(ex, tag);
} catch (NumberFormatException e){
@ -69,7 +71,7 @@ public class TagModule extends BaseHandler implements TagService { @@ -69,7 +71,7 @@ public class TagModule extends BaseHandler implements TagService {
if (module == null) throw unprocessable("Module missing in path.");
var head = path.pop();
if (USES.equals(module)) return getTagUses(ex,head,user.get());
long entityId = Long.parseLong(head);
var entityId = LongId.of(head);
return sendContent(ex, getTags(module,entityId,user.get()));
} catch (NumberFormatException e){
return sendContent(ex,HTTP_UNPROCESSABLE,"Entity id missing in path.");
@ -98,7 +100,7 @@ public class TagModule extends BaseHandler implements TagService { @@ -98,7 +100,7 @@ public class TagModule extends BaseHandler implements TagService {
var module = path.pop();
if (module == null) throw unprocessable("Module missing in path.");
var head = path.pop();
long entityId = Long.parseLong(head);
var entityId = LongId.of(head);
var json = json(ex);
if (!(json.has(TAG) && json.get(TAG) instanceof String tag)) throw missingFieldException(TAG);
List<Long> userList = null;
@ -122,17 +124,17 @@ public class TagModule extends BaseHandler implements TagService { @@ -122,17 +124,17 @@ public class TagModule extends BaseHandler implements TagService {
}
}
public Collection<String> getTags(String module, long entityId, UmbrellaUser user) throws UmbrellaException{
public Collection<String> getTags(String module, EntityId<?> entityId, UmbrellaUser user) throws UmbrellaException{
return tagDb.list(user.id(),module,entityId);
}
@Override
public void save(String module, long entityId, Collection<Long> userIds, Collection<String> tags) {
public void save(String module, EntityId<?> entityId, Collection<Long> userIds, Collection<String> tags) {
tagDb.save(userIds,module,entityId,tags);
}
@Override
public String save(String module, long entityId, Collection<Long> userIds, String tag) {
public String save(String module, EntityId<?> entityId, Collection<Long> userIds, String tag) {
save(module,entityId,userIds,List.of(tag));
return tag;
}

4
task/src/main/java/de/srsoftware/umbrella/task/TaskModule.java

@ -69,7 +69,7 @@ public class TaskModule extends BaseHandler implements TaskService { @@ -69,7 +69,7 @@ public class TaskModule extends BaseHandler implements TaskService {
if (member == null || !member.mayWrite()) throw forbidden("You are not allowed to delete {0}",task.name());
taskDb.delete(task);
notes.deleteEntity(TASK,taskId);
tags.deleteEntity(TASK,taskId);
tags.deleteEntity(TASK,LongId.of(taskId));
return sendContent(ex,Map.of(DELETED,taskId));
}
@ -328,7 +328,7 @@ public class TaskModule extends BaseHandler implements TaskService { @@ -328,7 +328,7 @@ public class TaskModule extends BaseHandler implements TaskService {
}
if (json.has(TAGS) && json.get(TAGS) instanceof JSONArray arr){
var tagList = arr.toList().stream().filter(e -> e instanceof String).map(String.class::cast).toList();
tags.save(TASK,task.id(),null,tagList);
tags.save(TASK,task.entityId(),null,tagList);
}
return sendContent(ex,loadMembers(task));
}

Loading…
Cancel
Save