use of org.openforis.collect.io.data.csv.CSVDataImportSettings 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.csv.CSVDataImportSettings 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.csv.CSVDataImportSettings in project collect by openforis.
the class CSVDataImportJobIntegrationTest method importCSVFile.
public CSVDataImportJob importCSVFile(String fileName, int parentEntityDefinitionId, boolean transactional, boolean insertNewRecords, String newRecordVersionName, boolean createAncestorEntities) throws Exception {
CSVDataImportSettings settings = new CSVDataImportSettings();
settings.setInsertNewRecords(insertNewRecords);
settings.setNewRecordVersionName(newRecordVersionName);
settings.setCreateAncestorEntities(createAncestorEntities);
return importCSVFile(fileName, parentEntityDefinitionId, transactional, settings);
}
use of org.openforis.collect.io.data.csv.CSVDataImportSettings in project collect by openforis.
the class CSVDataImportJobIntegrationTest method validDeleteExistingEntitiesTest.
@Test
public void validDeleteExistingEntitiesTest() throws Exception {
CollectRecord record = createTestRecord(survey, "10_114");
recordDao.insert(record);
EntityDefinition clusterDefn = survey.getSchema().getRootEntityDefinition("cluster");
EntityDefinition plotDefn = (EntityDefinition) clusterDefn.getChildDefinition("plot");
assertEquals(3, record.getRootEntity().getCount(plotDefn));
CSVDataImportSettings settings = new CSVDataImportSettings();
settings.setDeleteExistingEntities(true);
CSVDataImportJob process = importCSVFile(VALID_NESTED_ENTITY_TEST_CSV, plotDefn.getId(), true, settings);
assertTrue(process.isCompleted());
assertTrue(process.getParsingErrors().isEmpty());
CollectRecord reloadedRecord = recordDao.load(survey, record.getId(), Step.ENTRY);
assertEquals(2, reloadedRecord.getRootEntity().getCount(plotDefn));
Entity reloadedCluster = reloadedRecord.getRootEntity();
{
Entity plot = reloadedCluster.findChildEntitiesByKeys("plot", "1", "A").get(0);
CodeAttribute landUse = (CodeAttribute) plot.getChild("land_use");
assertEquals("2", landUse.getValue().getCode());
}
{
Entity plot = reloadedCluster.findChildEntitiesByKeys("plot", "2", "B").get(0);
CodeAttribute landUse = (CodeAttribute) plot.getChild("land_use");
assertEquals("3", landUse.getValue().getCode());
}
}
use of org.openforis.collect.io.data.csv.CSVDataImportSettings in project collect by openforis.
the class CSVDataImportProcessIntegrationTest method importCSVFile.
public CSVDataImportProcess importCSVFile(String fileName, int parentEntityDefinitionId, boolean transactional, boolean insertNewRecords, String newRecordVersionName, boolean createAncestorEntities) throws Exception {
CSVDataImportSettings settings = new CSVDataImportSettings();
settings.setInsertNewRecords(insertNewRecords);
settings.setNewRecordVersionName(newRecordVersionName);
settings.setCreateAncestorEntities(createAncestorEntities);
return importCSVFile(fileName, parentEntityDefinitionId, transactional, settings);
}
Aggregations