Search in sources :

Example 1 with PastedTable

use of org.activityinfo.ui.client.component.importDialog.model.source.PastedTable 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 2 with PastedTable

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

use of org.activityinfo.ui.client.component.importDialog.model.source.PastedTable 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 4 with PastedTable

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

the class PastedTableTest method libreOfficeImport.

@Test
public void libreOfficeImport() throws IOException {
    PastedTable pastedTable = new PastedTable(Resources.toString(getResource(getClass(), "somali-camps.txt"), Charsets.UTF_8));
    pastedTable.parseAllRows();
    pastedTable.guessColumnsType(JvmConverterFactory.get());
    assertThat(pastedTable.getColumns(), contains(hasProperty("header", equalTo("Region")), hasProperty("header", equalTo("District")), hasProperty("header", equalTo("Village/camp")), hasProperty("header", equalTo("Village Name")), hasProperty("header", equalTo("Pcode")), hasProperty("header", equalTo("Latitude")), hasProperty("header", equalTo("Longitude"))));
}
Also used : PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) Test(org.junit.Test)

Example 5 with PastedTable

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

the class PastedTableTest method parser.

@Test
public void parser() throws IOException {
    PastedTable pastedTable = new PastedTable(Resources.toString(getResource(getClass(), "qis.csv"), Charsets.UTF_8));
    pastedTable.parseAllRows();
    final List<SourceColumn> columns = pastedTable.getColumns();
    final List<? extends SourceRow> rows = pastedTable.getRows();
    Assert.assertEquals(columns.size(), 47);
    Assert.assertEquals(rows.size(), 63);
}
Also used : PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) SourceColumn(org.activityinfo.ui.client.component.importDialog.model.source.SourceColumn) Test(org.junit.Test)

Aggregations

PastedTable (org.activityinfo.ui.client.component.importDialog.model.source.PastedTable)19 Test (org.junit.Test)16 FormTree (org.activityinfo.model.formTree.FormTree)8 ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)8 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)5 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)3 SourceColumn (org.activityinfo.ui.client.component.importDialog.model.source.SourceColumn)3 SchemaImporterV3 (org.activityinfo.ui.client.page.config.design.importer.SchemaImporterV3)3 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 SortInfo (com.extjs.gxt.ui.client.data.SortInfo)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 FormClass (org.activityinfo.model.form.FormClass)1 FieldPath (org.activityinfo.model.formTree.FieldPath)1 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)1 FormTreePrettyPrinter (org.activityinfo.model.formTree.FormTreePrettyPrinter)1