Search in sources :

Example 1 with ValidationMessageBuilder

use of org.openforis.collect.model.validation.ValidationMessageBuilder 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 2 with ValidationMessageBuilder

use of org.openforis.collect.model.validation.ValidationMessageBuilder in project collect by openforis.

the class ValidationResultsProxy method extractValidationResultMessages.

private List<String> extractValidationResultMessages(List<ValidationResult> validationResultList) {
    List<String> result = new ArrayList<String>();
    ValidationMessageBuilder validationMessageBuilder = ValidationMessageBuilder.createInstance(context.getMessageSource());
    for (ValidationResult validationResult : validationResultList) {
        result.add(validationMessageBuilder.getValidationMessage(attribute, validationResult, context.getLocale()));
    }
    return result;
}
Also used : ValidationMessageBuilder(org.openforis.collect.model.validation.ValidationMessageBuilder) ArrayList(java.util.ArrayList) ValidationResult(org.openforis.idm.metamodel.validation.ValidationResult)

Aggregations

ValidationMessageBuilder (org.openforis.collect.model.validation.ValidationMessageBuilder)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 Step (org.openforis.collect.model.CollectRecord.Step)1 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 RecordFilter (org.openforis.collect.model.RecordFilter)1 User (org.openforis.collect.model.User)1 SessionState (org.openforis.collect.web.session.SessionState)1 ValidationResult (org.openforis.idm.metamodel.validation.ValidationResult)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1