Search in sources :

Example 21 with Step

use of org.openforis.collect.model.CollectRecord.Step in project collect by openforis.

the class ValidationController method validateAllRecords.

@RequestMapping(value = "/validateAllRecords.htm", method = RequestMethod.GET)
public void validateAllRecords(HttpServletRequest request, HttpServletResponse response, @RequestParam String s, @RequestParam String r) throws IOException {
    final ServletOutputStream outputStream = response.getOutputStream();
    try {
        if (s == null || r == null) {
            outputStream.println("Wrong parameters: please specify 's' (survey) and 'r' (root entity name).");
            return;
        }
        SessionState sessionState = getSessionState(request);
        final User user = sessionState.getUser();
        final String sessionId = sessionState.getSessionId();
        print(outputStream, "Starting validation of all records: ");
        final CollectSurvey survey = surveyManager.get(s);
        if (survey == null) {
            print(outputStream, "Survey not found");
            return;
        }
        RecordFilter filter = new RecordFilter(survey);
        filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(r).getId());
        final ValidationMessageBuilder validationMessageHelper = ValidationMessageBuilder.createInstance(messageContextHolder);
        recordManager.visitSummaries(filter, null, new Visitor<CollectRecordSummary>() {

            public void visit(CollectRecordSummary summary) {
                try {
                    String recordKey = validationMessageHelper.getRecordKey(summary);
                    long start = System.currentTimeMillis();
                    print(outputStream, "Start validating record: " + recordKey);
                    Integer id = summary.getId();
                    Step step = summary.getStep();
                    recordManager.validateAndSave(survey, user, sessionId, id, step);
                    long elapsedMillis = System.currentTimeMillis() - start;
                    print(outputStream, "Validation of record " + recordKey + " completed in " + elapsedMillis + " millis");
                } catch (Exception e) {
                    try {
                        String message = "ERROR validating record " + summary.getId();
                        outputStream.println(message);
                        LOG.error(message);
                    } catch (IOException e1) {
                    }
                }
            }
        });
        print(outputStream, "End of validation of all records.");
    } catch (Exception e) {
        outputStream.println("ERROR - Validation of records not completed: " + e.getMessage());
        LOG.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : ValidationMessageBuilder(org.openforis.collect.model.validation.ValidationMessageBuilder) SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User) ServletOutputStream(javax.servlet.ServletOutputStream) Step(org.openforis.collect.model.CollectRecord.Step) IOException(java.io.IOException) IOException(java.io.IOException) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with Step

use of org.openforis.collect.model.CollectRecord.Step in project collect by openforis.

the class RecordManager method performPromote.

private void performPromote(CollectRecord record, User user) {
    /**
     * 1. clear node states
     * 2. update record step
     * 3. update all validation states
     */
    Date now = new Date();
    record.setModifiedBy(user);
    record.setModifiedDate(now);
    record.setDataCreatedBy(user);
    record.setDataCreationDate(now);
    record.setDataModifiedBy(user);
    record.setDataModifiedDate(now);
    record.setState(null);
    record.clearNodeStates();
    // change step and update the record
    Step currentStep = record.getStep();
    Step nextStep = currentStep.getNext();
    if (accessControlManager.isOwnerToBeResetAfterPromoting(user, currentStep)) {
        record.setOwner(null);
    }
    record.setStep(nextStep);
    int workflowSequenceNumber = record.getDataWorkflowSequenceNumber() + 1;
    record.setDataWorkflowSequenceNumber(workflowSequenceNumber);
    record.setWorkflowSequenceNumber(workflowSequenceNumber);
    validate(record);
    recordDao.execute(Arrays.asList(recordDao.createRecordDataInsertQuery(record, record.getId(), nextStep, workflowSequenceNumber), recordDao.createSummaryUpdateQuery(record)));
}
Also used : Step(org.openforis.collect.model.CollectRecord.Step) Date(java.util.Date)

Example 23 with Step

use of org.openforis.collect.model.CollectRecord.Step 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 24 with Step

use of org.openforis.collect.model.CollectRecord.Step in project collect by openforis.

the class RecordValidationProcess method startProcessing.

@Override
@Transactional(propagation = Propagation.SUPPORTS)
public void startProcessing() throws Exception {
    super.startProcessing();
    validateParameters();
    status.setTotal(recordManager.countRecords(new RecordFilter(survey)));
    Schema schema = survey.getSchema();
    List<EntityDefinition> rootEntities = schema.getRootEntityDefinitions();
    for (EntityDefinition rootEntityDef : rootEntities) {
        RecordFilter filter = new RecordFilter(survey, rootEntityDef.getId());
        List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
        for (CollectRecordSummary summary : summaries) {
            // print(outputStream, "Start validating record: " + recordKey);
            if (status.isRunning()) {
                Step step = summary.getStep();
                Integer recordId = summary.getId();
                recordManager.validateAndSave(survey, user, sessionId, recordId, step);
                status.incrementProcessed();
            // long elapsedMillis = System.currentTimeMillis() - start;
            // print(outputStream, "Validation of record " + recordKey + " completed in " + elapsedMillis + " millis");
            }
        }
    }
    if (status.isRunning()) {
        status.complete();
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Schema(org.openforis.idm.metamodel.Schema) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Step(org.openforis.collect.model.CollectRecord.Step) RecordFilter(org.openforis.collect.model.RecordFilter) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with Step

use of org.openforis.collect.model.CollectRecord.Step 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

Step (org.openforis.collect.model.CollectRecord.Step)49 CollectRecord (org.openforis.collect.model.CollectRecord)24 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)21 CollectSurvey (org.openforis.collect.model.CollectSurvey)11 ArrayList (java.util.ArrayList)9 RecordStep (org.openforis.collect.event.RecordStep)8 SessionState (org.openforis.collect.web.session.SessionState)8 StepSummary (org.openforis.collect.model.CollectRecordSummary.StepSummary)7 IOException (java.io.IOException)5 RecordFilter (org.openforis.collect.model.RecordFilter)5 NodeUnmarshallingError (org.openforis.collect.persistence.xml.NodeUnmarshallingError)5 MainStep (org.openforis.collect.io.data.DataImportState.MainStep)4 SubStep (org.openforis.collect.io.data.DataImportState.SubStep)4 User (org.openforis.collect.model.User)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 Schema (org.openforis.idm.metamodel.Schema)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Secured (org.springframework.security.access.annotation.Secured)3