Search in sources :

Example 1 with DataQuery

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

the class DataQueryController method startExport.

@RequestMapping(value = "start-export.json", method = RequestMethod.POST)
@ResponseBody
public Response startExport(@Validated DataQueryForm form, @RequestParam Step recordStep) throws Exception {
    CollectSurvey survey = sessionManager.getActiveSurvey();
    DataQuery query = new DataQuery(survey);
    form.copyTo(query);
    exportJob = collectJobManager.createJob(CSVDataExportJob.class);
    exportJob.setOutputFile(File.createTempFile("data-query-export", ".csv"));
    CSVDataExportParameters parameters = new CSVDataExportParameters();
    RecordFilter recordFilter = new RecordFilter(survey);
    recordFilter.setStepGreaterOrEqual(recordStep);
    parameters.setRecordFilter(recordFilter);
    parameters.setEntityId(query.getEntityDefinitionId());
    parameters.setAlwaysGenerateZipFile(false);
    parameters.setNodeFilter(new DescendantNodeFilter(query.getAttributeDefinition(), query.getConditions()));
    exportJob.setParameters(parameters);
    collectJobManager.start(exportJob);
    /*
		csvExportItemProcessor = new CSVWriterDataQueryResultItemProcessor(query);
		csvExportItemProcessor.init();
		exportJob = collectJobManager.createJob(DataQueryExecutorJob.class);
		exportJob.setInput(new DataQueryExecutorJobInput(query, recordStep, csvExportItemProcessor));
		collectJobManager.start(exportJob);
		*/
    Response response = new Response();
    return response;
}
Also used : Response(org.openforis.commons.web.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) DescendantNodeFilter(org.openforis.collect.io.data.DescendantNodeFilter) DataQuery(org.openforis.collect.datacleansing.DataQuery) CSVDataExportJob(org.openforis.collect.io.data.CSVDataExportJob) CSVDataExportParameters(org.openforis.collect.io.data.csv.CSVDataExportParameters) 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 2 with DataQuery

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

the class DataQueryGroupController method copyFormIntoItem.

@Override
protected void copyFormIntoItem(DataQueryGroupForm form, DataQueryGroup item) {
    super.copyFormIntoItem(form, item);
    List<Integer> queryIds = new ArrayList<Integer>(form.getQueryIds());
    item.removeAllQueries();
    for (Integer id : queryIds) {
        DataQuery query = new DataQuery((CollectSurvey) item.getSurvey());
        query.setId(id);
        item.addQuery(query);
    }
}
Also used : ArrayList(java.util.ArrayList) DataQuery(org.openforis.collect.datacleansing.DataQuery)

Example 3 with DataQuery

use of org.openforis.collect.datacleansing.DataQuery 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 4 with DataQuery

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

the class DataQueryGroupManager method initializeItem.

@Override
protected void initializeItem(DataQueryGroup group) {
    super.initializeItem(group);
    group.removeAllQueries();
    List<Integer> queryIds = dao.loadQueryIds(group);
    for (Integer queryId : queryIds) {
        DataQuery query = dataQueryManager.loadById((CollectSurvey) group.getSurvey(), queryId);
        group.addQuery(query);
    }
}
Also used : DataQuery(org.openforis.collect.datacleansing.DataQuery)

Example 5 with DataQuery

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

the class DataQueryValidator method validateUniqueness.

private boolean validateUniqueness(DataQueryForm target, Errors errors) {
    CollectSurvey survey = sessionManager.getActiveSurvey();
    List<DataQuery> queries = dataQueryManager.loadBySurvey(survey);
    for (DataQuery dataQuery : queries) {
        if (!dataQuery.getId().equals(target.getId())) {
            boolean valid = true;
            if (dataQuery.getTitle().equalsIgnoreCase(target.getTitle())) {
                rejectDuplicateValue(errors, TITLE_FIELD);
                valid = false;
            } else if (Integer.valueOf(dataQuery.getEntityDefinitionId()).equals(target.getEntityDefinitionId()) && Integer.valueOf(dataQuery.getAttributeDefinitionId()).equals(target.getAttributeDefinitionId()) && dataQuery.getConditions().equals(target.getConditions())) {
                rejectDuplicateValue(errors, ENTITY_DEFINITION_ID_FIELD);
                rejectDuplicateValue(errors, ATTRIBUTE_DEFINITION_ID_FIELD);
                rejectDuplicateValue(errors, CONDITIONS_FIELD);
                valid = false;
            }
            if (!valid) {
                return false;
            }
        }
    }
    return true;
}
Also used : DataQuery(org.openforis.collect.datacleansing.DataQuery) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Aggregations

DataQuery (org.openforis.collect.datacleansing.DataQuery)11 CollectSurvey (org.openforis.collect.model.CollectSurvey)7 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)3 ArrayList (java.util.ArrayList)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 DataQueryGroup (org.openforis.collect.datacleansing.DataQueryGroup)2 Response (org.openforis.commons.web.Response)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 DataCleansingChain (org.openforis.collect.datacleansing.DataCleansingChain)1 DataCleansingMetadata (org.openforis.collect.datacleansing.DataCleansingMetadata)1 DataCleansingStep (org.openforis.collect.datacleansing.DataCleansingStep)1 DataCleansingStepValue (org.openforis.collect.datacleansing.DataCleansingStepValue)1 DataQueryExecutorJob (org.openforis.collect.datacleansing.DataQueryExecutorJob)1 DataQueryExecutorJobInput (org.openforis.collect.datacleansing.DataQueryExecutorJob.DataQueryExecutorJobInput)1 DataQueryType (org.openforis.collect.datacleansing.DataQueryType)1 CSVDataExportJob (org.openforis.collect.io.data.CSVDataExportJob)1 DescendantNodeFilter (org.openforis.collect.io.data.DescendantNodeFilter)1 CSVDataExportParameters (org.openforis.collect.io.data.csv.CSVDataExportParameters)1 RecordFilter (org.openforis.collect.model.RecordFilter)1