Search in sources :

Example 1 with DataCleansingChain

use of org.openforis.collect.datacleansing.DataCleansingChain in project collect by openforis.

the class DataCleansingManagerImpl method loadMetadata.

@Override
public DataCleansingMetadata loadMetadata(CollectSurvey survey) {
    List<DataQuery> dataQueries = dataQueryManager.loadBySurvey(survey);
    List<DataQueryType> dataQueryTypes = dataTypeManager.loadBySurvey(survey);
    for (DataQuery dataQuery : dataQueries) {
        Integer typeId = dataQuery.getTypeId();
        dataQuery.setType(typeId == null ? null : CollectionUtils.findItem(dataQueryTypes, typeId));
    }
    List<DataQueryGroup> dataQueryGroups = dataQueryGroupManager.loadBySurvey(survey);
    for (DataQueryGroup group : dataQueryGroups) {
        List<DataQuery> queries = group.getQueries();
        List<DataQuery> correctQueries = new ArrayList<DataQuery>(queries.size());
        for (DataQuery dataQuery : queries) {
            correctQueries.add(CollectionUtils.findItem(dataQueries, dataQuery.getId()));
        }
        group.removeAllQueries();
        group.allAllQueries(correctQueries);
    }
    List<DataCleansingStep> cleansingSteps = dataCleansingStepManager.loadBySurvey(survey);
    for (DataCleansingStep step : cleansingSteps) {
        step.setQuery(CollectionUtils.findItem(dataQueries, step.getQueryId()));
    }
    List<DataCleansingChain> cleansingChains = dataCleansingChainManager.loadBySurvey(survey);
    for (DataCleansingChain chain : cleansingChains) {
        List<DataCleansingStep> steps = chain.getSteps();
        List<DataCleansingStep> correctSteps = new ArrayList<DataCleansingStep>(steps.size());
        for (DataCleansingStep step : steps) {
            correctSteps.add(CollectionUtils.findItem(cleansingSteps, step.getId()));
        }
        chain.removeAllSteps();
        chain.addAllSteps(correctSteps);
    }
    DataCleansingMetadata metadata = new DataCleansingMetadata(survey, dataQueryTypes, dataQueries, dataQueryGroups, cleansingSteps, cleansingChains);
    return metadata;
}
Also used : ArrayList(java.util.ArrayList) DataQueryType(org.openforis.collect.datacleansing.DataQueryType) DataQueryGroup(org.openforis.collect.datacleansing.DataQueryGroup) DataCleansingMetadata(org.openforis.collect.datacleansing.DataCleansingMetadata) DataCleansingChain(org.openforis.collect.datacleansing.DataCleansingChain) DataCleansingStep(org.openforis.collect.datacleansing.DataCleansingStep) DataQuery(org.openforis.collect.datacleansing.DataQuery)

Example 2 with DataCleansingChain

use of org.openforis.collect.datacleansing.DataCleansingChain in project collect by openforis.

the class DataCleansingChainController method run.

@RequestMapping(value = "{chainId}/run.json", method = RequestMethod.POST)
@ResponseBody
public Response run(@PathVariable int chainId, @RequestParam Step recordStep) {
    CollectSurvey survey = sessionManager.getActiveSurvey();
    DataCleansingChain chain = itemManager.loadById(survey, chainId);
    DataCleansingChainExecutorJob job = collectJobManager.createJob(DataCleansingChainExecutorJob.class);
    job.setChain(chain);
    job.setRecordStep(recordStep);
    collectJobManager.startSurveyJob(job);
    Response response = new Response();
    return response;
}
Also used : Response(org.openforis.commons.web.Response) DataCleansingChain(org.openforis.collect.datacleansing.DataCleansingChain) DataCleansingChainExecutorJob(org.openforis.collect.datacleansing.DataCleansingChainExecutorJob) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with DataCleansingChain

use of org.openforis.collect.datacleansing.DataCleansingChain in project collect by openforis.

the class DataCleansingChainValidator method validateTitleUniqueness.

private boolean validateTitleUniqueness(DataCleansingChainForm target, Errors errors) {
    String title = target.getTitle();
    CollectSurvey survey = getActiveSurvey();
    List<DataCleansingChain> chains = dataCleansingChainManager.loadBySurvey(survey);
    for (DataCleansingChain chain : chains) {
        if (!chain.getId().equals(target.getId()) && chain.getTitle().equalsIgnoreCase(title)) {
            rejectDuplicateValue(errors, TITLE_FIELD);
            return false;
        }
    }
    return true;
}
Also used : DataCleansingChain(org.openforis.collect.datacleansing.DataCleansingChain) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 4 with DataCleansingChain

use of org.openforis.collect.datacleansing.DataCleansingChain in project collect by openforis.

the class DataCleansingChainValidator method validateStepsUniqueness.

private boolean validateStepsUniqueness(DataCleansingChainForm target, Errors errors) {
    CollectSurvey survey = getActiveSurvey();
    List<DataCleansingChain> chains = dataCleansingChainManager.loadBySurvey(survey);
    for (DataCleansingChain chain : chains) {
        if (!chain.getId().equals(target.getId())) {
            List<DataCleansingStep> steps = chain.getSteps();
            List<Integer> stepIds = new ArrayList<Integer>();
            for (DataCleansingStep step : steps) {
                stepIds.add(step.getId());
            }
            if (stepIds.equals(target.getStepIds())) {
                rejectDuplicateValue(errors, STEP_IDS_FIELD);
                return false;
            }
        }
    }
    return true;
}
Also used : DataCleansingChain(org.openforis.collect.datacleansing.DataCleansingChain) DataCleansingStep(org.openforis.collect.datacleansing.DataCleansingStep) ArrayList(java.util.ArrayList) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 5 with DataCleansingChain

use of org.openforis.collect.datacleansing.DataCleansingChain in project collect by openforis.

the class DataCleansingChainController method loadReports.

@RequestMapping(value = "{chainId}/reports.json", method = RequestMethod.GET)
@ResponseBody
public List<DataCleansingReportForm> loadReports(@PathVariable int chainId) {
    CollectSurvey survey = sessionManager.getActiveSurvey();
    DataCleansingChain chain = itemManager.loadById(survey, chainId);
    List<DataCleansingReport> reports = reportManager.loadByCleansingChain(chain);
    List<DataCleansingReportForm> forms = Forms.toForms(reports, DataCleansingReportForm.class);
    return forms;
}
Also used : DataCleansingChain(org.openforis.collect.datacleansing.DataCleansingChain) DataCleansingReportForm(org.openforis.collect.datacleansing.form.DataCleansingReportForm) CollectSurvey(org.openforis.collect.model.CollectSurvey) DataCleansingReport(org.openforis.collect.datacleansing.DataCleansingReport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DataCleansingChain (org.openforis.collect.datacleansing.DataCleansingChain)6 CollectSurvey (org.openforis.collect.model.CollectSurvey)5 DataCleansingStep (org.openforis.collect.datacleansing.DataCleansingStep)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ArrayList (java.util.ArrayList)2 DataCleansingChainExecutorJob (org.openforis.collect.datacleansing.DataCleansingChainExecutorJob)2 DataCleansingMetadata (org.openforis.collect.datacleansing.DataCleansingMetadata)1 DataCleansingReport (org.openforis.collect.datacleansing.DataCleansingReport)1 DataQuery (org.openforis.collect.datacleansing.DataQuery)1 DataQueryGroup (org.openforis.collect.datacleansing.DataQueryGroup)1 DataQueryType (org.openforis.collect.datacleansing.DataQueryType)1 DataCleansingReportForm (org.openforis.collect.datacleansing.form.DataCleansingReportForm)1 Response (org.openforis.commons.web.Response)1