Search in sources :

Example 1 with CSVDataImportInput

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();
}
Also used : TransactionalCSVDataImportJob(org.openforis.collect.io.data.TransactionalCSVDataImportJob) CSVDataImportJob(org.openforis.collect.io.data.CSVDataImportJob) SessionState(org.openforis.collect.web.session.SessionState) CSVDataImportInput(org.openforis.collect.io.data.CSVDataImportJob.CSVDataImportInput) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey) TransactionalCSVDataImportJob(org.openforis.collect.io.data.TransactionalCSVDataImportJob) CSVDataImportSettings(org.openforis.collect.io.data.csv.CSVDataImportSettings) File(java.io.File) Secured(org.springframework.security.access.annotation.Secured)

Example 2 with CSVDataImportInput

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);
}
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 3 with CSVDataImportInput

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;
}
Also used : CSVDataImportInput(org.openforis.collect.io.data.CSVDataImportJob.CSVDataImportInput) File(java.io.File)

Aggregations

File (java.io.File)3 CSVDataImportInput (org.openforis.collect.io.data.CSVDataImportJob.CSVDataImportInput)3 CSVDataImportJob (org.openforis.collect.io.data.CSVDataImportJob)2 TransactionalCSVDataImportJob (org.openforis.collect.io.data.TransactionalCSVDataImportJob)2 CSVDataImportSettings (org.openforis.collect.io.data.csv.CSVDataImportSettings)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 Step (org.openforis.collect.model.CollectRecord.Step)1 JobView (org.openforis.collect.web.controller.CollectJobController.JobView)1 SessionState (org.openforis.collect.web.session.SessionState)1 Secured (org.springframework.security.access.annotation.Secured)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1