use of org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable 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.validation.ValidatedRowTable 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.validation.ValidatedRowTable 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.validation.ValidatedRowTable 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));
}
use of org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable 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)));
}
Aggregations