fixed bugs with coords:
argument order is now [lat, lon] everywhere Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -6,10 +6,10 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* cartesian coords
|
* cartesian coords
|
||||||
* @param longitude the longitude
|
|
||||||
* @param latitude the latitude
|
* @param latitude the latitude
|
||||||
|
* @param longitude the longitude
|
||||||
*/
|
*/
|
||||||
public record Coords(double longitude, double latitude) {
|
public record Coords(double latitude,double longitude) {
|
||||||
/**
|
/**
|
||||||
* get a string representing this coords in the ICAL format, see <a href="https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.1.6">iCalendar spec</a>
|
* get a string representing this coords in the ICAL format, see <a href="https://datatracker.ietf.org/doc/html/rfc5545#section-3.8.1.6">iCalendar spec</a>
|
||||||
* @return the formatted coords
|
* @return the formatted coords
|
||||||
@@ -23,6 +23,11 @@ public record Coords(double longitude, double latitude) {
|
|||||||
* @return the json object
|
* @return the json object
|
||||||
*/
|
*/
|
||||||
public JSONObject json() {
|
public JSONObject json() {
|
||||||
return new JSONObject(Map.of("lon", longitude, "lat", latitude));
|
return new JSONObject(Map.of("lat", latitude,"lon", longitude ));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "%s, %s".formatted(latitude,longitude);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class Application {
|
|||||||
|
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
var jarDir = new File("/tmp/jars");
|
var jarDir = new File("/home/srichter/workspace/de.srsoftware.cal/de.srsoftware.cal.importer/build/libs");
|
||||||
var autoImport = new AutoImporter(db);
|
var autoImport = new AutoImporter(db);
|
||||||
new JarWatchdog()
|
new JarWatchdog()
|
||||||
.setContext(BaseImporter.class.getClassLoader())
|
.setContext(BaseImporter.class.getClassLoader())
|
||||||
@@ -75,7 +75,6 @@ public class Application {
|
|||||||
.start();
|
.start();
|
||||||
|
|
||||||
// TODO: add importers
|
// TODO: add importers
|
||||||
// TODO: add coordinates to importers
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class Util {
|
|||||||
try {
|
try {
|
||||||
var lat = Double.parseDouble(parts[0].trim());
|
var lat = Double.parseDouble(parts[0].trim());
|
||||||
var lon = Double.parseDouble(parts[1].trim());
|
var lon = Double.parseDouble(parts[1].trim());
|
||||||
return Payload.of(new Coords(lon, lat));
|
return Payload.of(new Coords(lat, lon));
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
return error(nfe, "Failed to parse coords from %s", coords);
|
return error(nfe, "Failed to parse coords from %s", coords);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,8 +61,12 @@ public class MariaDB implements Database {
|
|||||||
@Override
|
@Override
|
||||||
public Result<Appointment> add(Appointment appointment) {
|
public Result<Appointment> add(Appointment appointment) {
|
||||||
try {
|
try {
|
||||||
|
var start = Timestamp.valueOf(appointment.start());
|
||||||
|
var end = appointment.end().map(Timestamp::valueOf).orElse(null);
|
||||||
|
var coords = appointment.coords().map(Object::toString).orElse(null);
|
||||||
|
var location = appointment.location().orElse(null);
|
||||||
ResultSet keys = insertInto(APPOINTMENTS, TITLE, DESCRIPTION, START, END, LOCATION, COORDS) //
|
ResultSet keys = insertInto(APPOINTMENTS, TITLE, DESCRIPTION, START, END, LOCATION, COORDS) //
|
||||||
.values(appointment.title(), appointment.description(), appointment.start(), appointment.end().orElse(null), appointment.location().orElse(null), appointment.coords().orElse(null))
|
.values(appointment.title(), appointment.description(), start, end, location, coords)
|
||||||
.execute(connection)
|
.execute(connection)
|
||||||
.getGeneratedKeys();
|
.getGeneratedKeys();
|
||||||
Appointment saved = null;
|
Appointment saved = null;
|
||||||
@@ -309,14 +313,17 @@ public class MariaDB implements Database {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Appointment> update(Appointment event) {
|
public Result<Appointment> update(Appointment event) {
|
||||||
|
var start = Timestamp.valueOf(event.start());
|
||||||
var end = event.end().map(Timestamp::valueOf).orElse(null);
|
var end = event.end().map(Timestamp::valueOf).orElse(null);
|
||||||
|
var coords = event.coords().map(Object::toString).orElse(null);
|
||||||
|
var location = event.location().orElse(null);
|
||||||
try {
|
try {
|
||||||
Query
|
Query
|
||||||
.update(APPOINTMENTS) //
|
.update(APPOINTMENTS) //
|
||||||
.set(TITLE, DESCRIPTION, START, END, LOCATION, COORDS)
|
.set(TITLE, DESCRIPTION, START, END, LOCATION, COORDS)
|
||||||
.where(AID, equal(event.id()))
|
.where(AID, equal(event.id()))
|
||||||
.prepare(connection)
|
.prepare(connection)
|
||||||
.apply(event.title(), event.description(), Timestamp.valueOf(event.start()), end, event.location().orElse(null), event.coords().orElse(null));
|
.apply(event.title(), event.description(), start, end, location, coords);
|
||||||
|
|
||||||
// TODO: update links, attachments, tags
|
// TODO: update links, attachments, tags
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import static de.srsoftware.tools.Result.transform;
|
|||||||
import static de.srsoftware.tools.TagFilter.*;
|
import static de.srsoftware.tools.TagFilter.*;
|
||||||
|
|
||||||
import de.srsoftware.cal.BaseImporter;
|
import de.srsoftware.cal.BaseImporter;
|
||||||
|
import de.srsoftware.cal.api.Coords;
|
||||||
import de.srsoftware.tools.*;
|
import de.srsoftware.tools.*;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -17,6 +18,7 @@ public class Kassablanca extends BaseImporter {
|
|||||||
private static final String APPOINTMENT_TAG_ID = "entry-content";
|
private static final String APPOINTMENT_TAG_ID = "entry-content";
|
||||||
private static final Pattern START_DATE_PATTERN = Pattern.compile("(\\d+).(\\d+).(\\d+).*Beginn\\s*(\\d+):(\\d+)\\s*Uhr");
|
private static final Pattern START_DATE_PATTERN = Pattern.compile("(\\d+).(\\d+).(\\d+).*Beginn\\s*(\\d+):(\\d+)\\s*Uhr");
|
||||||
private static final String LOCATION = "Kassablanca e.V., Felsenkellerstr. 13a, 07745 Jena";
|
private static final String LOCATION = "Kassablanca e.V., Felsenkellerstr. 13a, 07745 Jena";
|
||||||
|
private static final Coords COORDS = new Coords(50.92093, 11.57788);
|
||||||
|
|
||||||
public Kassablanca() throws NoSuchAlgorithmException {
|
public Kassablanca() throws NoSuchAlgorithmException {
|
||||||
super();
|
super();
|
||||||
@@ -27,6 +29,11 @@ public class Kassablanca extends BaseImporter {
|
|||||||
return BASE_URL;
|
return BASE_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Result<Coords> extractCoords(Tag eventTag) {
|
||||||
|
return Payload.of(COORDS);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Result<Tag> extractDescriptionTag(Tag eventTag) {
|
protected Result<Tag> extractDescriptionTag(Tag eventTag) {
|
||||||
var list = eventTag.find(attributeHas("class", "se-content"));
|
var list = eventTag.find(attributeHas("class", "se-content"));
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import static de.srsoftware.tools.Result.transform;
|
|||||||
import static de.srsoftware.tools.TagFilter.*;
|
import static de.srsoftware.tools.TagFilter.*;
|
||||||
|
|
||||||
import de.srsoftware.cal.BaseImporter;
|
import de.srsoftware.cal.BaseImporter;
|
||||||
|
import de.srsoftware.cal.api.Coords;
|
||||||
import de.srsoftware.tools.Payload;
|
import de.srsoftware.tools.Payload;
|
||||||
import de.srsoftware.tools.Result;
|
import de.srsoftware.tools.Result;
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
@@ -20,7 +21,7 @@ public class Rosenkeller extends BaseImporter {
|
|||||||
private static final String BASE_URL = "https://rosenkeller.org";
|
private static final String BASE_URL = "https://rosenkeller.org";
|
||||||
private static final Pattern DATE_PATTERN = Pattern.compile("(\\d+) (\\w+)(\\W+(\\d+):(\\d+))?");
|
private static final Pattern DATE_PATTERN = Pattern.compile("(\\d+) (\\w+)(\\W+(\\d+):(\\d+))?");
|
||||||
private static final String DEFAULT_LOCATION = "Rosenkeller, Johannisstr. 13, 07743 Jena";
|
private static final String DEFAULT_LOCATION = "Rosenkeller, Johannisstr. 13, 07743 Jena";
|
||||||
|
private static final Coords COORDS = new Coords(50.92945, 11.58491);
|
||||||
public Rosenkeller() throws NoSuchAlgorithmException {
|
public Rosenkeller() throws NoSuchAlgorithmException {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -35,6 +36,11 @@ public class Rosenkeller extends BaseImporter {
|
|||||||
return Payload.of(eventTag);
|
return Payload.of(eventTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Result<Coords> extractCoords(Tag eventTag) {
|
||||||
|
return Payload.of(COORDS);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Result<Tag> extractDescriptionTag(Tag eventTag) {
|
protected Result<Tag> extractDescriptionTag(Tag eventTag) {
|
||||||
var opt = eventTag //
|
var opt = eventTag //
|
||||||
|
|||||||
Reference in New Issue
Block a user