added database code: attachments now also added to appointment lists
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -79,7 +79,7 @@ public class Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void configureLogging(JsonConfig jsonConfig) {
|
private static void configureLogging(JsonConfig jsonConfig) {
|
||||||
var rootLevel = jsonConfig.get("opencloudcal.logging.rootlevel", "INFO");
|
var rootLevel = jsonConfig.get("opencloudcal.logging.rootLevel", "INFO");
|
||||||
ColorLogger.setRootLogLevel(mapLogLevel(rootLevel));
|
ColorLogger.setRootLogLevel(mapLogLevel(rootLevel));
|
||||||
|
|
||||||
var loggers = jsonConfig.get("opencloudcal.logging.loggers").orElse(null);
|
var loggers = jsonConfig.get("opencloudcal.logging.loggers").orElse(null);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ 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.jdbc:1.1.4")
|
implementation("de.srsoftware:tools.jdbc:1.1.5")
|
||||||
implementation("de.srsoftware:tools.optionals:1.0.0")
|
implementation("de.srsoftware:tools.optionals:1.0.0")
|
||||||
implementation("de.srsoftware:tools.util:1.3.0")
|
implementation("de.srsoftware:tools.util:1.3.0")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,9 +74,9 @@ 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!");
|
||||||
|
|
||||||
addAttachments(saved);
|
writeAttachments(saved);
|
||||||
addLinks(saved);
|
writeLinks(saved);
|
||||||
addTags(saved);
|
writeTags(saved);
|
||||||
|
|
||||||
return Payload.of(saved);
|
return Payload.of(saved);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -85,7 +85,7 @@ public class MariaDB implements Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addAttachments(Appointment saved) throws SQLException { // link to attachments
|
private void writeAttachments(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) {
|
||||||
@@ -96,7 +96,7 @@ public class MariaDB implements Database {
|
|||||||
if (assignQuery != null) assignQuery.ignoreDuplicates().execute(connection);
|
if (assignQuery != null) assignQuery.ignoreDuplicates().execute(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLinks(Appointment saved) throws SQLException { // link to links
|
private void writeLinks(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) {
|
||||||
@@ -107,7 +107,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 {
|
private void writeTags(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) {
|
||||||
@@ -178,12 +178,41 @@ public class MariaDB implements Database {
|
|||||||
var list = new ArrayList<Appointment>();
|
var list = new ArrayList<Appointment>();
|
||||||
while (results.next()) createAppointmentOf(results).optional().ifPresent(list::add);
|
while (results.next()) createAppointmentOf(results).optional().ifPresent(list::add);
|
||||||
results.close();
|
results.close();
|
||||||
|
addAttachments(list);
|
||||||
return Payload.of(list);
|
return Payload.of(list);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
return SqlError.of(e, "Failed to fetch appointments from database!");
|
return SqlError.of(e, "Failed to fetch appointments from database!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addAttachments(ArrayList<Appointment> list) {
|
||||||
|
var map = new HashMap<Long,BaseAppointment>();
|
||||||
|
|
||||||
|
list.stream().filter(app -> app instanceof BaseAppointment)
|
||||||
|
.map(BaseAppointment.class::cast)
|
||||||
|
.forEach(app -> map.put(app.id(),app));
|
||||||
|
var keys = map.keySet().toArray();
|
||||||
|
try {
|
||||||
|
var rs = select(ALL).from(APPOINTMENT_ATTACHMENTS).leftJoin(UID,URLS,UID).where(AID,in(keys)).exec(connection);
|
||||||
|
while (rs.next()){
|
||||||
|
var aid = rs.getLong(AID);
|
||||||
|
var app = map.get(aid);
|
||||||
|
if (app == null) continue;
|
||||||
|
var mime = rs.getString(MIME);
|
||||||
|
var uri = rs.getString(URL);
|
||||||
|
try {
|
||||||
|
var url = URI.create(uri).toURL();
|
||||||
|
app.add(new Attachment(url,mime));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
LOG.log(WARNING,"Faild to create URL object from %s",uri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Appointment> loadEvent(long id) {
|
public Result<Appointment> loadEvent(long id) {
|
||||||
try {
|
try {
|
||||||
@@ -330,11 +359,11 @@ public class MariaDB implements Database {
|
|||||||
.apply(event.title(), event.description(), start, end, location, coords);
|
.apply(event.title(), event.description(), start, end, location, coords);
|
||||||
|
|
||||||
delete().from(APPOINTMENT_TAGS).where(AID, equal(id)).execute(connection);
|
delete().from(APPOINTMENT_TAGS).where(AID, equal(id)).execute(connection);
|
||||||
addTags(event);
|
writeTags(event);
|
||||||
delete().from(APPOINTMENT_ATTACHMENTS).where(AID, equal(id)).execute(connection);
|
delete().from(APPOINTMENT_ATTACHMENTS).where(AID, equal(id)).execute(connection);
|
||||||
addAttachments(event);
|
writeAttachments(event);
|
||||||
delete().from(APPOINTMENT_URLS).where(AID, equal(id)).execute(connection);
|
delete().from(APPOINTMENT_URLS).where(AID, equal(id)).execute(connection);
|
||||||
addLinks(event);
|
writeLinks(event);
|
||||||
|
|
||||||
return Payload.of(event);
|
return Payload.of(event);
|
||||||
} catch (SQLException sqle) {
|
} catch (SQLException sqle) {
|
||||||
|
|||||||
@@ -164,9 +164,9 @@ table#eventlist{
|
|||||||
.event h1{
|
.event h1{
|
||||||
margin-top: 40px;
|
margin-top: 40px;
|
||||||
}
|
}
|
||||||
td:nth-child(1) {
|
.eventlist td:nth-child(1) {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
tr:nth-child(4n) {
|
.eventlist tr:nth-child(4n) {
|
||||||
background: khaki;
|
background: khaki;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user