implemented loading of bookmarks and bookmark list

This commit is contained in:
2025-08-03 13:07:11 +02:00
parent 61b5a6ffbb
commit eac9eaeb9f
10 changed files with 201 additions and 32 deletions

View File

@@ -17,6 +17,7 @@ public class Constants {
public static final String BODY = "body";
public static final String CODE = "code";
public static final String COMMENT = "comment";
public static final String COMPANY = "company";
public static final String COMPANY_ID = "company_id";
public static final String CONTENT_TYPE = "Content-Type";
@@ -57,6 +58,8 @@ public class Constants {
public static final String GET = "GET";
public static final String HASH = "hash";
public static final String ID = "id";
public static final String JSONARRAY = "json array";
@@ -112,6 +115,7 @@ public class Constants {
public static final String TITLE = "title";
public static final String TIMESTAMP = "timestamp";
public static final String TOKEN = "token";
public static final String TYPE = "type";
public static final String UMBRELLA = "Umbrella";
public static final String URL = "url";

View File

@@ -13,6 +13,7 @@ import com.xrbpowered.jparsedown.JParsedown;
import de.srsoftware.tools.Mappable;
import de.srsoftware.tools.Query;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.Hash;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URI;
@@ -32,11 +33,12 @@ public class Util {
private static final Pattern UML_PATTERN = Pattern.compile("@start(\\w+)(.*)@end(\\1)",Pattern.DOTALL);
private static File plantumlJar = null;
private static final JParsedown MARKDOWN = new JParsedown();
private static final MessageDigest SHA1;
public static final String SHA1 = "SHA-1";
private static final MessageDigest SHA1_DIGEST;
static {
try {
SHA1 = MessageDigest.getInstance("SHA-1");
SHA1_DIGEST = MessageDigest.getInstance(SHA1);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
@@ -54,8 +56,8 @@ public class Util {
};
}
public static Map<Long,Map<String,Object>> mapValues(Map<Long, ? extends Mappable> map){
var result = new HashMap<Long,Map<String,Object>>();
public static <KEY> Map<KEY,Map<String,Object>> mapValues(Map<KEY, ? extends Mappable> map){
var result = new HashMap<KEY,Map<String,Object>>();
for (var entry : map.entrySet()) result.put(entry.getKey(),entry.getValue().toMap());
return result;
}
@@ -167,9 +169,9 @@ public class Util {
}
}
public static String sha1(String plain){
var bytes = SHA1.digest(plain.getBytes(UTF_8));
return hex(bytes);
public static Hash sha1(String plain){
var bytes = SHA1_DIGEST.digest(plain.getBytes(UTF_8));
return new Hash(hex(bytes),SHA1);
}
public static void setPlantUmlJar(File file){

View File

@@ -0,0 +1,37 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.core.model;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Util.SHA1;
import static de.srsoftware.umbrella.core.Util.sha1;
import static java.time.ZoneOffset.UTC;
import de.srsoftware.tools.Mappable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
public record Bookmark(String url, Hash hash, String comment, LocalDateTime timestamp, Collection<String> tags) implements Mappable {
public static Bookmark of(ResultSet rs) throws SQLException {
return new Bookmark(rs.getString(URL),new Hash(rs.getString(HASH),SHA1),rs.getString(COMMENT),LocalDateTime.ofEpochSecond(rs.getLong(TIMESTAMP),0, UTC),new ArrayList<>());
}
public static Bookmark of(String url, String comment, LocalDateTime timestamp){
return new Bookmark(url,sha1(url),comment,timestamp,new ArrayList<>());
}
@Override
public Map<String, Object> toMap() {
return Map.of(
URL, url,
COMMENT, comment,
HASH, Map.of(VALUE,hash.value(),TYPE,hash.type()),
TAGS, tags,
TIMESTAMP, timestamp.withNano(0)
);
}
}

View File

@@ -0,0 +1,22 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.core.model;
import java.util.Objects;
public record Hash(String value, String type){
@Override
public boolean equals(Object o) {
if (!(o instanceof Hash(String v, String t))) return false;
return Objects.equals(type, t) && Objects.equals(value, v);
}
@Override
public int hashCode() {
return Objects.hash(value, type);
}
@Override
public String toString() {
return value;
}
}