use of org.activityinfo.model.analysis.TableModel in project activityinfo by bedatadriven.
the class JobResourceTest method startJob.
@Test
public void startJob() {
final org.activityinfo.json.JsonParser parser = new org.activityinfo.json.JsonParser();
final Queue queue = QueueFactory.getDefaultQueue();
final AuthenticatedUser user = new AuthenticatedUser("XYZ", 1, "akbertram@gmail.com");
final JobResource resource = new JobResource(Providers.of(user), queue);
// First request starts the job
final String jobId = ObjectifyService.run(new Work<String>() {
@Override
public String run() {
TableModel tableModel = ImmutableTableModel.builder().formId(ResourceId.valueOf("FORM1")).build();
ExportFormJob exportForm = new ExportFormJob(tableModel);
JobRequest request = new JobRequest(exportForm, "en");
Response response = resource.start(request.toJsonObject().toJson());
JsonValue resultObject = parser.parse((String) response.getEntity());
JobStatus result = JobStatus.fromJson(resultObject);
assertThat(result.getState(), equalTo(JobState.STARTED));
return result.getId();
}
});
// Second request retrieves status
ObjectifyService.run(new VoidWork() {
@Override
public void vrun() {
Response statusResponse = resource.get(jobId);
JsonValue statusObject = parser.parse(((String) statusResponse.getEntity()));
JobStatus status = JobStatus.fromJson(statusObject);
assertThat(status.getState(), equalTo(JobState.STARTED));
}
});
}
use of org.activityinfo.model.analysis.TableModel in project activityinfo by bedatadriven.
the class TableViewModel method getEffectiveSubTable.
public Observable<EffectiveTableModel> getEffectiveSubTable(final ResourceId subFormId) {
Observable<EffectiveTableModel> effectiveSubTable = effectiveSubTables.get(subFormId);
if (effectiveSubTable == null) {
final TableModel subModel = ImmutableTableModel.builder().formId(subFormId).build();
effectiveSubTable = formTree.transform(tree -> tree.subTree(subFormId)).transform(subTree -> new EffectiveTableModel(formStore, subTree, subModel, Optional.of(getSelectedRecordRef())));
effectiveSubTables.put(subFormId, effectiveSubTable);
}
return effectiveSubTable;
}
use of org.activityinfo.model.analysis.TableModel in project activityinfo by bedatadriven.
the class TableViewModelTest method serializeModel.
@Test
public void serializeModel() {
ImmutableTableModel model = ImmutableTableModel.builder().formId(ResourceId.valueOf("MY_FORM")).addColumns(ImmutableTableColumn.builder().id("c1").label("Foo Squared").formula("foo*foo").build()).addColumns(ImmutableTableColumn.builder().id("c2").formula("foo").build()).build();
JsonValue object = model.toJson();
TableModel remodel = TableModel.fromJson(object);
assertThat(remodel.getFormId(), equalTo(model.getFormId()));
assertThat(remodel.getColumns(), hasSize(2));
assertThat(remodel.getColumns().get(0), equalTo(model.getColumns().get(0)));
assertThat(remodel.getColumns().get(1), equalTo(model.getColumns().get(1)));
}
use of org.activityinfo.model.analysis.TableModel in project activityinfo by bedatadriven.
the class TableViewModelTest method testDeletedForm.
@Test
public void testDeletedForm() {
TableModel tableModel = ImmutableTableModel.builder().formId(setup.getSurveyForm().getFormId()).build();
setup.deleteForm(setup.getSurveyForm().getFormId());
TableViewModel model = new TableViewModel(setup.getFormStore(), tableModel);
Connection<EffectiveTableModel> view = setup.connect(model.getEffectiveTable());
EffectiveTableModel effectiveTableModel = view.assertLoaded();
assertThat(effectiveTableModel.getFormTree().getRootState(), equalTo(FormTree.State.DELETED));
}
use of org.activityinfo.model.analysis.TableModel in project activityinfo by bedatadriven.
the class TableViewModelTest method testSubFormPane.
@Test
public void testSubFormPane() {
IncidentForm incidentForm = setup.getCatalog().getIncidentForm();
TableModel tableModel = ImmutableTableModel.builder().formId(incidentForm.getFormId()).build();
TableViewModel viewModel = new TableViewModel(setup.getFormStore(), tableModel);
Connection<EffectiveTableModel> subTableView = setup.connect(viewModel.getEffectiveSubTable(ReferralSubForm.FORM_ID));
Connection<ColumnSet> subTable = setup.connect(subTableView.assertLoaded().getColumnSet());
// The sub table should not include parent forms
for (EffectiveTableColumn subColumn : subTableView.assertLoaded().getColumns()) {
if (subColumn.getLabel().equals(incidentForm.getUrgencyField().getLabel())) {
throw new AssertionError("Sub table should not include parent fields");
}
}
// Initially there should be no rows because there is no selection
assertThat(subTable.assertLoaded().getNumRows(), equalTo(0));
// Once we make a selection, then the column set should update to show the sub records of the selected
// parent record
subTable.resetChangeCounter();
viewModel.select(incidentForm.getRecordRef(0));
setup.runScheduled();
subTable.assertChanged();
assertThat(subTable.assertLoaded().getNumRows(), equalTo(4));
}
Aggregations