Search in sources :

Example 11 with FormEntryPrompt

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);
        }
    }
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) RepeatsInFieldListException(org.odk.collect.android.javarosawrapper.RepeatsInFieldListException)

Example 12 with FormEntryPrompt

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;
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) ArrayList(java.util.ArrayList) FormIndex(org.javarosa.core.model.FormIndex) GroupDef(org.javarosa.core.model.GroupDef)

Example 13 with FormEntryPrompt

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);
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) Before(org.junit.Before)

Example 14 with FormEntryPrompt

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);
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) InOrder(org.mockito.InOrder) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) Test(org.junit.Test)

Example 15 with FormEntryPrompt

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);
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) InOrder(org.mockito.InOrder) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) Test(org.junit.Test)

Aggregations

FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)114 Test (org.junit.Test)92 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)45 Clip (org.odk.collect.audioclips.Clip)13 FormIndex (org.javarosa.core.model.FormIndex)10 File (java.io.File)9 SelectChoice (org.javarosa.core.model.SelectChoice)7 StringData (org.javarosa.core.model.data.StringData)7 IFormElement (org.javarosa.core.model.IFormElement)5 QuestionDef (org.javarosa.core.model.QuestionDef)5 FormController (org.odk.collect.android.javarosawrapper.FormController)5 GroupDef (org.javarosa.core.model.GroupDef)4 QuestionDetails (org.odk.collect.android.formentry.questions.QuestionDetails)4 DatePickerDetails (org.odk.collect.android.logic.DatePickerDetails)4 ArrayList (java.util.ArrayList)3 DateData (org.javarosa.core.model.data.DateData)3 IAnswerData (org.javarosa.core.model.data.IAnswerData)3 TreeReference (org.javarosa.core.model.instance.TreeReference)3 LocalDateTime (org.joda.time.LocalDateTime)3 AudioControllerView (org.odk.collect.android.audio.AudioControllerView)3