Search in sources :

Example 1 with LocalDate

use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.

the class LocalDateBinding method create.

public static FieldBinding create(DateField dateField, String datePropertyName) {
    FieldBinding binding = new FieldBinding(dateField, datePropertyName);
    binding.setConverter(new Converter() {

        @Override
        public Object convertModelValue(Object value) {
            if (value == null) {
                return null;
            } else {
                return ((LocalDate) value).atMidnightInMyTimezone();
            }
        }

        @Override
        public Object convertFieldValue(Object value) {
            if (value == null) {
                return null;
            } else {
                Date dateValue = (Date) value;
                return new LocalDate(dateValue);
            }
        }
    });
    return binding;
}
Also used : FieldBinding(com.extjs.gxt.ui.client.binding.FieldBinding) Converter(com.extjs.gxt.ui.client.binding.Converter) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) Date(java.util.Date) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate)

Example 2 with LocalDate

use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.

the class OldGetSitesHandler method applyDateRangeFilter.

private void applyDateRangeFilter(String field, DateRange range, SqlQuery query) {
    LocalDate filterMinDate = range.getMinLocalDate();
    if (filterMinDate != null) {
        query.where(field).greaterThanOrEqualTo(filterMinDate);
    }
    LocalDate filterMaxDate = range.getMaxLocalDate();
    if (filterMaxDate != null) {
        query.where(field).lessThanOrEqualTo(filterMaxDate);
    }
}
Also used : LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate)

Example 3 with LocalDate

use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.

the class CreateSiteHandlerAsync method insertIndicatorValues.

private void insertIndicatorValues(SqlTransaction tx, CreateSite cmd) {
    for (Entry<String, Object> property : cmd.getProperties().getTransientMap().entrySet()) {
        if (property.getKey().startsWith(IndicatorDTO.PROPERTY_PREFIX) && property.getValue() != null) {
            Object value = property.getValue();
            SqlInsert sqlInsert = SqlInsert.insertInto(Tables.INDICATOR_VALUE).value("IndicatorId", IndicatorDTO.indicatorIdForPropertyName(property.getKey())).value("ReportingPeriodId", cmd.getReportingPeriodId());
            if (value instanceof Number) {
                if (value instanceof Double && ((Double) value).isNaN()) {
                    throw new RuntimeException("It's not allowed to send Double.NaN values for update, indicatorId: " + IndicatorDTO.indicatorIdForPropertyName(property.getKey()));
                }
                sqlInsert.value("Value", value).execute(tx);
            } else if (value instanceof String) {
                sqlInsert.value("TextValue", value).execute(tx);
            } else if (value instanceof Date) {
                sqlInsert.value("DateValue", value).execute(tx);
            } else if (value instanceof LocalDate) {
                sqlInsert.value("DateValue", value).execute(tx);
            } else if (value instanceof Boolean) {
                sqlInsert.value("BooleanValue", value).execute(tx);
            }
        }
    }
}
Also used : SqlInsert(com.bedatadriven.rebar.sql.client.query.SqlInsert) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) Date(java.util.Date) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate)

Example 4 with LocalDate

use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.

the class LockedPeriodDTO method fallsWithinPeriod.

public boolean fallsWithinPeriod(@Nonnull LocalDate date) {
    LocalDate from = getFromDate();
    LocalDate to = getToDate();
    boolean isSameAsFrom = from.compareTo(date) == 0;
    boolean isSameAsTo = to.compareTo(date) == 0;
    boolean isBetween = from.before(date) && to.after(date);
    return isBetween || isSameAsFrom || isSameAsTo;
}
Also used : LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate)

Example 5 with LocalDate

use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.

the class JsonUtil method encodeMap.

public static JsonObject encodeMap(Map<String, Object> map) {
    JsonObject root = new JsonObject();
    for (Entry<String, Object> property : map.entrySet()) {
        if (property.getValue() != null) {
            JsonObject value = new JsonObject();
            if (property.getValue() instanceof String) {
                value.addProperty("type", "String");
                value.addProperty("value", (String) property.getValue());
            } else if (property.getValue() instanceof Integer) {
                value.addProperty("type", "Integer");
                value.addProperty("value", (Integer) property.getValue());
            } else if (property.getValue() instanceof Double) {
                value.addProperty("type", "Double");
                value.addProperty("value", (Double) property.getValue());
            } else if (property.getValue() instanceof Date) {
                Date date = (Date) property.getValue();
                value.addProperty("type", "Date");
                value.addProperty("time", date.getTime());
            } else if (property.getValue() instanceof Boolean) {
                value.addProperty("type", "Boolean");
                value.addProperty("value", (Boolean) property.getValue());
            } else if (property.getValue() instanceof LocalDate) {
                value.addProperty("type", "LocalDate");
                value.addProperty("value", property.getValue().toString());
            } else {
                Log.error("Cannot convert handle map value '" + property.getKey() + ", type " + property.getKey() + ": " + property.getValue().getClass().getName());
                value = null;
            }
            if (value != null) {
                root.add(property.getKey(), value);
            }
        }
    }
    return root;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) Date(java.util.Date) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate)

Aggregations

LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)19 Test (org.junit.Test)9 Date (java.util.Date)6 HashMap (java.util.HashMap)3 LockedPeriodDTO (org.activityinfo.legacy.shared.model.LockedPeriodDTO)3 SqlInsert (com.bedatadriven.rebar.sql.client.query.SqlInsert)2 JsonObject (com.google.gson.JsonObject)2 CreateLockedPeriod (org.activityinfo.legacy.shared.command.CreateLockedPeriod)2 GetSites (org.activityinfo.legacy.shared.command.GetSites)2 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)2 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 FormTree (org.activityinfo.model.formTree.FormTree)2 ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)2 PastedTable (org.activityinfo.ui.client.component.importDialog.model.source.PastedTable)2 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 SqlTransactionCallback (com.bedatadriven.rebar.sql.client.SqlTransactionCallback)1 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)1 Converter (com.extjs.gxt.ui.client.binding.Converter)1 FieldBinding (com.extjs.gxt.ui.client.binding.FieldBinding)1