Search in sources :

Example 6 with ImportModel

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

the class ImportSimpleTest method columnMappingGuesser.

@Test
public void columnMappingGuesser() 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));
    importModel.setSource(source);
    importer = new Importer(locator, formTree, FieldImportStrategies.get(JvmConverterFactory.get()));
    dumpList("COLUMNS", source.getColumns());
    dumpList("FIELDS", importer.getImportTargets());
    // Step 2: Guesser guess mapping
    final ColumnMappingGuesser guesser = new ColumnMappingGuesser(importModel, importer.getImportTargets());
    guesser.guess();
    assertMapping("Partner", "Partner Name");
    assertMapping("district name", "District Name");
}
Also used : FormTree(org.activityinfo.model.formTree.FormTree) PastedTable(org.activityinfo.ui.client.component.importDialog.model.source.PastedTable) ColumnMappingGuesser(org.activityinfo.ui.client.component.importDialog.model.match.ColumnMappingGuesser) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) Test(org.junit.Test)

Example 7 with ImportModel

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

the class ImportWithMultiClassRangeTest method testSimple.

@Test
public void testSimple() throws IOException {
    setUser(3);
    FormTree formTree = assertResolves(locator.getFormTree(NFI_DISTRIBUTION_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(), "nfi.csv"), Charsets.UTF_8));
    source.parseAllRows();
    importModel.setSource(source);
    dumpList("COLUMNS", source.getColumns());
    importModel.setColumnAction(columnIndex("Date1"), target("Start Date"));
    importModel.setColumnAction(columnIndex("Date2"), target("End Date"));
    importModel.setColumnAction(columnIndex("Partner"), target("Partner Name"));
    importModel.setColumnAction(columnIndex("Localité"), target("Localité Name"));
    importModel.setColumnAction(columnIndex("Province"), target("Province Name"));
    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("Groupement Name"));
    importModel.setColumnAction(columnIndex("Zone de Santé"), target("Zone de Santé Name"));
    importModel.setColumnAction(columnIndex("Nombre de ménages ayant reçu une assistance en NFI"), target("Nombre de ménages ayant reçu une assistance en NFI"));
    ValidatedRowTable validatedResult = assertResolves(importer.validateRows(importModel));
    showValidationGrid(validatedResult);
    assertResolves(importer.persist(importModel));
    GetSites query = new GetSites(Filter.filter().onActivity(33));
    query.setSortInfo(new SortInfo("date2", Style.SortDir.DESC));
    SiteResult result = execute(query);
    // 651 - 8 = 643 (8 records where start date is before end date)
    assertThat(result.getTotalLength(), equalTo(643));
    // assertThat(result.getTotalLength(), equalTo(313));
    SiteDTO lastSite = result.getData().get(0);
    // assertThat(lastSite.getDate2(), equalTo(new LocalDate(2013,4,26)));
    assertThat(lastSite.getDate2(), equalTo(new LocalDate(2013, 4, 30)));
    assertThat(lastSite.getLocationName(), equalTo("Kilimani Camp"));
    assertThat(lastSite.getAdminEntity(PROVINCE_LEVEL).getName(), equalTo("Nord Kivu"));
    assertThat(lastSite.getAdminEntity(DISTRICT_LEVEL).getName(), equalTo("Nord Kivu"));
    assertThat(lastSite.getAdminEntity(TERRITOIRE_LEVEL).getName(), equalTo("Masisi"));
    assertThat(lastSite.getAdminEntity(SECTEUR_LEVEL).getName(), equalTo("Masisi"));
    assertThat((Double) lastSite.getIndicatorValue(NUMBER_MENAGES), equalTo(348.0));
    assertThat(lastSite.getAttributeValue(ECHO), equalTo(false));
}
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) 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) SortInfo(com.extjs.gxt.ui.client.data.SortInfo) Test(org.junit.Test)

Example 8 with ImportModel

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

the class ImportWithMultiClassRangeTest method testMulti.

@Test
public void testMulti() throws IOException {
    setUser(3);
    FormTree formTree = assertResolves(locator.getFormTree(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("Groupement Name"));
    // health ministry hierarchy
    importModel.setColumnAction(columnIndex("Zone de Santé"), target("Zone de Santé Name"));
    ValidatedRowTable validatedResult = assertResolves(importer.validateRows(importModel));
    showValidationGrid(validatedResult);
    assertResolves(importer.persist(importModel));
    QueryModel resultQuery = new QueryModel(SCHOOL_FORM_CLASS);
    resultQuery.selectResourceId().as("id");
    resultQuery.selectField(CuidAdapter.field(SCHOOL_FORM_CLASS, CuidAdapter.NAME_FIELD)).as("name");
    resultSet = assertResolves(locator.queryTable(resultQuery));
    // we have 8 rows in school-import.csv
    assertThat(resultSet.getNumRows(), equalTo(8));
    assertThat(school("P"), equalTo(set(PROVINCE_KATANGA)));
    assertThat(school("D"), equalTo(set(DISTRICT_TANGANIKA)));
    assertThat(school("T"), equalTo(set(TERRITOIRE_KALEMIE)));
    assertThat(school("S"), equalTo(set(SECTEUR_TUMBWE)));
    assertThat(school("G"), equalTo(set(GROUPEMENT_LAMBO_KATENGA)));
    // assertThat(school("GZ"), equalTo(set(GROUPEMENT_LAMBO_KATENGA, ZONE_SANTE_NYEMBA)));
    // assertThat(school("TZ"), equalTo(set(TERRITOIRE_KALEMIE, ZONE_SANTE_NYEMBA)));
    assertThat(school("GZ"), equalTo(set(ZONE_SANTE_NYEMBA)));
    assertThat(school("TZ"), equalTo(set(ZONE_SANTE_NYEMBA)));
}
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) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 9 with ImportModel

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

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

the class ValidateRowsImportCommand method doRowValidation.

private ValidatedRowTable doRowValidation() {
    final List<ValidatedRow> rows = Lists.newArrayList();
    final ImportModel model = commandExecutor.getImportModel();
    // Row based validation
    for (SourceRow row : model.getSource().getRows()) {
        List<ValidationResult> results = Lists.newArrayList();
        for (FieldImporter importer : commandExecutor.getImporters()) {
            importer.validateInstance(row, results);
        }
        rows.add(new ValidatedRow(row, results));
    }
    ValidatedRowTable validatedRowTable = new ValidatedRowTable(commandExecutor.getColumns(), rows);
    model.setValidatedRowTable(validatedRowTable);
    return validatedRowTable;
}
Also used : FieldImporter(org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter) ValidatedRowTable(org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable) ValidatedRow(org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRow) SourceRow(org.activityinfo.ui.client.component.importDialog.model.source.SourceRow) ImportModel(org.activityinfo.ui.client.component.importDialog.model.ImportModel) ValidationResult(org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)

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