Search in sources :

Example 1 with JobView

use of org.openforis.collect.web.controller.CollectJobController.JobView in project collect by openforis.

the class RecordController method startCsvDataImportJob.

@RequestMapping(value = "survey/{surveyId}/data/csvimport/records", method = POST, consumes = MULTIPART_FORM_DATA_VALUE)
@ResponseBody
public JobView startCsvDataImportJob(@PathVariable("surveyId") int surveyId, @RequestParam("file") MultipartFile multipartFile, @RequestParam String rootEntityName, @RequestParam String importType, @RequestParam String steps, @RequestParam(required = false) Integer entityDefinitionId, @RequestParam(required = false) boolean validateRecords, @RequestParam(required = false) boolean deleteEntitiesBeforeImport, @RequestParam(required = false) String newRecordVersionName) throws IOException {
    File file = Files.writeToTempFile(multipartFile.getInputStream(), multipartFile.getOriginalFilename(), "ofc_csv_data_import");
    CollectSurvey survey = surveyManager.getById(surveyId);
    CSVDataImportJob job = jobManager.createJob(TransactionalCSVDataImportJob.class);
    CSVDataImportSettings settings = new CSVDataImportSettings();
    settings.setDeleteExistingEntities(deleteEntitiesBeforeImport);
    settings.setRecordValidationEnabled(validateRecords);
    settings.setInsertNewRecords("newRecords".equals(importType));
    settings.setNewRecordVersionName(newRecordVersionName);
    CSVDataImportInput input = new CSVDataImportInput(file, survey, fromStepNames(steps), entityDefinitionId, settings);
    job.setInput(input);
    jobManager.start(job);
    this.csvDataImportJob = job;
    return new JobView(job);
}
Also used : TransactionalCSVDataImportJob(org.openforis.collect.io.data.TransactionalCSVDataImportJob) CSVDataImportJob(org.openforis.collect.io.data.CSVDataImportJob) JobView(org.openforis.collect.web.controller.CollectJobController.JobView) CSVDataImportInput(org.openforis.collect.io.data.CSVDataImportJob.CSVDataImportInput) CollectSurvey(org.openforis.collect.model.CollectSurvey) CSVDataImportSettings(org.openforis.collect.io.data.csv.CSVDataImportSettings) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with JobView

use of org.openforis.collect.web.controller.CollectJobController.JobView in project collect by openforis.

the class RecordController method getFullBackupJobView.

@RequestMapping(value = "survey/{surveyId}/data/records/backupexportjob", method = GET)
@ResponseBody
public JobView getFullBackupJobView() {
    if (fullBackupJob == null) {
        return null;
    } else {
        JobView jobView = new JobView(fullBackupJob);
        jobView.putExtra("dataBackupErrors", fullBackupJob.getDataBackupErrors());
        return jobView;
    }
}
Also used : JobView(org.openforis.collect.web.controller.CollectJobController.JobView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with JobView

use of org.openforis.collect.web.controller.CollectJobController.JobView in project collect by openforis.

the class RecordController method startRecordImport.

@RequestMapping(value = "survey/{surveyId}/data/import/records", method = POST)
@ResponseBody
public JobView startRecordImport(@PathVariable("surveyId") int surveyId, @RequestParam List<Integer> entryIdsToImport, @RequestParam(defaultValue = "true") boolean validateRecords) throws IOException {
    RecordProvider recordProvider = dataRestoreSummaryJob.getRecordProvider();
    recordProvider.setConfiguration(new RecordProviderConfiguration(true));
    DataRestoreJob job = jobManager.createJob(TransactionalDataRestoreJob.class);
    job.setFile(dataRestoreSummaryJob.getFile());
    job.setUser(sessionManager.getLoggedUser());
    job.setValidateRecords(validateRecords);
    job.setRecordProvider(recordProvider);
    job.setPackagedSurvey(dataRestoreSummaryJob.getPackagedSurvey());
    job.setPublishedSurvey(dataRestoreSummaryJob.getPublishedSurvey());
    job.setEntryIdsToImport(entryIdsToImport);
    job.setRecordFilesToBeDeleted(dataRestoreSummaryJob.getSummary().getConflictingRecordFiles(entryIdsToImport));
    job.setRestoreUploadedFiles(true);
    job.setValidateRecords(validateRecords);
    jobManager.start(job);
    return new JobView(job);
}
Also used : RecordProvider(org.openforis.collect.io.data.RecordProvider) JobView(org.openforis.collect.web.controller.CollectJobController.JobView) RecordProviderConfiguration(org.openforis.collect.io.data.RecordProviderConfiguration) DataRestoreJob(org.openforis.collect.io.data.DataRestoreJob) TransactionalDataRestoreJob(org.openforis.collect.io.data.TransactionalDataRestoreJob) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with JobView

use of org.openforis.collect.web.controller.CollectJobController.JobView in project collect by openforis.

the class RecordController method startCsvDataExportJob.

@RequestMapping(value = "survey/{surveyId}/data/records/startcsvexport", method = POST)
@ResponseBody
public JobView startCsvDataExportJob(@PathVariable("surveyId") int surveyId, @RequestBody CSVExportParametersForm parameters) throws IOException {
    User user = sessionManager.getLoggedUser();
    CollectSurvey survey = surveyManager.getById(surveyId);
    csvDataExportJob = jobManager.createJob(CSVDataExportJob.class);
    csvDataExportJob.setSurvey(survey);
    csvDataExportJob.setOutputFile(File.createTempFile("collect-csv-data-export", ".zip"));
    CSVDataExportParameters exportParameters = parameters.toExportParameters(survey, user, userGroupManager);
    csvDataExportJob.setParameters(exportParameters);
    jobManager.start(csvDataExportJob);
    return new JobView(csvDataExportJob);
}
Also used : User(org.openforis.collect.model.User) JobView(org.openforis.collect.web.controller.CollectJobController.JobView) CSVDataExportJob(org.openforis.collect.io.data.CSVDataExportJob) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with JobView

use of org.openforis.collect.web.controller.CollectJobController.JobView in project collect by openforis.

the class SurveyController method startExport.

@RequestMapping(value = "export/{id}", method = POST)
@ResponseBody
public JobView startExport(@Valid SurveyExportParameters params, BindingResult result) {
    this.surveyBackupJob = null;
    String uri = params.getSurveyUri();
    // boolean skipValidation = params.isSkipValidation();
    SurveySummary surveySummary = surveyManager.loadSummaryByUri(uri);
    final CollectSurvey loadedSurvey;
    if (surveySummary.isTemporary() && params.getSurveyType() == SurveyType.TEMPORARY) {
        loadedSurvey = surveyManager.loadSurvey(surveySummary.getId());
    } else {
        loadedSurvey = surveyManager.getByUri(uri);
    }
    switch(params.getOutputFormat()) {
        case EARTH:
            {
                // if (skipValidation || collectEarthSurveyValidator.validate(loadedSurvey).isOk()) {
                CollectEarthSurveyExportJob job = jobManager.createJob(CollectEarthSurveyExportJob.class);
                job.setSurvey(loadedSurvey);
                job.setLanguageCode(params.getLanguageCode());
                jobManager.start(job, String.valueOf(loadedSurvey.getId()));
                this.surveyBackupJob = job;
                return new JobView(job);
            }
        // break;
        case MOBILE:
        default:
            SurveyBackupJob job = jobManager.createJob(SurveyBackupJob.class);
            job.setSurvey(loadedSurvey);
            // surveyBackupJob.setIncludeData(parameters.isIncludeData());
            // surveyBackupJob.setIncludeRecordFiles(parameters.isIncludeUploadedFiles());
            job.setOutputFormat(org.openforis.collect.io.SurveyBackupJob.OutputFormat.valueOf(params.getOutputFormat().name()));
            job.setOutputSurveyDefaultLanguage(ObjectUtils.defaultIfNull(params.getLanguageCode(), loadedSurvey.getDefaultLanguage()));
            jobManager.start(job, String.valueOf(loadedSurvey.getId()));
            this.surveyBackupJob = job;
            return new JobView(job);
    }
}
Also used : CollectEarthSurveyExportJob(org.openforis.collect.manager.CollectEarthSurveyExportJob) SurveySummary(org.openforis.collect.model.SurveySummary) JobView(org.openforis.collect.web.controller.CollectJobController.JobView) SurveyBackupJob(org.openforis.collect.io.SurveyBackupJob) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

JobView (org.openforis.collect.web.controller.CollectJobController.JobView)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 CollectSurvey (org.openforis.collect.model.CollectSurvey)5 File (java.io.File)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 DataReport (org.openforis.collect.datacleansing.DataReport)1 SurveyBackupJob (org.openforis.collect.io.SurveyBackupJob)1 CSVDataExportJob (org.openforis.collect.io.data.CSVDataExportJob)1 CSVDataImportJob (org.openforis.collect.io.data.CSVDataImportJob)1 CSVDataImportInput (org.openforis.collect.io.data.CSVDataImportJob.CSVDataImportInput)1 DataRestoreJob (org.openforis.collect.io.data.DataRestoreJob)1 DataRestoreSummaryJob (org.openforis.collect.io.data.DataRestoreSummaryJob)1 RecordProvider (org.openforis.collect.io.data.RecordProvider)1 RecordProviderConfiguration (org.openforis.collect.io.data.RecordProviderConfiguration)1 TransactionalCSVDataImportJob (org.openforis.collect.io.data.TransactionalCSVDataImportJob)1 TransactionalDataRestoreJob (org.openforis.collect.io.data.TransactionalDataRestoreJob)1 CSVDataExportParameters (org.openforis.collect.io.data.csv.CSVDataExportParameters)1 CSVDataImportSettings (org.openforis.collect.io.data.csv.CSVDataImportSettings)1 CollectEarthSurveyExportJob (org.openforis.collect.manager.CollectEarthSurveyExportJob)1