Search in sources :

Example 6 with LocalDate

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;
}
Also used : HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) Date(java.util.Date) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate)

Example 7 with LocalDate

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);
}
Also used : Date(java.util.Date) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate)

Example 8 with LocalDate

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);
}
Also used : LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) Test(org.junit.Test)

Example 9 with LocalDate

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"));
}
Also used : LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) PartnerResult(org.activityinfo.legacy.shared.command.result.PartnerResult) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 10 with LocalDate

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()));
}
Also used : SqlTransactionCallback(com.bedatadriven.rebar.sql.client.SqlTransactionCallback) HashMap(java.util.HashMap) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) Date(java.util.Date) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) CreateSite(org.activityinfo.legacy.shared.command.CreateSite) Test(org.junit.Test)

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