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;
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations