Search in sources :

Example 11 with PastedTable

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

the class InstanceScoreTest method adminEntityScoring.

@OnDataSet("/dbunit/nfi-import.db.xml")
@Test
public void adminEntityScoring() throws IOException {
    setUser(3);
    FormTree formTree = assertResolves(locator.getFormTree(ImportWithMultiClassRangeTest.SCHOOL_FORM_CLASS));
    FormTreePrettyPrinter.print(formTree);
    importModel = new ImportModel(formTree);
    importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
    // Step 1: User pastes in data to import
    PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "school-import.csv"), Charsets.UTF_8));
    importModel.setSource(source);
    dumpList("COLUMNS", source.getColumns());
    importModel.setColumnAction(columnIndex("School"), target("Name"));
    // Province is at the root of both hierarchies
    importModel.setColumnAction(columnIndex("Province"), target("Province Name"));
    // Admin hierarchy
    importModel.setColumnAction(columnIndex("District"), target("District Name"));
    importModel.setColumnAction(columnIndex("Territoire"), target("Territoire Name"));
    importModel.setColumnAction(columnIndex("Secteur"), target("Secteur Name"));
    importModel.setColumnAction(columnIndex("Groupement"), target("Secteur Name"));
    // health ministry hierarchy
    importModel.setColumnAction(columnIndex("Zone de Santé"), target("Zone de Santé Name"));
    FormTree.Node rootField = formTree.getRootField(ADMINISTRATIVE_UNIT_FIELD);
    TargetCollector targetCollector = new TargetCollector(rootField);
    Map<TargetSiteId, ColumnAccessor> mappedColumns = importModel.getMappedColumns(rootField.getFieldId());
    List<ColumnAccessor> sourceColumns = Lists.newArrayList();
    Map<FieldPath, Integer> referenceFields = targetCollector.getPathMap(mappedColumns, sourceColumns);
    // Province level
    ColumnSet columnSet = assertResolves(query(referenceFields, ImportWithMultiClassRangeTest.PROVINCE_LEVEL));
    InstanceScoreSource scoreSource = new InstanceScoreSourceBuilder(CuidAdapter.adminLevelFormClass(ImportWithMultiClassRangeTest.PROVINCE_LEVEL), referenceFields, sourceColumns).build(columnSet);
    InstanceScorer.Score score = score(source.getRows().get(0), scoreSource);
    assertScore(score, "Katanga");
    // District level
    columnSet = assertResolves(query(referenceFields, ImportWithMultiClassRangeTest.DISTRICT_LEVEL));
    scoreSource = new InstanceScoreSourceBuilder(CuidAdapter.adminLevelFormClass(ImportWithMultiClassRangeTest.DISTRICT_LEVEL), referenceFields, sourceColumns).build(columnSet);
    score = score(source.getRows().get(1), scoreSource);
    assertScore(score, "Katanga");
    assertScore(score, "Tanganika");
    // Territoire level
    columnSet = assertResolves(query(referenceFields, ImportWithMultiClassRangeTest.TERRITOIRE_LEVEL));
    scoreSource = new InstanceScoreSourceBuilder(CuidAdapter.adminLevelFormClass(ImportWithMultiClassRangeTest.TERRITOIRE_LEVEL), referenceFields, sourceColumns).build(columnSet);
    score = score(source.getRows().get(2), scoreSource);
    assertScore(score, "Katanga");
    assertScore(score, "Tanganika");
    assertScore(score, "Kalemie");
    assertThat(scoreSource.getReferenceInstanceIds().get(score.getBestMatchIndex()), equalTo(ImportWithMultiClassRangeTest.TERRITOIRE_KALEMIE));
}
Also used : PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnSet(org.activityinfo.model.query.ColumnSet) FormTree(org.activityinfo.model.formTree.FormTree) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 12 with PastedTable

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

the class PastedTableTest method columnTypeGuesser.

@Test
public void columnTypeGuesser() throws IOException {
    PastedTable pastedTable = new PastedTable(Resources.toString(getResource(getClass(), "qis.csv"), Charsets.UTF_8));
    // guess column types
    pastedTable.parseAllRows();
    pastedTable.guessColumnsType(JvmConverterFactory.get());
    Assert.assertEquals(column(pastedTable, "Partner").getGuessedType(), FieldTypeClass.FREE_TEXT);
    // Assert.assertEquals(column(pastedTable, "_CREATION_DATE").getGuessedType(), FormFieldType.LOCAL_DATE);
    Assert.assertEquals(column(pastedTable, "_MODEL_VERSION").getGuessedType(), FieldTypeClass.QUANTITY);
}
Also used : PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) Test(org.junit.Test)

Example 13 with PastedTable

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

the class PastedTableTest method nfiParsingPerformance.

@Test
public void nfiParsingPerformance() throws IOException {
    long start = System.currentTimeMillis();
    PastedTable pastedTable = new PastedTable(Resources.toString(getResource(getClass(), "nfi-import-test.csv"), Charsets.UTF_8));
    pastedTable.parseAllRows();
    final List<SourceColumn> columns = pastedTable.getColumns();
    final List<? extends SourceRow> rows = pastedTable.getRows();
    long end = System.currentTimeMillis();
    System.out.println("Done in " + (end - start) + "ms , rows count=" + rows.size() + ", columns count=" + columns.size());
}
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)

Example 14 with PastedTable

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

the class RowParserTest method qisCsvColumns.

@Test
public void qisCsvColumns() throws IOException {
    PastedTable source = new PastedTable(Resources.toString(getResource(getClass(), "qis.csv"), Charsets.UTF_8));
    final List<SourceColumn> columns = source.getColumns();
    System.out.println(Joiner.on('\n').join(columns));
    assertThat(columns.size(), equalTo(47));
}
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)

Example 15 with PastedTable

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

the class ChooseSourcePage method fireStateChanged.

@Override
public void fireStateChanged() {
    // validate
    boolean valid = false;
    PastedTable pastedTable = null;
    try {
        pastedTable = new PastedTable(textArea.getValue());
        valid = !pastedTable.getRows().isEmpty();
        if (valid) {
            boolean isFirstColumnHeaderBlank = Strings.isNullOrEmpty(pastedTable.getColumnHeader(0));
            if (isFirstColumnHeaderBlank) {
                // first row may be occupied by attribute group name, so we just cut it
                valid = false;
                String source = textArea.getValue().substring(textArea.getValue().indexOf("\n") + 1);
                pastedTable = new PastedTable(source);
                valid = !pastedTable.getRows().isEmpty();
            }
        }
    } catch (Exception e) {
    // ignore : text is not valid
    }
    if (valid) {
        pastedTable.guessColumnsType(JsConverterFactory.get());
        model.setSource(pastedTable);
        eventBus.fireEvent(new PageChangedEvent(true, ""));
    } else {
        eventBus.fireEvent(new PageChangedEvent(false, errorMessage(pastedTable)));
    }
}
Also used : PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) PageChangedEvent(org.activityinfo.ui.client.component.importDialog.PageChangedEvent)

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