use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.
the class JsonUtil method decodeMap.
public static Map<String, Object> decodeMap(JsonObject root) {
Map<String, Object> map = new HashMap<String, Object>();
for (Entry<String, JsonElement> property : root.entrySet()) {
JsonObject value = (JsonObject) property.getValue();
String type = value.get("type").getAsString();
if ("String".equals(type)) {
map.put(property.getKey(), value.get("value").getAsString());
} else if ("Integer".equals(type)) {
map.put(property.getKey(), value.get("value").getAsInt());
} else if ("Double".equals(type)) {
map.put(property.getKey(), value.get("value").getAsDouble());
} else if ("Date".equals(type)) {
map.put(property.getKey(), new Date(value.get("time").getAsLong()));
} else if ("Boolean".equals(type)) {
map.put(property.getKey(), value.get("value").getAsBoolean());
} else if ("LocalDate".equals(type)) {
map.put(property.getKey(), LocalDate.parse(value.get("value").getAsString()));
} else {
throw new IllegalArgumentException("map contains key with unsupported value type -- " + property.getKey() + ": " + type);
}
}
return map;
}
use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.
the class BaseEntityHandler method updateLockedPeriodProperties.
protected void updateLockedPeriodProperties(LockedPeriod lockedPeriod, Map<String, Object> changes) {
if (changes.containsKey(EntityDTO.NAME_PROPERTY)) {
lockedPeriod.setName(trimAndTruncate(changes.get(EntityDTO.NAME_PROPERTY)));
}
if (changes.containsKey(LockedPeriodDTO.END_DATE_PROPERTY)) {
lockedPeriod.setToDate((LocalDate) changes.get(LockedPeriodDTO.END_DATE_PROPERTY));
}
if (changes.containsKey(LockedPeriodDTO.START_DATE_PROPERTY)) {
lockedPeriod.setFromDate((LocalDate) changes.get(LockedPeriodDTO.START_DATE_PROPERTY));
}
if (changes.containsKey(LockedPeriodDTO.ENABLED_PROPERTY)) {
lockedPeriod.setEnabled((Boolean) changes.get(LockedPeriodDTO.ENABLED_PROPERTY));
}
if (!lockedPeriod.getFromDate().before(lockedPeriod.getToDate()) && !lockedPeriod.getFromDate().equals(lockedPeriod.getToDate())) {
throw new IllegalArgumentException("From date is not before To date. Refuse lock object persistence: " + lockedPeriod);
}
lockedPeriod.getParentDatabase().setLastSchemaUpdate(new Date());
entityManager().merge(lockedPeriod);
}
use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.
the class FilterUrlSerializerTest method withDates.
@Test
public void withDates() {
Filter filter = new Filter();
filter.getEndDateRange().setMinDate(new LocalDate(2011, 4, 19));
filter.getEndDateRange().setMaxDate(new LocalDate(2012, 3, 31));
filter.addRestriction(DimensionType.Activity, 1);
filter.addRestriction(DimensionType.Database, Sets.newHashSet(31, 42));
verifyCorrectSerde(filter);
}
use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.
the class GetPartnersDimensionHandlerTest method testActivityWithDateFilter.
@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void testActivityWithDateFilter() throws CommandException {
Filter filter = new Filter();
filter.addRestriction(DimensionType.Activity, 1);
filter.getEndDateRange().setMinDate(new LocalDate(1998, 1, 1).atMidnightInMyTimezone());
filter.getEndDateRange().setMaxDate(new LocalDate(2099, 1, 15).atMidnightInMyTimezone());
PartnerResult result = execute(filter);
assertThat(result.getData().size(), equalTo(2));
assertThat(result.getData().get(0).getName(), equalTo("NRC"));
assertThat(result.getData().get(1).getName(), equalTo("Solidarites"));
}
use of com.bedatadriven.rebar.time.calendar.LocalDate in project activityinfo by bedatadriven.
the class CommandQueueTest method testCreateSite.
@Test
public void testCreateSite() {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("anInt", 34);
properties.put("aString", "testing");
properties.put("aDouble", 3.0);
properties.put("aBoolean", true);
properties.put("anotherBoolean", false);
properties.put("aTime", new Date());
properties.put("aDate", new LocalDate(2011, 3, 15));
final CreateSite cmd = new CreateSite(properties);
db.transaction(new SqlTransactionCallback() {
@Override
public void begin(SqlTransaction tx) {
queue.queue(tx, cmd);
}
});
Collector<CommandQueue.QueueEntry> reread = Collector.newCollector();
queue.peek(reread);
assertThat(reread.getResult(), not(nullValue()));
assertThat(cmd, equalTo(reread.getResult().getCommand()));
Collector<Void> deleted = Collector.newCollector();
queue.remove(reread.getResult(), deleted);
Collector<CommandQueue.QueueEntry> entry2 = Collector.newCollector();
queue.peek(entry2);
assertThat(entry2.getResult(), is(nullValue()));
}
Aggregations