Search in sources :

Example 1 with ImportModel

use of org.activityinfo.ui.client.component.importDialog.model.ImportModel in project activityinfo by bedatadriven.

the class ValidateClassImportCommand method doClassValidation.

private List<ValidationResult> doClassValidation() {
    final ImportModel model = commandExecutor.getImportModel();
    final List<ValidationResult> validationResults = Lists.newArrayList();
    // Class based validation : check whether all mandatory fields has mapped
    for (FormTree.Node node : model.getFormTree().getRootFields()) {
        if (node.getField().isRequired() && model.getMapExistingActions(node.getField().getId()).isEmpty()) {
            final String fieldLabel = node.getField().getLabel();
            validationResults.add(ValidationResult.error(I18N.MESSAGES.fieldIsMandatory(fieldLabel)));
        }
    }
    return validationResults;
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) ValidationResult(org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)

Example 2 with ImportModel

use of org.activityinfo.ui.client.component.importDialog.model.ImportModel 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 3 with ImportModel

use of org.activityinfo.ui.client.component.importDialog.model.ImportModel 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)

Example 4 with ImportModel

use of org.activityinfo.ui.client.component.importDialog.model.ImportModel in project activityinfo by bedatadriven.

the class ImportSimpleTest method locationWithMissingAdminLevel.

@Test
public void locationWithMissingAdminLevel() throws IOException {
    FormTree formTree = assertResolves(locator.getFormTree(VILLAGE_FORM_ID));
    FormTreePrettyPrinter.print(formTree);
    importModel = new ImportModel(formTree);
    // Step 1: User pastes in data to import
    PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "qis-villages.csv"), Charsets.UTF_8));
    source.parseAllRows();
    assertThat(source.getRows().size(), equalTo(1));
    importModel.setSource(source);
    importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
    dumpList("COLUMNS", source.getColumns());
    // Step 2: User maps imported columns to FormFields
    List<ImportTarget> targets = importer.getImportTargets();
    dumpList("FIELDS", targets);
    importModel.setColumnAction(columnIndex("Name"), target("Name"));
    importModel.setColumnAction(columnIndex("District"), target("District Name"));
    // Step 3: Validate for user
    ValidatedRowTable validatedResult = assertResolves(importer.validateRows(importModel));
    showValidationGrid(validatedResult);
    assertResolves(importer.persist(importModel));
    // AND... verify
    QueryModel queryModel = new QueryModel(VILLAGE_FORM_ID);
    queryModel.selectExpr("Name").as("name");
    queryModel.selectField(CuidAdapter.field(VILLAGE_FORM_ID, CuidAdapter.ADMIN_FIELD)).as("admin");
    ColumnSet columnSet = assertResolves(locator.queryTable(queryModel));
    assertThat(columnSet.getNumRows(), equalTo(1));
    assertThat(columnSet.getColumnView("name").getString(0), equalTo("Village 1"));
    assertThat(columnSet.getColumnView("admin").getString(0), equalTo(CuidAdapter.cuid(CuidAdapter.ADMIN_ENTITY_DOMAIN, 2).asString()));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) ImportTarget(org.activityinfo.ui.client.component.importDialog.model.strategy.ImportTarget) ValidatedRowTable(org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable) ColumnSet(org.activityinfo.model.query.ColumnSet) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 5 with ImportModel

use of org.activityinfo.ui.client.component.importDialog.model.ImportModel in project activityinfo by bedatadriven.

the class ImportSimpleTest method testExceptionHandling.

@Test
public void testExceptionHandling() throws IOException {
    FormTree formTree = assertResolves(locator.getFormTree(HOUSEHOLD_SURVEY_FORM_CLASS));
    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));
    importModel.setSource(source);
    importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
    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"));
    Promise<Void> result = importer.persist(importModel);
    assertThat(result.getState(), equalTo(Promise.State.REJECTED));
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) Test(org.junit.Test)

Aggregations

ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)11 FormTree (org.activityinfo.model.formTree.FormTree)9 PastedTable (org.activityinfo.ui.client.component.importDialog.model.source.PastedTable)8 Test (org.junit.Test)8 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)7 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 GetSites (org.activityinfo.legacy.shared.command.GetSites)2 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)2 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 ColumnSet (org.activityinfo.model.query.ColumnSet)2 QueryModel (org.activityinfo.model.query.QueryModel)2 SourceRow (org.activityinfo.ui.client.component.importDialog.model.source.SourceRow)2 FieldImporter (org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter)2 ValidatedRow (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRow)2 ValidationResult (org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)2 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)1 Nullable (javax.annotation.Nullable)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 FormInstance (org.activityinfo.model.form.FormInstance)1 FieldPath (org.activityinfo.model.formTree.FieldPath)1