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;
}
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;
}
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);
}
}
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();
}
}
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);
}
}
}
Aggregations