working on document view/edit

This commit is contained in:
2025-07-10 15:42:37 +02:00
parent 0bfbe47d96
commit 90c27382a1
22 changed files with 281 additions and 34 deletions

View File

@@ -0,0 +1,10 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.contact;
public class Constants {
private Constants(){}
public static final String CONFIG_DATABASE = "umbrella.modules.contact.database";
public static final String TABLE_CONTACTS_USERS = "contacts_users";
public static final String TABLE_CONTACTS = "contacts";
}

View File

@@ -0,0 +1,10 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.contact;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.Contact;
import java.util.Collection;
public interface ContactDb {
Collection<Contact> listContactsOf(long id) throws UmbrellaException;
}

View File

@@ -0,0 +1,27 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.contact;
import static de.srsoftware.umbrella.contact.Constants.CONFIG_DATABASE;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
import de.srsoftware.configuration.Configuration;
import de.srsoftware.umbrella.core.api.ContactService;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.Contact;
import de.srsoftware.umbrella.core.model.UmbrellaUser;
import java.util.Collection;
public class ContactModule implements ContactService {
private final ContactDb contactDb;
public ContactModule(Configuration config) throws UmbrellaException {
var dbFile = config.get(CONFIG_DATABASE).orElseThrow(() -> missingFieldException(CONFIG_DATABASE));
contactDb = new SqliteDb(connect(dbFile));
}
@Override
public Collection<Contact> listContactsOf(UmbrellaUser user) throws UmbrellaException {
return contactDb.listContactsOf(user.id());
}
}

View File

@@ -0,0 +1,36 @@
/* © SRSoftware 2025 */
package de.srsoftware.umbrella.contact;
import static de.srsoftware.tools.jdbc.Condition.equal;
import static de.srsoftware.tools.jdbc.Query.select;
import static de.srsoftware.umbrella.contact.Constants.TABLE_CONTACTS;
import static de.srsoftware.umbrella.contact.Constants.TABLE_CONTACTS_USERS;
import static de.srsoftware.umbrella.core.Constants.*;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.Contact;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashSet;
public class SqliteDb implements ContactDb{
private final Connection conn;
public SqliteDb(Connection connection) {
conn = connection;
}
@Override
public Collection<Contact> listContactsOf(long userId) throws UmbrellaException{
try {
var rs = select("*").from(TABLE_CONTACTS).leftJoin(ID,TABLE_CONTACTS_USERS,USER_ID).where(USER_ID,equal(userId)).exec(conn);
var contacts = new HashSet<Contact>();
while (rs.next()) contacts.add(Contact.of(rs));
rs.close();
return contacts;
} catch (SQLException e) {
throw UmbrellaException.databaseException("Failed to load contacts og user {0}",userId);
}
}
}