Search in sources :

Example 1 with RecordPersistenceException

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) EventProducer(org.openforis.collect.event.EventProducer) RecordEvent(org.openforis.collect.event.RecordEvent) NodeChangeSetProxy(org.openforis.collect.model.proxy.NodeChangeSetProxy) RecordPromoteException(org.openforis.collect.manager.RecordPromoteException) RecordUnlockedException(org.openforis.collect.persistence.RecordUnlockedException) RecordIndexException(org.openforis.collect.manager.RecordIndexException) RecordLockedException(org.openforis.collect.persistence.RecordLockedException) MultipleEditException(org.openforis.collect.persistence.MultipleEditException) RecordPersistenceException(org.openforis.collect.persistence.RecordPersistenceException) Secured(org.springframework.security.access.annotation.Secured) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RecordPersistenceException

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);
    }
}
Also used : RecordDeletedEvent(org.openforis.collect.event.RecordDeletedEvent) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordPersistenceException(org.openforis.collect.persistence.RecordPersistenceException) Date(java.util.Date)

Example 3 with RecordPersistenceException

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();
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) DataTransformation(org.openforis.collect.io.data.csv.DataTransformation) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) OutputStreamWriter(java.io.OutputStreamWriter) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey) ModelCsvWriter(org.openforis.collect.io.data.csv.ModelCsvWriter) ModelCsvWriter(org.openforis.collect.io.data.csv.ModelCsvWriter) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) InvalidExpressionException(org.openforis.idm.model.expression.InvalidExpressionException) RecordPersistenceException(org.openforis.collect.persistence.RecordPersistenceException) IOException(java.io.IOException)

Aggregations

RecordPersistenceException (org.openforis.collect.persistence.RecordPersistenceException)3 CollectRecord (org.openforis.collect.model.CollectRecord)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Date (java.util.Date)1 EventProducer (org.openforis.collect.event.EventProducer)1 RecordDeletedEvent (org.openforis.collect.event.RecordDeletedEvent)1 RecordEvent (org.openforis.collect.event.RecordEvent)1 DataTransformation (org.openforis.collect.io.data.csv.DataTransformation)1 ModelCsvWriter (org.openforis.collect.io.data.csv.ModelCsvWriter)1 RecordIndexException (org.openforis.collect.manager.RecordIndexException)1 RecordPromoteException (org.openforis.collect.manager.RecordPromoteException)1 Step (org.openforis.collect.model.CollectRecord.Step)1 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)1 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)1 NodeChangeSetProxy (org.openforis.collect.model.proxy.NodeChangeSetProxy)1 MultipleEditException (org.openforis.collect.persistence.MultipleEditException)1 RecordLockedException (org.openforis.collect.persistence.RecordLockedException)1