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));
}
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()));
}
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()));
}
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"))));
}
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);
}
Aggregations