working on loading journal entries
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -0,0 +1,50 @@
|
|||||||
|
package de.srsoftware.umbrella.messagebus.events;
|
||||||
|
|
||||||
|
import de.srsoftware.tools.Mappable;
|
||||||
|
import de.srsoftware.umbrella.core.constants.Field;
|
||||||
|
import de.srsoftware.umbrella.core.model.ObjectWithId;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static de.srsoftware.umbrella.core.constants.Field.*;
|
||||||
|
|
||||||
|
public class JournalEntry extends ObjectWithId {
|
||||||
|
|
||||||
|
long timestamp, userId, entityId;
|
||||||
|
String action, description, module;
|
||||||
|
|
||||||
|
public JournalEntry(long id, long timestamp, long userId, String module, long entityId, String action, String description){
|
||||||
|
super(id);
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
this.userId = userId;
|
||||||
|
this.module = module;
|
||||||
|
this.entityId = entityId;
|
||||||
|
this.action = action;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
public static JournalEntry of(ResultSet rs) throws SQLException {
|
||||||
|
var id = rs.getLong(ID);
|
||||||
|
var timestamp = rs.getLong(TIMESTAMP);
|
||||||
|
var userId = rs.getLong(USER_ID);
|
||||||
|
var module = rs.getString(MODULE);
|
||||||
|
var entityId = rs.getLong(ENTITY_ID);
|
||||||
|
var action = rs.getString(ACTION);
|
||||||
|
var description = rs.getString(DESCRIPTION);
|
||||||
|
|
||||||
|
return new JournalEntry(id, timestamp, userId, module, entityId, action, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> toMap() {
|
||||||
|
return map(
|
||||||
|
TIMESTAMP, timestamp,
|
||||||
|
USER_ID, userId,
|
||||||
|
MODULE, module,
|
||||||
|
ENTITY_ID, entityId,
|
||||||
|
ACTION, action,
|
||||||
|
DESCRIPTION, description
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package de.srsoftware.umbrella.journal;
|
|||||||
|
|
||||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||||
import de.srsoftware.umbrella.messagebus.events.Event;
|
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||||
|
import de.srsoftware.umbrella.messagebus.events.JournalEntry;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -10,5 +11,5 @@ import java.util.List;
|
|||||||
public interface JournalDb {
|
public interface JournalDb {
|
||||||
void logEvent(Event<?> event);
|
void logEvent(Event<?> event);
|
||||||
|
|
||||||
List<Event<?>> list(String module, long entityId, HashMap<Long, UmbrellaUser> userLoader);
|
List<JournalEntry> list(String module, long entityId, HashMap<Long, UmbrellaUser> userLoader);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ public class JournalModule extends BaseHandler implements EventListener {
|
|||||||
if (head == null) throw missingField(Field.ENTITY_ID);
|
if (head == null) throw missingField(Field.ENTITY_ID);
|
||||||
try {
|
try {
|
||||||
var entityId = Long.parseLong(head);
|
var entityId = Long.parseLong(head);
|
||||||
journalDb.list(module, entityId, userService().loader());
|
var entries = journalDb.list(module, entityId, userService().loader());
|
||||||
|
return sendContent(ex,entries); // TODO: map entries
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw invalidField(Field.ENTITY_ID, Text.NUMBER);
|
throw invalidField(Field.ENTITY_ID, Text.NUMBER);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import de.srsoftware.umbrella.core.constants.Module;
|
|||||||
import de.srsoftware.umbrella.core.constants.Text;
|
import de.srsoftware.umbrella.core.constants.Text;
|
||||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||||
import de.srsoftware.umbrella.messagebus.events.Event;
|
import de.srsoftware.umbrella.messagebus.events.Event;
|
||||||
|
import de.srsoftware.umbrella.messagebus.events.JournalEntry;
|
||||||
import de.srsoftware.umbrella.messagebus.events.TaskEvent;
|
import de.srsoftware.umbrella.messagebus.events.TaskEvent;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -64,30 +65,16 @@ public class SqliteDb extends BaseDb implements JournalDb{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Event<?>> list(String module, long entityId, HashMap<Long, UmbrellaUser> userLoader) {
|
public List<JournalEntry> list(String module, long entityId, HashMap<Long, UmbrellaUser> userLoader) {
|
||||||
try {
|
try {
|
||||||
var rs = select(ALL).from(TABLE_JOURNAL).where(MODULE, equal(module)).where(ENTITY_ID,equal(entityId)).exec(db);
|
var rs = select(ALL).from(TABLE_JOURNAL).where(MODULE, equal(module)).where(ENTITY_ID,equal(entityId)).exec(db);
|
||||||
var list = new ArrayList<Event<?>>();
|
var list = new ArrayList<JournalEntry>();
|
||||||
|
while (rs.next()) list.add(JournalEntry.of(rs));
|
||||||
|
|
||||||
while (rs.next()){
|
|
||||||
var user = userLoader.get(rs.getLong(USER_ID));
|
|
||||||
var id = rs.getLong(Field.ID);
|
|
||||||
var timestamp = rs.getLong(TIMESTAMP);
|
|
||||||
var action = rs.getString(ACTION);
|
|
||||||
var descr = rs.getString(DESCRIPTION);
|
|
||||||
|
|
||||||
var event = switch (module){
|
|
||||||
case Module.TASK -> new TaskEvent(user,)
|
|
||||||
default -> throw notImplemented("No handler for "+module+" events!");
|
|
||||||
};
|
|
||||||
list.add(event);
|
|
||||||
}
|
|
||||||
rs.close();
|
rs.close();
|
||||||
return list;
|
return list;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw failedToLoadObject(Text.EVENT_LIST);
|
throw failedToLoadObject(Text.EVENT_LIST);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user