Search in sources :

Example 6 with TableModel

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));
        }
    });
}
Also used : JsonValue(org.activityinfo.json.JsonValue) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) ExportFormJob(org.activityinfo.model.job.ExportFormJob) Response(javax.ws.rs.core.Response) JobStatus(org.activityinfo.model.job.JobStatus) JobRequest(org.activityinfo.model.job.JobRequest) VoidWork(com.googlecode.objectify.VoidWork) Queue(com.google.appengine.api.taskqueue.Queue) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) Test(org.junit.Test)

Example 7 with TableModel

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;
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) FormSource(org.activityinfo.store.query.shared.FormSource) ParsedFormula(org.activityinfo.analysis.ParsedFormula) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResourceId(org.activityinfo.model.resource.ResourceId) TableModel(org.activityinfo.model.analysis.TableModel) Optional(com.google.common.base.Optional) ColumnModel(org.activityinfo.model.query.ColumnModel) Map(java.util.Map) RecordTree(org.activityinfo.model.formTree.RecordTree) RecordRef(org.activityinfo.model.type.RecordRef) Nullable(javax.annotation.Nullable) SymbolNode(org.activityinfo.model.formula.SymbolNode) Function(com.google.common.base.Function) StatefulValue(org.activityinfo.observable.StatefulValue) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) TableColumn(org.activityinfo.model.analysis.TableColumn) Logger(java.util.logging.Logger) FormulaNode(org.activityinfo.model.formula.FormulaNode) List(java.util.List) ColumnSet(org.activityinfo.model.query.ColumnSet) Observable(org.activityinfo.observable.Observable) ImmutableTableColumn(org.activityinfo.model.analysis.ImmutableTableColumn) FormTree(org.activityinfo.model.formTree.FormTree) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel)

Example 8 with TableModel

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)));
}
Also used : JsonValue(org.activityinfo.json.JsonValue) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) Test(org.junit.Test)

Example 9 with TableModel

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));
}
Also used : TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) Test(org.junit.Test)

Example 10 with TableModel

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));
}
Also used : ColumnSet(org.activityinfo.model.query.ColumnSet) TableModel(org.activityinfo.model.analysis.TableModel) ImmutableTableModel(org.activityinfo.model.analysis.ImmutableTableModel) IncidentForm(org.activityinfo.store.testing.IncidentForm) Test(org.junit.Test)

Aggregations

TableModel (org.activityinfo.model.analysis.TableModel)12 ImmutableTableModel (org.activityinfo.model.analysis.ImmutableTableModel)11 Test (org.junit.Test)9 ImmutableTableColumn (org.activityinfo.model.analysis.ImmutableTableColumn)4 TableColumn (org.activityinfo.model.analysis.TableColumn)4 ColumnSet (org.activityinfo.model.query.ColumnSet)3 Optional (com.google.common.base.Optional)2 ArrayList (java.util.ArrayList)2 EffectiveTableModel (org.activityinfo.analysis.table.EffectiveTableModel)2 JsonValue (org.activityinfo.json.JsonValue)2 CompoundExpr (org.activityinfo.model.formula.CompoundExpr)2 SymbolNode (org.activityinfo.model.formula.SymbolNode)2 RecordRef (org.activityinfo.model.type.RecordRef)2 IncidentForm (org.activityinfo.store.testing.IncidentForm)2 Queue (com.google.appengine.api.taskqueue.Queue)1 Function (com.google.common.base.Function)1 VoidWork (com.googlecode.objectify.VoidWork)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1