Search in sources :

Example 31 with ParsingError

use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.

the class SamplingDesignImportProcessIntegrationTest method testInvalidData.

@Test
public void testInvalidData() throws Exception {
    SamplingDesignImportProcess process = importCSVFile(INVALID_TEST_CSV);
    SamplingDesignImportStatus status = process.getStatus();
    assertTrue(status.isError());
    List<ParsingError> errors = status.getErrors();
    assertEquals(6, errors.size());
    assertTrue(containsError(errors, 3, SamplingDesignFileColumn.LEVEL_2, ErrorType.DUPLICATE_VALUE));
    assertTrue(containsError(errors, 4, SamplingDesignFileColumn.LEVEL_2, ErrorType.DUPLICATE_VALUE));
    assertTrue(containsError(errors, 14, SamplingDesignFileColumn.LEVEL_2, ErrorType.EMPTY));
    assertTrue(containsError(errors, 17, SamplingDesignFileColumn.LEVEL_1, ErrorType.EMPTY));
    assertTrue(containsError(errors, 22, SamplingDesignFileColumn.X, ErrorType.EMPTY));
    assertTrue(containsError(errors, 23, SamplingDesignFileColumn.Y, ErrorType.EMPTY));
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) SamplingDesignImportProcess(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportProcess) SamplingDesignImportStatus(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 32 with ParsingError

use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.

the class CSVDataImportJobIntegrationTest method invalidValuesTest.

@Test
public void invalidValuesTest() 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");
    CSVDataImportJob process = importCSVFile(INVALID_VALUES_TEST_CSV, clusterDefn.getId());
    assertFalse(process.isCompleted());
    assertTrue(process.isFailed());
    List<DataParsingError> errors = process.getParsingErrors();
    assertEquals(4, errors.size());
    {
        ParsingError error = errors.get(0);
        assertEquals(2, error.getRow());
        assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
        assertTrue(Arrays.equals(new String[] { "vehicle_location_srs" }, error.getColumns()));
    }
    {
        ParsingError error = errors.get(1);
        assertEquals(4, error.getRow());
        assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
        assertTrue(Arrays.equals(new String[] { "vehicle_location_x" }, error.getColumns()));
    }
    {
        ParsingError error = errors.get(2);
        assertEquals(4, error.getRow());
        assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
        assertTrue(Arrays.equals(new String[] { "plot_distance" }, error.getColumns()));
    }
    {
        ParsingError error = errors.get(3);
        assertEquals(5, error.getRow());
        assertEquals(ErrorType.INVALID_VALUE, error.getErrorType());
        assertTrue(Arrays.equals(new String[] { "vehicle_location_y" }, error.getColumns()));
    }
}
Also used : DataParsingError(org.openforis.collect.io.data.CSVDataImportJob.DataParsingError) CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) DataParsingError(org.openforis.collect.io.data.CSVDataImportJob.DataParsingError) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 33 with ParsingError

use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.

the class CSVDataImportJobIntegrationTest 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");
    CSVDataImportJob process = importCSVFile(MISSING_RECORD_TEST_CSV, clusterDefn.getId());
    assertTrue(process.isFailed());
    assertEquals(1, process.getParsingErrors().size());
    {
        ParsingError error = process.getParsingErrors().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());
    }
}
Also used : RealValue(org.openforis.idm.model.RealValue) CollectRecord(org.openforis.collect.model.CollectRecord) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) DataParsingError(org.openforis.collect.io.data.CSVDataImportJob.DataParsingError) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) RealAttribute(org.openforis.idm.model.RealAttribute)

Example 34 with ParsingError

use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.

the class SamplingDesignImportProcess method processLine.

protected boolean processLine(SamplingDesignLine line) throws ParsingException {
    SamplingDesignLineValidator validator = SamplingDesignLineValidator.createInstance(survey);
    validator.validate(line);
    List<ParsingError> errors = validator.getErrors();
    for (ParsingError error : errors) {
        status.addParsingError(error);
    }
    checkDuplicateLine(line);
    return true;
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError)

Example 35 with ParsingError

use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.

the class SamplingDesignImportTask method throwDuplicateLineException.

protected void throwDuplicateLineException(SamplingDesignLine line, SamplingDesignLine duplicateLine, SamplingDesignFileColumn[] columns) throws ParsingException {
    String[] colNames = new String[columns.length];
    for (int i = 0; i < columns.length; i++) {
        SamplingDesignFileColumn column = columns[i];
        colNames[i] = column.getColumnName();
    }
    ParsingError error = new ParsingError(ErrorType.DUPLICATE_VALUE, line.getLineNumber(), colNames);
    String duplicateLineNumber = Long.toString(duplicateLine.getLineNumber());
    error.setMessageArgs(new String[] { duplicateLineNumber });
    throw new ParsingException(error);
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) ParsingException(org.openforis.collect.io.exception.ParsingException)

Aggregations

ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)46 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)19 Test (org.junit.Test)17 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)17 CollectRecord (org.openforis.collect.model.CollectRecord)12 ParsingException (org.openforis.collect.io.exception.ParsingException)9 Entity (org.openforis.idm.model.Entity)9 CollectSurvey (org.openforis.collect.model.CollectSurvey)5 RealAttribute (org.openforis.idm.model.RealAttribute)5 DataParsingError (org.openforis.collect.io.data.CSVDataImportJob.DataParsingError)4 RealValue (org.openforis.idm.model.RealValue)4 IOException (java.io.IOException)3 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)3 Survey (org.openforis.idm.metamodel.Survey)3 ArrayList (java.util.ArrayList)2 SpeciesImportProcess (org.openforis.collect.manager.speciesimport.SpeciesImportProcess)2 SpeciesImportStatus (org.openforis.collect.manager.speciesimport.SpeciesImportStatus)2 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)2 CodeListItem (org.openforis.idm.metamodel.CodeListItem)2 SpatialReferenceSystem (org.openforis.idm.metamodel.SpatialReferenceSystem)2