Browse Source

improved tag handling

module/notes
Stephan Richter 3 months ago
parent
commit
57b68015c3
  1. 2
      core/src/main/java/de/srsoftware/umbrella/core/api/TagService.java
  2. 9
      frontend/src/routes/project/View.svelte
  3. 1
      frontend/src/routes/tags/TagList.svelte
  4. 1
      project/src/main/java/de/srsoftware/umbrella/project/ProjectModule.java
  5. 10
      tags/src/main/java/de/srsoftware/umbrella/tags/SqliteDb.java
  6. 19
      tags/src/main/java/de/srsoftware/umbrella/tags/TagModule.java

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

@ -3,9 +3,7 @@ package de.srsoftware.umbrella.core.api; @@ -3,9 +3,7 @@ package de.srsoftware.umbrella.core.api;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.UmbrellaUser;
import java.util.Collection;
import java.util.Set;
public interface TagService {
void deleteEntity(String task, long taskId);

9
frontend/src/routes/project/View.svelte

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
import MemberEditor from '../../Components/MemberEditor.svelte';
import StateSelector from '../../Components/StateSelector.svelte';
import Tags from '../tags/TagList.svelte';
import TaskList from '../task/TaskList.svelte';
let router = useTinyRouter();
@ -190,6 +191,12 @@ @@ -190,6 +191,12 @@
<td class="estimated_time">{estimated_time.sum} h</td>
</tr>
{/if}
<tr>
<th>{t('tags')}</th>
<td>
<Tags module="project" {id} user_list={null} />
</td>
</tr>
<tr>
<th>
{t('tasks')}
@ -203,4 +210,4 @@ @@ -203,4 +210,4 @@
</tr>
</tbody>
</table>
{/if}
{/if}

1
frontend/src/routes/tags/TagList.svelte

@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
tag = await resp.text();
tags.push(tag);
tags = tags.sort();
error = null;
} else {
error = await resp.text();
}

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

@ -26,7 +26,6 @@ import de.srsoftware.umbrella.core.exceptions.UmbrellaException; @@ -26,7 +26,6 @@ import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.*;
import java.io.IOException;
import java.util.*;
import org.json.JSONArray;
import org.json.JSONObject;

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

@ -2,8 +2,8 @@ @@ -2,8 +2,8 @@
package de.srsoftware.umbrella.tags;
import static de.srsoftware.tools.jdbc.Condition.equal;
import static de.srsoftware.tools.jdbc.Condition.isNull;
import static de.srsoftware.tools.jdbc.Query.*;
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Constants.ERROR_FAILED_CREATE_TABLE;
import static de.srsoftware.umbrella.core.Constants.USER_ID;
@ -14,7 +14,6 @@ import static java.text.MessageFormat.format; @@ -14,7 +14,6 @@ import static java.text.MessageFormat.format;
import de.srsoftware.tools.jdbc.Query;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
@ -72,7 +71,7 @@ CREATE TABLE IF NOT EXISTS "{0}" ( @@ -72,7 +71,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
{1} VARCHAR(255) NOT NULL,
{2} VARCHAR(20) NOT NULL,
{3} INTEGER NOT NULL,
{4} INTEGER NOT NULL,
{4} INTEGER,
PRIMARY KEY ({1}, {2}, {3}, {4})
)""";
try {
@ -91,6 +90,9 @@ CREATE TABLE IF NOT EXISTS "{0}" ( @@ -91,6 +90,9 @@ CREATE TABLE IF NOT EXISTS "{0}" (
Query.delete().from(TABLE_TAGS)
.where(TAG,equal(tag)).where(MODULE,equal(module)).where(ID,equal(entityId)).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())
.execute(db);
return tag;
} catch (SQLException e){
throw new UmbrellaException("Failed to delete tag {0}",tag);
@ -119,6 +121,8 @@ CREATE TABLE IF NOT EXISTS "{0}" ( @@ -119,6 +121,8 @@ CREATE TABLE IF NOT EXISTS "{0}" (
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);
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);
while (rs.next()) tags.add(rs.getString(1));
rs.close();
return tags;
} catch (SQLException e) {

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

@ -20,10 +20,9 @@ import de.srsoftware.umbrella.core.api.UserService; @@ -20,10 +20,9 @@ import de.srsoftware.umbrella.core.api.UserService;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.Token;
import de.srsoftware.umbrella.core.model.UmbrellaUser;
import org.json.JSONArray;
import java.io.IOException;
import java.util.*;
import org.json.JSONArray;
public class TagModule extends BaseHandler implements TagService {
private final SqliteDb tagDb;
@ -98,10 +97,18 @@ public class TagModule extends BaseHandler implements TagService { @@ -98,10 +97,18 @@ public class TagModule extends BaseHandler implements TagService {
long entityId = Long.parseLong(head);
var json = json(ex);
if (!(json.has(TAG) && json.get(TAG) instanceof String tag)) throw missingFieldException(TAG);
List<Long> userList = json.has(USER_LIST) && json.get(USER_LIST) instanceof JSONArray arr ?
arr.toList().stream().filter(elem -> elem instanceof Number).map(elem -> (Number) elem).map(Number::longValue).toList()
: List.of(user.get().id());
if (userList.isEmpty()) throw missingFieldException(USER_LIST);
List<Long> userList = null;
if (!json.has(USER_LIST)) throw missingFieldException(USER_LIST);
var ul = json.isNull(USER_LIST) ? null : json.get(USER_LIST);
if (ul instanceof JSONArray arr){
userList = arr.toList().stream()
.filter(elem -> elem instanceof Number)
.map(Number.class::cast)
.map(Number::longValue)
.toList();
} else if (ul != null) throw unprocessable("User list must be NULL or array of user ids!");
// userList == null → tag is shared with all users
if (userList != null && userList.isEmpty()) throw unprocessable("User list must not be an empty list!");
tag = save(module, entityId, userList, tag);
return sendContent(ex, tag);
} catch (NumberFormatException e) {

Loading…
Cancel
Save