use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class SpeciesImportProcessIntegrationTest method testInvalidColumns.
@Test
public void testInvalidColumns() throws Exception {
SpeciesImportProcess process = importCSVFile(INVALID_MISSING_COLUMNS_TEST_CSV);
SpeciesImportStatus status = process.getStatus();
assertTrue(status.isError());
List<ParsingError> errors = status.getErrors();
assertEquals(1, errors.size());
ParsingError error = errors.get(0);
ErrorType errorType = error.getErrorType();
assertEquals(ErrorType.MISSING_REQUIRED_COLUMNS, errorType);
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CSVDataImportJob method getParsingErrors.
public List<DataParsingError> getParsingErrors() {
List<DataParsingError> result = new ArrayList<DataParsingError>();
for (Worker worker : getTasks()) {
CSVDataImportTask task = (CSVDataImportTask) worker;
ReferenceDataImportStatus<ParsingError> dataImportStatus = task.getDataImportStatus();
if (dataImportStatus != null) {
List<ParsingError> errors = dataImportStatus.getErrors();
for (ParsingError parsingError : errors) {
DataParsingError dataParsingError = new DataParsingError(task.getInput().getFile().getName(), parsingError.getRow(), parsingError.getErrorType(), parsingError.getColumns(), parsingError.getMessage(), parsingError.getMessageArgs());
result.add(dataParsingError);
}
}
}
return result;
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CSVDataImportProcess method setSRSIdField.
private void setSRSIdField(Attribute<?, ?> attr, String value, long row, String colName) {
boolean valid = true;
if (StringUtils.isNotBlank(value)) {
// check SRS id validity
Survey survey = attr.getSurvey();
SpatialReferenceSystem srs = survey.getSpatialReferenceSystem(value);
if (srs == null) {
ParsingError parsingError = new ParsingError(ErrorType.INVALID_VALUE, row, colName, SRS_NOT_FOUND_MESSAGE_KEY);
parsingError.setMessageArgs(new String[] { value });
status.addParsingError(parsingError);
valid = false;
}
}
if (valid) {
Field<String> field = ((CoordinateAttribute) attr).getSrsIdField();
NodeChangeSet changes = recordUpdater.updateField(field, value);
if (nodeChangeBatchProcessor != null) {
nodeChangeBatchProcessor.add(changes, adminUser.getUsername());
}
}
}
use of org.openforis.collect.io.metadata.parsing.ParsingError in project collect by openforis.
the class CSVDataImportProcess method createParentEntitySearchError.
private ParsingError createParentEntitySearchError(CollectRecord record, DataLine line, EntityIdentifier<?> identifier, String messageKey) {
EntityIdentifierDefinition identifierDefn = identifier.getDefinition();
Survey survey = record.getSurvey();
Schema schema = survey.getSchema();
EntityDefinition parentEntityDefn = (EntityDefinition) schema.getDefinitionById(identifierDefn.getEntityDefinitionId());
String[] colNames = DataCSVReader.getKeyAttributeColumnNames(parentEntityDefn, parentEntityDefn.getKeyAttributeDefinitions());
ParsingError error = new ParsingError(ErrorType.INVALID_VALUE, line.getLineNumber(), colNames, messageKey);
List<String> recordKeys = record.getRootEntityKeyValues();
CollectionUtils.filter(recordKeys, new Predicate() {
@Override
public boolean evaluate(Object object) {
return StringUtils.isNotBlank((String) object);
}
});
String jointRecordKeys = StringUtils.join(recordKeys, ", ");
String jointParentEntityKeys = identifier instanceof EntityPositionIdentifier ? "[" + ((EntityPositionIdentifier) identifier).getPosition() + "]" : StringUtils.join(((EntityKeysIdentifier) identifier).getKeyValues(), ", ");
error.setMessageArgs(new String[] { parentEntityDefn.getName(), jointParentEntityKeys, jointRecordKeys });
return error;
}
use of org.openforis.collect.io.metadata.parsing.ParsingError 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()));
}
Aggregations