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