Search in sources :

Example 1 with SurveyFile

use of org.openforis.collect.model.SurveyFile in project collect by openforis.

the class SurveyFileFormValidator method validateFilenameUniqueness.

private boolean validateFilenameUniqueness(ValidationContext ctx) {
    List<SurveyFile> otherSurveyFiles = loadSurveyFilesDifferentFromThis(ctx);
    String filename = getValue(ctx, FILENAME_FIELD_NAME);
    for (SurveyFile surveyFile : otherSurveyFiles) {
        if (surveyFile.getFilename().equals(filename)) {
            addInvalidMessage(ctx, FILENAME_FIELD_NAME, Labels.getLabel("survey.file.error.duplicate_filename"));
            return false;
        }
    }
    return true;
}
Also used : SurveyFile(org.openforis.collect.model.SurveyFile)

Example 2 with SurveyFile

use of org.openforis.collect.model.SurveyFile in project collect by openforis.

the class SurveyFileFormValidator method loadSurveyFilesDifferentFromThis.

private List<SurveyFile> loadSurveyFilesDifferentFromThis(ValidationContext ctx) {
    List<SurveyFile> result = new ArrayList<SurveyFile>();
    SurveyFileVM vm = getVM(ctx);
    CollectSurvey survey = vm.getSurvey();
    SurveyManager surveyManager = getSurveyManager(ctx);
    List<SurveyFile> surveyFiles = surveyManager.loadSurveyFileSummaries(survey);
    SurveyFile editedSurveyFile = vm.getEditedItem();
    for (SurveyFile surveyFile : surveyFiles) {
        if (!surveyFile.getId().equals(editedSurveyFile.getId())) {
            result.add(surveyFile);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) SurveyFile(org.openforis.collect.model.SurveyFile) SurveyFileVM(org.openforis.collect.designer.viewmodel.SurveyFileVM) CollectSurvey(org.openforis.collect.model.CollectSurvey) SurveyManager(org.openforis.collect.manager.SurveyManager)

Example 3 with SurveyFile

use of org.openforis.collect.model.SurveyFile in project collect by openforis.

the class CollectEarthProjectFileCreatorImpl method includeSurveyFiles.

private void includeSurveyFiles(ZipFile zipFile, CollectSurvey survey, ZipParameters zipParameters) throws FileNotFoundException, IOException, ZipException {
    List<SurveyFile> surveyFiles = surveyManager.loadSurveyFileSummaries(survey);
    for (SurveyFile surveyFile : surveyFiles) {
        byte[] content = surveyManager.loadSurveyFileContent(surveyFile);
        File tempSurveyFile = copyToTempFile(content, surveyFile.getFilename());
        String namePrefix;
        switch(surveyFile.getType()) {
            case COLLECT_EARTH_GRID:
                namePrefix = GRID_FOLDER_NAME + "/";
                break;
            default:
                namePrefix = "";
        }
        Zip4jFiles.addFile(zipFile, tempSurveyFile, namePrefix + surveyFile.getFilename(), zipParameters);
    }
}
Also used : SurveyFile(org.openforis.collect.model.SurveyFile) SurveyFile(org.openforis.collect.model.SurveyFile) ZipFile(net.lingala.zip4j.core.ZipFile) File(java.io.File)

Example 4 with SurveyFile

use of org.openforis.collect.model.SurveyFile in project collect by openforis.

the class SurveyFileExportTask method execute.

@Override
protected void execute() throws Throwable {
    List<SurveyFile> surveyFiles = surveyManager.loadSurveyFileSummaries(survey);
    for (SurveyFile surveyFile : surveyFiles) {
        exportSurveyFile(surveyFile);
        incrementProcessedItems();
    }
}
Also used : SurveyFile(org.openforis.collect.model.SurveyFile)

Example 5 with SurveyFile

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

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