use of org.openforis.collect.persistence.RecordPersistenceException in project collect by openforis.
the class DataService method updateActiveRecord.
@Transactional
@Secured(ENTRY_LIMITED)
public NodeChangeSetProxy updateActiveRecord(NodeUpdateRequestSetProxy requestSet) throws RecordPersistenceException, RecordIndexException {
sessionManager.checkIsActiveRecordLocked();
CollectRecord activeRecord = getActiveRecord();
NodeUpdateRequestSet reqSet = requestSet.toNodeUpdateRequestSet(codeListManager, sessionManager, activeRecord);
NodeChangeSet changeSet = updateRecord(activeRecord, reqSet);
if (!changeSet.isEmpty() && isCurrentRecordIndexable()) {
recordIndexService.temporaryIndex(activeRecord);
}
String userName = sessionManager.getSessionState().getUser().getUsername();
List<RecordEvent> events = new EventProducer().produceFor(changeSet, userName);
sessionManager.onEvents(events);
NodeChangeSetProxy result = new NodeChangeSetProxy(activeRecord, changeSet, getProxyContext());
if (requestSet.isAutoSave()) {
try {
saveActiveRecord();
result.setRecordSaved(true);
} catch (Exception e) {
result.setRecordSaved(false);
}
}
return result;
}
use of org.openforis.collect.persistence.RecordPersistenceException in project collect by openforis.
the class DeleteRecordHandler method execute.
@Override
public RecordEvent execute(DeleteRecordCommand command) {
try {
CollectSurvey survey = surveyManager.getById(command.getSurveyId());
recordManager.delete(command.getRecordId());
return new RecordDeletedEvent(survey.getName(), command.getRecordId(), new Date(), command.getUsername());
} catch (RecordPersistenceException e) {
throw new RuntimeException(e);
}
}
use of org.openforis.collect.persistence.RecordPersistenceException 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();
}
Aggregations