Search in sources :

Example 1 with LocalDate

use of org.activityinfo.model.type.time.LocalDate in project activityinfo by bedatadriven.

the class FormInputViewModelTest method testPersistence.

@Test
public void testPersistence() {
    Survey survey = setup.getCatalog().getSurvey();
    FormInputViewModelBuilder builder = builderFor(survey);
    // Start with no input
    FormInputModel inputModel = new FormInputModel(new RecordRef(survey.getFormId(), ResourceId.generateId())).update(survey.getGenderFieldId(), new FieldInput(new EnumValue(survey.getMaleId()))).update(survey.getNameFieldId(), new FieldInput(TextValue.valueOf("BOB"))).update(survey.getDobFieldId(), new FieldInput(new LocalDate(1982, 1, 16))).update(survey.getAgeFieldId(), new FieldInput(new Quantity(35)));
    // Verify that it's valid
    FormInputViewModel viewModel = builder.build(inputModel);
    assertThat(viewModel.isValid(), equalTo(true));
    // Now build the update transaction and save!
    Promise<Void> completed = setup.getFormStore().updateRecords(viewModel.buildTransaction());
    assertThat(completed.getState(), equalTo(Promise.State.FULFILLED));
}
Also used : EnumValue(org.activityinfo.model.type.enumerated.EnumValue) RecordRef(org.activityinfo.model.type.RecordRef) Quantity(org.activityinfo.model.type.number.Quantity) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) FieldInput(org.activityinfo.ui.client.input.model.FieldInput) LocalDate(org.activityinfo.model.type.time.LocalDate) Test(org.junit.Test)

Example 2 with LocalDate

use of org.activityinfo.model.type.time.LocalDate in project activityinfo by bedatadriven.

the class FormInputViewModelTest method testMultipleSelectPersistence.

@Test
public void testMultipleSelectPersistence() {
    IntakeForm intakeForm = setup.getCatalog().getIntakeForm();
    FormInputViewModelBuilder builder = builderFor(intakeForm);
    FormInputModel inputModel = new FormInputModel(new RecordRef(intakeForm.getFormId(), ResourceId.generateId())).update(intakeForm.getOpenDateFieldId(), new LocalDate(2017, 1, 1)).update(intakeForm.getNationalityFieldId(), new EnumValue(intakeForm.getPalestinianId(), intakeForm.getJordanianId()));
    FormInputViewModel viewModel = builder.build(inputModel);
    assertThat(viewModel.isValid(), equalTo(true));
    Promise<Void> completed = setup.getFormStore().updateRecords(viewModel.buildTransaction());
    assertThat(completed.getState(), equalTo(Promise.State.FULFILLED));
}
Also used : EnumValue(org.activityinfo.model.type.enumerated.EnumValue) RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) LocalDate(org.activityinfo.model.type.time.LocalDate) Test(org.junit.Test)

Example 3 with LocalDate

use of org.activityinfo.model.type.time.LocalDate in project activityinfo by bedatadriven.

the class FormInputViewModelTest method inputMask.

@Test
public void inputMask() {
    IntakeForm intakeForm = setup.getCatalog().getIntakeForm();
    FormInputViewModelBuilder builder = builderFor(intakeForm);
    FormInputModel inputModel = new FormInputModel(new RecordRef(intakeForm.getFormId(), ResourceId.generateId()));
    // Fill in required fields
    inputModel = inputModel.update(intakeForm.getOpenDateFieldId(), new LocalDate(2017, 1, 1));
    // Does not match input mask "000"
    inputModel = inputModel.update(intakeForm.getRegNumberFieldId(), new FieldInput(TextValue.valueOf("FOOOOO")));
    FormInputViewModel viewModel = builder.build(inputModel);
    assertThat(viewModel.isValid(), equalTo(false));
    assertThat(viewModel.getValidationErrors(intakeForm.getRegNumberFieldId()), not(empty()));
}
Also used : RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) FieldInput(org.activityinfo.ui.client.input.model.FieldInput) LocalDate(org.activityinfo.model.type.time.LocalDate) Test(org.junit.Test)

Example 4 with LocalDate

use of org.activityinfo.model.type.time.LocalDate in project activityinfo by bedatadriven.

the class ColumnFilterParser method dateValue.

private static FormulaNode dateValue(FilterConfig filter) {
    // GXT serializes the date value as unix time value in milliseconds
    long time = Long.parseLong(filter.getValue());
    Date date = new Date(time);
    LocalDate localDate = new LocalDate(date);
    return new FunctionCallNode(DateFunction.INSTANCE, new ConstantNode(localDate.getYear()), new ConstantNode(localDate.getMonthOfYear()), new ConstantNode(localDate.getDayOfMonth()));
}
Also used : LocalDate(org.activityinfo.model.type.time.LocalDate) LocalDate(org.activityinfo.model.type.time.LocalDate)

Example 5 with LocalDate

use of org.activityinfo.model.type.time.LocalDate in project activityinfo by bedatadriven.

the class BuiltinFields method getDateRange.

public static DateRange getDateRange(FormInstance instance, FormClass formClass) {
    Date startDate = null;
    Date endDate = null;
    for (FormField field : formClass.getFields()) {
        if (isStartDate(field.getId())) {
            LocalDate localDate = instance.getDate(field.getId());
            if (localDate != null) {
                startDate = localDate.atMidnightInMyTimezone();
            }
        }
        if (isEndDate(field.getId())) {
            LocalDate localDate = instance.getDate(field.getId());
            if (localDate != null) {
                endDate = localDate.atMidnightInMyTimezone();
            }
        }
    }
    return new DateRange(startDate, endDate);
}
Also used : DateRange(org.activityinfo.model.date.DateRange) FormField(org.activityinfo.model.form.FormField) LocalDate(org.activityinfo.model.type.time.LocalDate) LocalDate(org.activityinfo.model.type.time.LocalDate) Date(java.util.Date)

Aggregations

LocalDate (org.activityinfo.model.type.time.LocalDate)24 Test (org.junit.Test)11 Quantity (org.activityinfo.model.type.number.Quantity)8 FormInstance (org.activityinfo.model.form.FormInstance)7 RecordRef (org.activityinfo.model.type.RecordRef)7 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)6 ResourceId (org.activityinfo.model.resource.ResourceId)5 OnDataSet (org.activityinfo.server.database.OnDataSet)5 FormClass (org.activityinfo.model.form.FormClass)4 FieldValue (org.activityinfo.model.type.FieldValue)4 ReferenceValue (org.activityinfo.model.type.ReferenceValue)4 Date (java.util.Date)3 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)3 FieldInput (org.activityinfo.ui.client.input.model.FieldInput)3 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)3 FormField (org.activityinfo.model.form.FormField)2 FormulaSyntaxException (org.activityinfo.model.formula.diagnostic.FormulaSyntaxException)2 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)2 FilterConfig (com.sencha.gxt.data.shared.loader.FilterConfig)1 Calendar (java.util.Calendar)1