@Beta public Map<String, LogEntries> toJson() { return getAll(); } }
public static SessionLogs fromJSON(Map<String, Object> rawSessionLogs) { SessionLogs sessionLogs = new SessionLogs(); for (Map.Entry<String, Object> entry : rawSessionLogs.entrySet()) { String logType = entry.getKey(); Collection<?> rawLogEntries = (Collection<?>) entry.getValue(); List<LogEntry> logEntries = new ArrayList<>(); for (Object o : rawLogEntries) { @SuppressWarnings("unchecked") Map<String, Object> rawEntry = (Map<String, Object>) o; logEntries.add(new LogEntry( LogLevelMapping.toLevel(String.valueOf(rawEntry.get("level"))), ((Number) rawEntry.get("timestamp")).longValue(), String.valueOf(rawEntry.get("message")))); } sessionLogs.addLog(logType, new LogEntries(logEntries)); } return sessionLogs; }
/** * Creates a session logs map, with session logs mapped to session IDs, given * a raw session log map as a JSON object. * * @param rawSessionMap The raw session map. * @return The session logs mapped to session IDs. */ public static Map<String, SessionLogs> getSessionLogs(Map<String, Object> rawSessionMap) { Map<String, SessionLogs> sessionLogsMap = new HashMap<>(); for (Map.Entry<String, Object> entry : rawSessionMap.entrySet()) { String sessionId = entry.getKey(); if (!(entry.getValue() instanceof Map)) { throw new InvalidArgumentException("Expected value to be an object: " + entry.getValue()); } @SuppressWarnings("unchecked") Map<String, Object> value = (Map<String, Object>) entry.getValue(); SessionLogs sessionLogs = SessionLogs.fromJSON(value); sessionLogsMap.put(sessionId, sessionLogs); } return sessionLogsMap; } }