Search in sources :

Example 1 with DateRange

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

Example 2 with DateRange

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();
}
Also used : DateRange(org.activityinfo.model.date.DateRange) FormClass(org.activityinfo.model.form.FormClass)

Example 3 with DateRange

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)));
}
Also used : DateRange(org.activityinfo.model.date.DateRange) FormField(org.activityinfo.model.form.FormField)

Aggregations

DateRange (org.activityinfo.model.date.DateRange)3 FormField (org.activityinfo.model.form.FormField)2 Date (java.util.Date)1 FormClass (org.activityinfo.model.form.FormClass)1 LocalDate (org.activityinfo.model.type.time.LocalDate)1