Search in sources :

Example 1 with SqlInsert

use of com.bedatadriven.rebar.sql.client.query.SqlInsert in project activityinfo by bedatadriven.

the class UpdateMonthlyReportsAsync method insertPeriod.

private Promise<Void> insertPeriod(SqlTransaction tx, int siteId, Integer periodId, Month month) {
    DateRange range = DateUtilGWTImpl.INSTANCE.monthRange(month);
    SqlInsert query = SqlInsert.insertInto(Tables.REPORTING_PERIOD).value("ReportingPeriodId", periodId).value("SiteId", siteId).value("Date1", range.getMinLocalDate()).value("Date2", range.getMaxLocalDate()).value("DateCreated", new Date()).value("DateEdited", new Date());
    return executeInsert(tx, query);
}
Also used : DateRange(org.activityinfo.legacy.shared.reports.model.DateRange) SqlInsert(com.bedatadriven.rebar.sql.client.query.SqlInsert) Date(java.util.Date)

Example 2 with SqlInsert

use of com.bedatadriven.rebar.sql.client.query.SqlInsert 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 3 with SqlInsert

use of com.bedatadriven.rebar.sql.client.query.SqlInsert in project activityinfo by bedatadriven.

the class UpdateSiteHandlerAsync method updateReportingPeriod.

private void updateReportingPeriod(SqlTransaction tx, int siteId, int reportingPeriodId, Map<String, Object> changes) {
    SqlUpdate.update(Tables.REPORTING_PERIOD).where("reportingPeriodId", reportingPeriodId).value("date1", changes).value("date2", changes).execute(tx);
    for (Map.Entry<String, Object> change : changes.entrySet()) {
        if (change.getKey().startsWith(IndicatorDTO.PROPERTY_PREFIX)) {
            int indicatorId = IndicatorDTO.indicatorIdForPropertyName(change.getKey());
            Object value = change.getValue();
            SqlUpdate.delete(Tables.INDICATOR_VALUE).where("reportingPeriodId", reportingPeriodId).where("indicatorId", indicatorId).execute(tx);
            if (value != null) {
                SqlInsert sqlInsert = SqlInsert.insertInto(Tables.INDICATOR_VALUE).value("reportingPeriodId", reportingPeriodId).value("indicatorId", indicatorId);
                if (value instanceof Double) {
                    if (((Double) value).isNaN()) {
                        throw new RuntimeException("It's not allowed to send Double.NaN values for update, indicatorId: " + indicatorId);
                    }
                    sqlInsert.value("value", value).execute(tx);
                } else if (value instanceof String) {
                    sqlInsert.value("TextValue", value).execute(tx);
                } else if (value instanceof LocalDate) {
                    sqlInsert.value("DateValue", value).execute(tx);
                }
            }
        }
    }
}
Also used : SqlInsert(com.bedatadriven.rebar.sql.client.query.SqlInsert) Map(java.util.Map) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate)

Aggregations

SqlInsert (com.bedatadriven.rebar.sql.client.query.SqlInsert)3 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 Date (java.util.Date)2 Map (java.util.Map)1 DateRange (org.activityinfo.legacy.shared.reports.model.DateRange)1