コード例 #1
0
  @Test
  public void columnMappingGuesser() throws IOException {
    FormTree formTree = assertResolves(formTreeBuilder.apply(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("org/activityinfo/core/shared/importing/qis.csv"), Charsets.UTF_8));

    importModel.setSource(source);
    importer =
        new Importer(
            resourceLocator, 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", "District Name");
    // assertMapping("upazila", "Upzilla Name");
  }
コード例 #2
0
  @Test
  public void testExceptionHandling() throws IOException {

    FormTree formTree = assertResolves(formTreeBuilder.apply(HOUSEHOLD_SURVEY_FORM_CLASS));
    importModel = new ImportModel(formTree);

    // Step 1: User pastes in data to import
    PastedTable source =
        new PastedTable(
            Resources.toString(
                getResource("org/activityinfo/core/shared/importing/qis.csv"), Charsets.UTF_8));

    importModel.setSource(source);
    importer =
        new Importer(
            resourceLocator, 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"), 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));
  }
コード例 #3
0
  @Test
  public void test() throws IOException {

    FormTree formTree = assertResolves(formTreeBuilder.apply(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("org/activityinfo/core/shared/importing/qis.csv"), Charsets.UTF_8));
    source.parseAllRows();

    assertThat(source.getRows().size(), equalTo(63));

    importModel.setSource(source);
    importer =
        new Importer(
            resourceLocator, 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"), 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));

    // 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)));
  }