use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.
the class AuditUtils method logCurrentScreen.
public static void logCurrentScreen(FormController formController, AuditEventLogger auditEventLogger, long currentTime) {
if (formController.getEvent() == EVENT_QUESTION || formController.getEvent() == EVENT_GROUP || formController.getEvent() == EVENT_REPEAT) {
try {
FormEntryPrompt[] prompts = formController.getQuestionPrompts();
for (FormEntryPrompt question : prompts) {
String answer = question.getAnswerValue() != null ? question.getAnswerValue().getDisplayText() : null;
auditEventLogger.logEvent(AuditEvent.AuditEventType.QUESTION, question.getIndex(), true, answer, currentTime, null);
}
} catch (RepeatsInFieldListException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.
the class FormController method getQuestionPrompts.
/**
* Returns an array of question prompts corresponding to the current {@link FormIndex}. These
* are the prompts that should be displayed to the user and don't include any non-relevant
* questions.
* <p>
* The array has a single element if there is a question at this {@link FormIndex} or multiple
* elements if there is a group.
*
* @throws RepeatsInFieldListException if there is a group at this {@link FormIndex} and it contains
* elements that are not questions or regular (non-repeat) groups.
*/
public FormEntryPrompt[] getQuestionPrompts() throws RepeatsInFieldListException {
// For questions, there is only one.
// For groups, there could be many, but we set that below
FormEntryPrompt[] questions = new FormEntryPrompt[0];
IFormElement element = formEntryController.getModel().getForm().getChild(getFormIndex());
if (element instanceof GroupDef) {
GroupDef gd = (GroupDef) element;
// we only display relevant questions
List<FormEntryPrompt> questionList = new ArrayList<>();
for (FormIndex index : getIndicesForGroup(gd)) {
if (getEvent(index) != FormEntryController.EVENT_QUESTION) {
throw new RepeatsInFieldListException("Repeats in 'field-list' groups " + "are not supported. Please update the form design to remove the " + "following repeat from a field list: " + index.getReference().toString(false));
}
// we only display relevant questions
if (formEntryController.getModel().isIndexRelevant(index)) {
questionList.add(getQuestionPrompt(index));
}
questions = new FormEntryPrompt[questionList.size()];
questionList.toArray(questions);
}
} else {
// We have a question, so just get the one prompt
questions = new FormEntryPrompt[1];
questions[0] = getQuestionPrompt();
}
return questions;
}
use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.
the class AuditEventLoggerTest method setup.
@Before
public void setup() {
FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withAnswerDisplayText("The answer").build();
when(formController.getQuestionPrompt(any())).thenReturn(prompt);
}
use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.
the class FormSaveViewModelTest method whenFormSaverFinishes_saved_andFormIsCurrentlyOnRepeat_logsSaveAndQuestionAuditEventsAfterFlush.
@Test
public void whenFormSaverFinishes_saved_andFormIsCurrentlyOnRepeat_logsSaveAndQuestionAuditEventsAfterFlush() throws RepeatsInFieldListException {
when(formController.getEvent()).thenReturn(EVENT_REPEAT);
FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withIndex("index1").withAnswerDisplayText("answer").build();
when(formController.getQuestionPrompts()).thenReturn(Arrays.asList(prompt).toArray(new FormEntryPrompt[] {}));
viewModel.saveForm(Uri.parse("file://form"), true, "", false);
whenFormSaverFinishes(SaveFormToDisk.SAVED);
InOrder verifier = inOrder(logger);
verifier.verify(logger).flush();
verifier.verify(logger).logEvent(AuditEvent.AuditEventType.FORM_SAVE, false, CURRENT_TIME);
verifier.verify(logger).logEvent(AuditEvent.AuditEventType.QUESTION, prompt.getIndex(), true, prompt.getAnswerValue().getDisplayText(), CURRENT_TIME, null);
}
use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.
the class FormSaveViewModelTest method whenFormSaverFinishes_saved_andFormIsCurrentlyOnGroup_logsSaveAndQuestionAuditEventsAfterFlush.
@Test
public void whenFormSaverFinishes_saved_andFormIsCurrentlyOnGroup_logsSaveAndQuestionAuditEventsAfterFlush() throws RepeatsInFieldListException {
when(formController.getEvent()).thenReturn(EVENT_GROUP);
FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withIndex("index1").withAnswerDisplayText("answer").build();
when(formController.getQuestionPrompts()).thenReturn(Arrays.asList(prompt).toArray(new FormEntryPrompt[] {}));
viewModel.saveForm(Uri.parse("file://form"), true, "", false);
whenFormSaverFinishes(SaveFormToDisk.SAVED);
InOrder verifier = inOrder(logger);
verifier.verify(logger).flush();
verifier.verify(logger).logEvent(AuditEvent.AuditEventType.FORM_SAVE, false, CURRENT_TIME);
verifier.verify(logger).logEvent(AuditEvent.AuditEventType.QUESTION, prompt.getIndex(), true, prompt.getAnswerValue().getDisplayText(), CURRENT_TIME, null);
}
Aggregations