use of org.openforis.collect.model.SurveyFile.SurveyFileType in project collect by openforis.
the class SurveyFileFormValidator method validateFilenamePattern.
private boolean validateFilenamePattern(ValidationContext ctx) {
if (validateRegEx(ctx, VALID_FILENAME_PATTERN, FILENAME_FIELD_NAME, "survey.file.error.invalid_filename")) {
String filename = getValue(ctx, FILENAME_FIELD_NAME);
String typeName = getValue(ctx, TYPE_FIELD_NAME);
SurveyFileType type = SurveyFileType.valueOf(typeName);
switch(type) {
case COLLECT_EARTH_AREA_PER_ATTRIBUTE:
String expectedFileName = SurveyFileType.COLLECT_EARTH_AREA_PER_ATTRIBUTE.getFixedFilename();
if (expectedFileName.equals(filename)) {
return true;
} else {
String message = Labels.getLabel("survey.file.error.unexpected_filename", new String[] { expectedFileName });
addInvalidMessage(ctx, message);
return false;
}
case COLLECT_EARTH_SAIKU_QUERY:
String extension = FilenameUtils.getExtension(filename);
if (!SAIKU_QUERY_FILE_EXTENSION.equalsIgnoreCase(extension)) {
String message = Labels.getLabel("survey.file.error.invalid_extension", new String[] { SAIKU_QUERY_FILE_EXTENSION, extension });
addInvalidMessage(ctx, FILENAME_FIELD_NAME, message);
return false;
}
default:
if (RESERVED_FILENAMES.contains(filename)) {
addInvalidMessage(ctx, FILENAME_FIELD_NAME, Labels.getLabel("survey.file.error.reserved_filename"));
return false;
} else {
return true;
}
}
} else {
return false;
}
}
use of org.openforis.collect.model.SurveyFile.SurveyFileType 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.model.SurveyFile.SurveyFileType in project collect by openforis.
the class SurveyFilesImportTask method execute.
@Override
protected void execute() throws Throwable {
surveyManager.deleteSurveyFiles(survey);
Set<String> types = backupFileExtractor.listDirectoriesInPath(SURVEY_FILES_FOLDER);
for (String typeCode : types) {
SurveyFileType type = SurveyFileType.fromCode(typeCode);
String surveyFilesPath = determineSurveyFilesPath(typeCode);
List<String> entryNames = backupFileExtractor.listEntriesInPath(surveyFilesPath);
for (String entryName : entryNames) {
File file = backupFileExtractor.extract(entryName);
String fileName = FilenameUtils.getName(entryName);
SurveyFile surveyFile = new SurveyFile(survey);
surveyFile.setFilename(fileName);
surveyFile.setType(type);
surveyManager.addSurveyFile(survey, surveyFile, file);
}
}
}
use of org.openforis.collect.model.SurveyFile.SurveyFileType 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.SurveyFileType in project collect by openforis.
the class SurveyFileVM method updateForm.
private void updateForm(Binder binder) {
String typeName = getFormFieldValue(binder, SurveyFileFormObject.TYPE_FIELD_NAME);
SurveyFileType type = SurveyFileType.valueOf(typeName);
String filename = type.getFixedFilename();
if (filename == null) {
if (uploadedFile == null) {
filename = getFormFieldValue(binder, SurveyFileFormObject.FILENAME_FIELD_NAME);
} else {
filename = uploadedFileName;
}
}
setFormFieldValue(binder, SurveyFileFormObject.FILENAME_FIELD_NAME, filename);
dispatchApplyChangesCommand(binder);
}
Aggregations