use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordManager method demote.
@Transactional(readOnly = false, propagation = REQUIRED)
public void demote(CollectSurvey survey, int recordId, Step currentStep, User user, RecordCallback callback) throws RecordPersistenceException {
CollectRecord record = demote(survey, recordId, currentStep, user);
callback.run(record);
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordManager method create.
public CollectRecord create(CollectSurvey survey, String rootEntityName, User user, String modelVersionName, String sessionId, Step step) {
CollectRecord record = instantiateRecord(survey, rootEntityName, user, modelVersionName, step);
initializeRecord(record, user);
return record;
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class RecordManager method demote.
@Transactional(readOnly = false, propagation = REQUIRED)
public CollectRecord demote(CollectSurvey survey, int recordId, Step currentStep, User user) throws RecordPersistenceException {
Step prevStep = currentStep.getPrevious();
recordDao.updateStepDataState(survey, recordId, currentStep, State.REJECTED);
Step newStep = recordDao.duplicateLatestNotRejectedStepData(survey, recordId, prevStep);
if (newStep != prevStep) {
throw new IllegalStateException(String.format("Unexpected step after demote: expected %s found %s", prevStep, newStep));
}
CollectRecord record = recordDao.load(survey, recordId, prevStep);
loadDetachedObjects(record);
record.setModifiedBy(user);
record.setModifiedDate(new Date());
record.setStep(prevStep);
record.setOwner(user);
record.setState(State.REJECTED);
validate(record);
recordDao.updateSummary(record);
return record;
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class CSVDataExportProcess method exportData.
// private String calculateOutputFileName() {
// return "data.zip";
// /*
// StringBuilder sb = new StringBuilder();
// sb.append(survey.getName());
// sb.append("_");
// sb.append(rootEntityName);
// sb.append("_");
// sb.append("csv_data");
// SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
// String today = formatter.format(new Date());
// sb.append(today);
// sb.append(".zip");
// return sb.toString();
// */
// }
private void exportData(OutputStream outputStream, int entityDefId) throws InvalidExpressionException, IOException, RecordPersistenceException {
Writer outputWriter = new OutputStreamWriter(outputStream, OpenForisIOUtils.UTF_8);
CSVDataExportColumnProviderGenerator csvDataExportColumnProviderGenerator = new CSVDataExportColumnProviderGenerator(recordFilter.getSurvey(), configuration);
DataTransformation transform = csvDataExportColumnProviderGenerator.generateDataTransformation(entityDefId);
@SuppressWarnings("resource") ModelCsvWriter // closing modelWriter will close referenced output stream
modelWriter = new ModelCsvWriter(outputWriter, transform);
modelWriter.printColumnHeadings();
CollectSurvey survey = recordFilter.getSurvey();
Step step = recordFilter.getStepGreaterOrEqual();
List<CollectRecordSummary> summaries = recordManager.loadSummaries(recordFilter);
for (CollectRecordSummary s : summaries) {
if (status.isRunning()) {
try {
CollectRecord record = recordManager.load(survey, s.getId(), step, false);
modelWriter.printData(record);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
status.incrementProcessed();
} else {
break;
}
}
modelWriter.flush();
}
use of org.openforis.collect.model.CollectRecord in project collect by openforis.
the class CSVDataImportProcess method processLine.
private void processLine(DataLine line) throws RecordPersistenceException {
if (!validateRecordKey(line)) {
return;
}
if (settings.isInsertNewRecords()) {
// create new record
EntityDefinition rootEntityDefn = survey.getSchema().getRootEntityDefinition(parentEntityDefinitionId);
CollectRecord record = recordManager.instantiateRecord(survey, rootEntityDefn.getName(), adminUser, settings.getNewRecordVersionName(), Step.ENTRY);
NodeChangeSet changes = recordManager.initializeRecord(record);
if (nodeChangeBatchProcessor != null) {
nodeChangeBatchProcessor.add(changes, adminUser.getUsername());
}
setRecordKeys(line, record);
setValuesInRecord(line, record, Step.ENTRY);
insertRecord(record);
} else {
CollectRecordSummary recordSummary = loadRecordSummaryIfAny(line);
if (recordSummary != null) {
Step originalRecordStep = recordSummary.getStep();
if (step == null) {
// set values in each step data
for (Step currentStep : Step.values()) {
if (currentStep.beforeEqual(originalRecordStep)) {
CollectRecord record = loadRecord(recordSummary.getId(), currentStep);
setValuesInRecord(line, record, currentStep);
// always save record when updating multiple record steps in the same process
updateRecord(record, originalRecordStep, currentStep);
}
}
} else {
if (step.beforeEqual(originalRecordStep)) {
CollectRecord record;
boolean recordChanged = lastModifiedRecordSummary == null || !recordSummary.getId().equals(lastModifiedRecordSummary.getId());
if (recordChanged) {
// record changed
if (lastModifiedRecordSummary != null) {
saveLastModifiedRecord();
}
record = loadRecord(recordSummary.getId(), this.step);
} else {
record = lastModifiedRecord;
}
setValuesInRecord(line, record, step);
lastModifiedRecordSummary = recordSummary;
lastModifiedRecord = record;
} else {
status.addParsingError(new ParsingError(ErrorType.INVALID_VALUE, line.getLineNumber(), (String) null, RECORD_NOT_IN_SELECTED_STEP_MESSAGE_KEY));
}
}
}
}
status.addProcessedRow(line.getLineNumber());
}
Aggregations