implemented restoring of wiki tags from tag and bookmark database
This commit is contained in:
@@ -23,6 +23,7 @@ import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.json.JSONArray;
|
||||
|
||||
@@ -85,6 +86,11 @@ public class BookmarkApi extends BaseHandler implements BookmarkService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> find(String key) {
|
||||
return db.findUrls(key);
|
||||
}
|
||||
|
||||
private boolean getUserBookmarks(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
var param = queryParam(ex);
|
||||
long offset = switch (param.get(OFFSET)){
|
||||
@@ -128,7 +134,7 @@ public class BookmarkApi extends BaseHandler implements BookmarkService {
|
||||
if (!(json.has(KEY) && json.get(KEY) instanceof String key)) throw missingFieldException(KEY);
|
||||
var keys = Arrays.asList(key.split(" "));
|
||||
var fulltext = json.has(FULLTEXT) && json.get(FULLTEXT) instanceof Boolean val && val;
|
||||
var bookmarks = db.find(user.id(),keys);
|
||||
var bookmarks = db.findUrls(user.id(),keys);
|
||||
return sendContent(ex,mapValues(bookmarks));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public interface BookmarkDb {
|
||||
Map<Long, Bookmark> find(long userId, Collection<String> key);
|
||||
Map<Long, Bookmark> findUrls(long userId, Collection<String> key);
|
||||
|
||||
Map<Long, String> findUrls(String key);
|
||||
|
||||
Map<Long, Bookmark> list(long userId, Long offset, Long limit);
|
||||
|
||||
|
||||
@@ -70,7 +70,20 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, Bookmark> find(long userId, Collection<String> keys) {
|
||||
public Map<Long, String> findUrls(String key) {
|
||||
try {
|
||||
var map = new HashMap<Long,String>();
|
||||
var rs = select(ALL).from(TABLE_URLS).where(URL, like(key)).exec(db);
|
||||
while (rs.next()) map.put(rs.getLong(ID),rs.getString(URL));
|
||||
rs.close();;
|
||||
return map;
|
||||
} catch (SQLException e) {
|
||||
throw new UmbrellaException("Failed to load bookmark list");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, Bookmark> findUrls(long userId, Collection<String> keys) {
|
||||
try {
|
||||
var map = new HashMap<Long,Bookmark>();
|
||||
var query = select(ALL).from(TABLE_URL_COMMENTS).leftJoin(URL_ID,TABLE_URLS,ID)
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
/* © SRSoftware 2025 */
|
||||
package de.srsoftware.umbrella.core.api;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface BookmarkService {
|
||||
Map<Long, String> find(String key);
|
||||
}
|
||||
|
||||
@@ -13,4 +13,6 @@ public interface TagService {
|
||||
void save(String module, long entityId, Collection<Long> userIds, Collection<String> tags);
|
||||
|
||||
String save(String module, long entityId, Collection<Long> userIds, String tag);
|
||||
|
||||
void updateId(String module, Object oldId, Object newId);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import static de.srsoftware.umbrella.bookmarks.Constants.*;
|
||||
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;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
|
||||
import static de.srsoftware.umbrella.tags.Constants.*;
|
||||
import static java.lang.System.Logger.Level.*;
|
||||
import static java.text.MessageFormat.format;
|
||||
@@ -279,4 +280,14 @@ CREATE TABLE IF NOT EXISTS {0} (
|
||||
throw new UmbrellaException("Failed to save tags: {0}",String.join(", ",tags));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateId(String module, Object oldId, Object newId) {
|
||||
try {
|
||||
update(TABLE_TAGS).set(ENTITY_ID).where(MODULE,equal(module)).where(ENTITY_ID,equal(oldId)).prepare(db).apply(newId).close();
|
||||
LOG.log(DEBUG,"Updated tag @ {0}.{1} → {0}.{2}",module,oldId,newId);
|
||||
} catch (SQLException e) {
|
||||
throw databaseException("Failed to update {0}.{1} → {0}.{2}",module,oldId,newId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,7 @@ public interface TagDB {
|
||||
Set<String> list(long userId, String module, long entityId);
|
||||
|
||||
void save(Collection<Long> userIds, String module, long entityId, Collection<String> tags);
|
||||
|
||||
void updateId(String module, Object oldId, Object newId);
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.*;
|
||||
import org.json.JSONArray;
|
||||
|
||||
public class TagModule extends BaseHandler implements TagService {
|
||||
private final SqliteDb tagDb;
|
||||
private final TagDB tagDb;
|
||||
|
||||
public TagModule(Configuration config) {
|
||||
super();
|
||||
@@ -131,4 +131,9 @@ public class TagModule extends BaseHandler implements TagService {
|
||||
save(module,entityId,userIds,List.of(tag));
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateId(String module, Object oldId, Object newId) {
|
||||
tagDb.updateId(module,oldId,newId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ 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.ModuleRegistry.noteService;
|
||||
import static de.srsoftware.umbrella.core.ModuleRegistry.*;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
|
||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.notFound;
|
||||
import static de.srsoftware.umbrella.core.model.Permission.EDIT;
|
||||
@@ -22,6 +22,7 @@ import de.srsoftware.umbrella.core.model.WikiPage;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SqliteDb extends BaseDb implements WikiDb {
|
||||
private static final System.Logger LOG = System.getLogger("WikiDb");
|
||||
@@ -241,11 +242,34 @@ public class SqliteDb extends BaseDb implements WikiDb {
|
||||
|
||||
}
|
||||
var notes = noteService();
|
||||
var tags = tagService();
|
||||
for (var entry : pageMap.entrySet()){
|
||||
var oldId = entry.getKey();
|
||||
var newId = entry.getValue();
|
||||
notes.updateId("wiki",oldId,newId);
|
||||
}
|
||||
|
||||
var urls = bookmarkService().find("%/wiki/%/view");
|
||||
var pattern = Pattern.compile("/wiki/([^/]+)/view");
|
||||
|
||||
var users = userService().list(null,null,null);
|
||||
for (var entry : urls.entrySet()){
|
||||
var urlId = entry.getKey();
|
||||
var url = entry.getValue();
|
||||
var match = pattern.matcher(url);
|
||||
if (match.find()){
|
||||
var title = match.group(1);
|
||||
var pageId = pageMap.get(title);
|
||||
if (pageId == null) continue;
|
||||
for (var user : users.values()){
|
||||
var tagList = tags.getTags("bookmark",urlId,user);
|
||||
if (!tagList.isEmpty()){
|
||||
LOG.log(DEBUG,"{0} has tags for page {1}: {2}",user.name(),title,tagList);
|
||||
tags.save("wiki",pageId,List.of(user.id()),tagList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int wikiPermissionCode(Permission perm){
|
||||
|
||||
Reference in New Issue
Block a user