added more automatic tags, implemented updating of links and attachments on event update
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -19,14 +19,19 @@ public class AutoImporter implements Runnable, ClassListener {
|
|||||||
private static final System.Logger LOG = System.getLogger(AutoImporter.class.getSimpleName());
|
private static final System.Logger LOG = System.getLogger(AutoImporter.class.getSimpleName());
|
||||||
private static final Map<String, String> DESCRIPTION_TAGS = Map.<String, String>ofEntries(
|
private static final Map<String, String> DESCRIPTION_TAGS = Map.<String, String>ofEntries(
|
||||||
entry("50s","50er"),
|
entry("50s","50er"),
|
||||||
|
entry("50’s","50er"),
|
||||||
entry("50er","50er"),
|
entry("50er","50er"),
|
||||||
entry("60s","60er"),
|
entry("60s","60er"),
|
||||||
|
entry("60’s","60er"),
|
||||||
entry("60er","60er"),
|
entry("60er","60er"),
|
||||||
entry("70s","70er"),
|
entry("70s","70er"),
|
||||||
|
entry("70’s","70er"),
|
||||||
entry("70er","70er"),
|
entry("70er","70er"),
|
||||||
entry("80s","80er"),
|
entry("80s","80er"),
|
||||||
|
entry("80’s","80er"),
|
||||||
entry("80er","80er"),
|
entry("80er","80er"),
|
||||||
entry("90s","90er"),
|
entry("90s","90er"),
|
||||||
|
entry("90’s","90er"),
|
||||||
entry("90er","90er"),
|
entry("90er","90er"),
|
||||||
entry("ac dc","Metal"),
|
entry("ac dc","Metal"),
|
||||||
entry("alternative rock","AlternativeRock"),
|
entry("alternative rock","AlternativeRock"),
|
||||||
@@ -91,6 +96,7 @@ public class AutoImporter implements Runnable, ClassListener {
|
|||||||
entry("humor","Comedy"),
|
entry("humor","Comedy"),
|
||||||
entry("humpa","Humppa"),
|
entry("humpa","Humppa"),
|
||||||
entry("humppa","Humppa"),
|
entry("humppa","Humppa"),
|
||||||
|
entry("indie","indie"),
|
||||||
entry("industrial","Industrial"),
|
entry("industrial","Industrial"),
|
||||||
entry("industrial metal","IndustrialMetal"),
|
entry("industrial metal","IndustrialMetal"),
|
||||||
entry("jam session","JamSession"),
|
entry("jam session","JamSession"),
|
||||||
@@ -281,7 +287,7 @@ public class AutoImporter implements Runnable, ClassListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void classAdded(Class<?> aClass) {
|
public void classAdded(Class<?> aClass) {
|
||||||
if (Importer.class.isAssignableFrom(aClass)) try {
|
if (Importer.class.isAssignableFrom(aClass) && aClass.getSimpleName().contains("Ebu")) try {
|
||||||
var instance = aClass.getDeclaredConstructor().newInstance();
|
var instance = aClass.getDeclaredConstructor().newInstance();
|
||||||
importers.add((Importer) instance);
|
importers.add((Importer) instance);
|
||||||
lastImport = null;
|
lastImport = null;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* © SRSoftware 2024 */
|
/* © SRSoftware 2024 */
|
||||||
package de.srsoftware.cal.db;
|
package de.srsoftware.cal.db;
|
||||||
|
|
||||||
|
import static de.srsoftware.cal.Util.extractCoords;
|
||||||
import static de.srsoftware.cal.db.Fields.*;
|
import static de.srsoftware.cal.db.Fields.*;
|
||||||
import static de.srsoftware.cal.db.Fields.ALL;
|
import static de.srsoftware.cal.db.Fields.ALL;
|
||||||
import static de.srsoftware.tools.Error.error;
|
import static de.srsoftware.tools.Error.error;
|
||||||
@@ -74,7 +75,18 @@ public class MariaDB implements Database {
|
|||||||
keys.close();
|
keys.close();
|
||||||
if (saved == null) return error("Insert query did not return appointment id!");
|
if (saved == null) return error("Insert query did not return appointment id!");
|
||||||
|
|
||||||
{ // link to attachments
|
addAttachments(saved);
|
||||||
|
addLinks(saved);
|
||||||
|
addTags(saved);
|
||||||
|
|
||||||
|
return Payload.of(saved);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOG.log(ERROR, "Failed to store appointment", e);
|
||||||
|
return error(e, "Failed to store appointment");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addAttachments(Appointment saved) throws SQLException { // link to attachments
|
||||||
var attachments = saved.attachments();
|
var attachments = saved.attachments();
|
||||||
InsertQuery assignQuery = null;
|
InsertQuery assignQuery = null;
|
||||||
for (var attachment : attachments) {
|
for (var attachment : attachments) {
|
||||||
@@ -85,7 +97,7 @@ public class MariaDB implements Database {
|
|||||||
if (assignQuery != null) assignQuery.ignoreDuplicates().execute(connection);
|
if (assignQuery != null) assignQuery.ignoreDuplicates().execute(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // link to links
|
private void addLinks(Appointment saved) throws SQLException { // link to links
|
||||||
var links = saved.links();
|
var links = saved.links();
|
||||||
InsertQuery assignQuery = null;
|
InsertQuery assignQuery = null;
|
||||||
for (var link : links) {
|
for (var link : links) {
|
||||||
@@ -96,7 +108,7 @@ public class MariaDB implements Database {
|
|||||||
if (assignQuery != null) assignQuery.ignoreDuplicates().execute(connection);
|
if (assignQuery != null) assignQuery.ignoreDuplicates().execute(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
private void addTags(Appointment saved) throws SQLException {
|
||||||
var tags = saved.tags();
|
var tags = saved.tags();
|
||||||
InsertQuery assignQuery = null;
|
InsertQuery assignQuery = null;
|
||||||
for (var tag : tags) {
|
for (var tag : tags) {
|
||||||
@@ -106,12 +118,6 @@ public class MariaDB implements Database {
|
|||||||
}
|
}
|
||||||
if (assignQuery != null) assignQuery.ignoreDuplicates().execute(connection);
|
if (assignQuery != null) assignQuery.ignoreDuplicates().execute(connection);
|
||||||
}
|
}
|
||||||
return Payload.of(saved);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
LOG.log(ERROR, "Failed to store appointment", e);
|
|
||||||
return error(e, "Failed to store appointment");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Optional<Long> getOrCreateUrl(URL url) throws SQLException {
|
private Optional<Long> getOrCreateUrl(URL url) throws SQLException {
|
||||||
var rs = select(UID).from(URLS).where(URL, equal(url.toString())).exec(connection);
|
var rs = select(UID).from(URLS).where(URL, equal(url.toString())).exec(connection);
|
||||||
@@ -158,8 +164,7 @@ public class MariaDB implements Database {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<List<Appointment>> list(LocalDateTime from, LocalDateTime till, Integer count, Integer offset) {
|
public Result<List<Appointment>> list(LocalDateTime from, LocalDateTime till, Integer count, Integer offset) {
|
||||||
var query = Query //
|
var query = select("appointments.*", "GROUP_CONCAT(keyword) AS tags")
|
||||||
.select("appointments.*", "GROUP_CONCAT(keyword) AS tags")
|
|
||||||
.from(APPOINTMENTS)
|
.from(APPOINTMENTS)
|
||||||
.leftJoin(AID, "appointment_tags", AID)
|
.leftJoin(AID, "appointment_tags", AID)
|
||||||
.leftJoin("tid", "tags", "tid")
|
.leftJoin("tid", "tags", "tid")
|
||||||
@@ -279,7 +284,7 @@ public class MariaDB implements Database {
|
|||||||
var appointment = new BaseAppointment(id, title, description, start, end, location);
|
var appointment = new BaseAppointment(id, title, description, start, end, location);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Util.extractCoords(results.getString(COORDS)).optional().ifPresent(appointment::coords);
|
extractCoords(results.getString(COORDS)).optional().ifPresent(appointment::coords);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOG.log(WARNING, "Failed to read coordinates from database!");
|
LOG.log(WARNING, "Failed to read coordinates from database!");
|
||||||
}
|
}
|
||||||
@@ -301,10 +306,10 @@ public class MariaDB implements Database {
|
|||||||
@Override
|
@Override
|
||||||
public Result<Long> removeAppointment(long id) {
|
public Result<Long> removeAppointment(long id) {
|
||||||
try {
|
try {
|
||||||
Query.delete().from(APPOINTMENTS).where(AID, equal(id)).execute(connection);
|
delete().from(APPOINTMENTS).where(AID, equal(id)).execute(connection);
|
||||||
Query.delete().from(APPOINTMENT_TAGS).where(AID, equal(id)).execute(connection);
|
delete().from(APPOINTMENT_TAGS).where(AID, equal(id)).execute(connection);
|
||||||
Query.delete().from(APPOINTMENT_ATTACHMENTS).where(AID, equal(id)).execute(connection);
|
delete().from(APPOINTMENT_ATTACHMENTS).where(AID, equal(id)).execute(connection);
|
||||||
Query.delete().from(APPOINTMENT_URLS).where(AID, equal(id)).execute(connection);
|
delete().from(APPOINTMENT_URLS).where(AID, equal(id)).execute(connection);
|
||||||
return Payload.of(id);
|
return Payload.of(id);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
return SqlError.of(e, "Failed to delete event %s", id);
|
return SqlError.of(e, "Failed to delete event %s", id);
|
||||||
@@ -318,15 +323,20 @@ public class MariaDB implements Database {
|
|||||||
var coords = event.coords().map(Object::toString).orElse(null);
|
var coords = event.coords().map(Object::toString).orElse(null);
|
||||||
var location = event.location().orElse(null);
|
var location = event.location().orElse(null);
|
||||||
try {
|
try {
|
||||||
Query
|
long id = event.id();
|
||||||
.update(APPOINTMENTS) //
|
Query.update(APPOINTMENTS)
|
||||||
.set(TITLE, DESCRIPTION, START, END, LOCATION, COORDS)
|
.set(TITLE, DESCRIPTION, START, END, LOCATION, COORDS)
|
||||||
.where(AID, equal(event.id()))
|
.where(AID, equal(id))
|
||||||
.prepare(connection)
|
.prepare(connection)
|
||||||
.apply(event.title(), event.description(), start, end, location, coords);
|
.apply(event.title(), event.description(), start, end, location, coords);
|
||||||
|
|
||||||
// TODO: update links, attachments, tags
|
delete().from(APPOINTMENT_TAGS).where(AID, equal(id)).execute(connection);
|
||||||
LOG.log(WARNING,"updating of tags, links and attachments not implemented!");
|
addTags(event);
|
||||||
|
delete().from(APPOINTMENT_ATTACHMENTS).where(AID, equal(id)).execute(connection);
|
||||||
|
addAttachments(event);
|
||||||
|
delete().from(APPOINTMENT_URLS).where(AID, equal(id)).execute(connection);
|
||||||
|
addLinks(event);
|
||||||
|
|
||||||
return Payload.of(event);
|
return Payload.of(event);
|
||||||
} catch (SQLException sqle) {
|
} catch (SQLException sqle) {
|
||||||
return error(sqle, "Failed to update database entry");
|
return error(sqle, "Failed to update database entry");
|
||||||
|
|||||||
Reference in New Issue
Block a user