Search in sources :

Example 6 with CodeAttribute

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());
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) CodeAttribute(org.openforis.idm.model.CodeAttribute) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 7 with CodeAttribute

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());
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) CodeAttribute(org.openforis.idm.model.CodeAttribute) CSVDataImportSettings(org.openforis.collect.io.data.csv.CSVDataImportSettings) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 8 with CodeAttribute

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());
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) CodeAttribute(org.openforis.idm.model.CodeAttribute) CSVDataImportSettings(org.openforis.collect.io.data.csv.CSVDataImportSettings) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 9 with CodeAttribute

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());
    }
}
Also used : Entity(org.openforis.idm.model.Entity) ValidationResults(org.openforis.idm.metamodel.validation.ValidationResults) CodeAttribute(org.openforis.idm.model.CodeAttribute) CodeList(org.openforis.idm.metamodel.CodeList) List(java.util.List) Code(org.openforis.idm.model.Code) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 10 with CodeAttribute

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);
}
Also used : CodeAttribute(org.openforis.idm.model.CodeAttribute) Code(org.openforis.idm.model.Code) Test(org.junit.Test)

Aggregations

CodeAttribute (org.openforis.idm.model.CodeAttribute)28 Code (org.openforis.idm.model.Code)16 Test (org.junit.Test)13 Entity (org.openforis.idm.model.Entity)12 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)7 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)5 CodeList (org.openforis.idm.metamodel.CodeList)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 ModelVersion (org.openforis.idm.metamodel.ModelVersion)5 CollectRecord (org.openforis.collect.model.CollectRecord)4 CodeListItem (org.openforis.idm.metamodel.CodeListItem)4 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)4 Record (org.openforis.idm.model.Record)4 ArrayList (java.util.ArrayList)3 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 AbstractTest (org.openforis.idm.AbstractTest)3 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)3 Node (org.openforis.idm.model.Node)3 List (java.util.List)2 CSVDataImportSettings (org.openforis.collect.io.data.csv.CSVDataImportSettings)2