use of org.openforis.collect.io.data.CSVDataImportJob 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);
}
Aggregations