use of org.openforis.collect.datacleansing.DataCleansingStep 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.DataCleansingStep in project collect by openforis.
the class DataCleansingChainManager method initializeItem.
@Override
protected void initializeItem(DataCleansingChain chain) {
super.initializeItem(chain);
chain.removeAllSteps();
List<Integer> stepIds = dao.loadStepIds(chain);
for (Integer stepId : stepIds) {
DataCleansingStep step = dataCleansingStepManager.loadById((CollectSurvey) chain.getSurvey(), stepId);
chain.addStep(step);
}
}
use of org.openforis.collect.datacleansing.DataCleansingStep in project collect by openforis.
the class DataCleansingStepValidator method validateUniqueness.
// @SuppressWarnings("unchecked")
// private boolean validateFieldFixExpressions(DataCleansingStepForm target, Errors errors) {
// CollectSurvey survey = sessionManager.getActiveSurvey();
// DataQuery query = dataQueryManager.loadById(survey, target.getQueryId());
//
// NodeDefinition contextNodeDef = survey.getSchema().getDefinitionById(query.getEntityDefinitionId());
// NodeDefinition thisNodeDef = survey.getSchema().getDefinitionById(query.getAttributeDefinitionId());
//
// boolean valid = true;
// List<String> fieldExpressions = (List<String>) ((AbstractBindingResult) errors).getRawFieldValue(FIELD_FIX_EXPRESSIONS_FIELD);
// for (int fieldIdx = 0; fieldIdx < fieldExpressions.size(); fieldIdx++) {
// String expression = fieldExpressions.get(fieldIdx);
// if (StringUtils.isNotBlank(expression)) {
// valid = valid && validateValueExpression(errors, contextNodeDef, thisNodeDef, FIELD_FIX_EXPRESSIONS_FIELD + "[" + fieldIdx + "]", expression);
// }
// }
// return valid;
// }
//
// private boolean validateFixExpression(DataCleansingStepForm target, Errors errors) {
// CollectSurvey survey = sessionManager.getActiveSurvey();
// DataQuery query = dataQueryManager.loadById(survey, target.getQueryId());
//
// NodeDefinition contextNodeDef = survey.getSchema().getDefinitionById(query.getEntityDefinitionId());
// NodeDefinition thisNodeDef = survey.getSchema().getDefinitionById(query.getAttributeDefinitionId());
//
// String expression = target.getFixExpression();
// boolean valid = validateValueExpression(errors, contextNodeDef, thisNodeDef, FIX_EXPRESSION_FIELD, expression);
// return valid;
// }
private boolean validateUniqueness(DataCleansingStepForm target, Errors errors) {
CollectSurvey survey = getActiveSurvey();
List<DataCleansingStep> steps = dataCleansingStepManager.loadBySurvey(survey);
for (DataCleansingStep step : steps) {
if (!step.getId().equals(target.getId()) && step.getQueryId().equals(target.getQueryId()) && CollectionUtils.deepEquals(step.getUpdateValues(), target.getUpdateValues())) {
rejectDuplicateValue(errors, QUERY_ID_FIELD);
return false;
}
}
return true;
}
use of org.openforis.collect.datacleansing.DataCleansingStep in project collect by openforis.
the class DataCleansingChainManager method save.
@Override
@Transactional
public DataCleansingChain save(DataCleansingChain chain, User activeUser) {
List<Integer> stepIds = new ArrayList<Integer>();
for (DataCleansingStep step : chain.getSteps()) {
stepIds.add(step.getId());
}
if (chain.getId() != null) {
dao.deleteStepAssociations(chain);
}
super.save(chain, activeUser);
dao.insertStepAssociations(chain, stepIds);
initializeItem(chain);
return chain;
}
use of org.openforis.collect.datacleansing.DataCleansingStep 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;
}
Aggregations