Search in sources :

Example 56 with Command

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());
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CSVDataExportJob(org.openforis.collect.io.data.CSVDataExportJob) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) File(java.io.File) RecordFilter(org.openforis.collect.model.RecordFilter) Date(java.util.Date) FileInputStream(java.io.FileInputStream) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand) Command(org.zkoss.bind.annotation.Command)

Example 57 with Command

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);
}
Also used : FileInputStream(java.io.FileInputStream) Command(org.zkoss.bind.annotation.Command)

Example 58 with Command

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:
    }
}
Also used : SurveyFile(org.openforis.collect.model.SurveyFile) File(java.io.File) Date(java.util.Date) FileInputStream(java.io.FileInputStream) CollectEarthGridTemplateGenerator(org.openforis.collect.io.metadata.collectearth.CollectEarthGridTemplateGenerator) Command(org.zkoss.bind.annotation.Command)

Example 59 with Command

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);
    }
}
Also used : Media(org.zkoss.util.media.Media) File(java.io.File) Command(org.zkoss.bind.annotation.Command) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Example 60 with Command

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

Aggregations

Command (org.zkoss.bind.annotation.Command)62 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)44 NotifyChange (org.zkoss.bind.annotation.NotifyChange)26 File (java.io.File)12 CollectSurvey (org.openforis.collect.model.CollectSurvey)10 MessageUtil (org.openforis.collect.designer.util.MessageUtil)9 UITab (org.openforis.collect.metamodel.ui.UITab)6 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)6 FileInputStream (java.io.FileInputStream)5 ConfirmParams (org.openforis.collect.designer.util.MessageUtil.ConfirmParams)5 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)5 SurveyObject (org.openforis.idm.metamodel.SurveyObject)5 Media (org.zkoss.util.media.Media)5 Window (org.zkoss.zul.Window)5 UserCredential (es.bsc.compss.ui.auth.UserCredential)4 IOException (java.io.IOException)4 Date (java.util.Date)4 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)4 SessionStatus (org.openforis.collect.designer.session.SessionStatus)3 ConfirmHandler (org.openforis.collect.designer.util.MessageUtil.ConfirmHandler)3