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