started first part of transition: importing bookmarks from tags.db to bookmarks.db
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
package de.srsoftware.umbrella.bookmarks;
|
package de.srsoftware.umbrella.bookmarks;
|
||||||
|
|
||||||
import de.srsoftware.umbrella.core.model.Bookmark;
|
import de.srsoftware.umbrella.core.model.Bookmark;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -10,5 +12,9 @@ public interface BookmarkDb {
|
|||||||
|
|
||||||
Bookmark load(long id, long userId);
|
Bookmark load(long id, long userId);
|
||||||
|
|
||||||
Bookmark save(String url, String comment, Collection<Long> userIds);
|
Bookmark save(String url, String comment, Collection<Long> userIds, LocalDateTime datetime);
|
||||||
|
|
||||||
|
default Bookmark save(String url, String comment, Collection<Long> userIds){
|
||||||
|
return save(url,comment,userIds,LocalDateTime.now());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,9 +99,8 @@ CREATE TABLE IF NOT EXISTS {0} (
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bookmark save(String url, String comment, Collection<Long> userIds) {
|
public Bookmark save(String url, String comment, Collection<Long> userIds, LocalDateTime timestamp) {
|
||||||
try {
|
try {
|
||||||
var timestamp = LocalDateTime.now();
|
|
||||||
var rs = select(ID).from(TABLE_URLS).where(URL, equal(url)).exec(db);
|
var rs = select(ID).from(TABLE_URLS).where(URL, equal(url)).exec(db);
|
||||||
var id = 0L;
|
var id = 0L;
|
||||||
if (rs.next()) id = rs.getLong(ID);
|
if (rs.next()) id = rs.getLong(ID);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
description = "Umbrella : Tags"
|
description = "Umbrella : Tags"
|
||||||
|
|
||||||
dependencies{
|
dependencies{
|
||||||
|
implementation(project(":bookmark"))
|
||||||
implementation(project(":core"))
|
implementation(project(":core"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ package de.srsoftware.umbrella.tags;
|
|||||||
public class Constants {
|
public class Constants {
|
||||||
private Constants(){}
|
private Constants(){}
|
||||||
|
|
||||||
|
public static final String COMMENT_HASH = "comment_hash";
|
||||||
public static final String CONFIG_DATABASE = "umbrella.modules.tags.database";
|
public static final String CONFIG_DATABASE = "umbrella.modules.tags.database";
|
||||||
|
public static final String TABLE_COMMENTS = "comments";
|
||||||
public static final String TABLE_TAGS = "tags";
|
public static final String TABLE_TAGS = "tags";
|
||||||
public static final String TAG = "tag";
|
public static final String TAG = "tag";
|
||||||
|
public static final String URL_HASH = "url_hash";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,48 +1,81 @@
|
|||||||
/* © SRSoftware 2025 */
|
/* © SRSoftware 2025 */
|
||||||
package de.srsoftware.umbrella.tags;
|
package de.srsoftware.umbrella.tags;
|
||||||
|
|
||||||
|
import static de.srsoftware.tools.Optionals.is0;
|
||||||
|
import static de.srsoftware.tools.Optionals.isSet;
|
||||||
import static de.srsoftware.tools.jdbc.Condition.equal;
|
import static de.srsoftware.tools.jdbc.Condition.equal;
|
||||||
import static de.srsoftware.tools.jdbc.Condition.isNull;
|
import static de.srsoftware.tools.jdbc.Condition.isNull;
|
||||||
import static de.srsoftware.tools.jdbc.Query.*;
|
import static de.srsoftware.tools.jdbc.Query.*;
|
||||||
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL;
|
||||||
|
import static de.srsoftware.umbrella.bookmarks.Constants.TABLE_URLS;
|
||||||
|
import static de.srsoftware.umbrella.bookmarks.Constants.TABLE_URL_COMMENTS;
|
||||||
import static de.srsoftware.umbrella.core.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.ERROR_FAILED_CREATE_TABLE;
|
||||||
import static de.srsoftware.umbrella.core.Constants.USER_ID;
|
import static de.srsoftware.umbrella.core.Constants.USER_ID;
|
||||||
import static de.srsoftware.umbrella.tags.Constants.*;
|
import static de.srsoftware.umbrella.tags.Constants.*;
|
||||||
import static java.lang.System.Logger.Level.ERROR;
|
import static java.lang.System.Logger.Level.*;
|
||||||
import static java.lang.System.Logger.Level.INFO;
|
|
||||||
import static java.text.MessageFormat.format;
|
import static java.text.MessageFormat.format;
|
||||||
|
import static java.time.ZoneOffset.UTC;
|
||||||
|
|
||||||
import de.srsoftware.tools.jdbc.Query;
|
import de.srsoftware.tools.jdbc.Query;
|
||||||
|
import de.srsoftware.umbrella.bookmarks.BookmarkDb;
|
||||||
import de.srsoftware.umbrella.core.BaseDb;
|
import de.srsoftware.umbrella.core.BaseDb;
|
||||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class SqliteDb extends BaseDb implements TagDB{
|
public class SqliteDb extends BaseDb implements TagDB{
|
||||||
private static final int INITIAL_DB_VERSION = 1;
|
|
||||||
private static final System.Logger LOG = System.getLogger("TagDB");
|
private static final System.Logger LOG = System.getLogger("TagDB");
|
||||||
|
private final BookmarkDb bookmarks;
|
||||||
|
|
||||||
public SqliteDb(Connection conn) {
|
|
||||||
super(conn);
|
public SqliteDb(Connection tagDb, Connection bmDb) {
|
||||||
|
super(tagDb);
|
||||||
|
bookmarks = new de.srsoftware.umbrella.bookmarks.SqliteDb(bmDb);
|
||||||
|
createTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int createTables() {
|
protected int createTables() {
|
||||||
var version = createSettingsTable();
|
var version = createSettingsTable();
|
||||||
|
if (bookmarks == null) return version;
|
||||||
switch (version){
|
switch (version){
|
||||||
case 0:
|
case 0:
|
||||||
/* createLegacyUrlsTable();
|
createLegacyUrlsTable();
|
||||||
createLegacyCommentsTable();
|
createLegacyCommentsTable();
|
||||||
createLegacyUrlCommentsTable();
|
createLegacyUrlCommentsTable();
|
||||||
createLegacyTagsTable();
|
createLegacyTagsTable();
|
||||||
case 1:
|
case 1:
|
||||||
splitContentToBookmarks();*/
|
splitContentToBookmarks();
|
||||||
createTagTables();
|
createTagTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
return setCurrentVersion(1);
|
return setCurrentVersion(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void splitContentToBookmarks() {
|
||||||
|
try {
|
||||||
|
// IMPORT BOOKMARKS
|
||||||
|
var commentedURLS = select(ALL).from(TABLE_URLS).leftJoin(HASH,TABLE_URL_COMMENTS,URL_HASH).leftJoin(COMMENT_HASH,TABLE_COMMENTS,HASH).exec(db);
|
||||||
|
while (commentedURLS.next()){
|
||||||
|
var userId = commentedURLS.getLong(USER_ID);
|
||||||
|
if (userId == 0) continue;
|
||||||
|
var url = commentedURLS.getString(URL);
|
||||||
|
var timestamp = commentedURLS.getLong(TIMESTAMP);
|
||||||
|
var comment = commentedURLS.getString(COMMENT);
|
||||||
|
if (!isSet(comment)) comment = "";
|
||||||
|
var dt = is0(timestamp) ? LocalDateTime.now() : LocalDateTime.ofEpochSecond(timestamp,0,UTC);
|
||||||
|
bookmarks.save(url,comment,List.of(userId),dt.withNano(0));
|
||||||
|
}
|
||||||
|
commentedURLS.close();
|
||||||
|
|
||||||
|
// UPDATE TAGS
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createLegacyCommentsTable() {
|
private void createLegacyCommentsTable() {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import com.sun.net.httpserver.HttpExchange;
|
|||||||
import de.srsoftware.configuration.Configuration;
|
import de.srsoftware.configuration.Configuration;
|
||||||
import de.srsoftware.tools.Path;
|
import de.srsoftware.tools.Path;
|
||||||
import de.srsoftware.tools.SessionToken;
|
import de.srsoftware.tools.SessionToken;
|
||||||
|
import de.srsoftware.umbrella.bookmarks.BookmarkDb;
|
||||||
import de.srsoftware.umbrella.core.BaseHandler;
|
import de.srsoftware.umbrella.core.BaseHandler;
|
||||||
import de.srsoftware.umbrella.core.api.TagService;
|
import de.srsoftware.umbrella.core.api.TagService;
|
||||||
import de.srsoftware.umbrella.core.api.UserService;
|
import de.srsoftware.umbrella.core.api.UserService;
|
||||||
@@ -29,8 +30,9 @@ public class TagModule extends BaseHandler implements TagService {
|
|||||||
private final UserService users;
|
private final UserService users;
|
||||||
|
|
||||||
public TagModule(Configuration config, UserService userService) {
|
public TagModule(Configuration config, UserService userService) {
|
||||||
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
|
var tagDbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
|
||||||
tagDb = new SqliteDb(connect(dbFile));
|
var bmDbFile = config.get(de.srsoftware.umbrella.bookmarks.Constants.CONFIG_DATABASE).orElseThrow(() -> missingFieldException(de.srsoftware.umbrella.bookmarks.Constants.CONFIG_DATABASE));
|
||||||
|
tagDb = new SqliteDb(connect(tagDbFile),connect(bmDbFile));
|
||||||
users = userService;
|
users = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -254,4 +254,8 @@ fieldset.bookmark legend.date{
|
|||||||
right: 0;
|
right: 0;
|
||||||
top: -17px;
|
top: -17px;
|
||||||
background: black;
|
background: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
legend{
|
||||||
|
max-width: 75vw;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user