use of org.openforis.collect.model.SurveyFile in project collect by openforis.
the class SurveyValidator method validateCollectEarthGridFile.
private List<SurveyValidationResult> validateCollectEarthGridFile(CollectSurvey survey, SurveyFile surveyFile, ValidationParameters validationParameters) {
List<SurveyValidationResult> results = new ArrayList<SurveyValidator.SurveyValidationResult>();
byte[] fileContent = surveyManager.loadSurveyFileContent(surveyFile);
ByteArrayInputStream is = new ByteArrayInputStream(fileContent);
File file = OpenForisIOUtils.copyToTempFile(is);
CSVFileValidationResult fileValidationResult = new CollectEarthGridTemplateGenerator().validate(file, survey, validationParameters);
if (!fileValidationResult.isSuccessful()) {
SurveyValidationResult validationResult = null;
switch(fileValidationResult.getErrorType()) {
case INVALID_FILE_TYPE:
validationResult = new SurveyValidationResult(Flag.WARNING, String.format(SURVEY_FILE_PATH_FORMAT, surveyFile.getFilename()), "survey.file.error.invalid_file_type", "CSV (Comma Separated Values)");
break;
case INVALID_HEADERS:
validationResult = new SurveyValidationResult(Flag.WARNING, String.format(SURVEY_FILE_PATH_FORMAT, surveyFile.getFilename()), "survey.file.type.collect_earth_grid.error.invalid_file_structure", fileValidationResult.getExpectedHeaders().toString(), fileValidationResult.getFoundHeaders().toString());
break;
case INVALID_VALUES_IN_CSV:
validationResult = new SurveyValidationResult(Flag.WARNING, String.format(SURVEY_FILE_PATH_FORMAT, surveyFile.getFilename()), "survey.file.error.invalid_content", getRowValidationMessages(fileValidationResult.getRowValidations()));
break;
case INVALID_NUMBER_OF_COLUMNS:
validationResult = new SurveyValidationResult(Flag.WARNING, String.format(SURVEY_FILE_PATH_FORMAT, surveyFile.getFilename()), "survey.file.type.collect_earth_grid.error.invalid_file_structure", fileValidationResult.getExpectedHeaders().toString(), fileValidationResult.getFoundHeaders().toString());
break;
case INVALID_NUMBER_OF_PLOTS_TOO_LARGE:
validationResult = new SurveyValidationResult(Flag.WARNING, String.format(SURVEY_FILE_PATH_FORMAT, surveyFile.getFilename()), "survey.file.error.error_csv_size", fileValidationResult.getNumberOfRows().toString());
break;
case INVALID_NUMBER_OF_PLOTS_WARNING:
validationResult = new SurveyValidationResult(Flag.WARNING, String.format(SURVEY_FILE_PATH_FORMAT, surveyFile.getFilename()), "survey.file.error.warning_csv_size", fileValidationResult.getNumberOfRows().toString());
break;
default:
}
if (validationResult != null)
results.add(validationResult);
}
return results;
}
use of org.openforis.collect.model.SurveyFile in project collect by openforis.
the class SurveyValidator method validateSurveyFiles.
private List<SurveyValidationResult> validateSurveyFiles(CollectSurvey survey, ValidationParameters validationParameters) {
List<SurveyValidationResult> results = new ArrayList<SurveyValidationResult>();
List<SurveyFile> surveyFileSummaries = surveyManager.loadSurveyFileSummaries(survey);
for (SurveyFile surveyFile : surveyFileSummaries) {
if (surveyFile.getType() == SurveyFileType.COLLECT_EARTH_GRID) {
results.addAll(validateCollectEarthGridFile(survey, surveyFile, validationParameters));
}
}
return results;
}
use of org.openforis.collect.model.SurveyFile in project collect by openforis.
the class SurveyFileFormValidator method validateTypeUniqueness.
private boolean validateTypeUniqueness(ValidationContext ctx) {
List<SurveyFile> otherSurveyFiles = loadSurveyFilesDifferentFromThis(ctx);
String typeName = getValue(ctx, TYPE_FIELD_NAME);
SurveyFileType type = SurveyFileType.valueOf(typeName);
switch(type) {
case COLLECT_EARTH_AREA_PER_ATTRIBUTE:
case COLLECT_EARTH_EE_SCRIPT:
if (containsFileWithType(otherSurveyFiles, type)) {
addInvalidMessage(ctx, TYPE_FIELD_NAME, Labels.getLabel("survey.file.error.type_already_defined"));
return false;
} else {
return true;
}
default:
return true;
}
}
use of org.openforis.collect.model.SurveyFile in project collect by openforis.
the class SurveyMainInfoVM method addSurveyFile.
@Command
public void addSurveyFile() {
editedSurveyFile = new SurveyFile(survey);
editingNewSurveyFile = true;
openSurveyFileEditPopUp();
}
Aggregations