use of org.openforis.collect.io.metadata.collectearth.CollectEarthGridTemplateGenerator in project collect by openforis.
the class SurveyFileVM method validateFileContent.
private boolean validateFileContent(Binder binder) {
String typeName = getFormFieldValue(binder, SurveyFileFormObject.TYPE_FIELD_NAME);
SurveyFileType type = SurveyFileType.valueOf(typeName);
switch(type) {
case COLLECT_EARTH_GRID:
CollectEarthGridTemplateGenerator templateGenerator = new CollectEarthGridTemplateGenerator();
CSVFileValidationResult headersValidationResult = templateGenerator.validate(uploadedFile, survey, new ValidationParameters());
if (headersValidationResult.isSuccessful()) {
return true;
} else {
switch(headersValidationResult.getErrorType()) {
case INVALID_FILE_TYPE:
MessageUtil.showWarning("survey.file.error.invalid_file_type", "CSV (Comma Separated Values)");
// don't block the user
return true;
case INVALID_HEADERS:
MessageUtil.showWarning("survey.file.type.collect_earth_grid.error.invalid_file_structure", new Object[] { headersValidationResult.getExpectedHeaders().toString(), headersValidationResult.getFoundHeaders().toString() });
// don't block the user
return true;
case INVALID_NUMBER_OF_PLOTS_WARNING:
MessageUtil.showWarning("survey.file.error.warning_csv_size", CollectEarthGridTemplateGenerator.CSV_LENGTH_WARNING + "");
// don't block the user
return true;
case INVALID_NUMBER_OF_PLOTS_TOO_LARGE:
MessageUtil.showWarning("survey.file.error.error_csv_size", CollectEarthGridTemplateGenerator.CSV_LENGTH_ERROR + "");
// block the user , a file so large would make the CEP file unusable!
return false;
default:
return true;
}
}
default:
return true;
}
}
use of org.openforis.collect.io.metadata.collectearth.CollectEarthGridTemplateGenerator 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.io.metadata.collectearth.CollectEarthGridTemplateGenerator in project collect by openforis.
the class SurveyEditVM method exportCEGridTemplate.
@Command
public void exportCEGridTemplate() throws IOException {
File templateFile = new CollectEarthGridTemplateGenerator().generateTemplateCSVFile(survey);
String fileName = String.format("%s_grid_template_%s.csv", survey.getName(), Dates.formatDateTime(new Date()));
Filedownload.save(new FileInputStream(templateFile), MediaTypes.CSV_CONTENT_TYPE, fileName);
}
use of org.openforis.collect.io.metadata.collectearth.CollectEarthGridTemplateGenerator in project collect by openforis.
the class SurveyFileVM method downloadExampleFile.
@Command
public void downloadExampleFile(@BindingParam("fileType") String fileType) throws IOException {
switch(SurveyFileType.valueOf(fileType)) {
case COLLECT_EARTH_GRID:
File templateFile = new CollectEarthGridTemplateGenerator().generateTemplateCSVFile(survey);
String fileName = String.format("%s_grid_template_%s.csv", survey.getName(), Dates.formatDateTime(new Date()));
Filedownload.save(new FileInputStream(templateFile), MediaTypes.CSV_CONTENT_TYPE, fileName);
break;
default:
}
}
Aggregations