use of org.zkoss.bind.annotation.Command in project collect by openforis.
the class SurveyEditVM method exportCsvDataImportTemplate.
@Command
public void exportCsvDataImportTemplate() throws IOException {
CSVDataExportJob job = jobManager.createJob(CSVDataExportJob.class);
job.setOutputFile(File.createTempFile("data-import-template", ".zip"));
CSVDataExportParameters parameters = new CSVDataExportParameters();
EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
RecordFilter recordFilter = new RecordFilter(survey, rootEntityDef.getId());
parameters.setRecordFilter(recordFilter);
parameters.setAlwaysGenerateZipFile(true);
parameters.setIncludeEnumeratedEntities(false);
job.setParameters(parameters);
jobManager.start(job, false);
if (job.isCompleted()) {
File outputFile = job.getOutputFile();
String dateStr = Dates.formatLocalDateTime(new Date());
String fileName = String.format(DATA_IMPORT_TEMPLATE_FILE_NAME_PATTERN, survey.getName(), dateStr, "zip");
String contentType = URLConnection.guessContentTypeFromName(fileName);
FileInputStream is = new FileInputStream(outputFile);
Filedownload.save(is, contentType, fileName);
} else {
throw new RuntimeException("Error generating the CSV data export template: " + job.getErrorMessage(), job.getLastException());
}
}
use of org.zkoss.bind.annotation.Command in project collect by openforis.
the class SurveyFileVM method downloadUploadedFile.
@Command
public void downloadUploadedFile() throws IOException {
String contentType = URLConnection.guessContentTypeFromName(uploadedFileName);
Filedownload.save(new FileInputStream(uploadedFile), contentType, uploadedFileName);
}
use of org.zkoss.bind.annotation.Command 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:
}
}
use of org.zkoss.bind.annotation.Command in project collect by openforis.
the class SurveyImportVM method fileUploaded.
@Command
public void fileUploaded(@ContextParam(ContextType.TRIGGER_EVENT) UploadEvent event) {
Media media = event.getMedia();
String fileName = media.getName();
if (validateBackupFile(fileName)) {
File tempFile;
String extension = FilenameUtils.getExtension(fileName);
boolean xmlFileUploaded = XML_FILE_EXTENSION.equalsIgnoreCase(extension);
if (xmlFileUploaded) {
tempFile = OpenForisIOUtils.copyToTempFile(media.getReaderData(), extension);
} else {
tempFile = OpenForisIOUtils.copyToTempFile(media.getStreamData(), extension);
}
this.uploadedFile = tempFile;
this.uploadedFileName = fileName;
notifyChange("uploadedFileName");
updateForm();
prepareSurveyImport(xmlFileUploaded);
}
}
use of org.zkoss.bind.annotation.Command in project collect by openforis.
the class SurveyMainInfoVM method addSurveyFile.
@Command
public void addSurveyFile() {
editedSurveyFile = new SurveyFile(survey);
editingNewSurveyFile = true;
openSurveyFileEditPopUp();
}
Aggregations