replaced appointment.hash by appointment.slug, incooperated slug column into appointments table
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
description = "OpenCloudCal : API"
|
description = "OpenCloudCal : API"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("de.srsoftware:tools.util:1.1.1")
|
implementation("de.srsoftware:tools.util:1.2.1")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,12 +34,6 @@ public interface Appointment {
|
|||||||
*/
|
*/
|
||||||
Optional<LocalDateTime> end();
|
Optional<LocalDateTime> end();
|
||||||
|
|
||||||
/**
|
|
||||||
* create a unique identifier based on the event content
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
String hash();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ID of the appointment – unique within this system
|
* ID of the appointment – unique within this system
|
||||||
* @return the appointment`s id
|
* @return the appointment`s id
|
||||||
@@ -53,6 +47,12 @@ public interface Appointment {
|
|||||||
*/
|
*/
|
||||||
String location();
|
String location();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create a unique identifier based on the event content
|
||||||
|
* @return the slug
|
||||||
|
*/
|
||||||
|
String slug();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The date and time, when the appointment starts
|
* The date and time, when the appointment starts
|
||||||
* @return the start time as LocalDateTime
|
* @return the start time as LocalDateTime
|
||||||
|
|||||||
13
de.srsoftware.cal.app/README.md
Normal file
13
de.srsoftware.cal.app/README.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
Notiz an mich selbst:
|
||||||
|
|
||||||
|
DB-Export auf Server:
|
||||||
|
|
||||||
|
`mysqldump -u root -p --result-file occ.sql --default-character-set=latin1 opencloudcal`
|
||||||
|
|
||||||
|
Patchen:
|
||||||
|
|
||||||
|
`sed -i 's/latin1/utf8mb4/g' occ.sql`
|
||||||
|
|
||||||
|
Import im lokalen Docker:
|
||||||
|
|
||||||
|
`mysql -u root -p opencloudcal < /var/lib/mysql/occ.sql`
|
||||||
@@ -7,5 +7,5 @@ dependencies {
|
|||||||
|
|
||||||
implementation("de.srsoftware:configuration.api:1.0.0")
|
implementation("de.srsoftware:configuration.api:1.0.0")
|
||||||
implementation("de.srsoftware:configuration.json:1.0.0")
|
implementation("de.srsoftware:configuration.json:1.0.0")
|
||||||
implementation("de.srsoftware:tools.util:1.1.1")
|
implementation("de.srsoftware:tools.util:1.2.1")
|
||||||
implementation("com.mysql:mysql-connector-j:9.1.0")}
|
implementation("com.mysql:mysql-connector-j:9.1.0")}
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ dependencies {
|
|||||||
implementation(project(":de.srsoftware.cal.api"))
|
implementation(project(":de.srsoftware.cal.api"))
|
||||||
|
|
||||||
implementation("de.srsoftware:tools.optionals:1.0.0")
|
implementation("de.srsoftware:tools.optionals:1.0.0")
|
||||||
implementation("de.srsoftware:tools.util:1.2.0")
|
implementation("de.srsoftware:tools.util:1.2.1")
|
||||||
implementation("de.srsoftware:tools.web:1.3.4")
|
implementation("de.srsoftware:tools.web:1.3.4")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ public class BaseAppointment implements Appointment {
|
|||||||
* @param end set the end date
|
* @param end set the end date
|
||||||
* @param location set the location
|
* @param location set the location
|
||||||
*/
|
*/
|
||||||
public BaseAppointment(long id, String title, String description, LocalDateTime start, LocalDateTime end, String location, String hash) {
|
public BaseAppointment(long id, String title, String description, LocalDateTime start, LocalDateTime end, String location, String slug) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
this.hash = hash;
|
this.hash = slug;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.start = start;
|
this.start = start;
|
||||||
@@ -134,7 +134,7 @@ public class BaseAppointment implements Appointment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String hash() {
|
public String slug() {
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ dependencies {
|
|||||||
|
|
||||||
implementation("de.srsoftware:tools.jdbc:1.0.0")
|
implementation("de.srsoftware:tools.jdbc:1.0.0")
|
||||||
implementation("de.srsoftware:tools.optionals:1.0.0")
|
implementation("de.srsoftware:tools.optionals:1.0.0")
|
||||||
implementation("de.srsoftware:tools.util:1.2.0")
|
implementation("de.srsoftware:tools.util:1.2.1")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package de.srsoftware.cal.db;
|
|||||||
|
|
||||||
import static de.srsoftware.tools.Optionals.allEmpty;
|
import static de.srsoftware.tools.Optionals.allEmpty;
|
||||||
import static de.srsoftware.tools.Optionals.nullable;
|
import static de.srsoftware.tools.Optionals.nullable;
|
||||||
|
import static de.srsoftware.tools.Strings.camelCase;
|
||||||
|
|
||||||
import de.srsoftware.cal.BaseAppointment;
|
import de.srsoftware.cal.BaseAppointment;
|
||||||
import de.srsoftware.cal.api.Appointment;
|
import de.srsoftware.cal.api.Appointment;
|
||||||
@@ -13,16 +14,17 @@ import java.sql.DriverManager;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class MariaDB implements Database {
|
public class MariaDB implements Database {
|
||||||
private static final String SELECT_APPOINTMENTS = "SELECT * FROM appointments";
|
private static final String SELECT_APPOINTMENTS = "SELECT * FROM appointments";
|
||||||
private static final String SELECT_APPOINTMENTS_WITH_HASHES = SELECT_APPOINTMENTS + " a LEFT JOIN appointment_hashes h ON a.aid = h.aid";
|
private static final String SELECT_VERSION = "SELECT value FROM config WHERE keyname = 'dbversion'";
|
||||||
private static final String SELECT_VERSION = "SELECT value FROM config WHERE keyname = 'dbversion'";
|
private static final String ADD_SLUG = "ALTER TABLE appointments ADD slug VARCHAR(255) UNIQUE";
|
||||||
private static final String CREATE_HASHES = "CREATE TABLE appointment_hashes (aid INT NOT NULL, hash VARCHAR(255) NOT NULL, UNIQUE(aid), UNIQUE(hash))";
|
private static final String INSERT_HASH = "INSERT INTO appointment_hashes (aid, hash) values (?, ?) ON DUPLICATE KEY UPDATE hash=hash;";
|
||||||
private static final String INSERT_HASH = "INSERT INTO appointment_hashes (aid, hash) values (?, ?) ON DUPLICATE KEY UPDATE hash=hash;";
|
private static final String UPDATE_DB_VERSION = "UPDATE config SET value = ? WHERE keyname = 'dbversion'";
|
||||||
private static final String UPDATE_DB_VERSION = "UPDATE config SET value = ? WHERE keyname = 'dbversion'";
|
private static final String INSERT_SLUG = "UPDATE IGNORE appointments SET slug = ? WHERE aid = ?";
|
||||||
private static Connection connection;
|
private static Connection connection;
|
||||||
|
|
||||||
private MariaDB(Connection conn) throws SQLException {
|
private MariaDB(Connection conn) throws SQLException {
|
||||||
@@ -46,34 +48,33 @@ public class MariaDB implements Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void update1() throws SQLException {
|
private void update1() throws SQLException {
|
||||||
var list = new ArrayList<Appointment>();
|
var list = new ArrayList<Appointment>();
|
||||||
var results = Query.of(SELECT_APPOINTMENTS).execute(connection);
|
|
||||||
while (results.next()) {
|
|
||||||
var id = results.getInt("aid");
|
|
||||||
var title = results.getString("title");
|
|
||||||
var description = results.getString("description");
|
|
||||||
if (allEmpty(title, description)) continue;
|
|
||||||
var stamp = results.getTimestamp("start");
|
|
||||||
var start = nullable(stamp).map(Timestamp::toLocalDateTime).orElse(null);
|
|
||||||
var end = nullable(results.getTimestamp("end")).map(Timestamp::toLocalDateTime).orElse(null);
|
|
||||||
var location = results.getString("location");
|
|
||||||
Calc //
|
|
||||||
.hash(start + "@" + location)
|
|
||||||
.map(hash -> new BaseAppointment(id, title, description, start, end, location, hash))
|
|
||||||
.ifPresent(list::add);
|
|
||||||
}
|
|
||||||
results.close();
|
|
||||||
connection.setAutoCommit(false);
|
connection.setAutoCommit(false);
|
||||||
|
|
||||||
Query.of(CREATE_HASHES).statement(connection).execute();
|
Query.of(ADD_SLUG).statement(connection).execute();
|
||||||
for (var appointment : list) {
|
var slugMap = new HashMap<Long, String>();
|
||||||
var stmt = Query.of(INSERT_HASH).statement(connection);
|
var rs = Query.of(SELECT_APPOINTMENTS).execute(connection);
|
||||||
stmt.setLong(1, appointment.id());
|
while (rs.next()) {
|
||||||
stmt.setString(2, appointment.hash());
|
var id = rs.getLong("aid");
|
||||||
|
var location = nullable(rs.getString("location"));
|
||||||
|
if (location.isEmpty()) continue;
|
||||||
|
var title = rs.getString("title");
|
||||||
|
var descr = rs.getString("description");
|
||||||
|
if (allEmpty(title, descr)) continue;
|
||||||
|
var start = nullable(rs.getTimestamp("start"));
|
||||||
|
if (start.isEmpty()) continue;
|
||||||
|
var slug = "%s@%s".formatted(start.get().toLocalDateTime(), camelCase(location.get()));
|
||||||
|
if (slug.length() > 250) slug = slug.substring(0, 250);
|
||||||
|
slugMap.put(id, slug);
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
var stmt = Query.of(INSERT_SLUG).statement(connection);
|
||||||
|
for (var entry : slugMap.entrySet()) {
|
||||||
|
stmt.setString(1, entry.getValue());
|
||||||
|
stmt.setLong(2, entry.getKey());
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
}
|
}
|
||||||
connection.commit();
|
stmt = Query.of(UPDATE_DB_VERSION).statement(connection);
|
||||||
var stmt = Query.of(UPDATE_DB_VERSION).statement(connection);
|
|
||||||
stmt.setLong(1, 2);
|
stmt.setLong(1, 2);
|
||||||
stmt.execute();
|
stmt.execute();
|
||||||
connection.setAutoCommit(true);
|
connection.setAutoCommit(true);
|
||||||
@@ -97,7 +98,7 @@ public class MariaDB implements Database {
|
|||||||
@Override
|
@Override
|
||||||
public List<Appointment> list(Integer count, Integer offset) throws SQLException {
|
public List<Appointment> list(Integer count, Integer offset) throws SQLException {
|
||||||
var list = new ArrayList<Appointment>();
|
var list = new ArrayList<Appointment>();
|
||||||
var results = Query.of(SELECT_APPOINTMENTS_WITH_HASHES).execute(connection);
|
var results = Query.of(SELECT_APPOINTMENTS).execute(connection);
|
||||||
while (results.next()) {
|
while (results.next()) {
|
||||||
var id = results.getInt("aid");
|
var id = results.getInt("aid");
|
||||||
var title = results.getString("title");
|
var title = results.getString("title");
|
||||||
@@ -106,9 +107,9 @@ public class MariaDB implements Database {
|
|||||||
var start = results.getTimestamp("start").toLocalDateTime();
|
var start = results.getTimestamp("start").toLocalDateTime();
|
||||||
var end = nullable(results.getTimestamp("end")).map(Timestamp::toLocalDateTime).orElse(null);
|
var end = nullable(results.getTimestamp("end")).map(Timestamp::toLocalDateTime).orElse(null);
|
||||||
var location = results.getString("location");
|
var location = results.getString("location");
|
||||||
var hash = results.getString("hash");
|
var slug = results.getString("slug");
|
||||||
if (hash == null) hash = Calc.hash(start + "@" + location).orElse(null);
|
if (slug == null) slug = Calc.hash(start + "@" + location).orElse(null);
|
||||||
list.add(new BaseAppointment(id, title, description, start, end, location, hash));
|
list.add(new BaseAppointment(id, title, description, start, end, location, slug));
|
||||||
}
|
}
|
||||||
results.close();
|
results.close();
|
||||||
return list;
|
return list;
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ dependencies {
|
|||||||
implementation(project(":de.srsoftware.cal.api"))
|
implementation(project(":de.srsoftware.cal.api"))
|
||||||
implementation(project(":de.srsoftware.cal.base"))
|
implementation(project(":de.srsoftware.cal.base"))
|
||||||
implementation("de.srsoftware:tools.optionals:1.0.0")
|
implementation("de.srsoftware:tools.optionals:1.0.0")
|
||||||
implementation("de.srsoftware:tools.util:1.2.0")
|
implementation("de.srsoftware:tools.util:1.2.1")
|
||||||
implementation("de.srsoftware:tools.web:1.3.4")
|
implementation("de.srsoftware:tools.web:1.3.4")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user