Search in sources :

Example 16 with FormTree

use of org.activityinfo.model.formTree.FormTree in project activityinfo by bedatadriven.

the class FormulaValidator method findCalculatedFieldType.

private FieldType findCalculatedFieldType(FormTree.Node fieldNode) {
    CalculatedFieldType fieldType = (CalculatedFieldType) fieldNode.getType();
    FormulaNode rootNode;
    try {
        rootNode = FormulaParser.parse(fieldType.getExpression());
    } catch (FormulaException e) {
        throw new ValidationFailed();
    }
    FormClass formClass = fieldNode.getDefiningFormClass();
    FormTree subTree = formTree.subTree(formClass.getId());
    FormulaValidator validator = new FormulaValidator(subTree);
    if (!validator.validate(rootNode)) {
        throw new ValidationFailed();
    }
    return validator.getResultType();
}
Also used : CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) FormTree(org.activityinfo.model.formTree.FormTree) FormClass(org.activityinfo.model.form.FormClass) FormulaException(org.activityinfo.model.formula.diagnostic.FormulaException)

Example 17 with FormTree

use of org.activityinfo.model.formTree.FormTree in project activityinfo by bedatadriven.

the class GetSitesHandler method buildQueries.

private void buildQueries() {
    TraceContext queryBuildTrace = Trace.startSpan("ai/cmd/GetSites/buildQuery");
    queryBuildTime.start();
    for (Map.Entry<ResourceId, FormTree> formTreeEntry : formTreeMap.entrySet()) {
        addToQueryMap(formTreeEntry, null);
    }
    if (command.isFetchLinks() && linkedFormTreeMap != null) {
        for (Map.Entry<ResourceId, FormTree> linkedFormTreeEntry : linkedFormTreeMap.entrySet()) {
            for (ActivityLink activityLink : activityLinkMap.get(CuidAdapter.getLegacyIdFromCuid(linkedFormTreeEntry.getKey()))) {
                addToQueryMap(linkedFormTreeEntry, activityLink);
            }
        }
    }
    queryBuildTime.stop();
    Trace.endSpan(queryBuildTrace);
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) TraceContext(com.google.cloud.trace.core.TraceContext)

Example 18 with FormTree

use of org.activityinfo.model.formTree.FormTree in project activityinfo by bedatadriven.

the class FormResource method buildDefaultQueryModel.

private QueryModel buildDefaultQueryModel() {
    QueryModel queryModel;
    FormTreeBuilder treeBuilder = new FormTreeBuilder(backend.getStorage());
    FormTree tree = treeBuilder.queryTree(formId);
    queryModel = new DefaultQueryBuilder(tree).build();
    return queryModel;
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) QueryModel(org.activityinfo.model.query.QueryModel) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) JsonFormTreeBuilder(org.activityinfo.model.formTree.JsonFormTreeBuilder)

Example 19 with FormTree

use of org.activityinfo.model.formTree.FormTree in project activityinfo by bedatadriven.

the class ImportGeoTest method test.

@Test
public void test() throws IOException {
    FormTree formTree = assertResolves(locator.getFormTree(CuidAdapter.locationFormClass(1451)));
    FormTreePrettyPrinter.print(formTree);
    importModel = new ImportModel(formTree);
    // Step 1: User pastes in data to import
    PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "somali-camps-cleaned.txt"), Charsets.UTF_8));
    source.parseAllRows();
    importModel.setSource(source);
    importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
    assertThat(importer.getImportTargets(), contains(hasProperty("label", Matchers.equalTo("Name")), hasProperty("label", Matchers.equalTo("Alternate Name")), hasProperty("label", Matchers.equalTo("Region Name")), hasProperty("label", Matchers.equalTo("Region Code")), hasProperty("label", Matchers.equalTo("District Name")), hasProperty("label", Matchers.equalTo("District Code")), hasProperty("label", Matchers.equalTo("Latitude")), hasProperty("label", Matchers.equalTo("Longitude"))));
    dumpList("COLUMNS", source.getColumns());
    // Step 2: User maps imported columns to FormFields
    dumpList("FIELDS", importer.getImportTargets());
    importModel.setColumnAction(columnIndex("Region"), target("Region Name"));
    importModel.setColumnAction(columnIndex("Admin2"), target("District Name"));
    importModel.setColumnAction(columnIndex("Village Name"), target("Name"));
    importModel.setColumnAction(columnIndex("Pcode"), target("Alternate Name"));
    importModel.setColumnAction(columnIndex("Latitude"), target("Latitude"));
    importModel.setColumnAction(columnIndex("Longitude"), target("Longitude"));
    // Step 3: Validate for user
    ValidatedRowTable validatedResult = assertResolves(importer.validateRows(importModel));
    showValidationGrid(validatedResult);
    assertResolves(importer.persist(importModel));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) ValidatedRowTable(org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) Test(org.junit.Test)

Example 20 with FormTree

use of org.activityinfo.model.formTree.FormTree in project activityinfo by bedatadriven.

the class ImportSimpleTest method test.

@Test
public void test() throws IOException {
    FormTree formTree = assertResolves(locator.getFormTree(HOUSEHOLD_SURVEY_FORM_CLASS));
    FormTreePrettyPrinter.print(formTree);
    importModel = new ImportModel(formTree);
    // Step 1: User pastes in data to import
    PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "qis.csv"), Charsets.UTF_8));
    source.parseAllRows();
    assertThat(source.getRows().size(), equalTo(63));
    importModel.setSource(source);
    importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
    dumpList("COLUMNS", source.getColumns());
    // Step 2: User maps imported columns to FormFields
    dumpList("FIELDS", importer.getImportTargets());
    importModel.setColumnAction(columnIndex("MEMBER_NO_ADULT_FEMALE"), target("NumAdultMale"));
    importModel.setColumnAction(columnIndex("MEMBER_NO_ADULT_FEMALE"), target("NumAdultFemale"));
    importModel.setColumnAction(columnIndex("_CREATION_DATE"), target("Start Date"));
    importModel.setColumnAction(columnIndex("_SUBMISSION_DATE"), target("End Date"));
    importModel.setColumnAction(columnIndex("district name"), target("District Name"));
    importModel.setColumnAction(columnIndex("upazila"), target("Upzilla Name"));
    importModel.setColumnAction(columnIndex("Partner"), target("Partner Name"));
    // Step 3: Validate for user
    ValidatedRowTable validatedResult = assertResolves(importer.validateRows(importModel));
    showValidationGrid(validatedResult);
    assertResolves(importer.persist(importModel));
    // VERIFY total count
    SiteResult allResults = execute(new GetSites(Filter.filter().onActivity(1)));
    assertThat(allResults.getData().size(), equalTo(63));
    // AND... verify
    Filter filter = new Filter();
    filter.addRestriction(DimensionType.AdminLevel, MODHUPUR);
    SiteResult sites = execute(new GetSites(filter));
    assertThat(sites.getTotalLength(), equalTo(1));
    SiteDTO site = sites.getData().get(0);
    assertThat(site.getDate1(), equalTo(new LocalDate(2012, 12, 19)));
    assertThat(site.getDate2(), equalTo(new LocalDate(2012, 12, 19)));
    assertThat(site.getAdminEntity(3), not(nullValue()));
}
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) Filter(org.activityinfo.legacy.shared.command.Filter) 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) Test(org.junit.Test)

Aggregations

FormTree (org.activityinfo.model.formTree.FormTree)55 Test (org.junit.Test)35 ResourceId (org.activityinfo.model.resource.ResourceId)12 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)10 FormClass (org.activityinfo.model.form.FormClass)9 ColumnSet (org.activityinfo.model.query.ColumnSet)9 QueryModel (org.activityinfo.model.query.QueryModel)8 ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)8 PastedTable (org.activityinfo.ui.client.component.importDialog.model.source.PastedTable)8 FormField (org.activityinfo.model.form.FormField)7 RecordRef (org.activityinfo.model.type.RecordRef)7 LookupKeySet (org.activityinfo.model.formTree.LookupKeySet)6 FormulaNode (org.activityinfo.model.formula.FormulaNode)6 ReferenceType (org.activityinfo.model.type.ReferenceType)6 LookupKey (org.activityinfo.model.formTree.LookupKey)5 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)5 Optional (com.google.common.base.Optional)4 ColumnView (org.activityinfo.model.query.ColumnView)4 Nullable (javax.annotation.Nullable)3 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)3