use of org.openforis.collect.io.data.CSVDataImportJob.CSVDataImportInput in project collect by openforis.
the class CSVDataImportService method start.
@Secured("ROLE_ADMIN")
public DataImportStatusProxy start(String tempFileName, int parentEntityId, Step step, boolean transactional, boolean validateRecords, boolean insertNewRecords, String newRecordVersionName, boolean deleteExistingEntities) throws DataImportExeption {
if (importJob == null || !importJob.isRunning()) {
File importFile = new File(tempFileName);
SessionState sessionState = sessionManager.getSessionState();
CollectSurvey survey = sessionState.getActiveSurvey();
if (transactional) {
importJob = jobManager.createJob(TransactionalCSVDataImportJob.class);
} else {
importJob = jobManager.createJob(CSVDataImportJob.BEAN_NAME, CSVDataImportJob.class);
}
CSVDataImportSettings settings = new CSVDataImportSettings();
settings.setRecordValidationEnabled(validateRecords);
settings.setInsertNewRecords(insertNewRecords);
settings.setNewRecordVersionName(newRecordVersionName);
settings.setDeleteExistingEntities(deleteExistingEntities);
Step[] steps = step == null ? Step.values() : new Step[] { step };
CSVDataImportInput input = new CSVDataImportInput(importFile, survey, steps, parentEntityId, settings);
importJob.setInput(input);
jobManager.start(importJob);
}
return getStatus();
}
use of org.openforis.collect.io.data.CSVDataImportJob.CSVDataImportInput 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);
}
use of org.openforis.collect.io.data.CSVDataImportJob.CSVDataImportInput in project collect by openforis.
the class CSVDataImportJobIntegrationTest method importCSVFile.
public CSVDataImportJob importCSVFile(String fileName, int parentEntityDefinitionId, boolean transactional, CSVDataImportSettings settings) throws Exception {
File file = getTestFile(fileName);
CSVDataImportJob job = jobManager.createJob(transactional ? TransactionalCSVDataImportJob.BEAN_NAME : CSVDataImportJob.BEAN_NAME, CSVDataImportJob.class);
job.setInput(new CSVDataImportInput(file, survey, Step.values(), parentEntityDefinitionId, settings));
jobManager.start(job, false);
return job;
}
Aggregations