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