use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.
the class RecordUpdater method validateCardinality.
private Set<NodePointer> validateCardinality(Record record, Collection<NodePointer> pointers, NodeChangeMap changeMap) {
Set<NodePointer> updatedPointers = new HashSet<NodePointer>();
Validator validator = record.getSurveyContext().getValidator();
for (NodePointer nodePointer : pointers) {
Entity entity = nodePointer.getEntity();
NodeDefinition childDef = nodePointer.getChildDefinition();
ValidationResultFlag minCountResult, maxCountResult;
if (entity.isRelevant(childDef)) {
minCountResult = validator.validateMinCount(entity, childDef);
maxCountResult = validator.validateMaxCount(entity, childDef);
} else {
minCountResult = maxCountResult = ValidationResultFlag.OK;
}
if (entity.getMinCountValidationResult(childDef) != minCountResult) {
entity.setMinCountValidationResult(childDef, minCountResult);
changeMap.addMinCountValidationResultChange(nodePointer, minCountResult);
updatedPointers.add(nodePointer);
}
if (entity.getMaxCountValidationResult(childDef) != maxCountResult) {
entity.setMaxCountValidationResult(childDef, maxCountResult);
changeMap.addMaxCountValidationResultChange(nodePointer, maxCountResult);
updatedPointers.add(nodePointer);
}
}
return updatedPointers;
}
use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.
the class EntityProxy method getChildrenMaxCountValidation.
@ExternalizedProperty
public List<ValidationResultFlag> getChildrenMaxCountValidation() {
List<ValidationResultFlag> result = new ArrayList<ValidationResultFlag>(availableChildDefinitions.size());
for (NodeDefinition childDefinition : availableChildDefinitions) {
ValidationResultFlag valid = entity.getMaxCountValidationResult(childDefinition);
result.add(valid);
}
return result;
}
use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.
the class EntityProxy method getChildrenMinCountValidation.
@ExternalizedProperty
public List<ValidationResultFlag> getChildrenMinCountValidation() {
List<ValidationResultFlag> result = new ArrayList<ValidationResultFlag>(availableChildDefinitions.size());
for (NodeDefinition childDefinition : availableChildDefinitions) {
ValidationResultFlag valid = entity.getMinCountValidationResult(childDefinition);
result.add(valid);
}
return result;
}
use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.
the class CollectRecordIntegrationTest method testRemoveRequiredEntity.
@Test
public void testRemoveRequiredEntity() throws Exception {
CollectSurvey survey = loadSurvey();
CollectRecord record = createTestRecord(survey);
Entity cluster = record.getRootEntity();
Entity timeStudy = (Entity) cluster.getChild("time_study", 0);
NodeChangeSet changeSet = recordUpdater.deleteNode(timeStudy);
assertEquals(2, changeSet.size());
{
NodeChange<?> timeStudyDeleteChange = changeSet.getChange(timeStudy);
assertTrue(timeStudyDeleteChange instanceof NodeDeleteChange);
Node<?> deletedNode = timeStudyDeleteChange.getNode();
assertEquals(timeStudy.getInternalId(), deletedNode.getInternalId());
}
{
NodeChange<?> clusterChange = changeSet.getChange(cluster);
assertTrue(clusterChange instanceof EntityChange);
EntityChange clusterEntityChange = (EntityChange) clusterChange;
Map<String, ValidationResultFlag> childrenMinCountValid = clusterEntityChange.getChildrenMinCountValidation();
ValidationResultFlag timeStudyMinCountValid = childrenMinCountValid.get("time_study");
assertEquals(ValidationResultFlag.ERROR, timeStudyMinCountValid);
Map<String, ValidationResultFlag> childrenMaxCountValid = clusterEntityChange.getChildrenMaxCountValidation();
ValidationResultFlag timeStudyMaxCountValid = childrenMaxCountValid.get("time_study");
assertNull(timeStudyMaxCountValid);
}
}
use of org.openforis.idm.metamodel.validation.ValidationResultFlag in project collect by openforis.
the class RecordValidationReportGenerator method extractAttributeValidationResultItem.
protected List<RecordValidationReportItem> extractAttributeValidationResultItem(Locale locale, Integer attrId, ValidationResultFlag level, boolean includeConfirmedErrors) {
List<RecordValidationReportItem> items = new ArrayList<RecordValidationReportItem>();
Attribute<?, ?> attr = (Attribute<?, ?>) record.getNodeByInternalId(attrId);
ValidationResults validationResults = validationCache.getAttributeValidationResults(attrId);
List<ValidationResult> failed = validationResults.getFailed();
if (CollectionUtils.isNotEmpty(failed)) {
String path = getPath(attr);
String prettyFormatPath = messageBuilder.getPrettyFormatPath(attr, locale);
for (ValidationResult validationResult : failed) {
ValidationResultFlag flag = validationResult.getFlag();
if (isInLevel(flag, level) || flag == ValidationResultFlag.WARNING && includeConfirmedErrors && record.isErrorConfirmed(attr)) {
String message = messageBuilder.getValidationMessage(attr, validationResult, locale);
RecordValidationReportItem recordValidationItem = new RecordValidationReportItem(attrId, path, prettyFormatPath, flag, message);
items.add(recordValidationItem);
}
}
}
return items;
}
Aggregations