Skip to content

Commit

Permalink
Fixed the problem with empty values in the last question
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed May 24, 2019
1 parent 05dd200 commit 949540e
Showing 1 changed file with 34 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ public void logEvent(AuditEvent.AuditEventType eventType, FormIndex formIndex,
* Close any existing interval events if the view is being exited
*/
if (eventType == AuditEvent.AuditEventType.FORM_EXIT) {
for (AuditEvent aev : auditEvents) {
if (!aev.isEndTimeSet() && aev.isIntervalAuditEventType()) {
aev.setEnd(start);
}
}
manageSavedEvents();
}

/*
Expand Down Expand Up @@ -155,29 +151,42 @@ private boolean isDuplicatedIntervalEvent(AuditEvent newAuditEvent) {
*/
public void exitView() {
if (isAuditEnabled()) {
// Calculate the time and add the event to the auditEvents array
long end = getEventTime();
ArrayList<AuditEvent> filteredAuditEvents = new ArrayList<>();
for (AuditEvent aev : auditEvents) {
if (!aev.isEndTimeSet() && aev.isIntervalAuditEventType()) {
if (auditConfig.isLocationEnabled()) {
addLocationCoordinatesToAuditEvent(aev);
}
FormController formController = Collect.getInstance().getFormController();
if (aev.getAuditEventType().equals(AuditEvent.AuditEventType.QUESTION) && formController != null) {
addNewValueToQuestionAuditEvent(aev, formController);
}
aev.setEnd(end);
if (shouldEventBeLogged(aev)) {
filteredAuditEvents.add(aev);
}
}
manageSavedEvents();
writeEvents();
}
}

private void manageSavedEvents() {
// Calculate the time and add the event to the auditEvents array
long end = getEventTime();
ArrayList<AuditEvent> filteredAuditEvents = new ArrayList<>();
for (AuditEvent aev : auditEvents) {
if (!aev.isEndTimeSet() && aev.isIntervalAuditEventType()) {
setIntervalEventFinalParameters(aev, end);
}
if (shouldEventBeLogged(aev)) {
filteredAuditEvents.add(aev);
}
}

auditEvents.clear();
auditEvents.addAll(filteredAuditEvents);
writeEvents();
auditEvents.clear();
auditEvents.addAll(filteredAuditEvents);
}

private void setIntervalEventFinalParameters(AuditEvent aev, long end) {
// Set location parameters
if (auditConfig.isLocationEnabled()) {
addLocationCoordinatesToAuditEvent(aev);
}

// Set answers
FormController formController = Collect.getInstance().getFormController();
if (aev.getAuditEventType().equals(AuditEvent.AuditEventType.QUESTION) && formController != null) {
addNewValueToQuestionAuditEvent(aev, formController);
}

// Set end time
aev.setEnd(end);
}

/*
Expand Down

0 comments on commit 949540e

Please sign in to comment.