Search in sources :

Example 16 with LocalDate

use of com.bedatadriven.rebar.time.calendar.LocalDate 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)

Example 17 with LocalDate

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

the class ImportWithMultiClassRangeTest method testSimple.

@Test
public void testSimple() throws IOException {
    setUser(3);
    FormTree formTree = assertResolves(locator.getFormTree(NFI_DISTRIBUTION_FORM_CLASS));
    FormTreePrettyPrinter.print(formTree);
    importModel = new ImportModel(formTree);
    importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
    // Step 1: User pastes in data to import
    PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "nfi.csv"), Charsets.UTF_8));
    source.parseAllRows();
    importModel.setSource(source);
    dumpList("COLUMNS", source.getColumns());
    importModel.setColumnAction(columnIndex("Date1"), target("Start Date"));
    importModel.setColumnAction(columnIndex("Date2"), target("End Date"));
    importModel.setColumnAction(columnIndex("Partner"), target("Partner Name"));
    importModel.setColumnAction(columnIndex("Localité"), target("Localité Name"));
    importModel.setColumnAction(columnIndex("Province"), target("Province Name"));
    importModel.setColumnAction(columnIndex("District"), target("District Name"));
    importModel.setColumnAction(columnIndex("Territoire"), target("Territoire Name"));
    importModel.setColumnAction(columnIndex("Secteur"), target("Secteur Name"));
    importModel.setColumnAction(columnIndex("Groupement"), target("Groupement Name"));
    importModel.setColumnAction(columnIndex("Zone de Santé"), target("Zone de Santé Name"));
    importModel.setColumnAction(columnIndex("Nombre de ménages ayant reçu une assistance en NFI"), target("Nombre de ménages ayant reçu une assistance en NFI"));
    ValidatedRowTable validatedResult = assertResolves(importer.validateRows(importModel));
    showValidationGrid(validatedResult);
    assertResolves(importer.persist(importModel));
    GetSites query = new GetSites(Filter.filter().onActivity(33));
    query.setSortInfo(new SortInfo("date2", Style.SortDir.DESC));
    SiteResult result = execute(query);
    // 651 - 8 = 643 (8 records where start date is before end date)
    assertThat(result.getTotalLength(), equalTo(643));
    // assertThat(result.getTotalLength(), equalTo(313));
    SiteDTO lastSite = result.getData().get(0);
    // assertThat(lastSite.getDate2(), equalTo(new LocalDate(2013,4,26)));
    assertThat(lastSite.getDate2(), equalTo(new LocalDate(2013, 4, 30)));
    assertThat(lastSite.getLocationName(), equalTo("Kilimani Camp"));
    assertThat(lastSite.getAdminEntity(PROVINCE_LEVEL).getName(), equalTo("Nord Kivu"));
    assertThat(lastSite.getAdminEntity(DISTRICT_LEVEL).getName(), equalTo("Nord Kivu"));
    assertThat(lastSite.getAdminEntity(TERRITOIRE_LEVEL).getName(), equalTo("Masisi"));
    assertThat(lastSite.getAdminEntity(SECTEUR_LEVEL).getName(), equalTo("Masisi"));
    assertThat((Double) lastSite.getIndicatorValue(NUMBER_MENAGES), equalTo(348.0));
    assertThat(lastSite.getAttributeValue(ECHO), equalTo(false));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) ValidatedRowTable(org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable) GetSites(org.activityinfo.legacy.shared.command.GetSites) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) Test(org.junit.Test)

Example 18 with LocalDate

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

the class LockedPeriodGrid method createGrid.

private void createGrid() {
    List<ColumnConfig> configs = new ArrayList<>();
    columnEnabled = new EditCheckColumnConfig("enabled", I18N.CONSTANTS.enabledColumn(), 55);
    columnEnabled.setSortable(false);
    ColumnConfig columnPeriodType = new ColumnConfig();
    columnPeriodType.setHeaderText(I18N.CONSTANTS.type());
    columnPeriodType.setToolTip(I18N.CONSTANTS.type());
    columnPeriodType.setWidth(48);
    columnPeriodType.setRowHeader(true);
    columnPeriodType.setRenderer(new LockTypeIconCellRenderer());
    configs.add(columnEnabled);
    configs.add(columnPeriodType);
    configs.add(new ReadTextColumn("parentName", I18N.CONSTANTS.parentName(), 150));
    configs.add(new ReadTextColumn("name", I18N.CONSTANTS.name(), 100));
    configs.add(new EditableLocalDateColumn("fromDate", I18N.CONSTANTS.fromDate(), 100));
    configs.add(new EditableLocalDateColumn("toDate", I18N.CONSTANTS.toDate(), 100));
    lockedPeriodGrid = new EditorGrid<>(lockedPeriodStore, new ColumnModel(configs));
    lockedPeriodGrid.addListener(Events.ValidateEdit, new Listener<BaseEvent>() {

        @Override
        public void handleEvent(BaseEvent baseEvent) {
            GridEvent gridEvent = (GridEvent) baseEvent;
            LockedPeriodDTO model = (LockedPeriodDTO) gridEvent.getModel();
            LocalDate fromDate = model.getFromDate();
            LocalDate toDate = model.getToDate();
            if ("fromDate".equals(gridEvent.getProperty())) {
                fromDate = (LocalDate) gridEvent.getValue();
            }
            if ("toDate".equals(gridEvent.getProperty())) {
                toDate = (LocalDate) gridEvent.getValue();
            }
            if (!fromDate.before(toDate) && !fromDate.equals(toDate)) {
                MessageBox.alert(I18N.CONSTANTS.alert(), I18N.CONSTANTS.fromDateIsBeforeToDate(), null);
                lockedPeriodGrid.getActiveEditor().cancelEdit();
            }
        }
    });
    lockedPeriodGrid.addListener(Events.OnClick, new Listener<ComponentEvent>() {

        @Override
        public void handleEvent(ComponentEvent be) {
            updateState(be);
        }
    });
    add(lockedPeriodGrid);
}
Also used : ReadTextColumn(org.activityinfo.ui.client.page.common.columns.ReadTextColumn) ArrayList(java.util.ArrayList) EditableLocalDateColumn(org.activityinfo.ui.client.page.common.columns.EditableLocalDateColumn) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) LockedPeriodDTO(org.activityinfo.legacy.shared.model.LockedPeriodDTO)

Example 19 with LocalDate

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

the class TargetTest method updateTarget.

@Test
public void updateTarget() throws Throwable {
    LocalDate fromDate = new LocalDate(2015, 3, 3);
    LocalDate toDate = new LocalDate(2015, 3, 4);
    Map<String, Object> changes = new HashMap<String, Object>();
    changes.put("name", "newNameOfTarget");
    changes.put("fromDate", fromDate);
    changes.put("toDate", toDate);
    execute(new BatchCommand(new UpdateEntity("Target", 1, changes)));
    List<TargetDTO> targets = execute(new GetTargets(db.getId())).getData();
    TargetDTO dto = getTargetById(targets, 1);
    assertThat(dto.getName(), equalTo("newNameOfTarget"));
    assertThat(dto.getFromDate(), equalTo(fromDate));
    assertThat(dto.getToDate(), equalTo(toDate));
}
Also used : HashMap(java.util.HashMap) TargetDTO(org.activityinfo.legacy.shared.model.TargetDTO) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) 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