// TODO: Deal with potential runtime exceptions
public void finalizeReports(String currentSessionId) {
    // TODO: Need to implement procedure to skip finalizing the current session when this is
    //  called on app start, but keep the current session when called at crash time. Currently
    //  this only works when called at app start.
    List<File> sessionDirectories = capAndGetOpenSessions(currentSessionId);
    for (File sessionDirectory : sessionDirectories) {
      final List<File> eventFiles =
          getFilesInDirectory(
              sessionDirectory, (f, name) -> name.startsWith(EVENT_FILE_NAME_PREFIX));
      Collections.sort(eventFiles);
      // TODO: Fix nulls
      // Only process the session if it has associated events
      if (!eventFiles.isEmpty()) {
        final List<Event> events = new ArrayList<>();
        boolean isHighPriorityReport = false;
        for (File eventFile : eventFiles) {
          final Event event = TRANSFORM.eventFromJson(readTextFile(eventFile));
          isHighPriorityReport =
              isHighPriorityReport || isHighPriorityEventFile(eventFile.getName());
          events.add(event);
        }
        // FIXME: If we fail to parse the events, we'll need to bail.
        String userId = null;
        final File userFile = new File(sessionDirectory, USER_FILE_NAME);
        if (userFile.exists()) {
          userId = readTextFile(userFile);
        }
        CrashlyticsReport report =
            TRANSFORM.reportFromJson(readTextFile(new File(sessionDirectory, REPORT_FILE_NAME)));
        final String sessionId = report.getSession().getIdentifier();
        if (userId != null) {
          report = report.withUserId(userId);
        }
        final File outputDirectory =
            prepareDirectory(isHighPriorityReport ? priorityReportsDirectory : reportsDirectory);
        writeTextFile(
            new File(outputDirectory, sessionId),
            TRANSFORM.reportToJson(report.withEvents(ImmutableList.from(events))));
      }
      recursiveDelete(sessionDirectory);
    }
    capFinalizedReports();
  }
public void finalizeReports(String currentSessionId) {
// TODO: Need to implement procedure to skip finalizing the current session when this is
// called on app start, but keep the current session when called at crash time. Currently
// this only works when called at app start.
List<File> sessionDirectories = capAndGetOpenSessions(currentSessionId);
for (File sessionDirectory : sessionDirectories) {
final List<File> eventFiles =
getFilesInDirectory(
sessionDirectory, (f, name) -> name.startsWith(EVENT_FILE_NAME_PREFIX));
Collections.sort(eventFiles);
// TODO: Fix nulls
// Only process the session if it has associated events
if (!eventFiles.isEmpty()) {
final List<Event> events = new ArrayList<>();
boolean isHighPriorityReport = false;
for (File eventFile : eventFiles) {
final Event event = TRANSFORM.eventFromJson(readTextFile(eventFile));
isHighPriorityReport =
isHighPriorityReport || isHighPriorityEventFile(eventFile.getName());
events.add(event);
}
// FIXME: If we fail to parse the events, we'll need to bail.
String userId = null;
final File userFile = new File(sessionDirectory, USER_FILE_NAME);
if (userFile.exists()) {
userId = readTextFile(userFile);
}
CrashlyticsReport report =
TRANSFORM.reportFromJson(readTextFile(new File(sessionDirectory, REPORT_FILE_NAME)));
final String sessionId = report.getSession().getIdentifier();
if (userId != null) {
report = report.withUserId(userId);
}
final File outputDirectory =
prepareDirectory(isHighPriorityReport ? priorityReportsDirectory : reportsDirectory);
writeTextFile(
new File(outputDirectory, sessionId),
TRANSFORM.reportToJson(report.withEvents(ImmutableList.from(events))));
}
recursiveDelete(sessionDirectory);
}
capFinalizedReports();
}
public void finalizeReports(String currentSessionId) {
// TODO: Need to implement procedure to skip finalizing the current session when this is
// called on app start, but keep the current session when called at crash time. Currently
// this only works when called at app start.
List<File> sessionDirectories = capAndGetOpenSessions(currentSessionId);
for (File sessionDirectory : sessionDirectories) {
final List<File> eventFiles =
getFilesInDirectory(
sessionDirectory, (f, name) -> name.startsWith(EVENT_FILE_NAME_PREFIX));
Collections.sort(eventFiles);
// TODO: Fix nulls
// Only process the session if it has associated events
if (!eventFiles.isEmpty()) {
final List<Event> events = new ArrayList<>();
boolean isHighPriorityReport = false;
for (File eventFile : eventFiles) {
final Event event = TRANSFORM.eventFromJson(readTextFile(eventFile));
isHighPriorityReport =
isHighPriorityReport || isHighPriorityEventFile(eventFile.getName());
events.add(event);
}
// FIXME: If we fail to parse the events, we'll need to bail.
String userId = null;
final File userFile = new File(sessionDirectory, USER_FILE_NAME);
if (userFile.exists()) {
userId = readTextFile(userFile);
}
CrashlyticsReport report =
TRANSFORM.reportFromJson(readTextFile(new File(sessionDirectory, REPORT_FILE_NAME)));
final String sessionId = report.getSession().getIdentifier();
if (userId != null) {
report = report.withUserId(userId);
}
final File outputDirectory =
prepareDirectory(isHighPriorityReport ? priorityReportsDirectory : reportsDirectory);
writeTextFile(
new File(outputDirectory, sessionId),
TRANSFORM.reportToJson(report.withEvents(ImmutableList.from(events))));
}
recursiveDelete(sessionDirectory);
}
capFinalizedReports();
}
public void finalizeReports(String currentSessionId) {
// TODO: Need to implement procedure to skip finalizing the current session when this is
// called on app start, but keep the current session when called at crash time. Currently
// this only works when called at app start.
List<File> sessionDirectories = capAndGetOpenSessions(currentSessionId);
for (File sessionDirectory : sessionDirectories) {
final List<File> eventFiles =
getFilesInDirectory(
sessionDirectory, (f, name) -> name.startsWith(EVENT_FILE_NAME_PREFIX));
Collections.sort(eventFiles);
// TODO: Fix nulls
// Only process the session if it has associated events
if (!eventFiles.isEmpty()) {
final List<Event> events = new ArrayList<>();
boolean isHighPriorityReport = false;
for (File eventFile : eventFiles) {
final Event event = TRANSFORM.eventFromJson(readTextFile(eventFile));
isHighPriorityReport =
isHighPriorityReport || isHighPriorityEventFile(eventFile.getName());
events.add(event);
}
// FIXME: If we fail to parse the events, we'll need to bail.
String userId = null;
final File userFile = new File(sessionDirectory, USER_FILE_NAME);
if (userFile.exists()) {
userId = readTextFile(userFile);
}
CrashlyticsReport report =
TRANSFORM.reportFromJson(readTextFile(new File(sessionDirectory, REPORT_FILE_NAME)));
final String sessionId = report.getSession().getIdentifier();
if (userId != null) {
report = report.withUserId(userId);
}
final File outputDirectory =
prepareDirectory(isHighPriorityReport ? priorityReportsDirectory : reportsDirectory);
writeTextFile(
new File(outputDirectory, sessionId),
TRANSFORM.reportToJson(report.withEvents(ImmutableList.from(events))));
}
recursiveDelete(sessionDirectory);
}
capFinalizedReports();
}