Search in sources :

Example 6 with SurveyFile

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) SurveyFile(org.openforis.collect.model.SurveyFile) File(java.io.File) CSVFileValidationResult(org.openforis.collect.io.metadata.collectearth.CSVFileValidationResult) CollectEarthGridTemplateGenerator(org.openforis.collect.io.metadata.collectearth.CollectEarthGridTemplateGenerator)

Example 7 with SurveyFile

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;
}
Also used : ArrayList(java.util.ArrayList) SurveyFile(org.openforis.collect.model.SurveyFile)

Example 8 with SurveyFile

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;
    }
}
Also used : SurveyFileType(org.openforis.collect.model.SurveyFile.SurveyFileType) SurveyFile(org.openforis.collect.model.SurveyFile)

Example 9 with SurveyFile

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();
}
Also used : SurveyFile(org.openforis.collect.model.SurveyFile) Command(org.zkoss.bind.annotation.Command) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Aggregations

SurveyFile (org.openforis.collect.model.SurveyFile)9 File (java.io.File)3 ArrayList (java.util.ArrayList)3 SurveyFileType (org.openforis.collect.model.SurveyFile.SurveyFileType)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ZipFile (net.lingala.zip4j.core.ZipFile)1 SurveyFileVM (org.openforis.collect.designer.viewmodel.SurveyFileVM)1 CSVFileValidationResult (org.openforis.collect.io.metadata.collectearth.CSVFileValidationResult)1 CollectEarthGridTemplateGenerator (org.openforis.collect.io.metadata.collectearth.CollectEarthGridTemplateGenerator)1 SurveyManager (org.openforis.collect.manager.SurveyManager)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 Command (org.zkoss.bind.annotation.Command)1 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)1