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));
}
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));
}
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()));
}
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()));
}
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);
}
Aggregations