use of org.activityinfo.model.analysis.TableModel in project activityinfo by bedatadriven.
the class TableViewModelTest method test.
@Test
public void test() {
TableModel tableModel = ImmutableTableModel.builder().formId(setup.getSurveyForm().getFormId()).build();
TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
Connection<EffectiveTableModel> view = setup.connect(viewModel.getEffectiveTable());
EffectiveTableModel effectiveTableModel = view.assertLoaded();
EffectiveTableColumn nameColumn = effectiveTableModel.getColumns().get(0);
assertThat(nameColumn.getLabel(), equalTo("Respondent Name"));
// Now verify that we can update the column label
view.resetChangeCounter();
TableColumn updatedColumn = ImmutableTableColumn.builder().from(nameColumn.getModel()).label("MY column").build();
viewModel.update(ImmutableTableModel.builder().from(tableModel).columns(Arrays.asList(updatedColumn)).build());
setup.runScheduled();
// Should receive a change event...
view.assertChanged();
EffectiveTableModel updatedModel = view.assertLoaded();
assertThat(updatedModel.getColumns().get(0).getLabel(), equalTo("MY column"));
}
use of org.activityinfo.model.analysis.TableModel in project activityinfo by bedatadriven.
the class TableViewModelTest method testSubFormExport.
@Test
public void testSubFormExport() {
IncidentForm incidentForm = setup.getCatalog().getIncidentForm();
TableModel tableModel = ImmutableTableModel.builder().formId(incidentForm.getFormId()).addColumns(ImmutableTableColumn.builder().label("My PCODE").formula(IncidentForm.PROTECTION_CODE_FIELD_ID.asString()).build()).build();
TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
Connection<TableModel> exportModel = setup.connect(viewModel.computeExportModel(Observable.just(ReferralSubForm.FORM_ID), Observable.just(ExportScope.SELECTED)));
System.out.println(Json.stringify(exportModel.assertLoaded().toJson(), 2));
assertThat(exportModel.assertLoaded().getFormId(), equalTo(ReferralSubForm.FORM_ID));
assertThat(exportModel.assertLoaded().getColumns(), hasSize(3));
TableColumn firstColumn = exportModel.assertLoaded().getColumns().get(0);
assertThat(firstColumn.getLabel(), equalTo(Optional.of("My PCODE")));
assertThat(firstColumn.getFormula(), equalTo(new CompoundExpr(new SymbolNode(ColumnModel.PARENT_SYMBOL), IncidentForm.PROTECTION_CODE_FIELD_ID).asExpression()));
}
use of org.activityinfo.model.analysis.TableModel in project activityinfo by bedatadriven.
the class TableViewModel method updateColumnWidth.
@Override
public void updateColumnWidth(String columnId, int newWidth) {
TableModel model = this.tableModel.get();
List<TableColumn> updatedColumns = new ArrayList<>();
for (TableColumn column : model.getColumns()) {
if (column.getId().equals(columnId)) {
updatedColumns.add(ImmutableTableColumn.builder().from(column).width(newWidth).build());
} else {
updatedColumns.add(column);
}
}
tableModel.updateIfNotSame(ImmutableTableModel.builder().from(model).columns(updatedColumns).build());
}
use of org.activityinfo.model.analysis.TableModel in project activityinfo by bedatadriven.
the class XlsTableWriterTest method surveyForm.
@Test
public void surveyForm() throws IOException {
TableModel tableModel = ImmutableTableModel.builder().formId(catalog.getSurvey().getFormId()).build();
assertThat(export(tableModel), sameWorkbook(getWorkBook("survey-expected.xls")));
}
use of org.activityinfo.model.analysis.TableModel in project activityinfo by bedatadriven.
the class ExportFormExecutor method execute.
@Override
public ExportResult execute(ExportFormJob descriptor) throws IOException {
TableModel tableModel = descriptor.getTableModel();
GeneratedResource export = storageProvider.create(XlsTableWriter.EXCEL_MIME_TYPE, "Export.xls");
TableViewModel viewModel = new TableViewModel(formSource, tableModel);
EffectiveTableModel effectiveTableModel = viewModel.getEffectiveTable().waitFor();
ColumnSet columnSet = effectiveTableModel.getColumnSet().waitFor();
XlsTableWriter writer = new XlsTableWriter();
writer.addSheet(effectiveTableModel, columnSet);
try (OutputStream out = export.openOutputStream()) {
writer.write(out);
}
return new ExportResult(export.getDownloadUri());
}
Aggregations