use of org.activityinfo.model.date.DateRange 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);
}
use of org.activityinfo.model.date.DateRange in project activityinfo by bedatadriven.
the class SimpleFormPanel method validateBuiltinDates.
private Optional<Boolean> validateBuiltinDates(FieldContainer container, FormField field) {
if (BuiltinFields.isBuiltInDate(field.getId())) {
FormClass rootFormClass = getModel().getRootFormClass();
DateRange dateRange = BuiltinFields.getDateRange(getModel().getWorkingRootInstance(), rootFormClass);
if (!dateRange.isValidWithNull()) {
container.setInvalid(I18N.CONSTANTS.inconsistentDateRangeWarning());
return Optional.of(false);
} else {
if (dateRange.isValid()) {
getWidgetCreator().get(BuiltinFields.getStartDateField(rootFormClass).getId()).setValid();
getWidgetCreator().get(BuiltinFields.getEndDateField(rootFormClass).getId()).setValid();
return Optional.of(true);
}
}
}
return Optional.absent();
}
use of org.activityinfo.model.date.DateRange in project activityinfo by bedatadriven.
the class DataFieldImporter method getRangeDate.
private DateRange getRangeDate(SourceRow row, FieldValueParser converter) throws NullPointerException {
ColumnAccessor startDateAccessor = null;
ColumnAccessor endDateAccessor = null;
for (FormField field : node.getDefiningFormClass().getFields()) {
if (BuiltinFields.isStartDate(field.getId())) {
startDateAccessor = model.getMappedColumns(field.getId()).get(DataFieldImportStrategy.VALUE);
}
if (BuiltinFields.isEndDate(field.getId())) {
endDateAccessor = model.getMappedColumns(field.getId()).get(DataFieldImportStrategy.VALUE);
}
}
Preconditions.checkNotNull(startDateAccessor, "It must not be null because start date is built-in required field.");
Preconditions.checkNotNull(endDateAccessor, "It must not be null because end date is built-in required field.");
return new DateRange((LocalDate) converter.convert(startDateAccessor.getValue(row)), (LocalDate) converter.convert(endDateAccessor.getValue(row)));
}