use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class CSVDataImportJobIntegrationTest method newRecordsTest.
@Test
public void newRecordsTest() throws Exception {
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
CSVDataImportJob process = importCSVFile(VALID_TEST_CSV, clusterDefn.getId(), true, true, "2.0");
assertTrue(process.isCompleted());
assertTrue(process.getParsingErrors().isEmpty());
{
CollectRecord reloadedRecord = loadRecord("10_111");
Entity cluster = reloadedRecord.getRootEntity();
RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
RealValue plotDistanceVal = plotDistance.getValue();
assertEquals(Double.valueOf(200d), plotDistanceVal.getValue());
assertEquals(meterUnit, plotDistanceVal.getUnit());
}
{
CollectRecord reloadedRecord = loadRecord("10_114");
Entity cluster = reloadedRecord.getRootEntity();
RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
RealValue plotDistanceVal = plotDistance.getValue();
assertEquals(Double.valueOf(0.3d), plotDistanceVal.getValue());
assertEquals(kilometerUnit, plotDistanceVal.getUnit());
}
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class CSVDataImportJobIntegrationTest method validDeleteExistingEntitiesTest.
@Test
public void validDeleteExistingEntitiesTest() throws Exception {
CollectRecord record = createTestRecord(survey, "10_114");
recordDao.insert(record);
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
assertEquals(3, record.getRootEntity().getCount(plotDefn));
CSVDataImportSettings settings = new CSVDataImportSettings();
settings.setDeleteExistingEntities(true);
CSVDataImportJob process = importCSVFile(VALID_NESTED_ENTITY_TEST_CSV, plotDefn.getId(), true, settings);
assertTrue(process.isCompleted());
assertTrue(process.getParsingErrors().isEmpty());
CollectRecord reloadedRecord = recordDao.load(survey, record.getId(), Step.ENTRY);
assertEquals(2, reloadedRecord.getRootEntity().getCount(plotDefn));
Entity reloadedCluster = reloadedRecord.getRootEntity();
{
Entity plot = reloadedCluster.findChildEntitiesByKeys("plot", "1", "A").get(0);
CodeAttribute landUse = (CodeAttribute) plot.getChild("land_use");
assertEquals("2", landUse.getValue().getCode());
}
{
Entity plot = reloadedCluster.findChildEntitiesByKeys("plot", "2", "B").get(0);
CodeAttribute landUse = (CodeAttribute) plot.getChild("land_use");
assertEquals("3", landUse.getValue().getCode());
}
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class CSVDataImportProcessIntegrationTest method invalidHeaderTest.
@Test
public void invalidHeaderTest() throws Exception {
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
CSVDataImportProcess process = importCSVFile(INVALID_HEADER_TEST_CSV, plotDefn.getId());
ReferenceDataImportStatus<ParsingError> status = process.getStatus();
assertFalse(status.isComplete());
assertTrue(status.isError());
List<ParsingError> errors = status.getErrors();
assertEquals(1, errors.size());
ParsingError headerError = errors.get(0);
assertEquals(ErrorType.WRONG_COLUMN_NAME, headerError.getErrorType());
assertTrue(Arrays.equals(new String[] { "land_usage" }, headerError.getColumns()));
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class CSVDataImportProcessIntegrationTest method missingRequiredColumnsTest.
@Test
public void missingRequiredColumnsTest() throws Exception {
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
CSVDataImportProcess process = importCSVFile(MISSING_REQUIRED_COLUMNS_TEST_CSV, plotDefn.getId());
ReferenceDataImportStatus<ParsingError> status = process.getStatus();
assertFalse(status.isComplete());
assertTrue(status.isError());
List<ParsingError> errors = status.getErrors();
assertEquals(1, errors.size());
ParsingError headerError = errors.get(0);
assertEquals(ErrorType.MISSING_REQUIRED_COLUMNS, headerError.getErrorType());
}
use of org.openforis.idm.metamodel.EntityDefinition in project collect by openforis.
the class CSVDataImportProcessIntegrationTest method missingRecordTest.
// @Test
// TODO transactional process not working only in test spring context
public void missingRecordTest() throws Exception {
{
CollectRecord record = createTestRecord(survey, "10_111");
recordDao.insert(record);
}
{
CollectRecord record = createTestRecord(survey, "10_114");
recordDao.insert(record);
}
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
CSVDataImportProcess process = importCSVFile(MISSING_RECORD_TEST_CSV, clusterDefn.getId());
ReferenceDataImportStatus<ParsingError> status = process.getStatus();
assertTrue(status.isError());
assertEquals(1, status.getSkippedRows().size());
assertEquals(1, status.getRowsInError().size());
assertEquals(3, status.getProcessed());
{
ParsingError error = status.getErrors().get(0);
assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
assertEquals(4, error.getRow());
assertTrue(Arrays.equals(new String[] { "id" }, error.getColumns()));
}
// verify that the transaction is rolled back properly
{
CollectRecord reloadedRecord = loadRecord("10_111");
Entity cluster = reloadedRecord.getRootEntity();
RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
RealValue plotDistanceVal = plotDistance.getValue();
assertEquals(Double.valueOf(100d), plotDistanceVal.getValue());
assertEquals(meterUnit, plotDistanceVal.getUnit());
}
{
CollectRecord reloadedRecord = loadRecord("10_114");
Entity cluster = reloadedRecord.getRootEntity();
RealAttribute plotDistance = (RealAttribute) cluster.getChild("plot_distance");
RealValue plotDistanceVal = plotDistance.getValue();
assertEquals(Double.valueOf(100d), plotDistanceVal.getValue());
assertEquals(meterUnit, plotDistanceVal.getUnit());
}
}
Aggregations