Search in sources :

Example 56 with CollectSurvey

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

the class RecordController method downloadValidationReportResult.

@RequestMapping(value = "survey/{surveyId}/data/records/validationreport.csv", method = GET)
public void downloadValidationReportResult(HttpServletResponse response) throws FileNotFoundException, IOException {
    File file = validationReportJob.getOutputFile();
    CollectSurvey survey = validationReportJob.getInput().getRecordFilter().getSurvey();
    String surveyName = survey.getName();
    Controllers.writeFileToResponse(response, file, String.format("collect-validation-report-%s-%s.csv", surveyName, Dates.formatDate(new Date())), Controllers.CSV_CONTENT_TYPE);
}
Also used : CollectSurvey(org.openforis.collect.model.CollectSurvey) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 57 with CollectSurvey

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

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

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

the class SaikuController method generateRepository.

@RequestMapping(value = "datasources/{surveyName}/generate", method = POST)
@ResponseBody
public JobProxy generateRepository(@PathVariable String surveyName, @RequestParam String language) throws CollectRdbException, SQLException {
    CollectSurvey survey = surveyManager.get(surveyName);
    ReportingRepositoriesGeneratorJob job = jobManager.createJob(ReportingRepositoriesGeneratorJob.class);
    job.setInput(new Input(language));
    job.setSurvey(survey);
    jobManager.startSurveyJob(job);
    return new JobProxy(job);
}
Also used : Input(org.openforis.collect.reporting.ReportingRepositoriesGeneratorJob.Input) JobProxy(org.openforis.concurrency.proxy.JobProxy) ReportingRepositoriesGeneratorJob(org.openforis.collect.reporting.ReportingRepositoriesGeneratorJob) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 60 with CollectSurvey

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

the class SamplingPointsController method loadSamplingPointBounds.

@RequestMapping(value = "survey/{surveyId}/sampling_point_bounds.json", method = GET)
@ResponseBody
public Bounds loadSamplingPointBounds(@PathVariable int surveyId) {
    CollectSurvey survey = surveyManager.loadSurvey(surveyId);
    CollectSurveyContext surveyContext = survey.getContext();
    CoordinateOperations coordinateOperations = surveyContext.getCoordinateOperations();
    SamplingDesignSummaries samplingDesignSummaries = samplingDesignManager.loadBySurvey(survey.getId());
    List<SamplingDesignItem> samplingDesignItems = samplingDesignSummaries.getRecords();
    Bounds bounds = new Bounds();
    for (SamplingDesignItem item : samplingDesignItems) {
        Coordinate coordinate = new Coordinate(item.getX(), item.getY(), item.getSrsId());
        LngLatAlt lngLatAlt = createLngLatAlt(coordinateOperations, coordinate);
        if (lngLatAlt != null) {
            if (bounds.topLeft == null) {
                bounds.topLeft = bounds.topRight = bounds.bottomLeft = bounds.bottomRight = lngLatAlt;
            } else {
                if (lngLatAlt.getLatitude() < bounds.topLeft.getLatitude() && lngLatAlt.getLongitude() < bounds.topLeft.getLongitude()) {
                    bounds.topLeft = lngLatAlt;
                } else if (lngLatAlt.getLatitude() < bounds.topRight.getLatitude() && lngLatAlt.getLongitude() > bounds.topRight.getLongitude()) {
                    bounds.topRight = lngLatAlt;
                } else if (lngLatAlt.getLatitude() > bounds.bottomRight.getLatitude() && lngLatAlt.getLongitude() > bounds.bottomRight.getLongitude()) {
                    bounds.bottomRight = lngLatAlt;
                } else if (lngLatAlt.getLatitude() > bounds.bottomLeft.getLatitude() && lngLatAlt.getLongitude() > bounds.bottomLeft.getLongitude()) {
                    bounds.bottomLeft = lngLatAlt;
                }
            }
        }
    }
    return bounds;
}
Also used : CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) Coordinate(org.openforis.idm.model.Coordinate) CollectSurveyContext(org.openforis.collect.model.CollectSurveyContext) SamplingDesignSummaries(org.openforis.collect.model.SamplingDesignSummaries) CollectSurvey(org.openforis.collect.model.CollectSurvey) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) LngLatAlt(org.geojson.LngLatAlt) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

CollectSurvey (org.openforis.collect.model.CollectSurvey)329 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)53 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)40 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)38 CollectRecord (org.openforis.collect.model.CollectRecord)30 RecordFilter (org.openforis.collect.model.RecordFilter)27 Transactional (org.springframework.transaction.annotation.Transactional)26 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)25 ArrayList (java.util.ArrayList)23 File (java.io.File)21 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)21 Secured (org.springframework.security.access.annotation.Secured)20 User (org.openforis.collect.model.User)19 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)19 SessionState (org.openforis.collect.web.session.SessionState)18 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)17 Test (org.junit.Test)16 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)15 CodeList (org.openforis.idm.metamodel.CodeList)15 Schema (org.openforis.idm.metamodel.Schema)15