Search in sources :

Example 71 with CollectRecord

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);
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Transactional(org.springframework.transaction.annotation.Transactional)

Example 72 with CollectRecord

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord)

Example 73 with CollectRecord

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;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Step(org.openforis.collect.model.CollectRecord.Step) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 74 with CollectRecord

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();
}
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)

Example 75 with CollectRecord

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());
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Step(org.openforis.collect.model.CollectRecord.Step)

Aggregations

CollectRecord (org.openforis.collect.model.CollectRecord)141 Entity (org.openforis.idm.model.Entity)36 Test (org.junit.Test)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)29 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)29 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)27 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)24 Step (org.openforis.collect.model.CollectRecord.Step)23 User (org.openforis.collect.model.User)19 SessionState (org.openforis.collect.web.session.SessionState)15 RecordFilter (org.openforis.collect.model.RecordFilter)14 Transactional (org.springframework.transaction.annotation.Transactional)14 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)12 Secured (org.springframework.security.access.annotation.Secured)12 ArrayList (java.util.ArrayList)11 Date (org.openforis.idm.model.Date)10 GregorianCalendar (java.util.GregorianCalendar)9 Code (org.openforis.idm.model.Code)9 RealAttribute (org.openforis.idm.model.RealAttribute)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9