use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class CSVDataImportJobIntegrationTest method nestedEntityTest.
@Test
public void nestedEntityTest() throws Exception {
CollectRecord record = createTestRecord(survey, "10_114");
recordDao.insert(record);
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
CSVDataImportJob process = importCSVFile(VALID_NESTED_ENTITY_TEST_CSV, plotDefn.getId());
assertTrue(process.isCompleted());
assertTrue(process.getParsingErrors().isEmpty());
CollectRecord reloadedRecord = recordDao.load(survey, record.getId(), Step.ENTRY);
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.model.CodeAttribute 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.model.CodeAttribute in project collect by openforis.
the class CSVDataImportProcessIntegrationTest 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);
CSVDataImportProcess process = importCSVFile(VALID_NESTED_ENTITY_TEST_CSV, plotDefn.getId(), true, settings);
ReferenceDataImportStatus<ParsingError> status = process.getStatus();
assertTrue(status.isComplete());
assertTrue(status.getSkippedRows().isEmpty());
assertEquals(3, status.getProcessed());
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.model.CodeAttribute in project collect by openforis.
the class CollectRecordIntegrationTest method testConfirmError.
@Test
public void testConfirmError() throws Exception {
CollectSurvey survey = loadSurvey();
CollectRecord record = createTestRecord(survey);
Entity cluster = record.getRootEntity();
CodeAttribute region = (CodeAttribute) cluster.getChild("region", 0);
// add wrong value
{
NodeChangeSet changeSet = recordUpdater.updateAttribute(region, new Code("ZZZ"));
assertFalse(changeSet.isEmpty());
NodeChange<?> regionChange = changeSet.getChange(region);
assertTrue(regionChange instanceof AttributeChange);
ValidationResults validationResults = ((AttributeChange) regionChange).getValidationResults();
List<ValidationResult> errors = validationResults.getErrors();
assertFalse(errors.isEmpty());
List<ValidationResult> warnings = validationResults.getWarnings();
assertTrue(warnings.isEmpty());
}
{
NodeChangeSet changeSet = recordUpdater.confirmError(region);
assertFalse(changeSet.isEmpty());
NodeChange<?> regionChange = changeSet.getChange(region);
assertTrue(regionChange instanceof AttributeChange);
ValidationResults validationResults = ((AttributeChange) regionChange).getValidationResults();
List<ValidationResult> errors = validationResults.getErrors();
assertTrue(errors.isEmpty());
List<ValidationResult> warnings = validationResults.getWarnings();
assertFalse(warnings.isEmpty());
}
}
use of org.openforis.idm.model.CodeAttribute in project collect by openforis.
the class ComparisonCheckTest method testCodeLtConstant.
@Test
public void testCodeLtConstant() {
ComparisonCheck check = new ComparisonCheck();
check.setLessThanExpression("-1");
CodeAttribute region = EntityBuilder.addValue(cluster, "region", new Code("001"));
ValidationResultFlag result = check.evaluate(region);
assertEquals(ERROR, result);
}
Aggregations