Search in sources :

Example 16 with RecordFilter

use of org.openforis.collect.model.RecordFilter in project collect by openforis.

the class RecordController method startValidationResportJob.

@RequestMapping(value = "survey/{surveyId}/data/records/validationreport", method = POST)
@ResponseBody
public JobProxy startValidationResportJob(@PathVariable("surveyId") int surveyId) {
    User user = sessionManager.getLoggedUser();
    Locale locale = sessionManager.getSessionState().getLocale();
    CollectSurvey survey = surveyManager.getById(surveyId);
    EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
    ValidationReportJob job = jobManager.createJob(ValidationReportJob.class);
    Input input = new Input();
    input.setLocale(locale);
    input.setReportType(ReportType.CSV);
    RecordFilter recordFilter = createRecordFilter(survey, user, userGroupManager, rootEntityDef.getId(), false);
    input.setRecordFilter(recordFilter);
    job.setInput(input);
    this.validationReportJob = job;
    jobManager.start(job);
    return new JobProxy(job);
}
Also used : Locale(java.util.Locale) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Input(org.openforis.collect.manager.ValidationReportJob.Input) CSVDataImportInput(org.openforis.collect.io.data.CSVDataImportJob.CSVDataImportInput) User(org.openforis.collect.model.User) JobProxy(org.openforis.concurrency.proxy.JobProxy) ValidationReportJob(org.openforis.collect.manager.ValidationReportJob) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 17 with RecordFilter

use of org.openforis.collect.model.RecordFilter in project collect by openforis.

the class RecordStatsGenerator method generate.

public RecordsStats generate(int surveyId, Date[] period) {
    final RecordsStats stats = new RecordsStats(period);
    CollectSurvey survey = surveyManager.getById(surveyId);
    recordManager.visitSummaries(new RecordFilter(survey), null, new Visitor<CollectRecordSummary>() {

        public void visit(CollectRecordSummary s) {
            for (Entry<Step, StepSummary> entry : s.getStepSummaries().entrySet()) {
                Step step = entry.getKey();
                StepSummary stepSummary = entry.getValue();
                if (stepSummary.getCreationDate() != null) {
                    PointStats pointStats = stats.getOrCreateDailyStats(stepSummary.getCreationDate());
                    switch(step) {
                        case ENTRY:
                            pointStats.incrementCreated();
                            break;
                        case CLEANSING:
                            pointStats.incrementEntered();
                            break;
                        case ANALYSIS:
                            pointStats.incrementCleansed();
                            break;
                    }
                }
            }
            if (s.getModifiedDate() != null) {
                PointStats pointStats = stats.getOrCreateDailyStats(s.getModifiedDate());
                pointStats.incrementModified();
            }
        }
    }, true);
    stats.finalize();
    return stats;
}
Also used : Entry(java.util.Map.Entry) StepSummary(org.openforis.collect.model.CollectRecordSummary.StepSummary) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 18 with RecordFilter

use of org.openforis.collect.model.RecordFilter 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 19 with RecordFilter

use of org.openforis.collect.model.RecordFilter in project collect by openforis.

the class GeoDataController method processNodes.

private void processNodes(CollectSurvey survey, Integer recordOffset, Integer maxNumberOfRecords, int attributeId, NodeProcessor nodeProcessor) throws Exception {
    NodeDefinition nodeDef = survey.getSchema().getDefinitionById(attributeId);
    RecordFilter filter = new RecordFilter(survey);
    filter.setOffset(recordOffset);
    filter.setMaxNumberOfRecords(maxNumberOfRecords);
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
    for (CollectRecordSummary summary : summaries) {
        CollectRecord record = recordManager.load(survey, summary.getId(), summary.getStep(), false);
        List<Node<?>> nodes = record.findNodesByPath(nodeDef.getPath());
        for (Node<?> node : nodes) {
            nodeProcessor.process(node);
        }
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Node(org.openforis.idm.model.Node) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 20 with RecordFilter

use of org.openforis.collect.model.RecordFilter in project collect by openforis.

the class BackupRestoreController method getLatestBackupInfo.

@RequestMapping(value = "survey/{surveyId}/backup/latest/info", method = GET)
@ResponseBody
public BackupInfo getLatestBackupInfo(@PathVariable("surveyId") int surveyId) {
    CollectSurvey survey = surveyManager.getById(surveyId);
    final Date date = backupStorageManager.getLastBackupDate(survey.getName());
    RecordFilter filter = new RecordFilter(survey);
    filter.setModifiedSince(date);
    final int updatedRecordsSinceBackupDateCount = recordManager.countRecords(filter);
    return new BackupInfo(date, updatedRecordsSinceBackupDateCount);
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey) Date(java.util.Date) RecordFilter(org.openforis.collect.model.RecordFilter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RecordFilter (org.openforis.collect.model.RecordFilter)66 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)33 CollectSurvey (org.openforis.collect.model.CollectSurvey)27 CollectRecord (org.openforis.collect.model.CollectRecord)14 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Date (java.util.Date)10 User (org.openforis.collect.model.User)10 SessionState (org.openforis.collect.web.session.SessionState)7 Transactional (org.springframework.transaction.annotation.Transactional)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 File (java.io.File)5 HashMap (java.util.HashMap)5 CSVDataExportParameters (org.openforis.collect.io.data.csv.CSVDataExportParameters)5 Step (org.openforis.collect.model.CollectRecord.Step)5 IOException (java.io.IOException)4 SurveyBackupJob (org.openforis.collect.io.SurveyBackupJob)4 CSVDataExportJob (org.openforis.collect.io.data.CSVDataExportJob)4 Schema (org.openforis.idm.metamodel.Schema)4 Test (org.junit.Test)3